#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 */
scalar_t__ memcmp(unsigned char const *, unsigned char const *, int);
int strlen(unsigned char const *);
unsigned char *strfind(const unsigned char *buf, const unsigned char *str) {
  const unsigned char *pos;
  int len = strlen(str);
  for (pos = buf; *pos != '\0'; pos++) {
    if (memcmp(pos, str, len) == 0)
      return (unsigned char *)pos;
  }
  return NULL;
}


x86 assembly (clang, -O0):
<strfind>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movzbl (%rax),%eax
cmp    $0x0,%eax
je     1191 <strfind+0x71>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x24(%rbp),%edx
call   1040 <memcmp@plt>
cmp    $0x0,%rax
jne    117b <strfind+0x5b>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1199 <strfind+0x79>
jmp    1180 <strfind+0x60>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1144 <strfind+0x24>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strfind>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%rbx
mov    %rsi,%rdi
call   1030 <strlen@plt>
cmpb   $0x0,(%rbx)
je     115c <strfind+0x3c>
mov    %eax,%ebp
nopl   0x0(%rax)
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %ebp,%edx
call   1040 <memcmp@plt>
test   %rax,%rax
je     115e <strfind+0x3e>
cmpb   $0x0,0x1(%rbx)
lea    0x1(%rbx),%rbx
jne    1140 <strfind+0x20>
xor    %ebx,%ebx
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i8* @strfind(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
%8 = load i8*, i8** %5
%9 = call i32 @strlen(i8* %8)
store i32 %9, i32* %7
%10 = load i8*, i8** %4
store i8* %10, i8** %6
br label %11
11: ; preds = %25, %2
%12 = load i8*, i8** %6
%13 = load i8, i8* %12
%14 = zext i8 %13 to i32
%15 = icmp ne i32 %14, 0
br i1 %15, label %16, label %28
16: ; preds = %11
%17 = load i8*, i8** %6
%18 = load i8*, i8** %5
%19 = load i32, i32* %7
%20 = call i64 @memcmp(i8* %17, i8* %18, i32 %19)
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %16
%23 = load i8*, i8** %6
store i8* %23, i8** %3
br label %29
24: ; preds = %16
br label %25
25: ; preds = %24
%26 = load i8*, i8** %6
%27 = getelementptr inbounds i8, i8* %26, i32 1
store i8* %27, i8** %6
br label %11
28: ; preds = %11
store i8* null, i8** %3
br label %29
29: ; preds = %28, %22
%30 = load i8*, i8** %3
ret i8* %30
}

LLVM IR (-O2):
define i8* @strfind(i8* %0, i8* %1) {
%3 = tail call i32 @strlen(i8* %1)
%4 = load i8, i8* %0
%5 = icmp eq i8 %4, 0
br i1 %5, label %14, label %6
6: ; preds = %2, %10
%7 = phi i8* [ %11, %10 ], [ %0, %2 ]
%8 = tail call i64 @memcmp(i8* %7, i8* %1, i32 %3)
%9 = icmp eq i64 %8, 0
br i1 %9, label %14, label %10
10: ; preds = %6
%11 = getelementptr inbounds i8, i8* %7, i64 1
%12 = load i8, i8* %11
%13 = icmp eq i8 %12, 0
br i1 %13, label %14, label %6
14: ; preds = %6, %10, %2
%15 = phi i8* [ null, %2 ], [ null, %10 ], [ %7, %6 ]
ret i8* %15
}