#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 */
typedef int /*<<< orphan*/ array;

/* Variables and functions */
int EXIT_SUCCESS;
int linear_search(int *, size_t, int);
int /*<<< orphan*/ printf(char *, int, int);
int main(void) {
  int array[] = {10, 1, 42, 3, 4, 42, 6, 7, -1, 9};
  size_t size = sizeof(array) / sizeof(array[0]);
  printf("Found %d at index: %d\n\n", 3, linear_search(array, size, 3));
  printf("Found %d at index: %d\n\n", 42, linear_search(array, size, 42));
  printf("Found %d at index: %d\n", 999, linear_search(array, size, 999));
  return (EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x30(%rbp),%rdi
lea    0xeb6(%rip),%rsi
mov    $0x28,%edx
call   1050 <memcpy@plt>
movq   $0xa,-0x38(%rbp)
lea    -0x30(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    $0x3,%edx
call   1030 <linear_search@plt>
mov    %eax,%edx
lea    0xeb1(%rip),%rdi
mov    $0x3,%esi
call   1040 <printf@plt>
lea    -0x30(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    $0x2a,%edx
call   1030 <linear_search@plt>
mov    %eax,%edx
lea    0xe8c(%rip),%rdi
mov    $0x2a,%esi
call   1040 <printf@plt>
lea    -0x30(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    $0x3e7,%edx
call   1030 <linear_search@plt>
mov    %eax,%edx
lea    0xe7f(%rip),%rdi
mov    $0x3e7,%esi
call   1040 <printf@plt>
mov    0x2e0e(%rip),%rax
mov    (%rax),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x28,%rsp
mov    0xef2(%rip),%rax
mov    %rax,0x20(%rsp)
movaps 0xed6(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movaps 0xeba(%rip),%xmm0
movaps %xmm0,(%rsp)
mov    %rsp,%r14
mov    $0xa,%esi
mov    %r14,%rdi
mov    $0x3,%edx
call   1030 <linear_search@plt>
lea    0xec2(%rip),%rbx
mov    %rbx,%rdi
mov    $0x3,%esi
mov    %eax,%edx
call   1040 <printf@plt>
mov    $0xa,%esi
mov    %r14,%rdi
mov    $0x2a,%edx
call   1030 <linear_search@plt>
mov    %rbx,%rdi
mov    $0x2a,%esi
mov    %eax,%edx
call   1040 <printf@plt>
mov    $0xa,%esi
mov    %r14,%rdi
mov    $0x3e7,%edx
call   1030 <linear_search@plt>
lea    0xe91(%rip),%rdi
mov    $0x3e7,%esi
mov    %eax,%edx
call   1040 <printf@plt>
mov    0x2e1e(%rip),%rax
mov    (%rax),%eax
add    $0x28,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@__const.main.array = [10 x i32] [i32 10, i32 1, i32 42, i32 3, i32 4, i32 42, i32 6, i32 7, i32 -1, i32 9]
@.str = [24 x i8] c"Found %d at index: %d\0A\0A\00"
@.str.1 = [23 x i8] c"Found %d at index: %d\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca [10 x i32]
%3 = alloca i64
store i32 0, i32* %1
%4 = bitcast [10 x i32]* %2 to i8*
store i64 10, i64* %3
%5 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 0
%6 = load i64, i64* %3
%7 = call i32 @linear_search(i32* %5, i64 %6, i32 3)
%8 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i32 3, i32 %7)
%9 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 0
%10 = load i64, i64* %3
%11 = call i32 @linear_search(i32* %9, i64 %10, i32 42)
%12 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i32 42, i32 %11)
%13 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 0
%14 = load i64, i64* %3
%15 = call i32 @linear_search(i32* %13, i64 %14, i32 999)
%16 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 999, i32 %15)
%17 = load i32, i32* @EXIT_SUCCESS
ret i32 %17
}

LLVM IR (-O2):
@__const.main.array = [10 x i32] [i32 10, i32 1, i32 42, i32 3, i32 4, i32 42, i32 6, i32 7, i32 -1, i32 9]
@.str = [24 x i8] c"Found %d at index: %d\0A\0A\00"
@.str.1 = [23 x i8] c"Found %d at index: %d\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca [10 x i32]
%2 = bitcast [10 x i32]* %1 to i8*
%3 = getelementptr inbounds [10 x i32], [10 x i32]* %1, i64 0, i64 0
%4 = call i32 @linear_search(i32* %3, i64 10, i32 3)
%5 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i32 3, i32 %4)
%6 = call i32 @linear_search(i32* %3, i64 10, i32 42)
%7 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i32 42, i32 %6)
%8 = call i32 @linear_search(i32* %3, i64 10, i32 999)
%9 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 999, i32 %8)
%10 = load i32, i32* @EXIT_SUCCESS
ret i32 %10
}