#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 *);
char *find(char *haystack, char needle) {
  int counter;
  for (counter = 0; counter < strlen(haystack); counter++) {
    if (needle == haystack[counter]) {
      return &haystack[counter];
    }
  }
  return NULL;
}


x86 assembly (clang, -O0):
<find>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %sil,%al
mov    %rdi,-0x10(%rbp)
mov    %al,-0x11(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x1c(%rbp),%eax
cmp    %ecx,%eax
jge    1184 <find+0x74>
movsbl -0x11(%rbp),%eax
mov    -0x10(%rbp),%rcx
movslq -0x18(%rbp),%rdx
movsbl (%rcx,%rdx,1),%ecx
cmp    %ecx,%eax
jne    1171 <find+0x61>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x8(%rbp)
jmp    118c <find+0x7c>
jmp    1176 <find+0x66>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1129 <find+0x19>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<find>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%r15d
mov    %rdi,%rbx
call   1030 <strlen@plt>
xor    %r14d,%r14d
test   %eax,%eax
jle    1151 <find+0x41>
xor    %ebp,%ebp
nopl   0x0(%rax,%rax,1)
cmp    %r15b,(%rbx,%rbp,1)
je     114b <find+0x3b>
add    $0x1,%rbp
mov    %rbx,%rdi
call   1030 <strlen@plt>
cltq
cmp    %rax,%rbp
jl     1130 <find+0x20>
jmp    1151 <find+0x41>
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(i8* %0, i8 signext %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 = %28, %2
%8 = load i32, i32* %6
%9 = load i8*, i8** %4
%10 = call i32 @strlen(i8* %9)
%11 = icmp slt i32 %8, %10
br i1 %11, label %12, label %31
12: ; preds = %7
%13 = load i8, i8* %5
%14 = sext i8 %13 to i32
%15 = load i8*, i8** %4
%16 = load i32, i32* %6
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i8, i8* %15, i64 %17
%19 = load i8, i8* %18
%20 = sext i8 %19 to i32
%21 = icmp eq i32 %14, %20
br i1 %21, label %22, label %27
22: ; preds = %12
%23 = load i8*, i8** %4
%24 = load i32, i32* %6
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8, i8* %23, i64 %25
store i8* %26, i8** %3
br label %32
27: ; preds = %12
br label %28
28: ; preds = %27
%29 = load i32, i32* %6
%30 = add nsw i32 %29, 1
store i32 %30, i32* %6
br label %7
31: ; preds = %7
store i8* null, i8** %3
br label %32
32: ; preds = %31, %22
%33 = load i8*, i8** %3
ret i8* %33
}

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