#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 /*<<< orphan*/ system(char *);
int mai() {
  int N[20] = {4,  15, 19, 27, 38, 43, 48, 55, 58, 62,
               66, 69, 74, 75, 82, 84, 86, 91, 92, 95};
  int num;
  int max;
  int min;
  int centro;
  int flag;
  int i;
  printf("Inserire il numero da cercare nel vettore");
  scanf("%d", &num);
  min = 0;
  max = 19;
  flag = 0;
  i = 0;
  centro = 0;
  printf("Inserire il numero da cercare nel vettore");
  scanf("%d", &num);
  centro = (max - min) / 2;
  while ((max != min) && (flag == 0)) {
    if (N[centro] == num) {
      flag = 1;
    } else {
      if (N[centro] < num) {
        min = centro;
        centro = (max - min) / 2 + min;
      } else {
        max = centro;
        centro = (max - min) / 2 + min;
      }
    }
    printf("\nil centro è %d", centro);
  }
  if (flag == 1) {
    printf("\n Il numero è stato trovato in posizione %d\n", centro);
  } else {
    printf("\n Il numero non è stato trovato\n");
  }
  system("PAUSE");
}


x86 assembly (clang, -O0):
<mai>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
lea    -0x60(%rbp),%rdi
lea    0xeaa(%rip),%rsi
mov    $0x50,%edx
call   1050 <memcpy@plt>
lea    0xee9(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xf13(%rip),%rdi
lea    -0x64(%rbp),%rsi
call   1060 <scanf@plt>
movl   $0x0,-0x6c(%rbp)
movl   $0x13,-0x68(%rbp)
movl   $0x0,-0x74(%rbp)
movl   $0x0,-0x78(%rbp)
movl   $0x0,-0x70(%rbp)
lea    0xea8(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xed2(%rip),%rdi
lea    -0x64(%rbp),%rsi
call   1060 <scanf@plt>
mov    -0x68(%rbp),%eax
sub    -0x6c(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x70(%rbp)
mov    -0x68(%rbp),%ecx
xor    %eax,%eax
cmp    -0x6c(%rbp),%ecx
mov    %al,-0x79(%rbp)
je     11eb <mai+0xab>
cmpl   $0x0,-0x74(%rbp)
sete   %al
mov    %al,-0x79(%rbp)
mov    -0x79(%rbp),%al
test   $0x1,%al
jne    11fb <mai+0xbb>
jmp    127d <mai+0x13d>
movslq -0x70(%rbp),%rax
mov    -0x60(%rbp,%rax,4),%eax
cmp    -0x64(%rbp),%eax
jne    1218 <mai+0xd8>
movl   $0x1,-0x74(%rbp)
jmp    1267 <mai+0x127>
movslq -0x70(%rbp),%rax
mov    -0x60(%rbp,%rax,4),%eax
cmp    -0x64(%rbp),%eax
jge    1248 <mai+0x108>
mov    -0x70(%rbp),%eax
mov    %eax,-0x6c(%rbp)
mov    -0x68(%rbp),%eax
sub    -0x6c(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
add    -0x6c(%rbp),%eax
mov    %eax,-0x70(%rbp)
jmp    1262 <mai+0x122>
mov    -0x70(%rbp),%eax
mov    %eax,-0x68(%rbp)
mov    -0x68(%rbp),%eax
sub    -0x6c(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
add    -0x6c(%rbp),%eax
mov    %eax,-0x70(%rbp)
jmp    1267 <mai+0x127>
mov    -0x70(%rbp),%esi
lea    0xe09(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11d0 <mai+0x90>
cmpl   $0x1,-0x74(%rbp)
jne    129d <mai+0x15d>
mov    -0x70(%rbp),%esi
lea    0xdfa(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    12ab <mai+0x16b>
lea    0xe15(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe29(%rip),%rdi
call   1030 <system@plt>
mov    -0x4(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mai>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
lea    0xefd(%rip),%r14
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xf24(%rip),%rbx
lea    0xc(%rsp),%r15
mov    %rbx,%rdi
mov    %r15,%rsi
call   1060 <scanf@plt>
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1060 <scanf@plt>
mov    $0x9,%ebx
mov    $0x13,%r12d
lea    0xe65(%rip),%r15
lea    0xed8(%rip),%r14
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movslq %ebx,%rax
mov    (%r15,%rax,4),%eax
mov    0xc(%rsp),%ecx
cmp    %ecx,%eax
je     11fe <mai+0xbe>
mov    %r12d,%edx
sub    %ebx,%edx
mov    %ebx,%esi
sub    %ebp,%esi
cmp    %ecx,%eax
cmovl  %edx,%esi
cmovl  %ebx,%ebp
cmovge %ebx,%r12d
mov    %esi,%ebx
shr    $0x1f,%ebx
add    %esi,%ebx
sar    %ebx
add    %ebp,%ebx
mov    %r14,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <printf@plt>
cmp    %ebp,%r12d
jne    11b0 <mai+0x70>
lea    0xec8(%rip),%rdi
call   1030 <puts@plt>
jmp    121e <mai+0xde>
lea    0xe75(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe76(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe94(%rip),%rdi
call   1040 <system@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@__const.mai.N = [20 x i32] [i32 4, i32 15, i32 19, i32 27, i32 38, i32 43, i32 48, i32 55, i32 58, i32 62, i32 66, i32 69, i32 74, i32 75, i32 82, i32 84, i32 86, i32 91, i32 92, i32 95]
@.str = [42 x i8] c"Inserire il numero da cercare nel vettore\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [17 x i8] c"\0Ail centro \C3\A8 %d\00"
@.str.3 = [46 x i8] c"\0A Il numero \C3\A8 stato trovato in posizione %d\0A\00"
@.str.4 = [34 x i8] c"\0A Il numero non \C3\A8 stato trovato\0A\00"
@.str.5 = [6 x i8] c"PAUSE\00"
define i32 @mai() {
%1 = alloca i32
%2 = alloca [20 x i32]
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = bitcast [20 x i32]* %2 to i8*
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0))
%11 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
store i32 0, i32* %5
store i32 19, i32* %4
store i32 0, i32* %7
store i32 0, i32* %8
store i32 0, i32* %6
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0))
%13 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
%14 = load i32, i32* %4
%15 = load i32, i32* %5
%16 = sub nsw i32 %14, %15
%17 = sdiv i32 %16, 2
store i32 %17, i32* %6
br label %18
18: ; preds = %59, %0
%19 = load i32, i32* %4
%20 = load i32, i32* %5
%21 = icmp ne i32 %19, %20
br i1 %21, label %22, label %25
22: ; preds = %18
%23 = load i32, i32* %7
%24 = icmp eq i32 %23, 0
br label %25
25: ; preds = %22, %18
%26 = phi i1 [ false, %18 ], [ %24, %22 ]
br i1 %26, label %27, label %62
27: ; preds = %25
%28 = load i32, i32* %6
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds [20 x i32], [20 x i32]* %2, i64 0, i64 %29
%31 = load i32, i32* %30
%32 = load i32, i32* %3
%33 = icmp eq i32 %31, %32
br i1 %33, label %34, label %35
34: ; preds = %27
store i32 1, i32* %7
br label %59
35: ; preds = %27
%36 = load i32, i32* %6
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds [20 x i32], [20 x i32]* %2, i64 0, i64 %37
%39 = load i32, i32* %38
%40 = load i32, i32* %3
%41 = icmp slt i32 %39, %40
br i1 %41, label %42, label %50
42: ; preds = %35
%43 = load i32, i32* %6
store i32 %43, i32* %5
%44 = load i32, i32* %4
%45 = load i32, i32* %5
%46 = sub nsw i32 %44, %45
%47 = sdiv i32 %46, 2
%48 = load i32, i32* %5
%49 = add nsw i32 %47, %48
store i32 %49, i32* %6
br label %58
50: ; preds = %35
%51 = load i32, i32* %6
store i32 %51, i32* %4
%52 = load i32, i32* %4
%53 = load i32, i32* %5
%54 = sub nsw i32 %52, %53
%55 = sdiv i32 %54, 2
%56 = load i32, i32* %5
%57 = add nsw i32 %55, %56
store i32 %57, i32* %6
br label %58
58: ; preds = %50, %42
br label %59
59: ; preds = %58, %34
%60 = load i32, i32* %6
%61 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i32 %60)
br label %18
62: ; preds = %25
%63 = load i32, i32* %7
%64 = icmp eq i32 %63, 1
br i1 %64, label %65, label %68
65: ; preds = %62
%66 = load i32, i32* %6
%67 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.3, i64 0, i64 0), i32 %66)
br label %70
68: ; preds = %62
%69 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.4, i64 0, i64 0))
br label %70
70: ; preds = %68, %65
%71 = call i32 @system(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
%72 = load i32, i32* %1
ret i32 %72
}

LLVM IR (-O2):
@__const.mai.N = [20 x i32] [i32 4, i32 15, i32 19, i32 27, i32 38, i32 43, i32 48, i32 55, i32 58, i32 62, i32 66, i32 69, i32 74, i32 75, i32 82, i32 84, i32 86, i32 91, i32 92, i32 95]
@.str = [42 x i8] c"Inserire il numero da cercare nel vettore\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [17 x i8] c"\0Ail centro \C3\A8 %d\00"
@.str.3 = [46 x i8] c"\0A Il numero \C3\A8 stato trovato in posizione %d\0A\00"
@.str.5 = [6 x i8] c"PAUSE\00"
@str = [33 x i8] c"\0A Il numero non \C3\A8 stato trovato\00"
define i32 @mai() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0))
%4 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%5 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 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)
br label %7
7: ; preds = %0, %16
%8 = phi i32 [ 19, %0 ], [ %22, %16 ]
%9 = phi i32 [ 9, %0 ], [ %24, %16 ]
%10 = phi i32 [ 0, %0 ], [ %21, %16 ]
%11 = sext i32 %9 to i64
%12 = getelementptr inbounds [20 x i32], [20 x i32]* @__const.mai.N, i64 0, i64 %11
%13 = load i32, i32* %12
%14 = load i32, i32* %1
%15 = icmp eq i32 %13, %14
br i1 %15, label %27, label %16
16: ; preds = %7
%17 = icmp slt i32 %13, %14
%18 = sub nsw i32 %8, %9
%19 = sub nsw i32 %9, %10
%20 = select i1 %17, i32 %18, i32 %19
%21 = select i1 %17, i32 %9, i32 %10
%22 = select i1 %17, i32 %8, i32 %9
%23 = sdiv i32 %20, 2
%24 = add nsw i32 %23, %21
%25 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i32 %24)
%26 = icmp eq i32 %22, %21
br i1 %26, label %30, label %7
27: ; preds = %7
%28 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i32 %9)
%29 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([46 x i8], [46 x i8]* @.str.3, i64 0, i64 0), i32 %9)
br label %32
30: ; preds = %16
%31 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @str, i64 0, i64 0))
br label %32
32: ; preds = %30, %27
%33 = call i32 @system(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
ret i32 undef
}