Challenge RE #32

Here is the solution for challenge #32. After this one I possibly will take a break publishing these solutions. As always the original challenge is in challenges.re, you can find the assembly code there.

Analysis

The code in C associated with this challenge should look like this

#include <stdio.h>

//...main goes here

char *f(char *str1, char *str2) {
	char *cur_str1 = NULL, *cur_str2 = NULL;
	char *cur = str1;

	if ((*str2 != 0) && (*str1 == 0))
			return NULL;

	if (*str2 == 0)
		return str1;

	while (*cur != 0) {
		cur_str1 = cur;
		cur_str2 = str2;

		while (*cur_str1 != 0 && *cur_str2 != 0 && *cur_str1 == *cur_str2) {
			cur_str1++;
			cur_str2++;
		}

		if (*cur_str2 == 0) {
			return cur;
		}

		cur++;
	}

	return NULL;
}

This code seems to find the first occurrence of a substring.