#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 exponentialSearch(int *, int, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
int main() {
  int n;
  printf("Enter size of Array \n");
  scanf("%d", &n);
  int arr[n], i;
  printf("Enter %d integers in ascending order \n", n);
  for (i = 0; i < n; i++)
    scanf("%d", &arr[i]);
  int x;
  printf("Enter integer to be searched \n");
  scanf("%d", &x);
  int result = exponentialSearch(arr, n, x);
  if (result == -1)
    printf("%d is not present in array \n", x);
  else
    printf("%d is present at index %d \n", x, result);
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeba(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xec2(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1050 <scanf@plt>
mov    -0x8(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x10(%rbp)
lea    0xf(,%rax,4),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x30(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%esi
lea    0xe8b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11d1 <main+0xa1>
mov    -0x30(%rbp),%rsi
movslq -0x1c(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe58(%rip),%rdi
call   1050 <scanf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    119c <main+0x6c>
lea    0xe68(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe30(%rip),%rdi
lea    -0x20(%rbp),%rsi
call   1050 <scanf@plt>
mov    -0x30(%rbp),%rdi
mov    -0x8(%rbp),%esi
mov    -0x20(%rbp),%edx
call   1040 <exponentialSearch@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0xffffffff,-0x24(%rbp)
jne    1221 <main+0xf1>
mov    -0x20(%rbp),%esi
lea    0xe4a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1235 <main+0x105>
mov    -0x20(%rbp),%esi
mov    -0x24(%rbp),%edx
lea    0xe4e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x10(%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    0xf0e(%rip),%rdi
call   1030 <puts@plt>
lea    0xe9f(%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
mov    -0x2c(%rbp),%esi
lea    0xe74(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
cmpl   $0x0,-0x2c(%rbp)
jle    11cc <main+0x8c>
xor    %r13d,%r13d
lea    0xe5a(%rip),%r15
mov    %r14,%rbx
nopl   0x0(%rax)
mov    %r15,%rdi
mov    %rbx,%rsi
call   1060 <scanf@plt>
add    $0x1,%r13
movslq -0x2c(%rbp),%rax
add    $0x4,%rbx
cmp    %rax,%r13
jl     11b0 <main+0x70>
lea    0xea5(%rip),%rdi
call   1030 <puts@plt>
lea    0xe21(%rip),%rdi
lea    -0x30(%rbp),%rsi
call   1060 <scanf@plt>
mov    -0x2c(%rbp),%esi
mov    -0x30(%rbp),%edx
mov    %r14,%rdi
call   1050 <exponentialSearch@plt>
mov    -0x30(%rbp),%esi
cmp    $0xffffffff,%eax
je     1210 <main+0xd0>
lea    0xe42(%rip),%rdi
mov    %eax,%edx
xor    %eax,%eax
call   1040 <printf@plt>
jmp    121e <main+0xde>
lea    0xe13(%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 = [22 x i8] c"Enter size of Array \0A\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [39 x i8] c"Enter %d integers in ascending order \0A\00"
@.str.3 = [31 x i8] c"Enter integer to be searched \0A\00"
@.str.4 = [29 x i8] c"%d is not present in array \0A\00"
@.str.5 = [28 x i8] c"%d is present at index %d \0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %1
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%9 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%10 = load i32, i32* %2
%11 = zext i32 %10 to i64
%12 = call i8* @llvm.stacksave()
store i8* %12, i8** %3
%13 = alloca i32, i64 %11
store i64 %11, i64* %4
%14 = load i32, i32* %2
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.2, i64 0, i64 0), i32 %14)
store i32 0, i32* %5
br label %16
16: ; preds = %25, %0
%17 = load i32, i32* %5
%18 = load i32, i32* %2
%19 = icmp slt i32 %17, %18
br i1 %19, label %20, label %28
20: ; preds = %16
%21 = load i32, i32* %5
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i32, i32* %13, i64 %22
%24 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %23)
br label %25
25: ; preds = %20
%26 = load i32, i32* %5
%27 = add nsw i32 %26, 1
store i32 %27, i32* %5
br label %16
28: ; preds = %16
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0))
%30 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %6)
%31 = load i32, i32* %2
%32 = load i32, i32* %6
%33 = call i32 @exponentialSearch(i32* %13, i32 %31, i32 %32)
store i32 %33, i32* %7
%34 = load i32, i32* %7
%35 = icmp eq i32 %34, -1
br i1 %35, label %36, label %39
36: ; preds = %28
%37 = load i32, i32* %6
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0), i32 %37)
br label %43
39: ; preds = %28
%40 = load i32, i32* %6
%41 = load i32, i32* %7
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0), i32 %40, i32 %41)
br label %43
43: ; preds = %39, %36
store i32 0, i32* %1
%44 = load i8*, i8** %3
%45 = load i32, i32* %1
ret i32 %45
}

LLVM IR (-O2):
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [39 x i8] c"Enter %d integers in ascending order \0A\00"
@.str.4 = [29 x i8] c"%d is not present in array \0A\00"
@.str.5 = [28 x i8] c"%d is present at index %d \0A\00"
@str = [21 x i8] c"Enter size of Array \00"
@str.6 = [30 x i8] c"Enter integer to be searched \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 ([21 x i8], [21 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 = zext i32 %6 to i64
%8 = call i8* @llvm.stacksave()
%9 = alloca i32, i64 %7
%10 = load i32, i32* %1
%11 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @.str.2, i64 0, i64 0), i32 %10)
%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* %9, i64 %15
%17 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, 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 = bitcast i32* %2 to i8*
%24 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str.6, i64 0, i64 0))
%25 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%26 = load i32, i32* %1
%27 = load i32, i32* %2
%28 = call i32 @exponentialSearch(i32* %9, i32 %26, i32 %27)
%29 = icmp eq i32 %28, -1
%30 = load i32, i32* %2
br i1 %29, label %31, label %33
31: ; preds = %22
%32 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0), i32 %30)
br label %35
33: ; preds = %22
%34 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0), i32 %30, i32 %28)
br label %35
35: ; preds = %33, %31
ret i32 0
}