#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 /*<<< orphan*/ scanf(char *, int *);
int search(int *, int /*<<< orphan*/, int, int);
void main() {
  int element_index, number_of_elements, element_to_search_for, i = 0;
  printf("Enter the number of elements: ");
  scanf("%d", &number_of_elements);
  int elements[number_of_elements];
  while (i < number_of_elements) {
    printf("Enter element(%d): ", i + 1);
    scanf("%d", &elements[i]);
    i++;
  }
  printf("\n\nThe array is: ");
  for (i = 0; i < number_of_elements; i++) {
    printf("%d ", elements[i]);
  }
  printf("\n\nEnter element to search for: ");
  scanf("%d", &element_to_search_for);
  element_index =
      search(elements, 0, number_of_elements - 1, element_to_search_for);
  if (element_index == -1) {
    printf("\nElement not found!\n");
  } else {
    printf("\nElement found at index: %d\n", element_index);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x10(%rbp)
lea    0xeba(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xecb(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1050 <scanf@plt>
mov    -0x8(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
lea    0xf(,%rax,4),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x28(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11cd <main+0x9d>
mov    -0x10(%rbp),%esi
add    $0x1,%esi
lea    0xe85(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x28(%rbp),%rsi
movslq -0x10(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe65(%rip),%rdi
call   1050 <scanf@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1184 <main+0x54>
lea    0xe62(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1215 <main+0xe5>
mov    -0x28(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xe47(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    11e2 <main+0xb2>
lea    0xe2f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xdf5(%rip),%rdi
lea    -0xc(%rbp),%rsi
call   1050 <scanf@plt>
mov    -0x28(%rbp),%rdi
mov    -0x8(%rbp),%edx
sub    $0x1,%edx
mov    -0xc(%rbp),%ecx
xor    %esi,%esi
call   1040 <search@plt>
mov    %eax,-0x4(%rbp)
cmpl   $0xffffffff,-0x4(%rbp)
jne    1267 <main+0x137>
lea    0xe10(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1278 <main+0x148>
mov    -0x4(%rbp),%esi
lea    0xe0f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
lea    0xea8(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xeb9(%rip),%rdi
lea    -0x2c(%rbp),%rsi
call   1060 <scanf@plt>
mov    %rsp,-0x38(%rbp)
mov    -0x2c(%rbp),%eax
mov    %rsp,%r12
lea    0xf(,%rax,4),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r12
mov    %r12,%rsp
cmpl   $0x0,-0x2c(%rbp)
jle    11d8 <main+0x98>
lea    0xe8a(%rip),%r14
lea    0xe80(%rip),%r15
mov    %r12,%r13
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
add    $0x1,%rbx
mov    %r14,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r15,%rdi
mov    %r13,%rsi
call   1060 <scanf@plt>
movslq -0x2c(%rbp),%rax
add    $0x4,%r13
cmp    %rax,%rbx
jl     11b0 <main+0x70>
lea    0xe57(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
cmpl   $0x0,-0x2c(%rbp)
jle    121b <main+0xdb>
lea    0xe54(%rip),%r14
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nop
mov    (%r12,%rbx,4),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%rbx
movslq -0x2c(%rbp),%rax
cmp    %rax,%rbx
jl     1200 <main+0xc0>
lea    0xe29(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xdef(%rip),%rdi
lea    -0x30(%rbp),%rsi
call   1060 <scanf@plt>
mov    -0x2c(%rbp),%edx
add    $0xffffffff,%edx
mov    -0x30(%rbp),%ecx
mov    %r12,%rdi
xor    %esi,%esi
call   1050 <search@plt>
cmp    $0xffffffff,%eax
je     1263 <main+0x123>
lea    0xe13(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    126f <main+0x12f>
lea    0xe1e(%rip),%rdi
call   1030 <puts@plt>
mov    -0x38(%rbp),%rsp
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [31 x i8] c"Enter the number of elements: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [20 x i8] c"Enter element(%d): \00"
@.str.3 = [17 x i8] c"\0A\0AThe array is: \00"
@.str.4 = [4 x i8] c"%d \00"
@.str.5 = [32 x i8] c"\0A\0AEnter element to search for: \00"
@.str.6 = [21 x i8] c"\0AElement not found!\0A\00"
@.str.7 = [29 x i8] c"\0AElement found at index: %d\0A\00"
define void @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i64
store i32 0, i32* %4
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
%8 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%9 = load i32, i32* %2
%10 = zext i32 %9 to i64
%11 = call i8* @llvm.stacksave()
store i8* %11, i8** %5
%12 = alloca i32, i64 %10
store i64 %10, i64* %6
br label %13
13: ; preds = %17, %0
%14 = load i32, i32* %4
%15 = load i32, i32* %2
%16 = icmp slt i32 %14, %15
br i1 %16, label %17, label %27
17: ; preds = %13
%18 = load i32, i32* %4
%19 = add nsw i32 %18, 1
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i32 %19)
%21 = load i32, i32* %4
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i32, i32* %12, i64 %22
%24 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %23)
%25 = load i32, i32* %4
%26 = add nsw i32 %25, 1
store i32 %26, i32* %4
br label %13
27: ; preds = %13
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %4
br label %29
29: ; preds = %39, %27
%30 = load i32, i32* %4
%31 = load i32, i32* %2
%32 = icmp slt i32 %30, %31
br i1 %32, label %33, label %42
33: ; preds = %29
%34 = load i32, i32* %4
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i32, i32* %12, i64 %35
%37 = load i32, i32* %36
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %37)
br label %39
39: ; preds = %33
%40 = load i32, i32* %4
%41 = add nsw i32 %40, 1
store i32 %41, i32* %4
br label %29
42: ; preds = %29
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.5, i64 0, i64 0))
%44 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
%45 = load i32, i32* %2
%46 = sub nsw i32 %45, 1
%47 = load i32, i32* %3
%48 = call i32 @search(i32* %12, i32 0, i32 %46, i32 %47)
store i32 %48, i32* %1
%49 = load i32, i32* %1
%50 = icmp eq i32 %49, -1
br i1 %50, label %51, label %53
51: ; preds = %42
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.6, i64 0, i64 0))
br label %56
53: ; preds = %42
%54 = load i32, i32* %1
%55 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.7, i64 0, i64 0), i32 %54)
br label %56
56: ; preds = %53, %51
%57 = load i8*, i8** %5
ret void
}

LLVM IR (-O2):
@.str = [31 x i8] c"Enter the number of elements: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [20 x i8] c"Enter element(%d): \00"
@.str.3 = [17 x i8] c"\0A\0AThe array is: \00"
@.str.4 = [4 x i8] c"%d \00"
@.str.5 = [32 x i8] c"\0A\0AEnter element to search for: \00"
@.str.7 = [29 x i8] c"\0AElement found at index: %d\0A\00"
@str = [20 x i8] c"\0AElement not found!\00"
define void @main() {
%1 = alloca i32
%2 = alloca i32
%3 = bitcast i32* %1 to i8*
%4 = bitcast i32* %2 to i8*
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
%6 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%7 = load i32, i32* %1
%8 = zext i32 %7 to i64
%9 = call i8* @llvm.stacksave()
%10 = alloca i32, i64 %8
%11 = load i32, i32* %1
%12 = icmp sgt i32 %11, 0
br i1 %12, label %13, label %23
13: ; preds = %0, %13
%14 = phi i64 [ %15, %13 ], [ 0, %0 ]
%15 = add nuw nsw i64 %14, 1
%16 = trunc i64 %15 to i32
%17 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i32 %16)
%18 = getelementptr inbounds i32, i32* %10, i64 %14
%19 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %18)
%20 = load i32, i32* %1
%21 = sext i32 %20 to i64
%22 = icmp slt i64 %15, %21
br i1 %22, label %13, label %23
23: ; preds = %13, %0
%24 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0))
%25 = load i32, i32* %1
%26 = icmp sgt i32 %25, 0
br i1 %26, label %27, label %36
27: ; preds = %23, %27
%28 = phi i64 [ %32, %27 ], [ 0, %23 ]
%29 = getelementptr inbounds i32, i32* %10, i64 %28
%30 = load i32, i32* %29
%31 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %30)
%32 = add nuw nsw i64 %28, 1
%33 = load i32, i32* %1
%34 = sext i32 %33 to i64
%35 = icmp slt i64 %32, %34
br i1 %35, label %27, label %36
36: ; preds = %27, %23
%37 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.5, i64 0, i64 0))
%38 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%39 = load i32, i32* %1
%40 = add nsw i32 %39, -1
%41 = load i32, i32* %2
%42 = call i32 @search(i32* %10, i32 0, i32 %40, i32 %41)
%43 = icmp eq i32 %42, -1
br i1 %43, label %44, label %46
44: ; preds = %36
%45 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str, i64 0, i64 0))
br label %48
46: ; preds = %36
%47 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.7, i64 0, i64 0), i32 %42)
br label %48
48: ; preds = %46, %44
ret void
}