#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 /*<<< orphan*/ printf(char *, ...);
char *find(char *haystack, char needle) {
  int count;
  for (count = 0; count < 400; count++) {
    if (haystack[count] == needle) {
      printf("%d", count);
      return haystack;
    }
  }
  printf("-1");
  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)
cmpl   $0x190,-0x18(%rbp)
jge    117f <find+0x6f>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
movsbl -0x11(%rbp),%ecx
cmp    %ecx,%eax
jne    116c <find+0x5c>
mov    -0x18(%rbp),%esi
lea    0xea8(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1195 <find+0x85>
jmp    1171 <find+0x61>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1129 <find+0x19>
lea    0xe7d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<find>:
push   %rbx
mov    %esi,%eax
mov    %rdi,%rbx
mov    $0x4,%esi
nopl   0x0(%rax,%rax,1)
cmp    %al,-0x4(%rbx,%rsi,1)
je     115c <find+0x4c>
cmp    %al,-0x3(%rbx,%rsi,1)
je     1162 <find+0x52>
cmp    %al,-0x2(%rbx,%rsi,1)
je     1168 <find+0x58>
cmp    %al,-0x1(%rbx,%rsi,1)
je     116e <find+0x5e>
cmp    %al,(%rbx,%rsi,1)
je     1172 <find+0x62>
add    $0x5,%rsi
cmp    $0x194,%rsi
jne    1120 <find+0x10>
lea    0xeb2(%rip),%rdi
xor    %ebx,%ebx
xor    %eax,%eax
call   1030 <printf@plt>
jmp    1180 <find+0x70>
add    $0xfffffffffffffffc,%rsi
jmp    1172 <find+0x62>
add    $0xfffffffffffffffd,%rsi
jmp    1172 <find+0x62>
add    $0xfffffffffffffffe,%rsi
jmp    1172 <find+0x62>
add    $0xffffffffffffffff,%rsi
lea    0xe87(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %rbx,%rax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
@.str.1 = [3 x i8] c"-1\00"
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 = %25, %2
%8 = load i32, i32* %6
%9 = icmp slt i32 %8, 400
br i1 %9, label %10, label %28
10: ; preds = %7
%11 = load i8*, i8** %4
%12 = load i32, i32* %6
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds i8, i8* %11, i64 %13
%15 = load i8, i8* %14
%16 = sext i8 %15 to i32
%17 = load i8, i8* %5
%18 = sext i8 %17 to i32
%19 = icmp eq i32 %16, %18
br i1 %19, label %20, label %24
20: ; preds = %10
%21 = load i32, i32* %6
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %21)
%23 = load i8*, i8** %4
store i8* %23, i8** %3
br label %30
24: ; preds = %10
br label %25
25: ; preds = %24
%26 = load i32, i32* %6
%27 = add nsw i32 %26, 1
store i32 %27, i32* %6
br label %7
28: ; preds = %7
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i8* null, i8** %3
br label %30
30: ; preds = %28, %20
%31 = load i8*, i8** %3
ret i8* %31
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@.str.1 = [3 x i8] c"-1\00"
define i8* @find(i8* %0, i8 signext %1) {
br label %3
3: ; preds = %32, %2
%4 = phi i64 [ 0, %2 ], [ %33, %32 ]
%5 = getelementptr inbounds i8, i8* %0, i64 %4
%6 = load i8, i8* %5
%7 = icmp eq i8 %6, %1
br i1 %7, label %8, label %12
8: ; preds = %27, %22, %17, %12, %3
%9 = phi i64 [ %4, %3 ], [ %13, %12 ], [ %18, %17 ], [ %23, %22 ], [ %28, %27 ]
%10 = trunc i64 %9 to i32
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %10)
br label %37
12: ; preds = %3
%13 = add nuw nsw i64 %4, 1
%14 = getelementptr inbounds i8, i8* %0, i64 %13
%15 = load i8, i8* %14
%16 = icmp eq i8 %15, %1
br i1 %16, label %8, label %17
17: ; preds = %12
%18 = add nuw nsw i64 %4, 2
%19 = getelementptr inbounds i8, i8* %0, i64 %18
%20 = load i8, i8* %19
%21 = icmp eq i8 %20, %1
br i1 %21, label %8, label %22
22: ; preds = %17
%23 = add nuw nsw i64 %4, 3
%24 = getelementptr inbounds i8, i8* %0, i64 %23
%25 = load i8, i8* %24
%26 = icmp eq i8 %25, %1
br i1 %26, label %8, label %27
27: ; preds = %22
%28 = add nuw nsw i64 %4, 4
%29 = getelementptr inbounds i8, i8* %0, i64 %28
%30 = load i8, i8* %29
%31 = icmp eq i8 %30, %1
br i1 %31, label %8, label %32
32: ; preds = %27
%33 = add nuw nsw i64 %4, 5
%34 = icmp eq i64 %33, 400
br i1 %34, label %35, label %3
35: ; preds = %32
%36 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
br label %37
37: ; preds = %35, %8
%38 = phi i8* [ %0, %8 ], [ null, %35 ]
ret i8* %38
}