#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 main() {
  int numeri[] = {3,  5,  9,  13, 15, 19, 20, 24, 28, 34,
                  38, 45, 50, 54, 57, 63, 70, 75, 83, 94};
  int max;
  int min;
  int num;
  int centro;
  int trovato;
  int cont;
  printf("\"Inserire il numero da cercare nell'array\": ");
  scanf("%d", &num);
  cont = 0;
  min = 0;
  max = 19;
  trovato = 0;
  while ((trovato == 0) && (min <= max)) {
    centro = (max + min) / 2;
    if (num == numeri[centro]) {
      trovato = 1;
      cont++;
    } else {
      if (num > numeri[centro]) {
        min = centro + 1;
        centro = (max + min) / 2;
        cont++;
      } else {
        max = centro - 1;
        centro = (max + min) / 2;
        cont++;
      }
    }
  }
  if (trovato == 1) {
    printf("\"hai trovato il numero\": [%d];si trova alla posizione: [%d];e' "
           "stato trovato in %d passo/i",
           numeri[centro], centro, cont);
  } else {
    printf("\"il numero che cerchi non e' presente\"");
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x60(%rbp),%rdi
lea    0xeb3(%rip),%rsi
mov    $0x50,%edx
call   1040 <memcpy@plt>
lea    0xef2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xf11(%rip),%rdi
lea    -0x6c(%rbp),%rsi
call   1050 <scanf@plt>
movl   $0x0,-0x78(%rbp)
movl   $0x0,-0x68(%rbp)
movl   $0x13,-0x64(%rbp)
movl   $0x0,-0x74(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0x74(%rbp)
mov    %al,-0x79(%rbp)
jne    11ac <main+0x7c>
mov    -0x68(%rbp),%eax
cmp    -0x64(%rbp),%eax
setle  %al
mov    %al,-0x79(%rbp)
mov    -0x79(%rbp),%al
test   $0x1,%al
jne    11bc <main+0x8c>
jmp    1259 <main+0x129>
mov    -0x64(%rbp),%eax
add    -0x68(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x70(%rbp)
mov    -0x6c(%rbp),%eax
movslq -0x70(%rbp),%rcx
cmp    -0x60(%rbp,%rcx,4),%eax
jne    11f3 <main+0xc3>
movl   $0x1,-0x74(%rbp)
mov    -0x78(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x78(%rbp)
jmp    1254 <main+0x124>
mov    -0x6c(%rbp),%eax
movslq -0x70(%rbp),%rcx
cmp    -0x60(%rbp,%rcx,4),%eax
jle    122c <main+0xfc>
mov    -0x70(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x68(%rbp)
mov    -0x64(%rbp),%eax
add    -0x68(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x70(%rbp)
mov    -0x78(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x78(%rbp)
jmp    124f <main+0x11f>
mov    -0x70(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x64(%rbp)
mov    -0x64(%rbp),%eax
add    -0x68(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x70(%rbp)
mov    -0x78(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x78(%rbp)
jmp    1254 <main+0x124>
jmp    1191 <main+0x61>
cmpl   $0x1,-0x74(%rbp)
jne    1284 <main+0x154>
movslq -0x70(%rbp),%rax
mov    -0x60(%rbp,%rax,4),%esi
mov    -0x70(%rbp),%edx
mov    -0x78(%rbp),%ecx
lea    0xe08(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1292 <main+0x162>
lea    0xe50(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
lea    0xf24(%rip),%rdi
xor    %ebx,%ebx
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xf41(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1040 <scanf@plt>
mov    $0x13,%edi
mov    $0x1,%ecx
mov    0xc(%rsp),%eax
lea    0xea5(%rip),%r8
jmp    116c <main+0x4c>
nopl   (%rax)
add    $0xffffffff,%edx
mov    %edx,%edi
add    $0x1,%ecx
cmp    %edi,%ebx
jg     118c <main+0x6c>
lea    (%rbx,%rdi,1),%esi
mov    %esi,%edx
shr    $0x1f,%edx
add    %esi,%edx
sar    %edx
movslq %edx,%rsi
mov    (%r8,%rsi,4),%esi
cmp    %esi,%eax
je     119c <main+0x7c>
jle    1160 <main+0x40>
add    $0x1,%edx
mov    %edx,%ebx
jmp    1165 <main+0x45>
lea    0xf48(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
jmp    11aa <main+0x8a>
lea    0xedd(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@__const.main.numeri = [20 x i32] [i32 3, i32 5, i32 9, i32 13, i32 15, i32 19, i32 20, i32 24, i32 28, i32 34, i32 38, i32 45, i32 50, i32 54, i32 57, i32 63, i32 70, i32 75, i32 83, i32 94]
@.str = [45 x i8] c"\22Inserire il numero da cercare nell'array\22: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [91 x i8] c"\22hai trovato il numero\22: [%d];si trova alla posizione: [%d];e' stato trovato in %d passo/i\00"
@.str.3 = [39 x i8] c"\22il numero che cerchi non e' presente\22\00"
define i32 @main() {
%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
store i32 0, i32* %1
%9 = bitcast [20 x i32]* %2 to i8*
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([45 x i8], [45 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* %5)
store i32 0, i32* %8
store i32 0, i32* %4
store i32 19, i32* %3
store i32 0, i32* %7
br label %12
12: ; preds = %61, %0
%13 = load i32, i32* %7
%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* %3
%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 %62
21: ; preds = %19
%22 = load i32, i32* %3
%23 = load i32, i32* %4
%24 = add nsw i32 %22, %23
%25 = sdiv i32 %24, 2
store i32 %25, i32* %6
%26 = load i32, i32* %5
%27 = load i32, i32* %6
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds [20 x i32], [20 x i32]* %2, i64 0, i64 %28
%30 = load i32, i32* %29
%31 = icmp eq i32 %26, %30
br i1 %31, label %32, label %35
32: ; preds = %21
store i32 1, i32* %7
%33 = load i32, i32* %8
%34 = add nsw i32 %33, 1
store i32 %34, i32* %8
br label %61
35: ; preds = %21
%36 = load i32, i32* %5
%37 = load i32, i32* %6
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds [20 x i32], [20 x i32]* %2, i64 0, i64 %38
%40 = load i32, i32* %39
%41 = icmp sgt i32 %36, %40
br i1 %41, label %42, label %51
42: ; preds = %35
%43 = load i32, i32* %6
%44 = add nsw i32 %43, 1
store i32 %44, i32* %4
%45 = load i32, i32* %3
%46 = load i32, i32* %4
%47 = add nsw i32 %45, %46
%48 = sdiv i32 %47, 2
store i32 %48, i32* %6
%49 = load i32, i32* %8
%50 = add nsw i32 %49, 1
store i32 %50, i32* %8
br label %60
51: ; preds = %35
%52 = load i32, i32* %6
%53 = sub nsw i32 %52, 1
store i32 %53, i32* %3
%54 = load i32, i32* %3
%55 = load i32, i32* %4
%56 = add nsw i32 %54, %55
%57 = sdiv i32 %56, 2
store i32 %57, i32* %6
%58 = load i32, i32* %8
%59 = add nsw i32 %58, 1
store i32 %59, i32* %8
br label %60
60: ; preds = %51, %42
br label %61
61: ; preds = %60, %32
br label %12
62: ; preds = %19
%63 = load i32, i32* %7
%64 = icmp eq i32 %63, 1
br i1 %64, label %65, label %73
65: ; preds = %62
%66 = load i32, i32* %6
%67 = sext i32 %66 to i64
%68 = getelementptr inbounds [20 x i32], [20 x i32]* %2, i64 0, i64 %67
%69 = load i32, i32* %68
%70 = load i32, i32* %6
%71 = load i32, i32* %8
%72 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([91 x i8], [91 x i8]* @.str.2, i64 0, i64 0), i32 %69, i32 %70, i32 %71)
br label %75
73: ; preds = %62
%74 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.3, i64 0, i64 0))
br label %75
75: ; preds = %73, %65
%76 = load i32, i32* %1
ret i32 %76
}

LLVM IR (-O2):
@__const.main.numeri = [20 x i32] [i32 3, i32 5, i32 9, i32 13, i32 15, i32 19, i32 20, i32 24, i32 28, i32 34, i32 38, i32 45, i32 50, i32 54, i32 57, i32 63, i32 70, i32 75, i32 83, i32 94]
@.str = [45 x i8] c"\22Inserire il numero da cercare nell'array\22: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [91 x i8] c"\22hai trovato il numero\22: [%d];si trova alla posizione: [%d];e' stato trovato in %d passo/i\00"
@.str.3 = [39 x i8] c"\22il numero che cerchi non e' presente\22\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 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 [ 0, %0 ], [ %21, %16 ]
%9 = phi i32 [ 19, %0 ], [ %20, %16 ]
%10 = add nsw i32 %8, %9
%11 = sdiv i32 %10, 2
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds [20 x i32], [20 x i32]* @__const.main.numeri, 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 %9, i32 %19
%21 = select i1 %17, i32 %18, i32 %8
%22 = add nuw nsw i32 %7, 1
%23 = icmp sgt i32 %21, %20
br i1 %23, label %30, label %6
24: ; preds = %6
%25 = add nuw nsw i32 %7, 1
%26 = sext i32 %11 to i64
%27 = getelementptr inbounds [20 x i32], [20 x i32]* @__const.main.numeri, i64 0, i64 %26
%28 = load i32, i32* %27
%29 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([91 x i8], [91 x i8]* @.str.2, i64 0, i64 0), i32 %28, i32 %11, i32 %25)
br label %32
30: ; preds = %16
%31 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @.str.3, i64 0, i64 0))
br label %32
32: ; preds = %30, %24
ret i32 0
}