#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 len(char *);
int indexOf(char *data, char c, int startPosition) {
  if (len(data) < startPosition)
    return -1;
  int position = startPosition;
  while (position < len(data)) {
    if (data[position++] == c) {
      return position - 1;
    }
  }
  return -1;
}


x86 assembly (clang, -O0):
<indexOf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %sil,%al
mov    %rdi,-0x10(%rbp)
mov    %al,-0x11(%rbp)
mov    %edx,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <len@plt>
cmp    -0x18(%rbp),%eax
jge    1143 <indexOf+0x33>
movl   $0xffffffff,-0x4(%rbp)
jmp    11a1 <indexOf+0x91>
mov    -0x18(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <len@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%eax
cmp    %ecx,%eax
jge    119a <indexOf+0x8a>
mov    -0x10(%rbp),%rax
mov    -0x1c(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x1c(%rbp)
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
movsbl -0x11(%rbp),%ecx
cmp    %ecx,%eax
jne    1195 <indexOf+0x85>
mov    -0x1c(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    11a1 <indexOf+0x91>
jmp    1149 <indexOf+0x39>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<indexOf>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%ebx
mov    %esi,%r14d
mov    %rdi,%r15
call   1030 <len@plt>
cmp    %ebx,%eax
jge    112f <indexOf+0x1f>
mov    $0xffffffff,%ebx
jmp    115f <indexOf+0x4f>
movslq %ebx,%rbp
add    $0xffffffff,%ebx
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r15,%rdi
call   1030 <len@plt>
cltq
cmp    %rax,%rbp
jge    1128 <indexOf+0x18>
lea    0x1(%rbp),%rax
add    $0x1,%ebx
cmp    %r14b,(%r15,%rbp,1)
mov    %rax,%rbp
jne    1140 <indexOf+0x30>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @indexOf(i8* %0, i8 signext %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %5
store i8 %1, i8* %6
store i32 %2, i32* %7
%9 = load i8*, i8** %5
%10 = call i32 @len(i8* %9)
%11 = load i32, i32* %7
%12 = icmp slt i32 %10, %11
br i1 %12, label %13, label %14
13: ; preds = %3
store i32 -1, i32* %4
br label %37
14: ; preds = %3
%15 = load i32, i32* %7
store i32 %15, i32* %8
br label %16
16: ; preds = %35, %14
%17 = load i32, i32* %8
%18 = load i8*, i8** %5
%19 = call i32 @len(i8* %18)
%20 = icmp slt i32 %17, %19
br i1 %20, label %21, label %36
21: ; preds = %16
%22 = load i8*, i8** %5
%23 = load i32, i32* %8
%24 = add nsw i32 %23, 1
store i32 %24, i32* %8
%25 = sext i32 %23 to i64
%26 = getelementptr inbounds i8, i8* %22, i64 %25
%27 = load i8, i8* %26
%28 = sext i8 %27 to i32
%29 = load i8, i8* %6
%30 = sext i8 %29 to i32
%31 = icmp eq i32 %28, %30
br i1 %31, label %32, label %35
32: ; preds = %21
%33 = load i32, i32* %8
%34 = sub nsw i32 %33, 1
store i32 %34, i32* %4
br label %37
35: ; preds = %21
br label %16
36: ; preds = %16
store i32 -1, i32* %4
br label %37
37: ; preds = %36, %32, %13
%38 = load i32, i32* %4
ret i32 %38
}

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