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


x86 assembly (clang, -O0):
<find>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %sil,%al
mov    %rdi,-0x10(%rbp)
mov    %al,-0x11(%rbp)
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x2c(%rbp),%eax
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    1181 <find+0x71>
movsbl -0x11(%rbp),%eax
mov    -0x10(%rbp),%rcx
movslq -0x28(%rbp),%rdx
movsbl (%rcx,%rdx,1),%ecx
cmp    %ecx,%eax
jne    116e <find+0x5e>
mov    -0x28(%rbp),%eax
add    $0x30,%eax
mov    %al,-0x21(%rbp)
jmp    1181 <find+0x71>
jmp    1173 <find+0x63>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1129 <find+0x19>
movsbl -0x21(%rbp),%eax
cmp    $0x0,%eax
jne    119b <find+0x8b>
movq   $0x0,-0x8(%rbp)
jmp    11ab <find+0x9b>
lea    -0x21(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%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
cmp    $0x2,%eax
jl     115d <find+0x4d>
xor    %ebp,%ebp
nopl   0x0(%rax)
cmp    %r15b,(%rbx,%rbp,1)
je     114e <find+0x3e>
add    $0x1,%rbp
mov    %rbx,%rdi
call   1030 <strlen@plt>
add    $0xffffffff,%eax
cltq
cmp    %rax,%rbp
jl     1130 <find+0x20>
jmp    115d <find+0x4d>
xor    %eax,%eax
cmp    $0xd0,%bpl
lea    0x7(%rsp),%r14
cmove  %rax,%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 i8*
%7 = alloca i8
%8 = alloca i32
store i8* %0, i8** %4
store i8 %1, i8* %5
store i32 0, i32* %8
br label %9
9: ; preds = %30, %2
%10 = load i32, i32* %8
%11 = load i8*, i8** %4
%12 = call i32 @strlen(i8* %11)
%13 = sub nsw i32 %12, 1
%14 = icmp slt i32 %10, %13
br i1 %14, label %15, label %33
15: ; preds = %9
%16 = load i8, i8* %5
%17 = sext i8 %16 to i32
%18 = load i8*, i8** %4
%19 = load i32, i32* %8
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i8, i8* %18, i64 %20
%22 = load i8, i8* %21
%23 = sext i8 %22 to i32
%24 = icmp eq i32 %17, %23
br i1 %24, label %25, label %29
25: ; preds = %15
%26 = load i32, i32* %8
%27 = add nsw i32 %26, 48
%28 = trunc i32 %27 to i8
store i8 %28, i8* %7
br label %33
29: ; preds = %15
br label %30
30: ; preds = %29
%31 = load i32, i32* %8
%32 = add nsw i32 %31, 1
store i32 %32, i32* %8
br label %9
33: ; preds = %25, %9
%34 = load i8, i8* %7
%35 = sext i8 %34 to i32
%36 = icmp eq i32 %35, 0
br i1 %36, label %37, label %38
37: ; preds = %33
store i8* null, i8** %3
br label %40
38: ; preds = %33
store i8* %7, i8** %6
%39 = load i8*, i8** %6
store i8* %39, i8** %3
br label %40
40: ; preds = %38, %37
%41 = load i8*, i8** %3
ret i8* %41
}

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