#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 */
typedef int /*<<< orphan*/ A;

/* Variables and functions */
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
void main() {
  int i, A[500], inf, sup, meio, p;
  for (i = 0; i < 500; i++)
    A[i] = i * 3;
  printf("Digite um numero inteiro: ");
  scanf("%d", &p);
  inf = 0;
  sup = sizeof(A) / 4 - 1;
  while (inf <= sup) {
    meio = (inf + sup) / 2;
    if (A[meio] == p) {
      printf("Numero encontrado na posicao %d.\n", meio);
      inf = sup + 1;
    } else {
      if (A[meio] < p)
        inf = meio + 1;
      else
        sup = meio - 1;
      if (inf > sup)
        printf("Numero nao existe no vetor. Deveria estar entre posicoes %d e "
               "%d.\n",
               sup, inf);
    }
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x7f0,%rsp
movl   $0x0,-0x4(%rbp)
cmpl   $0x1f4,-0x4(%rbp)
jge    115c <main+0x3c>
imul   $0x3,-0x4(%rbp),%ecx
movslq -0x4(%rbp),%rax
mov    %ecx,-0x7e0(%rbp,%rax,4)
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    1132 <main+0x12>
lea    0xe9d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xeaa(%rip),%rdi
lea    -0x7f0(%rbp),%rsi
call   1040 <scanf@plt>
movl   $0x0,-0x7e4(%rbp)
movl   $0x1f3,-0x7e8(%rbp)
mov    -0x7e4(%rbp),%eax
cmp    -0x7e8(%rbp),%eax
jg     1272 <main+0x152>
mov    -0x7e4(%rbp),%eax
add    -0x7e8(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x7ec(%rbp)
movslq -0x7ec(%rbp),%rax
mov    -0x7e0(%rbp,%rax,4),%eax
cmp    -0x7f0(%rbp),%eax
jne    11ff <main+0xdf>
mov    -0x7ec(%rbp),%esi
lea    0xe3a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x7e8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x7e4(%rbp)
jmp    126d <main+0x14d>
movslq -0x7ec(%rbp),%rax
mov    -0x7e0(%rbp,%rax,4),%eax
cmp    -0x7f0(%rbp),%eax
jge    122d <main+0x10d>
mov    -0x7ec(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x7e4(%rbp)
jmp    123c <main+0x11c>
mov    -0x7ec(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x7e8(%rbp)
mov    -0x7e4(%rbp),%eax
cmp    -0x7e8(%rbp),%eax
jle    1268 <main+0x148>
mov    -0x7e8(%rbp),%esi
mov    -0x7e4(%rbp),%edx
lea    0xddf(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    126d <main+0x14d>
jmp    1191 <main+0x71>
add    $0x7f0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x7e0,%rsp
movdqa 0xecc(%rip),%xmm0
mov    $0xc,%eax
movdqa 0xecf(%rip),%xmm1
movdqa 0xed7(%rip),%xmm2
movdqa 0xedf(%rip),%xmm3
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movdqa %xmm0,%xmm4
paddd  %xmm0,%xmm4
paddd  %xmm0,%xmm4
movdqa %xmm4,-0x20(%rsp,%rax,4)
paddd  %xmm1,%xmm4
movdqa %xmm4,-0x10(%rsp,%rax,4)
movdqa %xmm0,%xmm4
paddd  %xmm2,%xmm4
movdqa %xmm4,%xmm5
paddd  %xmm4,%xmm5
paddd  %xmm4,%xmm5
movdqa %xmm5,(%rsp,%rax,4)
paddd  %xmm1,%xmm5
movdqa %xmm5,0x10(%rsp,%rax,4)
paddd  %xmm3,%xmm0
add    $0x10,%rax
cmp    $0x1fc,%rax
jne    1160 <main+0x40>
movaps 0xe8a(%rip),%xmm0
movaps %xmm0,0x7d0(%rsp)
lea    0xe8b(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xe98(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1040 <scanf@plt>
mov    $0x1f3,%r15d
lea    0xea6(%rip),%r14
xor    %ebx,%ebx
jmp    11f5 <main+0xd5>
xchg   %ax,%ax
cmp    %r15d,%ebx
jg     1249 <main+0x129>
lea    (%r15,%rbx,1),%eax
mov    %eax,%esi
shr    $0x1f,%esi
add    %eax,%esi
sar    %esi
movslq %esi,%rax
mov    0x10(%rsp,%rax,4),%eax
mov    0xc(%rsp),%ecx
cmp    %ecx,%eax
je     123b <main+0x11b>
jl     1220 <main+0x100>
add    $0xffffffff,%esi
mov    %esi,%r15d
cmp    %r15d,%ebx
jle    11f0 <main+0xd0>
jmp    122a <main+0x10a>
add    $0x1,%esi
mov    %esi,%ebx
cmp    %r15d,%ebx
jle    11f0 <main+0xd0>
mov    %r14,%rdi
mov    %r15d,%esi
mov    %ebx,%edx
xor    %eax,%eax
call   1030 <printf@plt>
jmp    11f0 <main+0xd0>
lea    0xe2c(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
add    $0x7e0,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [27 x i8] c"Digite um numero inteiro: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [34 x i8] c"Numero encontrado na posicao %d.\0A\00"
@.str.3 = [67 x i8] c"Numero nao existe no vetor. Deveria estar entre posicoes %d e %d.\0A\00"
define void @main() {
%1 = alloca i32
%2 = alloca [500 x i32]
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 0, i32* %1
br label %7
7: ; preds = %16, %0
%8 = load i32, i32* %1
%9 = icmp slt i32 %8, 500
br i1 %9, label %10, label %19
10: ; preds = %7
%11 = load i32, i32* %1
%12 = mul nsw i32 %11, 3
%13 = load i32, i32* %1
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds [500 x i32], [500 x i32]* %2, i64 0, i64 %14
store i32 %12, i32* %15
br label %16
16: ; preds = %10
%17 = load i32, i32* %1
%18 = add nsw i32 %17, 1
store i32 %18, i32* %1
br label %7
19: ; preds = %7
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%21 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %6)
store i32 0, i32* %3
store i32 499, i32* %4
br label %22
22: ; preds = %64, %19
%23 = load i32, i32* %3
%24 = load i32, i32* %4
%25 = icmp sle i32 %23, %24
br i1 %25, label %26, label %65
26: ; preds = %22
%27 = load i32, i32* %3
%28 = load i32, i32* %4
%29 = add nsw i32 %27, %28
%30 = sdiv i32 %29, 2
store i32 %30, i32* %5
%31 = load i32, i32* %5
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds [500 x i32], [500 x i32]* %2, i64 0, i64 %32
%34 = load i32, i32* %33
%35 = load i32, i32* %6
%36 = icmp eq i32 %34, %35
br i1 %36, label %37, label %42
37: ; preds = %26
%38 = load i32, i32* %5
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0), i32 %38)
%40 = load i32, i32* %4
%41 = add nsw i32 %40, 1
store i32 %41, i32* %3
br label %64
42: ; preds = %26
%43 = load i32, i32* %5
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds [500 x i32], [500 x i32]* %2, i64 0, i64 %44
%46 = load i32, i32* %45
%47 = load i32, i32* %6
%48 = icmp slt i32 %46, %47
br i1 %48, label %49, label %52
49: ; preds = %42
%50 = load i32, i32* %5
%51 = add nsw i32 %50, 1
store i32 %51, i32* %3
br label %55
52: ; preds = %42
%53 = load i32, i32* %5
%54 = sub nsw i32 %53, 1
store i32 %54, i32* %4
br label %55
55: ; preds = %52, %49
%56 = load i32, i32* %3
%57 = load i32, i32* %4
%58 = icmp sgt i32 %56, %57
br i1 %58, label %59, label %63
59: ; preds = %55
%60 = load i32, i32* %4
%61 = load i32, i32* %3
%62 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([67 x i8], [67 x i8]* @.str.3, i64 0, i64 0), i32 %60, i32 %61)
br label %63
63: ; preds = %59, %55
br label %64
64: ; preds = %63, %37
br label %22
65: ; preds = %22
ret void
}

LLVM IR (-O2):
@.str = [27 x i8] c"Digite um numero inteiro: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [34 x i8] c"Numero encontrado na posicao %d.\0A\00"
@.str.3 = [67 x i8] c"Numero nao existe no vetor. Deveria estar entre posicoes %d e %d.\0A\00"
define void @main() {
%1 = alloca [500 x i32]
%2 = alloca i32
%3 = bitcast [500 x i32]* %1 to i8*
%4 = bitcast i32* %2 to i8*
br label %5
5: ; preds = %5, %0
%6 = phi i64 [ 0, %0 ], [ %24, %5 ]
%7 = phi <4 x i32> [ <i32 0, i32 1, i32 2, i32 3>, %0 ], [ %25, %5 ]
%8 = getelementptr inbounds [500 x i32], [500 x i32]* %1, i64 0, i64 %6
%9 = mul <4 x i32> %7, <i32 3, i32 3, i32 3, i32 3>
%10 = mul <4 x i32> %7, <i32 3, i32 3, i32 3, i32 3>
%11 = add <4 x i32> %10, <i32 12, i32 12, i32 12, i32 12>
%12 = bitcast i32* %8 to <4 x i32>*
store <4 x i32> %9, <4 x i32>* %12
%13 = getelementptr inbounds i32, i32* %8, i64 4
%14 = bitcast i32* %13 to <4 x i32>*
store <4 x i32> %11, <4 x i32>* %14
%15 = or i64 %6, 8
%16 = add <4 x i32> %7, <i32 8, i32 8, i32 8, i32 8>
%17 = getelementptr inbounds [500 x i32], [500 x i32]* %1, i64 0, i64 %15
%18 = mul <4 x i32> %16, <i32 3, i32 3, i32 3, i32 3>
%19 = mul <4 x i32> %16, <i32 3, i32 3, i32 3, i32 3>
%20 = add <4 x i32> %19, <i32 12, i32 12, i32 12, i32 12>
%21 = bitcast i32* %17 to <4 x i32>*
store <4 x i32> %18, <4 x i32>* %21
%22 = getelementptr inbounds i32, i32* %17, i64 4
%23 = bitcast i32* %22 to <4 x i32>*
store <4 x i32> %20, <4 x i32>* %23
%24 = add nuw nsw i64 %6, 16
%25 = add <4 x i32> %7, <i32 16, i32 16, i32 16, i32 16>
%26 = icmp eq i64 %24, 496
br i1 %26, label %27, label %5
27: ; preds = %5
%28 = getelementptr inbounds [500 x i32], [500 x i32]* %1, i64 0, i64 496
store i32 1488, i32* %28
%29 = getelementptr inbounds [500 x i32], [500 x i32]* %1, i64 0, i64 497
store i32 1491, i32* %29
%30 = getelementptr inbounds [500 x i32], [500 x i32]* %1, i64 0, i64 498
store i32 1494, i32* %30
%31 = getelementptr inbounds [500 x i32], [500 x i32]* %1, i64 0, i64 499
store i32 1497, i32* %31
%32 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%33 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
br label %34
34: ; preds = %27, %55
%35 = phi i32 [ 499, %27 ], [ %51, %55 ]
%36 = phi i32 [ 0, %27 ], [ %50, %55 ]
%37 = add nsw i32 %35, %36
%38 = sdiv i32 %37, 2
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds [500 x i32], [500 x i32]* %1, i64 0, i64 %39
%41 = load i32, i32* %40
%42 = load i32, i32* %2
%43 = icmp eq i32 %41, %42
br i1 %43, label %44, label %46
44: ; preds = %34
%45 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0), i32 %38)
br label %57
46: ; preds = %34
%47 = icmp slt i32 %41, %42
%48 = add nsw i32 %38, 1
%49 = add nsw i32 %38, -1
%50 = select i1 %47, i32 %48, i32 %36
%51 = select i1 %47, i32 %35, i32 %49
%52 = icmp sgt i32 %50, %51
br i1 %52, label %53, label %55
53: ; preds = %46
%54 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([67 x i8], [67 x i8]* @.str.3, i64 0, i64 0), i32 %51, i32 %50)
br label %55
55: ; preds = %46, %53
%56 = icmp sgt i32 %50, %51
br i1 %56, label %57, label %34
57: ; preds = %55, %44
ret void
}