#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__ is_eq(char, char);
int strlen(char *);
char *find(char *haystack, char needle) {
  int i = 0;
  for (; i < strlen(haystack); i++) {
    if (is_eq(haystack[i], needle)) {
      return &haystack[i];
    }
  }
  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    119d <find+0x7d>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,1),%al
movsbl %al,%edi
movsbl -0x11(%rbp),%esi
call   1040 <is_eq@plt>
cmp    $0x0,%rax
je     118a <find+0x6a>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x8(%rbp)
jmp    11a5 <find+0x85>
jmp    118f <find+0x6f>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1139 <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,%ebp
mov    %rdi,%rbx
call   1030 <strlen@plt>
xor    %r14d,%r14d
test   %eax,%eax
jle    116c <find+0x4c>
movsbl %bpl,%r15d
xor    %ebp,%ebp
xchg   %ax,%ax
movsbl (%rbx,%rbp,1),%edi
mov    %r15d,%esi
call   1040 <is_eq@plt>
test   %rax,%rax
jne    1166 <find+0x46>
add    $0x1,%rbp
mov    %rbx,%rdi
call   1030 <strlen@plt>
cltq
cmp    %rax,%rbp
jl     1140 <find+0x20>
jmp    116c <find+0x4c>
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 = %27, %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 %30
12: ; preds = %7
%13 = load i8*, i8** %4
%14 = load i32, i32* %6
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds i8, i8* %13, i64 %15
%17 = load i8, i8* %16
%18 = load i8, i8* %5
%19 = call i64 @is_eq(i8 signext %17, i8 signext %18)
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %26
21: ; preds = %12
%22 = load i8*, i8** %4
%23 = load i32, i32* %6
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8, i8* %22, i64 %24
store i8* %25, i8** %3
br label %31
26: ; preds = %12
br label %27
27: ; preds = %26
%28 = load i32, i32* %6
%29 = add nsw i32 %28, 1
store i32 %29, i32* %6
br label %7
30: ; preds = %7
store i8* null, i8** %3
br label %31
31: ; preds = %30, %21
%32 = load i8*, i8** %3
ret i8* %32
}

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 %19
5: ; preds = %2, %11
%6 = phi i64 [ %12, %11 ], [ 0, %2 ]
%7 = getelementptr inbounds i8, i8* %0, i64 %6
%8 = load i8, i8* %7
%9 = tail call i64 @is_eq(i8 signext %8, i8 signext %1)
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %16
11: ; preds = %5
%12 = add nuw nsw i64 %6, 1
%13 = tail call i32 @strlen(i8* %0)
%14 = sext i32 %13 to i64
%15 = icmp slt i64 %12, %14
br i1 %15, label %5, label %19
16: ; preds = %5
%17 = and i64 %6, 4294967295
%18 = getelementptr inbounds i8, i8* %0, i64 %17
br label %19
19: ; preds = %11, %2, %16
%20 = phi i8* [ %18, %16 ], [ null, %2 ], [ null, %11 ]
ret i8* %20
}