#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
unsigned int strlen(char *);
unsigned strstr(char a[], char b[]) {
  unsigned i, j, match;
  for (i = 0; i < strlen(a); i++) {
    match = 1;
    for (j = 0; j < strlen(b); j++) {
      if (a[i + j] != b[j]) {
        match = 0;
        break;
      }
    }
    if (match)
      return match;
  }
  return -1;
}


x86 assembly (clang, -O0):
<strstr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%eax
cmp    %ecx,%eax
jae    11d7 <strstr+0xc7>
movl   $0x1,-0x24(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x2c(%rbp),%eax
cmp    %ecx,%eax
jae    11af <strstr+0x9f>
mov    -0x10(%rbp),%rax
mov    -0x1c(%rbp),%ecx
add    -0x20(%rbp),%ecx
mov    %ecx,%ecx
movsbl (%rax,%rcx,1),%eax
mov    -0x18(%rbp),%rcx
mov    -0x20(%rbp),%edx
movsbl (%rcx,%rdx,1),%ecx
cmp    %ecx,%eax
je     119c <strstr+0x8c>
movl   $0x0,-0x24(%rbp)
jmp    11af <strstr+0x9f>
jmp    11a1 <strstr+0x91>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1151 <strstr+0x41>
cmpl   $0x0,-0x24(%rbp)
je     11c4 <strstr+0xb4>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11de <strstr+0xce>
jmp    11c9 <strstr+0xb9>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1127 <strstr+0x17>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strstr>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%rbx
mov    %rdi,%r15
call   1030 <strlen@plt>
mov    $0xffffffff,%r14d
test   %eax,%eax
je     1189 <strstr+0x79>
xor    %r12d,%r12d
mov    %rbx,%rdi
call   1030 <strlen@plt>
test   %eax,%eax
je     1183 <strstr+0x73>
xor    %ebp,%ebp
xchg   %ax,%ax
lea    (%r12,%rbp,1),%eax
movzbl (%r15,%rax,1),%eax
cmp    (%rbx,%rbp,1),%al
jne    1170 <strstr+0x60>
add    $0x1,%rbp
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %eax,%eax
cmp    %rax,%rbp
jb     1140 <strstr+0x30>
jmp    1183 <strstr+0x73>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
add    $0x1,%r12
mov    %r15,%rdi
call   1030 <strlen@plt>
cmp    %eax,%r12d
jb     1130 <strstr+0x20>
jmp    1189 <strstr+0x79>
mov    $0x1,%r14d
mov    %r14d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @strstr(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 0, i32* %6
br label %9
9: ; preds = %47, %2
%10 = load i32, i32* %6
%11 = load i8*, i8** %4
%12 = call i32 @strlen(i8* %11)
%13 = icmp ult i32 %10, %12
br i1 %13, label %14, label %50
14: ; preds = %9
store i32 1, i32* %8
store i32 0, i32* %7
br label %15
15: ; preds = %38, %14
%16 = load i32, i32* %7
%17 = load i8*, i8** %5
%18 = call i32 @strlen(i8* %17)
%19 = icmp ult i32 %16, %18
br i1 %19, label %20, label %41
20: ; preds = %15
%21 = load i8*, i8** %4
%22 = load i32, i32* %6
%23 = load i32, i32* %7
%24 = add i32 %22, %23
%25 = zext i32 %24 to i64
%26 = getelementptr inbounds i8, i8* %21, i64 %25
%27 = load i8, i8* %26
%28 = sext i8 %27 to i32
%29 = load i8*, i8** %5
%30 = load i32, i32* %7
%31 = zext i32 %30 to i64
%32 = getelementptr inbounds i8, i8* %29, i64 %31
%33 = load i8, i8* %32
%34 = sext i8 %33 to i32
%35 = icmp ne i32 %28, %34
br i1 %35, label %36, label %37
36: ; preds = %20
store i32 0, i32* %8
br label %41
37: ; preds = %20
br label %38
38: ; preds = %37
%39 = load i32, i32* %7
%40 = add i32 %39, 1
store i32 %40, i32* %7
br label %15
41: ; preds = %36, %15
%42 = load i32, i32* %8
%43 = icmp ne i32 %42, 0
br i1 %43, label %44, label %46
44: ; preds = %41
%45 = load i32, i32* %8
store i32 %45, i32* %3
br label %51
46: ; preds = %41
br label %47
47: ; preds = %46
%48 = load i32, i32* %6
%49 = add i32 %48, 1
store i32 %49, i32* %6
br label %9
50: ; preds = %9
store i32 -1, i32* %3
br label %51
51: ; preds = %50, %44
%52 = load i32, i32* %3
ret i32 %52
}

LLVM IR (-O2):
define i32 @strstr(i8* %0, i8* %1) {
%3 = tail call i32 @strlen(i8* %0)
%4 = icmp eq i32 %3, 0
br i1 %4, label %28, label %5
5: ; preds = %2, %24
%6 = phi i32 [ %25, %24 ], [ 0, %2 ]
%7 = tail call i32 @strlen(i8* %1)
%8 = icmp eq i32 %7, 0
br i1 %8, label %28, label %13
9: ; preds = %13
%10 = tail call i32 @strlen(i8* %1)
%11 = zext i32 %10 to i64
%12 = icmp ult i64 %23, %11
br i1 %12, label %13, label %28
13: ; preds = %5, %9
%14 = phi i64 [ %23, %9 ], [ 0, %5 ]
%15 = trunc i64 %14 to i32
%16 = add i32 %6, %15
%17 = zext i32 %16 to i64
%18 = getelementptr inbounds i8, i8* %0, i64 %17
%19 = load i8, i8* %18
%20 = getelementptr inbounds i8, i8* %1, i64 %14
%21 = load i8, i8* %20
%22 = icmp eq i8 %19, %21
%23 = add nuw nsw i64 %14, 1
br i1 %22, label %9, label %24
24: ; preds = %13
%25 = add nuw i32 %6, 1
%26 = tail call i32 @strlen(i8* %0)
%27 = icmp ult i32 %25, %26
br i1 %27, label %5, label %28
28: ; preds = %24, %5, %9, %2
%29 = phi i32 [ -1, %2 ], [ 1, %9 ], [ 1, %5 ], [ -1, %24 ]
ret i32 %29
}