#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 LinearSearch(int key, int array[], int size) {
  for (int x = 0; x <= size; x++) {
    if (array[x] == key) {
      printf("Element found at position: %i", x);
      return x;
    }
  }
  printf("Element not found.\n");
  return 0;
}


x86 assembly (clang, -O0):
<LinearSearch>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jg     1178 <LinearSearch+0x68>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
cmp    -0x8(%rbp),%eax
jne    1165 <LinearSearch+0x55>
mov    -0x18(%rbp),%esi
lea    0xead(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    118d <LinearSearch+0x7d>
jmp    116a <LinearSearch+0x5a>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1129 <LinearSearch+0x19>
lea    0xe9f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<LinearSearch>:
push   %rbx
test   %edx,%edx
js     113e <LinearSearch+0x1e>
add    $0x1,%edx
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
cmp    %edi,(%rsi,%rbx,4)
je     114e <LinearSearch+0x2e>
add    $0x1,%rbx
cmp    %rbx,%rdx
jne    1130 <LinearSearch+0x10>
lea    0xed9(%rip),%rdi
call   1030 <puts@plt>
xor    %ebx,%ebx
jmp    115e <LinearSearch+0x3e>
lea    0xeab(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %ebx,%eax
pop    %rbx
ret

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

LLVM IR (-O2):
@.str = [30 x i8] c"Element found at position: %i\00"
@str = [19 x i8] c"Element not found.\00"
define i32 @LinearSearch(i32 %0, i32* nocapture %1, i32 %2) {
%4 = icmp slt i32 %2, 0
br i1 %4, label %19, label %5
5: ; preds = %3
%6 = add nuw i32 %2, 1
%7 = zext i32 %6 to i64
br label %8
8: ; preds = %5, %13
%9 = phi i64 [ 0, %5 ], [ %14, %13 ]
%10 = getelementptr inbounds i32, i32* %1, i64 %9
%11 = load i32, i32* %10
%12 = icmp eq i32 %11, %0
br i1 %12, label %16, label %13
13: ; preds = %8
%14 = add nuw nsw i64 %9, 1
%15 = icmp eq i64 %14, %7
br i1 %15, label %19, label %8
16: ; preds = %8
%17 = trunc i64 %9 to i32
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i32 %17)
br label %21
19: ; preds = %13, %3
%20 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str, i64 0, i64 0))
br label %21
21: ; preds = %16, %19
%22 = phi i32 [ %17, %16 ], [ 0, %19 ]
ret i32 %22
}