#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 */
int strlen(char *);
int locate(char inp[], char searchstr[], int lpos) {
  int i, j = 0;
  if (lpos + strlen(searchstr) > strlen(inp))
    return 0;
  i = 0;
  while (i <= strlen(searchstr)) {
    if (inp[lpos + i] == searchstr[i])
      j = 1;
    else
      return 0;
    i++;
  }
  return j;
}


x86 assembly (clang, -O0):
<locate>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x2c(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%eax
cmp    %ecx,%eax
jle    1165 <locate+0x55>
movl   $0x0,-0x4(%rbp)
jmp    11d9 <locate+0xc9>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x30(%rbp),%eax
cmp    %ecx,%eax
jg     11d3 <locate+0xc3>
mov    -0x10(%rbp),%rax
mov    -0x1c(%rbp),%ecx
add    -0x20(%rbp),%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
mov    -0x18(%rbp),%rcx
movslq -0x20(%rbp),%rdx
movsbl (%rcx,%rdx,1),%ecx
cmp    %ecx,%eax
jne    11b9 <locate+0xa9>
movl   $0x1,-0x24(%rbp)
jmp    11c5 <locate+0xb5>
movl   $0x0,-0x4(%rbp)
jmp    11d9 <locate+0xc9>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    116c <locate+0x5c>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<locate>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edx,%r12d
mov    %rsi,%rbx
mov    %rdi,%r14
mov    %rsi,%rdi
call   1030 <strlen@plt>
mov    %eax,%ebp
add    %r12d,%ebp
mov    %r14,%rdi
call   1030 <strlen@plt>
xor    %r15d,%r15d
cmp    %eax,%ebp
jg     1185 <locate+0x75>
mov    %rbx,%rdi
call   1030 <strlen@plt>
test   %eax,%eax
js     1185 <locate+0x75>
movslq %r12d,%rax
add    %rax,%r14
mov    $0xffffffffffffffff,%rbp
cs nopw 0x0(%rax,%rax,1)
movzbl 0x1(%r14,%rbp,1),%eax
cmp    0x1(%rbx,%rbp,1),%al
jne    1185 <locate+0x75>
mov    %rbx,%rdi
call   1030 <strlen@plt>
cltq
add    $0x1,%rbp
cmp    %rax,%rbp
jl     1160 <locate+0x50>
mov    $0x1,%r15d
mov    %r15d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

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