#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*/ fill_array(int, int *);
int /*<<< orphan*/ free(int *);
int *malloc(int);
int /*<<< orphan*/ print_array(int, int *);
int /*<<< orphan*/ printf(char *, ...);
int search(int *, int, int);
int main() {
  int *input_array, result;
  int array_size = 10;
  int element = 17;
  input_array = malloc(array_size * sizeof(int));
  fill_array(array_size, input_array);
  print_array(array_size, input_array);
  result = search(input_array, array_size, element);
  if (result != -1) {
    printf("element found at position %d\n", result);
  } else {
    printf("element not found!\n");
  }
  free(input_array);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0xa,-0x18(%rbp)
movl   $0x11,-0x1c(%rbp)
movslq -0x18(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x18(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1080 <fill_array@plt>
mov    -0x18(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1040 <print_array@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%esi
mov    -0x1c(%rbp),%edx
call   1060 <search@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
je     11da <main+0x7a>
mov    -0x14(%rbp),%esi
lea    0xe32(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    11e8 <main+0x88>
lea    0xe3d(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    $0x28,%edi
call   1080 <malloc@plt>
mov    %rax,%rbx
mov    $0xa,%edi
mov    %rax,%rsi
call   1090 <fill_array@plt>
mov    $0xa,%edi
mov    %rbx,%rsi
call   1050 <print_array@plt>
mov    %rbx,%rdi
mov    $0xa,%esi
mov    $0x11,%edx
call   1070 <search@plt>
cmp    $0xffffffff,%eax
je     11c1 <main+0x51>
lea    0xe4a(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1060 <printf@plt>
jmp    11cd <main+0x5d>
lea    0xe56(%rip),%rdi
call   1040 <puts@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %eax,%eax
pop    %rbx
ret

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

LLVM IR (-O2):
@.str = [30 x i8] c"element found at position %d\0A\00"
@str = [19 x i8] c"element not found!\00"
define i32 @main() {
%1 = tail call i32* @malloc(i32 40)
%2 = tail call i32 @fill_array(i32 10, i32* %1)
%3 = tail call i32 @print_array(i32 10, i32* %1)
%4 = tail call i32 @search(i32* %1, i32 10, i32 17)
%5 = icmp eq i32 %4, -1
br i1 %5, label %8, label %6
6: ; preds = %0
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i32 %4)
br label %10
8: ; preds = %0
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str, i64 0, i64 0))
br label %10
10: ; preds = %8, %6
%11 = tail call i32 @free(i32* %1)
ret i32 0
}