#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__ strcmp(char *, char const *);
int strlen(char const *);
int /*<<< orphan*/ strncpy(char *, char const *, int);
int pos(const char *source, const char *to_find) {
  int i = 0, find_len, found = 0, position;
  char substring[100];
  find_len = strlen(to_find);
  while (!found && i <= strlen(source) - find_len) {
    strncpy(substring, &source[i], find_len);
    substring[find_len] = '\0';
    if (strcmp(substring, to_find) == 0)
      found = 1;
    else
      ++i;
  }
  if (found)
    position = i;
  else
    position = -1;
  return (position);
}


x86 assembly (clang, -O0):
<pos>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x18(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0x1c(%rbp)
mov    %al,-0x91(%rbp)
jne    1197 <pos+0x67>
mov    -0x14(%rbp),%eax
mov    %eax,-0x98(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x98(%rbp),%eax
sub    -0x18(%rbp),%ecx
cmp    %ecx,%eax
setle  %al
mov    %al,-0x91(%rbp)
mov    -0x91(%rbp),%al
test   $0x1,%al
jne    11aa <pos+0x7a>
jmp    1204 <pos+0xd4>
lea    -0x90(%rbp),%rdi
mov    -0x8(%rbp),%rsi
movslq -0x14(%rbp),%rax
add    %rax,%rsi
mov    -0x18(%rbp),%edx
call   1030 <strncpy@plt>
movslq -0x18(%rbp),%rax
movb   $0x0,-0x90(%rbp,%rax,1)
lea    -0x90(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    11f6 <pos+0xc6>
movl   $0x1,-0x1c(%rbp)
jmp    11ff <pos+0xcf>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    115d <pos+0x2d>
cmpl   $0x0,-0x1c(%rbp)
je     1219 <pos+0xe9>
mov    -0x14(%rbp),%eax
mov    %eax,-0x20(%rbp)
jmp    1220 <pos+0xf0>
movl   $0xffffffff,-0x20(%rbp)
mov    -0x20(%rbp),%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pos>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x68,%rsp
mov    %rsi,%r14
mov    %rdi,%r15
mov    %rsi,%rdi
call   1040 <strlen@plt>
mov    %eax,%r12d
movslq %eax,%rbp
xor    %ebx,%ebx
mov    %rsp,%r13
nopw   0x0(%rax,%rax,1)
mov    %r15,%rdi
call   1040 <strlen@plt>
sub    %r12d,%eax
cltq
cmp    %rax,%rbx
jg     11a4 <pos+0x74>
lea    (%r15,%rbx,1),%rsi
mov    %r13,%rdi
mov    %ebp,%edx
call   1030 <strncpy@plt>
movb   $0x0,(%rsp,%rbp,1)
mov    %r13,%rdi
mov    %r14,%rsi
call   1050 <strcmp@plt>
add    $0x1,%rbx
test   %rax,%rax
jne    1160 <pos+0x30>
cmp    $0x1,%rax
sbb    $0xffffffff,%ebx
add    $0xffffffff,%ebx
jmp    11a9 <pos+0x79>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x68,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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