#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*/ arr;

/* Variables and functions */
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ scanf(char *, int *);
int search(int *, int, int);
int main() {
  int n;
  printf("Enter the number of elements:");
  scanf("%d", &n);
  int *arr = (int *)malloc(n * sizeof(int));
  for (int i = 0; i < n; i++)
    scanf("%d", &arr[i]);
  printf("Enter the key to be found\n");
  int key;
  scanf("%d", &key);
  if (search(arr, key, sizeof(arr) / sizeof(arr[0])) == 1) {
    printf("Found\n");
  } else {
    printf("Not Found\n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeaa(%rip),%rdi
call   1030 <printf@plt>
lea    0xebc(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1060 <scanf@plt>
movslq -0x8(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11ba <main+0x7a>
mov    -0x10(%rbp),%rsi
movslq -0x14(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe77(%rip),%rdi
call   1060 <scanf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1185 <main+0x45>
lea    0xe60(%rip),%rdi
call   1030 <printf@plt>
lea    0xe51(%rip),%rdi
lea    -0x18(%rbp),%rsi
call   1060 <scanf@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%esi
mov    $0x2,%edx
call   1040 <search@plt>
cmp    $0x1,%eax
jne    1201 <main+0xc1>
lea    0xe49(%rip),%rdi
call   1030 <printf@plt>
jmp    120d <main+0xcd>
lea    0xe34(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
lea    0xea1(%rip),%rdi
call   1040 <printf@plt>
lea    0xeb3(%rip),%rdi
mov    %rsp,%rsi
call   1070 <scanf@plt>
mov    (%rsp),%edi
shl    $0x2,%edi
call   1060 <malloc@plt>
mov    %rax,%r14
cmpl   $0x0,(%rsp)
jle    11bc <main+0x6c>
xor    %r12d,%r12d
lea    0xe8d(%rip),%r15
mov    %r14,%rbx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r15,%rdi
mov    %rbx,%rsi
call   1070 <scanf@plt>
add    $0x1,%r12
movslq (%rsp),%rax
add    $0x4,%rbx
cmp    %rax,%r12
jl     11a0 <main+0x50>
lea    0xe5e(%rip),%rdi
call   1030 <puts@plt>
lea    0xe4f(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1070 <scanf@plt>
mov    0x4(%rsp),%esi
mov    %r14,%rdi
mov    $0x2,%edx
call   1050 <search@plt>
cmp    $0x1,%eax
lea    0xe4b(%rip),%rax
lea    0xe40(%rip),%rdi
cmove  %rax,%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [30 x i8] c"Enter the number of elements:\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [27 x i8] c"Enter the key to be found\0A\00"
@.str.3 = [7 x i8] c"Found\0A\00"
@.str.4 = [11 x i8] c"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
%6 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
%7 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%8 = load i32, i32* %2
%9 = sext i32 %8 to i64
%10 = mul i64 %9, 4
%11 = trunc i64 %10 to i32
%12 = call i64 @malloc(i32 %11)
%13 = inttoptr i64 %12 to i32*
store i32* %13, i32** %3
store i32 0, i32* %4
br label %14
14: ; preds = %24, %0
%15 = load i32, i32* %4
%16 = load i32, i32* %2
%17 = icmp slt i32 %15, %16
br i1 %17, label %18, label %27
18: ; preds = %14
%19 = load i32*, i32** %3
%20 = load i32, i32* %4
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i32, i32* %19, i64 %21
%23 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %22)
br label %24
24: ; preds = %18
%25 = load i32, i32* %4
%26 = add nsw i32 %25, 1
store i32 %26, i32* %4
br label %14
27: ; preds = %14
%28 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
%29 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %5)
%30 = load i32*, i32** %3
%31 = load i32, i32* %5
%32 = call i32 @search(i32* %30, i32 %31, i32 2)
%33 = icmp eq i32 %32, 1
br i1 %33, label %34, label %36
34: ; preds = %27
%35 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
br label %38
36: ; preds = %27
%37 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0))
br label %38
38: ; preds = %36, %34
ret i32 0
}

LLVM IR (-O2):
@.str = [30 x i8] c"Enter the number of elements:\00"
@.str.1 = [3 x i8] c"%d\00"
@str = [26 x i8] c"Enter the key to be found\00"
@str.5 = [10 x i8] c"Not Found\00"
@str.6 = [6 x i8] c"Found\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = bitcast i32* %1 to i8*
%4 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
%5 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%6 = load i32, i32* %1
%7 = shl i32 %6, 2
%8 = call i64 @malloc(i32 %7)
%9 = inttoptr i64 %8 to i32*
%10 = load i32, i32* %1
%11 = icmp sgt i32 %10, 0
br i1 %11, label %21, label %12
12: ; preds = %21, %0
%13 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str, i64 0, i64 0))
%14 = bitcast i32* %2 to i8*
%15 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%16 = load i32, i32* %2
%17 = call i32 @search(i32* %9, i32 %16, i32 2)
%18 = icmp eq i32 %17, 1
%19 = select i1 %18, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @str.6, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @str.5, i64 0, i64 0)
%20 = call i32 @puts(i8* dereferenceable(1) %19)
ret i32 0
21: ; preds = %0, %21
%22 = phi i64 [ %25, %21 ], [ 0, %0 ]
%23 = getelementptr inbounds i32, i32* %9, i64 %22
%24 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %23)
%25 = add nuw nsw i64 %22, 1
%26 = load i32, i32* %1
%27 = sext i32 %26 to i64
%28 = icmp slt i64 %25, %27
br i1 %28, label %21, label %12
}