#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 *, int, ...);
void search(int *array, int num) {
  int idx;
  for (idx = 0; idx < 5; idx++) {
    if (array[idx] == num) {
      printf("%d found in position %d\n", num, idx + 1);
      return;
    }
  }
  if (idx == 5)
    printf("%d not found in array\n", num);
}


x86 assembly (clang, -O0):
<search>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
cmpl   $0x5,-0x10(%rbp)
jge    1173 <search+0x63>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
cmp    -0xc(%rbp),%eax
jne    1160 <search+0x50>
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
add    $0x1,%edx
lea    0xeac(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    118e <search+0x7e>
jmp    1165 <search+0x55>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1126 <search+0x16>
cmpl   $0x5,-0x10(%rbp)
jne    118e <search+0x7e>
mov    -0xc(%rbp),%esi
lea    0xe92(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<search>:
mov    $0x1,%edx
cmp    %esi,(%rdi)
je     1141 <search+0x31>
mov    $0x2,%edx
cmp    %esi,0x4(%rdi)
je     1141 <search+0x31>
mov    $0x3,%edx
cmp    %esi,0x8(%rdi)
je     1141 <search+0x31>
mov    $0x4,%edx
cmp    %esi,0xc(%rdi)
je     1141 <search+0x31>
mov    $0x5,%edx
cmp    %esi,0x10(%rdi)
jne    114f <search+0x3f>
lea    0xeb8(%rip),%rdi
xor    %eax,%eax
jmp    1030 <printf@plt>
lea    0xec3(%rip),%rdi
xor    %eax,%eax
jmp    1030 <printf@plt>

LLVM IR (-O0):
@.str = [25 x i8] c"%d found in position %d\0A\00"
@.str.1 = [23 x i8] c"%d not found in array\0A\00"
define void @search(i32* %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
store i32* %0, i32** %3
store i32 %1, i32* %4
store i32 0, i32* %5
br label %6
6: ; preds = %23, %2
%7 = load i32, i32* %5
%8 = icmp slt i32 %7, 5
br i1 %8, label %9, label %26
9: ; preds = %6
%10 = load i32*, i32** %3
%11 = load i32, i32* %5
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds i32, i32* %10, i64 %12
%14 = load i32, i32* %13
%15 = load i32, i32* %4
%16 = icmp eq i32 %14, %15
br i1 %16, label %17, label %22
17: ; preds = %9
%18 = load i32, i32* %4
%19 = load i32, i32* %5
%20 = add nsw i32 %19, 1
%21 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 %18, i32 %20)
br label %32
22: ; preds = %9
br label %23
23: ; preds = %22
%24 = load i32, i32* %5
%25 = add nsw i32 %24, 1
store i32 %25, i32* %5
br label %6
26: ; preds = %6
%27 = load i32, i32* %5
%28 = icmp eq i32 %27, 5
br i1 %28, label %29, label %32
29: ; preds = %26
%30 = load i32, i32* %4
%31 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 %30)
br label %32
32: ; preds = %17, %29, %26
ret void
}

LLVM IR (-O2):
@.str = [25 x i8] c"%d found in position %d\0A\00"
@.str.1 = [23 x i8] c"%d not found in array\0A\00"
define void @search(i32* nocapture %0, i32 %1) {
%3 = load i32, i32* %0
%4 = icmp eq i32 %3, %1
br i1 %4, label %5, label %8
5: ; preds = %20, %16, %12, %8, %2
%6 = phi i32 [ 1, %2 ], [ 2, %8 ], [ 3, %12 ], [ 4, %16 ], [ 5, %20 ]
%7 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 %1, i32 %6)
br label %26
8: ; preds = %2
%9 = getelementptr inbounds i32, i32* %0, i64 1
%10 = load i32, i32* %9
%11 = icmp eq i32 %10, %1
br i1 %11, label %5, label %12
12: ; preds = %8
%13 = getelementptr inbounds i32, i32* %0, i64 2
%14 = load i32, i32* %13
%15 = icmp eq i32 %14, %1
br i1 %15, label %5, label %16
16: ; preds = %12
%17 = getelementptr inbounds i32, i32* %0, i64 3
%18 = load i32, i32* %17
%19 = icmp eq i32 %18, %1
br i1 %19, label %5, label %20
20: ; preds = %16
%21 = getelementptr inbounds i32, i32* %0, i64 4
%22 = load i32, i32* %21
%23 = icmp eq i32 %22, %1
br i1 %23, label %5, label %24
24: ; preds = %20
%25 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 %1)
br label %26
26: ; preds = %24, %5
ret void
}