#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 find(int *, int, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
int main() {
  int n, i, ans;
  printf("--------------------PROGRAM THAT FINDS A NUMBER IN AN "
         "ARRAY--------------------\n\n\n\n\n");
  printf("Enter a size for the array: ");
  scanf("%d", &n);
  int a[n];
  int *p = a;
  printf("\nEnter the elements of the array: ");
  for (i = 0; i < n; i++) {
    scanf("%d", (p + i));
  }
  printf("\nEnter the number to be found: ");
  int x;
  scanf("%d", &x);
  ans = find(a, n, x);
  if (ans != -1)
    printf("\n%d is found at location %d in the array.\n\n\n", x, ans);
  else
    printf("\nThe number %d could not be found in the array.\n\n\n", x);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeba(%rip),%rdi
xor    %eax,%eax
mov    %al,-0x39(%rbp)
call   1030 <printf@plt>
mov    -0x39(%rbp),%al
lea    0xefb(%rip),%rdi
call   1030 <printf@plt>
lea    0xf0c(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1050 <scanf@plt>
mov    -0x8(%rbp),%eax
mov    %eax,%ecx
mov    %rsp,%rax
mov    %rax,-0x18(%rbp)
lea    0xf(,%rcx,4),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rax
sub    %rdx,%rax
mov    %rax,-0x38(%rbp)
mov    %rax,%rsp
mov    %rcx,-0x20(%rbp)
mov    %rax,-0x28(%rbp)
lea    0xed2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11e6 <main+0xb6>
mov    -0x28(%rbp),%rsi
movslq -0xc(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe9f(%rip),%rdi
call   1050 <scanf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    11b1 <main+0x81>
lea    0xeab(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe77(%rip),%rdi
lea    -0x2c(%rbp),%rsi
call   1050 <scanf@plt>
mov    -0x38(%rbp),%rdi
mov    -0x8(%rbp),%esi
mov    -0x2c(%rbp),%edx
call   1040 <find@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0xffffffff,-0x10(%rbp)
je     1239 <main+0x109>
mov    -0x2c(%rbp),%esi
mov    -0x10(%rbp),%edx
lea    0xe8b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    124a <main+0x11a>
mov    -0x2c(%rbp),%esi
lea    0xea2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
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
push   %rax
lea    0xf6e(%rip),%rdi
call   1030 <puts@plt>
lea    0xe9f(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xeae(%rip),%rdi
lea    -0x2c(%rbp),%rsi
call   1060 <scanf@plt>
mov    %rsp,%r12
mov    -0x2c(%rbp),%eax
mov    %rsp,%r14
lea    0xf(,%rax,4),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r14
mov    %r14,%rsp
lea    0xe86(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
cmpl   $0x0,-0x2c(%rbp)
jle    11dc <main+0x9c>
xor    %r13d,%r13d
lea    0xe6c(%rip),%r15
mov    %r14,%rbx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r15,%rdi
mov    %rbx,%rsi
call   1060 <scanf@plt>
add    $0x1,%r13
movslq -0x2c(%rbp),%rax
add    $0x4,%rbx
cmp    %rax,%r13
jl     11c0 <main+0x80>
lea    0xe60(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe2c(%rip),%rdi
lea    -0x30(%rbp),%rsi
call   1060 <scanf@plt>
mov    -0x2c(%rbp),%esi
mov    -0x30(%rbp),%edx
mov    %r14,%rdi
call   1050 <find@plt>
mov    -0x30(%rbp),%esi
cmp    $0xffffffff,%eax
je     1222 <main+0xe2>
lea    0xe4c(%rip),%rdi
mov    %eax,%edx
xor    %eax,%eax
call   1040 <printf@plt>
jmp    1230 <main+0xf0>
lea    0xe67(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r12,%rsp
xor    %eax,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [85 x i8] c"--------------------PROGRAM THAT FINDS A NUMBER IN AN ARRAY--------------------\0A\0A\0A\0A\0A\00"
@.str.1 = [29 x i8] c"Enter a size for the array: \00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [35 x i8] c"\0AEnter the elements of the array: \00"
@.str.4 = [32 x i8] c"\0AEnter the number to be found: \00"
@.str.5 = [45 x i8] c"\0A%d is found at location %d in the array.\0A\0A\0A\00"
@.str.6 = [51 x i8] c"\0AThe number %d could not be found in the array.\0A\0A\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i32*
%8 = alloca i32
store i32 0, i32* %1
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([85 x i8], [85 x i8]* @.str, i64 0, i64 0))
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0))
%11 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %2)
%12 = load i32, i32* %2
%13 = zext i32 %12 to i64
%14 = call i8* @llvm.stacksave()
store i8* %14, i8** %5
%15 = alloca i32, i64 %13
store i64 %13, i64* %6
store i32* %15, i32** %7
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %3
br label %17
17: ; preds = %27, %0
%18 = load i32, i32* %3
%19 = load i32, i32* %2
%20 = icmp slt i32 %18, %19
br i1 %20, label %21, label %30
21: ; preds = %17
%22 = load i32*, i32** %7
%23 = load i32, i32* %3
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i32, i32* %22, i64 %24
%26 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %25)
br label %27
27: ; preds = %21
%28 = load i32, i32* %3
%29 = add nsw i32 %28, 1
store i32 %29, i32* %3
br label %17
30: ; preds = %17
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.4, i64 0, i64 0))
%32 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %8)
%33 = load i32, i32* %2
%34 = load i32, i32* %8
%35 = call i32 @find(i32* %15, i32 %33, i32 %34)
store i32 %35, i32* %4
%36 = load i32, i32* %4
%37 = icmp ne i32 %36, -1
br i1 %37, label %38, label %42
38: ; preds = %30
%39 = load i32, i32* %8
%40 = load i32, i32* %4
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.5, i64 0, i64 0), i32 %39, i32 %40)
br label %45
42: ; preds = %30
%43 = load i32, i32* %8
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.6, i64 0, i64 0), i32 %43)
br label %45
45: ; preds = %42, %38
store i32 0, i32* %1
%46 = load i8*, i8** %5
%47 = load i32, i32* %1
ret i32 %47
}

LLVM IR (-O2):
@.str.1 = [29 x i8] c"Enter a size for the array: \00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [35 x i8] c"\0AEnter the elements of the array: \00"
@.str.4 = [32 x i8] c"\0AEnter the number to be found: \00"
@.str.5 = [45 x i8] c"\0A%d is found at location %d in the array.\0A\0A\0A\00"
@.str.6 = [51 x i8] c"\0AThe number %d could not be found in the array.\0A\0A\0A\00"
@str = [84 x i8] c"--------------------PROGRAM THAT FINDS A NUMBER IN AN ARRAY--------------------\0A\0A\0A\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = bitcast i32* %1 to i8*
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([84 x i8], [84 x i8]* @str, i64 0, i64 0))
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0))
%6 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, 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 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.3, i64 0, i64 0))
%12 = load i32, i32* %1
%13 = icmp sgt i32 %12, 0
br i1 %13, label %14, label %22
14: ; preds = %0, %14
%15 = phi i64 [ %18, %14 ], [ 0, %0 ]
%16 = getelementptr inbounds i32, i32* %10, i64 %15
%17 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %16)
%18 = add nuw nsw i64 %15, 1
%19 = load i32, i32* %1
%20 = sext i32 %19 to i64
%21 = icmp slt i64 %18, %20
br i1 %21, label %14, label %22
22: ; preds = %14, %0
%23 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.4, i64 0, i64 0))
%24 = bitcast i32* %2 to i8*
%25 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %2)
%26 = load i32, i32* %1
%27 = load i32, i32* %2
%28 = call i32 @find(i32* %10, i32 %26, i32 %27)
%29 = icmp eq i32 %28, -1
%30 = load i32, i32* %2
br i1 %29, label %33, label %31
31: ; preds = %22
%32 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @.str.5, i64 0, i64 0), i32 %30, i32 %28)
br label %35
33: ; preds = %22
%34 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([51 x i8], [51 x i8]* @.str.6, i64 0, i64 0), i32 %30)
br label %35
35: ; preds = %33, %31
ret i32 0
}