#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 */
scalar_t__ abs(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
int /*<<< orphan*/ system(char *);
int main() {
  int X, N, T[100], PP, i, j, test;
  printf("Enter N:");
  scanf("%d", &N);
  printf("Enter X:");
  scanf("%d", &X);
  printf("Elements of array  :");
  for (i = 0; i < N; i++) {
    scanf("%d", &T[i]);
  }
  for (i = 0; i < N; i++) {
    test = 1;
    for (j = 0; j < N; j++) {
      if (abs(X - T[j]) < abs(X - T[i]))
        test = 0;
    }
    if (test == 1)
      printf("Nearest Element of X = %d is: %d", X, T[i]);
  }
  system("pause");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1c0,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xea7(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xede(%rip),%rdi
lea    -0xc(%rbp),%rsi
call   1060 <scanf@plt>
lea    0xe92(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xec0(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1060 <scanf@plt>
lea    0xe7d(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x1a8(%rbp)
mov    -0x1a8(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11ea <main+0xaa>
movslq -0x1a8(%rbp),%rax
lea    -0x1a0(%rbp),%rsi
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe74(%rip),%rdi
call   1060 <scanf@plt>
mov    -0x1a8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1a8(%rbp)
jmp    11a6 <main+0x66>
movl   $0x0,-0x1a8(%rbp)
mov    -0x1a8(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    12d4 <main+0x194>
movl   $0x1,-0x1b0(%rbp)
movl   $0x0,-0x1ac(%rbp)
mov    -0x1ac(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    128f <main+0x14f>
mov    -0x8(%rbp),%edi
movslq -0x1ac(%rbp),%rax
sub    -0x1a0(%rbp,%rax,4),%edi
call   1030 <abs@plt>
mov    %rax,-0x1b8(%rbp)
mov    -0x8(%rbp),%edi
movslq -0x1a8(%rbp),%rax
sub    -0x1a0(%rbp,%rax,4),%edi
call   1030 <abs@plt>
mov    %rax,%rcx
mov    -0x1b8(%rbp),%rax
cmp    %rcx,%rax
jge    1276 <main+0x136>
movl   $0x0,-0x1b0(%rbp)
jmp    127b <main+0x13b>
mov    -0x1ac(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1ac(%rbp)
jmp    1217 <main+0xd7>
cmpl   $0x1,-0x1b0(%rbp)
jne    12bb <main+0x17b>
mov    -0x8(%rbp),%esi
movslq -0x1a8(%rbp),%rax
mov    -0x1a0(%rbp,%rax,4),%edx
lea    0xd73(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    12c0 <main+0x180>
mov    -0x1a8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1a8(%rbp)
jmp    11f4 <main+0xb4>
lea    0xd6d(%rip),%rdi
call   1040 <system@plt>
xor    %eax,%eax
add    $0x1c0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x1a0,%rsp
lea    0xeaa(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xee1(%rip),%rbx
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
call   1060 <scanf@plt>
lea    0xe91(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xc(%rsp),%rsi
mov    %rbx,%rdi
call   1060 <scanf@plt>
lea    0xe7f(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
cmpl   $0x0,0x8(%rsp)
jle    1277 <main+0x137>
lea    0x10(%rsp),%rbx
xor    %ebp,%ebp
lea    0xe92(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r14,%rdi
mov    %rbx,%rsi
call   1060 <scanf@plt>
add    $0x1,%rbp
movslq 0x8(%rsp),%rax
add    $0x4,%rbx
cmp    %rax,%rbp
jl     11c0 <main+0x80>
test   %eax,%eax
jle    1277 <main+0x137>
lea    0xe3b(%rip),%r14
xor    %r15d,%r15d
jmp    1223 <main+0xe3>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    0xc(%rsp),%esi
mov    0x10(%rsp,%r15,4),%edx
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x8(%rsp),%eax
add    $0x1,%r15
movslq %eax,%rcx
cmp    %rcx,%r15
jge    1277 <main+0x137>
test   %eax,%eax
jle    1200 <main+0xc0>
mov    $0x1,%ebp
xor    %ebx,%ebx
jmp    1240 <main+0x100>
add    $0x1,%rbx
movslq 0x8(%rsp),%rax
mov    %ecx,%ebp
cmp    %rax,%rbx
jge    1270 <main+0x130>
mov    0xc(%rsp),%edi
sub    0x10(%rsp,%rbx,4),%edi
call   1030 <abs@plt>
mov    %rax,%r12
mov    0xc(%rsp),%edi
sub    0x10(%rsp,%r15,4),%edi
call   1030 <abs@plt>
xor    %ecx,%ecx
cmp    %rax,%r12
jl     1230 <main+0xf0>
mov    %ebp,%ecx
jmp    1230 <main+0xf0>
nopl   0x0(%rax)
cmp    $0x1,%ecx
je     1200 <main+0xc0>
jmp    1217 <main+0xd7>
lea    0xdca(%rip),%rdi
call   1040 <system@plt>
xor    %eax,%eax
add    $0x1a0,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [9 x i8] c"Enter N:\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [9 x i8] c"Enter X:\00"
@.str.3 = [21 x i8] c"Elements of array :\00"
@.str.4 = [33 x i8] c"Nearest Element of X = %d is: %d\00"
@.str.5 = [6 x i8] c"pause\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca [100 x i32]
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %1
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%10 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
%12 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %6
br label %14
14: ; preds = %23, %0
%15 = load i32, i32* %6
%16 = load i32, i32* %3
%17 = icmp slt i32 %15, %16
br i1 %17, label %18, label %26
18: ; preds = %14
%19 = load i32, i32* %6
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds [100 x i32], [100 x i32]* %4, i64 0, i64 %20
%22 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %21)
br label %23
23: ; preds = %18
%24 = load i32, i32* %6
%25 = add nsw i32 %24, 1
store i32 %25, i32* %6
br label %14
26: ; preds = %14
store i32 0, i32* %6
br label %27
27: ; preds = %68, %26
%28 = load i32, i32* %6
%29 = load i32, i32* %3
%30 = icmp slt i32 %28, %29
br i1 %30, label %31, label %71
31: ; preds = %27
store i32 1, i32* %8
store i32 0, i32* %7
br label %32
32: ; preds = %54, %31
%33 = load i32, i32* %7
%34 = load i32, i32* %3
%35 = icmp slt i32 %33, %34
br i1 %35, label %36, label %57
36: ; preds = %32
%37 = load i32, i32* %2
%38 = load i32, i32* %7
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds [100 x i32], [100 x i32]* %4, i64 0, i64 %39
%41 = load i32, i32* %40
%42 = sub nsw i32 %37, %41
%43 = call i64 @abs(i32 %42)
%44 = load i32, i32* %2
%45 = load i32, i32* %6
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds [100 x i32], [100 x i32]* %4, i64 0, i64 %46
%48 = load i32, i32* %47
%49 = sub nsw i32 %44, %48
%50 = call i64 @abs(i32 %49)
%51 = icmp slt i64 %43, %50
br i1 %51, label %52, label %53
52: ; preds = %36
store i32 0, i32* %8
br label %53
53: ; preds = %52, %36
br label %54
54: ; preds = %53
%55 = load i32, i32* %7
%56 = add nsw i32 %55, 1
store i32 %56, i32* %7
br label %32
57: ; preds = %32
%58 = load i32, i32* %8
%59 = icmp eq i32 %58, 1
br i1 %59, label %60, label %67
60: ; preds = %57
%61 = load i32, i32* %2
%62 = load i32, i32* %6
%63 = sext i32 %62 to i64
%64 = getelementptr inbounds [100 x i32], [100 x i32]* %4, i64 0, i64 %63
%65 = load i32, i32* %64
%66 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0), i32 %61, i32 %65)
br label %67
67: ; preds = %60, %57
br label %68
68: ; preds = %67
%69 = load i32, i32* %6
%70 = add nsw i32 %69, 1
store i32 %70, i32* %6
br label %27
71: ; preds = %27
%72 = call i32 @system(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str = [9 x i8] c"Enter N:\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [9 x i8] c"Enter X:\00"
@.str.3 = [21 x i8] c"Elements of array :\00"
@.str.4 = [33 x i8] c"Nearest Element of X = %d is: %d\00"
@.str.5 = [6 x i8] c"pause\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [100 x i32]
%4 = bitcast i32* %1 to i8*
%5 = bitcast i32* %2 to i8*
%6 = bitcast [100 x i32]* %3 to i8*
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 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 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
%10 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%11 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0))
%12 = load i32, i32* %2
%13 = icmp sgt i32 %12, 0
br i1 %13, label %16, label %61
14: ; preds = %16
%15 = icmp sgt i32 %21, 0
br i1 %15, label %24, label %61
16: ; preds = %0, %16
%17 = phi i64 [ %20, %16 ], [ 0, %0 ]
%18 = getelementptr inbounds [100 x i32], [100 x i32]* %3, i64 0, i64 %17
%19 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %18)
%20 = add nuw nsw i64 %17, 1
%21 = load i32, i32* %2
%22 = sext i32 %21 to i64
%23 = icmp slt i64 %20, %22
br i1 %23, label %16, label %14
24: ; preds = %14, %56
%25 = phi i32 [ %57, %56 ], [ %21, %14 ]
%26 = phi i64 [ %58, %56 ], [ 0, %14 ]
%27 = icmp sgt i32 %25, 0
br i1 %27, label %28, label %50
28: ; preds = %24
%29 = getelementptr inbounds [100 x i32], [100 x i32]* %3, i64 0, i64 %26
br label %30
30: ; preds = %28, %30
%31 = phi i64 [ 0, %28 ], [ %44, %30 ]
%32 = phi i32 [ 1, %28 ], [ %43, %30 ]
%33 = load i32, i32* %1
%34 = getelementptr inbounds [100 x i32], [100 x i32]* %3, i64 0, i64 %31
%35 = load i32, i32* %34
%36 = sub nsw i32 %33, %35
%37 = call i64 @abs(i32 %36)
%38 = load i32, i32* %1
%39 = load i32, i32* %29
%40 = sub nsw i32 %38, %39
%41 = call i64 @abs(i32 %40)
%42 = icmp slt i64 %37, %41
%43 = select i1 %42, i32 0, i32 %32
%44 = add nuw nsw i64 %31, 1
%45 = load i32, i32* %2
%46 = sext i32 %45 to i64
%47 = icmp slt i64 %44, %46
br i1 %47, label %30, label %48
48: ; preds = %30
%49 = icmp eq i32 %43, 1
br i1 %49, label %50, label %56
50: ; preds = %24, %48
%51 = load i32, i32* %1
%52 = getelementptr inbounds [100 x i32], [100 x i32]* %3, i64 0, i64 %26
%53 = load i32, i32* %52
%54 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0), i32 %51, i32 %53)
%55 = load i32, i32* %2
br label %56
56: ; preds = %48, %50
%57 = phi i32 [ %45, %48 ], [ %55, %50 ]
%58 = add nuw nsw i64 %26, 1
%59 = sext i32 %57 to i64
%60 = icmp slt i64 %58, %59
br i1 %60, label %24, label %61
61: ; preds = %56, %0, %14
%62 = call i32 @system(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
ret i32 0
}