#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 i = 0, temp = 0;
  char *ptr;
  while (i < strlen(haystack)) {
    if (needle == haystack[i]) {
      temp = 1;
      break;
    }
    i++;
  }
  if (temp == 1) {
    ptr = &haystack[i];
  } else {
    ptr = NULL;
  }
  return ptr;
}


x86 assembly (clang, -O0):
<find>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %sil,%al
mov    %rdi,-0x8(%rbp)
mov    %al,-0x9(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x24(%rbp),%eax
cmp    %ecx,%eax
jge    117e <find+0x6e>
movsbl -0x9(%rbp),%eax
mov    -0x8(%rbp),%rcx
movslq -0x10(%rbp),%rdx
movsbl (%rcx,%rdx,1),%ecx
cmp    %ecx,%eax
jne    1170 <find+0x60>
movl   $0x1,-0x14(%rbp)
jmp    117e <find+0x6e>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1130 <find+0x20>
cmpl   $0x1,-0x14(%rbp)
jne    119c <find+0x8c>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
jmp    11a4 <find+0x94>
movq   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%rax
add    $0x30,%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 i32
%6 = alloca i32
%7 = alloca i8*
store i8* %0, i8** %3
store i8 %1, i8* %4
store i32 0, i32* %5
store i32 0, i32* %6
br label %8
8: ; preds = %24, %2
%9 = load i32, i32* %5
%10 = load i8*, i8** %3
%11 = call i32 @strlen(i8* %10)
%12 = icmp slt i32 %9, %11
br i1 %12, label %13, label %27
13: ; preds = %8
%14 = load i8, i8* %4
%15 = sext i8 %14 to i32
%16 = load i8*, i8** %3
%17 = load i32, i32* %5
%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 = icmp eq i32 %15, %21
br i1 %22, label %23, label %24
23: ; preds = %13
store i32 1, i32* %6
br label %27
24: ; preds = %13
%25 = load i32, i32* %5
%26 = add nsw i32 %25, 1
store i32 %26, i32* %5
br label %8
27: ; preds = %23, %8
%28 = load i32, i32* %6
%29 = icmp eq i32 %28, 1
br i1 %29, label %30, label %35
30: ; preds = %27
%31 = load i8*, i8** %3
%32 = load i32, i32* %5
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8, i8* %31, i64 %33
store i8* %34, i8** %7
br label %36
35: ; preds = %27
store i8* null, i8** %7
br label %36
36: ; preds = %35, %30
%37 = load i8*, i8** %7
ret i8* %37
}

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
}