#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 findStringPosition(char *token, char *s) {
  int i, j;
  for (i = 0; i < strlen(s) - strlen(token) + 1; i++) {
    j = 0;
    while (s[i + j] == token[j] && j < strlen(token)) {
      j++;
    }
    if (j == strlen(token)) {
      return i;
    }
  }
  return -1;
}


x86 assembly (clang, -O0):
<findStringPosition>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x28(%rbp),%ecx
mov    %eax,%edx
mov    -0x24(%rbp),%eax
sub    %edx,%ecx
add    $0x1,%ecx
cmp    %ecx,%eax
jge    11fc <findStringPosition+0xec>
movl   $0x0,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    -0x1c(%rbp),%ecx
add    -0x20(%rbp),%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%ecx
mov    -0x10(%rbp),%rax
movslq -0x20(%rbp),%rdx
movsbl (%rax,%rdx,1),%edx
xor    %eax,%eax
cmp    %edx,%ecx
mov    %al,-0x29(%rbp)
jne    11a4 <findStringPosition+0x94>
mov    -0x20(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x30(%rbp),%eax
cmp    %ecx,%eax
setl   %al
mov    %al,-0x29(%rbp)
mov    -0x29(%rbp),%al
test   $0x1,%al
jne    11b4 <findStringPosition+0xa4>
jmp    11c2 <findStringPosition+0xb2>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    115e <findStringPosition+0x4e>
mov    -0x20(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x34(%rbp),%eax
cmp    %ecx,%eax
jne    11e9 <findStringPosition+0xd9>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1203 <findStringPosition+0xf3>
jmp    11ee <findStringPosition+0xde>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1127 <findStringPosition+0x17>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<findStringPosition>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r14
mov    %rsi,%rdi
call   1030 <strlen@plt>
mov    %eax,%ebp
mov    %r14,%rdi
call   1030 <strlen@plt>
mov    $0xffffffff,%ecx
cmp    %eax,%ebp
jl     11e9 <findStringPosition+0xd9>
lea    0x1(%rbx),%r15
xor    %r13d,%r13d
mov    %rbx,%rbp
nopw   0x0(%rax,%rax,1)
mov    0x0(%rbp,%r13,1),%al
mov    $0x0,%ebx
cmp    (%r14),%al
jne    11a6 <findStringPosition+0x96>
mov    %rbp,%r12
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r14,%rdi
call   1030 <strlen@plt>
cltq
cmp    %rax,%rbp
jge    11a0 <findStringPosition+0x90>
lea    0x1(%rbp),%rbx
movzbl (%r15,%rbp,1),%eax
cmp    0x1(%r14,%rbp,1),%al
mov    %rbx,%rbp
je     1170 <findStringPosition+0x60>
jmp    11a3 <findStringPosition+0x93>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %rbp,%rbx
mov    %r12,%rbp
mov    %r14,%rdi
call   1030 <strlen@plt>
cmp    %eax,%ebx
je     11e6 <findStringPosition+0xd6>
lea    0x1(%r13),%rbx
mov    %rbp,%rdi
call   1030 <strlen@plt>
mov    %eax,%r12d
mov    %r14,%rdi
call   1030 <strlen@plt>
sub    %eax,%r12d
movslq %r12d,%rax
add    $0x1,%r15
cmp    %rax,%r13
mov    %rbx,%r13
jl     1150 <findStringPosition+0x40>
mov    $0xffffffff,%ecx
jmp    11e9 <findStringPosition+0xd9>
mov    %r13d,%ecx
mov    %ecx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @findStringPosition(i8* %0, i8* %1) {
%3 = tail call i32 @strlen(i8* %1)
%4 = tail call i32 @strlen(i8* %0)
%5 = icmp slt i32 %3, %4
br i1 %5, label %41, label %6
6: ; preds = %2, %32
%7 = phi i64 [ %33, %32 ], [ 0, %2 ]
%8 = getelementptr inbounds i8, i8* %1, i64 %7
%9 = load i8, i8* %8
%10 = load i8, i8* %0
%11 = icmp eq i8 %9, %10
br i1 %11, label %12, label %28
12: ; preds = %6, %17
%13 = phi i64 [ %18, %17 ], [ 0, %6 ]
%14 = tail call i32 @strlen(i8* %0)
%15 = sext i32 %14 to i64
%16 = icmp slt i64 %13, %15
br i1 %16, label %17, label %25
17: ; preds = %12
%18 = add nuw nsw i64 %13, 1
%19 = add nuw nsw i64 %18, %7
%20 = getelementptr inbounds i8, i8* %1, i64 %19
%21 = load i8, i8* %20
%22 = getelementptr inbounds i8, i8* %0, i64 %18
%23 = load i8, i8* %22
%24 = icmp eq i8 %21, %23
br i1 %24, label %12, label %25
25: ; preds = %17, %12
%26 = phi i64 [ %13, %12 ], [ %18, %17 ]
%27 = trunc i64 %26 to i32
br label %28
28: ; preds = %25, %6
%29 = phi i32 [ 0, %6 ], [ %27, %25 ]
%30 = tail call i32 @strlen(i8* %0)
%31 = icmp eq i32 %29, %30
br i1 %31, label %39, label %32
32: ; preds = %28
%33 = add nuw nsw i64 %7, 1
%34 = tail call i32 @strlen(i8* %1)
%35 = tail call i32 @strlen(i8* %0)
%36 = sub nsw i32 %34, %35
%37 = sext i32 %36 to i64
%38 = icmp slt i64 %7, %37
br i1 %38, label %6, label %41
39: ; preds = %28
%40 = trunc i64 %7 to i32
br label %41
41: ; preds = %32, %39, %2
%42 = phi i32 [ -1, %2 ], [ %40, %39 ], [ -1, %32 ]
ret i32 %42
}