#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 firstIndexOf(char *str, char target, int max) {
  int i;
  for (i = max; i < strlen(str); i++)
    if (str[i] == target)
      return i;
  return -1;
}


x86 assembly (clang, -O0):
<firstIndexOf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %sil,%al
mov    %rdi,-0x10(%rbp)
mov    %al,-0x11(%rbp)
mov    %edx,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%eax
cmp    %ecx,%eax
jge    117d <firstIndexOf+0x6d>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
movsbl -0x11(%rbp),%ecx
cmp    %ecx,%eax
jne    116a <firstIndexOf+0x5a>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1184 <firstIndexOf+0x74>
jmp    116f <firstIndexOf+0x5f>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    112b <firstIndexOf+0x1b>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<firstIndexOf>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edx,%r15d
mov    %esi,%r12d
mov    %rdi,%rbx
call   1030 <strlen@plt>
mov    $0xffffffff,%r14d
cmp    %r15d,%eax
jle    115e <firstIndexOf+0x4e>
movslq %r15d,%rbp
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
cmp    %r12b,(%rbx,%rbp,1)
je     115b <firstIndexOf+0x4b>
add    $0x1,%rbp
mov    %rbx,%rdi
call   1030 <strlen@plt>
cltq
cmp    %rax,%rbp
jl     1140 <firstIndexOf+0x30>
jmp    115e <firstIndexOf+0x4e>
mov    %ebp,%r14d
mov    %r14d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @firstIndexOf(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 i32, i32* %7
store i32 %9, i32* %8
br label %10
10: ; preds = %28, %3
%11 = load i32, i32* %8
%12 = load i8*, i8** %5
%13 = call i32 @strlen(i8* %12)
%14 = icmp slt i32 %11, %13
br i1 %14, label %15, label %31
15: ; preds = %10
%16 = load i8*, i8** %5
%17 = load i32, i32* %8
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8, i8* %16, i64 %18
%20 = load i8, i8* %19
%21 = sext i8 %20 to i32
%22 = load i8, i8* %6
%23 = sext i8 %22 to i32
%24 = icmp eq i32 %21, %23
br i1 %24, label %25, label %27
25: ; preds = %15
%26 = load i32, i32* %8
store i32 %26, i32* %4
br label %32
27: ; preds = %15
br label %28
28: ; preds = %27
%29 = load i32, i32* %8
%30 = add nsw i32 %29, 1
store i32 %30, i32* %8
br label %10
31: ; preds = %10
store i32 -1, i32* %4
br label %32
32: ; preds = %31, %25
%33 = load i32, i32* %4
ret i32 %33
}

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