#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 const *, char const *);
int strlen(char *);
char *find_index(char candidate, char *chars) {
  for (int i = 0; i < strlen(chars); i++) {
    if (strcmp((const char *)candidate, (const char *)chars[i]) == 0) {
      return &chars[i];
    }
  }
  return (char *)'f';
}


x86 assembly (clang, -O0):
<find_index>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %dil,%al
mov    %al,-0x9(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%eax
cmp    %ecx,%eax
jge    119d <find_index+0x7d>
movsbq -0x9(%rbp),%rdi
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsbq (%rax,%rcx,1),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    118a <find_index+0x6a>
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x8(%rbp)
jmp    11a6 <find_index+0x86>
jmp    118f <find_index+0x6f>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1139 <find_index+0x19>
mov    $0x66,%eax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<find_index>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %edi,%ebp
mov    %rsi,%rdi
call   1030 <strlen@plt>
mov    $0x66,%r14d
test   %eax,%eax
jle    117d <find_index+0x5d>
movslq %ebp,%r15
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movsbq (%rbx,%rbp,1),%rsi
mov    %r15,%rdi
call   1040 <strcmp@plt>
test   %rax,%rax
je     1177 <find_index+0x57>
add    $0x1,%rbp
mov    %rbx,%rdi
call   1030 <strlen@plt>
cltq
cmp    %rax,%rbp
jl     1150 <find_index+0x30>
jmp    117d <find_index+0x5d>
add    %rbp,%rbx
mov    %rbx,%r14
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

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