#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__ toupper(char const);
int find_index(const char string[], char letter) {
  for (int i = 0;; i++) {
    if (toupper(string[i]) == toupper(letter))
      return i;
    else if (string[i] == '\0')
      return -1;
  }
}


x86 assembly (clang, -O0):
<find_index>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %sil,%al
mov    %rdi,-0x10(%rbp)
mov    %al,-0x11(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1030 <toupper@plt>
mov    %rax,-0x20(%rbp)
movsbl -0x11(%rbp),%edi
call   1030 <toupper@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
cmp    %rcx,%rax
jne    1162 <find_index+0x52>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    119b <find_index+0x8b>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
jne    1183 <find_index+0x73>
movl   $0xffffffff,-0x4(%rbp)
jmp    119b <find_index+0x8b>
jmp    1188 <find_index+0x78>
jmp    118d <find_index+0x7d>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1129 <find_index+0x19>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<find_index>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%r15d
mov    %rdi,%r14
movsbl (%rdi),%edi
call   1030 <toupper@plt>
mov    %rax,%rbp
mov    %r15d,%edi
call   1030 <toupper@plt>
xor    %ebx,%ebx
cmp    %rax,%rbp
je     116d <find_index+0x5d>
xor    %ebx,%ebx
movsbl %r15b,%r15d
nopl   (%rax)
cmpb   $0x0,(%r14,%rbx,1)
je     1168 <find_index+0x58>
movsbl 0x1(%r14,%rbx,1),%edi
add    $0x1,%rbx
call   1030 <toupper@plt>
mov    %rax,%rbp
mov    %r15d,%edi
call   1030 <toupper@plt>
cmp    %rax,%rbp
jne    1140 <find_index+0x30>
jmp    116d <find_index+0x5d>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

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