#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 main() {
  int num[] = {8, 10, 14, 16, 20, 25, 31, 37, 40, 50};
  int n;
  int min;
  int max;
  int trovato;
  int centro;
  int passi;
  printf("Inserire il numero da trovare");
  scanf("%d", &n);
  min = 0;
  max = 9;
  trovato = 0;
  passi = 0;
  while ((trovato == 0) && (min <= max)) {
    centro = (min + max) / 2;
    if (n == num[centro]) {
      trovato = 1;
    } else {
      if (n > num[centro]) {
        min = centro + 1;
      } else {
        max = centro - 1;
      }
    }
    passi++;
  }
  if (trovato == 1) {
    printf("Hai trovato il numero nella posizione  %d\n Il numero di passi "
           "eseguiti è %d ",
           centro + 1, passi);
  } else {
    printf("Non hai trovato il numero\n");
  }
  system("PAUSE");
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x30(%rbp),%rdi
lea    0xea6(%rip),%rsi
mov    $0x28,%edx
call   1050 <memcpy@plt>
lea    0xebd(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xecd(%rip),%rdi
lea    -0x34(%rbp),%rsi
call   1060 <scanf@plt>
movl   $0x0,-0x38(%rbp)
movl   $0x9,-0x3c(%rbp)
movl   $0x0,-0x40(%rbp)
movl   $0x0,-0x48(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0x40(%rbp)
mov    %al,-0x49(%rbp)
jne    11b9 <main+0x79>
mov    -0x38(%rbp),%eax
cmp    -0x3c(%rbp),%eax
setle  %al
mov    %al,-0x49(%rbp)
mov    -0x49(%rbp),%al
test   $0x1,%al
jne    11c9 <main+0x89>
jmp    1232 <main+0xf2>
mov    -0x38(%rbp),%eax
add    -0x3c(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x44(%rbp)
mov    -0x34(%rbp),%eax
movslq -0x44(%rbp),%rcx
cmp    -0x30(%rbp,%rcx,4),%eax
jne    11f7 <main+0xb7>
movl   $0x1,-0x40(%rbp)
jmp    1224 <main+0xe4>
mov    -0x34(%rbp),%eax
movslq -0x44(%rbp),%rcx
cmp    -0x30(%rbp,%rcx,4),%eax
jle    1216 <main+0xd6>
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    121f <main+0xdf>
mov    -0x44(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    1224 <main+0xe4>
mov    -0x48(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x48(%rbp)
jmp    119e <main+0x5e>
cmpl   $0x1,-0x40(%rbp)
jne    1258 <main+0x118>
mov    -0x44(%rbp),%esi
add    $0x1,%esi
mov    -0x48(%rbp),%edx
lea    0xdfd(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1266 <main+0x126>
lea    0xe38(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe45(%rip),%rdi
call   1030 <system@plt>
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
lea    0xedc(%rip),%rdi
xor    %ebx,%ebx
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xeea(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1060 <scanf@plt>
mov    $0x9,%edi
mov    $0x1,%edx
mov    0xc(%rsp),%eax
lea    0xe85(%rip),%r8
jmp    118c <main+0x4c>
nopl   (%rax)
add    $0xffffffff,%esi
mov    %esi,%edi
add    $0x1,%edx
cmp    %edi,%ebx
jg     11ac <main+0x6c>
lea    (%rdi,%rbx,1),%ecx
mov    %ecx,%esi
shr    $0x1f,%esi
add    %ecx,%esi
sar    %esi
movslq %esi,%rcx
mov    (%r8,%rcx,4),%ecx
cmp    %ecx,%eax
je     11ba <main+0x7a>
jle    1180 <main+0x40>
add    $0x1,%esi
mov    %esi,%ebx
jmp    1185 <main+0x45>
lea    0xeea(%rip),%rdi
call   1030 <puts@plt>
jmp    11cb <main+0x8b>
add    $0x1,%esi
lea    0xe85(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xec5(%rip),%rdi
call   1040 <system@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@__const.main.num = [10 x i32] [i32 8, i32 10, i32 14, i32 16, i32 20, i32 25, i32 31, i32 37, i32 40, i32 50]
@.str = [30 x i8] c"Inserire il numero da trovare\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [78 x i8] c"Hai trovato il numero nella posizione %d\0A Il numero di passi eseguiti \C3\A8 %d \00"
@.str.3 = [27 x i8] c"Non hai trovato il numero\0A\00"
@.str.4 = [6 x i8] c"PAUSE\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [10 x i32]
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %1
%9 = bitcast [10 x i32]* %2 to i8*
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 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* %4
store i32 9, i32* %5
store i32 0, i32* %6
store i32 0, i32* %8
br label %12
12: ; preds = %47, %0
%13 = load i32, i32* %6
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %19
15: ; preds = %12
%16 = load i32, i32* %4
%17 = load i32, i32* %5
%18 = icmp sle i32 %16, %17
br label %19
19: ; preds = %15, %12
%20 = phi i1 [ false, %12 ], [ %18, %15 ]
br i1 %20, label %21, label %50
21: ; preds = %19
%22 = load i32, i32* %4
%23 = load i32, i32* %5
%24 = add nsw i32 %22, %23
%25 = sdiv i32 %24, 2
store i32 %25, i32* %7
%26 = load i32, i32* %3
%27 = load i32, i32* %7
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 %28
%30 = load i32, i32* %29
%31 = icmp eq i32 %26, %30
br i1 %31, label %32, label %33
32: ; preds = %21
store i32 1, i32* %6
br label %47
33: ; preds = %21
%34 = load i32, i32* %3
%35 = load i32, i32* %7
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 %36
%38 = load i32, i32* %37
%39 = icmp sgt i32 %34, %38
br i1 %39, label %40, label %43
40: ; preds = %33
%41 = load i32, i32* %7
%42 = add nsw i32 %41, 1
store i32 %42, i32* %4
br label %46
43: ; preds = %33
%44 = load i32, i32* %7
%45 = sub nsw i32 %44, 1
store i32 %45, i32* %5
br label %46
46: ; preds = %43, %40
br label %47
47: ; preds = %46, %32
%48 = load i32, i32* %8
%49 = add nsw i32 %48, 1
store i32 %49, i32* %8
br label %12
50: ; preds = %19
%51 = load i32, i32* %6
%52 = icmp eq i32 %51, 1
br i1 %52, label %53, label %58
53: ; preds = %50
%54 = load i32, i32* %7
%55 = add nsw i32 %54, 1
%56 = load i32, i32* %8
%57 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([78 x i8], [78 x i8]* @.str.2, i64 0, i64 0), i32 %55, i32 %56)
br label %60
58: ; preds = %50
%59 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0))
br label %60
60: ; preds = %58, %53
%61 = call i32 @system(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
%62 = load i32, i32* %1
ret i32 %62
}

LLVM IR (-O2):
@__const.main.num = [10 x i32] [i32 8, i32 10, i32 14, i32 16, i32 20, i32 25, i32 31, i32 37, i32 40, i32 50]
@.str = [30 x i8] c"Inserire il numero da trovare\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [78 x i8] c"Hai trovato il numero nella posizione %d\0A Il numero di passi eseguiti \C3\A8 %d \00"
@.str.4 = [6 x i8] c"PAUSE\00"
@str = [26 x i8] c"Non hai trovato il numero\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 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 = load i32, i32* %1
br label %6
6: ; preds = %0, %16
%7 = phi i32 [ 0, %0 ], [ %22, %16 ]
%8 = phi i32 [ 9, %0 ], [ %21, %16 ]
%9 = phi i32 [ 0, %0 ], [ %20, %16 ]
%10 = add nsw i32 %8, %9
%11 = sdiv i32 %10, 2
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds [10 x i32], [10 x i32]* @__const.main.num, i64 0, i64 %12
%14 = load i32, i32* %13
%15 = icmp eq i32 %5, %14
br i1 %15, label %24, label %16
16: ; preds = %6
%17 = icmp sgt i32 %5, %14
%18 = add nsw i32 %11, 1
%19 = add nsw i32 %11, -1
%20 = select i1 %17, i32 %18, i32 %9
%21 = select i1 %17, i32 %8, i32 %19
%22 = add nuw nsw i32 %7, 1
%23 = icmp sgt i32 %20, %21
br i1 %23, label %28, label %6
24: ; preds = %6
%25 = add nuw nsw i32 %7, 1
%26 = add nsw i32 %11, 1
%27 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([78 x i8], [78 x i8]* @.str.2, i64 0, i64 0), i32 %26, i32 %25)
br label %30
28: ; preds = %16
%29 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str, i64 0, i64 0))
br label %30
30: ; preds = %28, %24
%31 = call i32 @system(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
ret i32 0
}