#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], p, inf, sup, meio;
  for (i = 0; i < 500; i++)
    A[i] = i * 3;
  printf("Digite um inteiro multiplo de 3 entre 0 e 1495: ");
  scanf("%d", &p);
  inf = 0;
  sup = sizeof(A) / 4 - 1;
  while (inf <= sup) {
    meio = (inf + sup) / 2;
    if (A[meio] == p) {
      printf("Valor encontrado! Posicao de P no vetor A: %d.\n", meio);
      inf = sup + 1;
    } else {
      if (A[meio] < p)
        inf = meio + 1;
      else
        sup = meio - 1;
    }
  }
}


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    0xec0(%rip),%rdi
lea    -0x7e4(%rbp),%rsi
call   1040 <scanf@plt>
movl   $0x0,-0x7e8(%rbp)
movl   $0x1f3,-0x7ec(%rbp)
mov    -0x7e8(%rbp),%eax
cmp    -0x7ec(%rbp),%eax
jg     1246 <main+0x126>
mov    -0x7e8(%rbp),%eax
add    -0x7ec(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x7f0(%rbp)
movslq -0x7f0(%rbp),%rax
mov    -0x7e0(%rbp,%rax,4),%eax
cmp    -0x7e4(%rbp),%eax
jne    11ff <main+0xdf>
mov    -0x7f0(%rbp),%esi
lea    0xe50(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x7ec(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x7e8(%rbp)
jmp    1241 <main+0x121>
movslq -0x7f0(%rbp),%rax
mov    -0x7e0(%rbp,%rax,4),%eax
cmp    -0x7e4(%rbp),%eax
jge    122d <main+0x10d>
mov    -0x7f0(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x7e8(%rbp)
jmp    123c <main+0x11c>
mov    -0x7f0(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x7ec(%rbp)
jmp    1241 <main+0x121>
jmp    1191 <main+0x71>
add    $0x7f0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x7e0,%rsp
movdqa 0xed0(%rip),%xmm0
mov    $0xc,%eax
movdqa 0xed3(%rip),%xmm1
movdqa 0xedb(%rip),%xmm2
movdqa 0xee3(%rip),%xmm3
nopl   (%rax)
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    1150 <main+0x30>
movaps 0xe9a(%rip),%xmm0
movaps %xmm0,0x7d0(%rsp)
lea    0xe9b(%rip),%rdi
xor    %ebx,%ebx
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xebc(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1040 <scanf@plt>
mov    $0x1f3,%ecx
mov    0xc(%rsp),%eax
jmp    11e9 <main+0xc9>
nopw   0x0(%rax,%rax,1)
add    $0xffffffff,%esi
mov    %esi,%ecx
cmp    %ecx,%ebx
jg     121b <main+0xfb>
lea    (%rcx,%rbx,1),%edx
mov    %edx,%esi
shr    $0x1f,%esi
add    %edx,%esi
sar    %esi
movslq %esi,%rdx
mov    0x10(%rsp,%rdx,4),%edx
cmp    %eax,%edx
je     120d <main+0xed>
jge    11e0 <main+0xc0>
add    $0x1,%esi
mov    %esi,%ebx
cmp    %ecx,%ebx
jle    11e9 <main+0xc9>
jmp    121b <main+0xfb>
lea    0xe70(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
add    $0x7e0,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [49 x i8] c"Digite um inteiro multiplo de 3 entre 0 e 1495: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [48 x i8] c"Valor encontrado! Posicao de P no vetor A: %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 ([49 x i8], [49 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* %3)
store i32 0, i32* %4
store i32 499, i32* %5
br label %22
22: ; preds = %56, %19
%23 = load i32, i32* %4
%24 = load i32, i32* %5
%25 = icmp sle i32 %23, %24
br i1 %25, label %26, label %57
26: ; preds = %22
%27 = load i32, i32* %4
%28 = load i32, i32* %5
%29 = add nsw i32 %27, %28
%30 = sdiv i32 %29, 2
store i32 %30, i32* %6
%31 = load i32, i32* %6
%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* %3
%36 = icmp eq i32 %34, %35
br i1 %36, label %37, label %42
37: ; preds = %26
%38 = load i32, i32* %6
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.2, i64 0, i64 0), i32 %38)
%40 = load i32, i32* %5
%41 = add nsw i32 %40, 1
store i32 %41, i32* %4
br label %56
42: ; preds = %26
%43 = load i32, i32* %6
%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* %3
%48 = icmp slt i32 %46, %47
br i1 %48, label %49, label %52
49: ; preds = %42
%50 = load i32, i32* %6
%51 = add nsw i32 %50, 1
store i32 %51, i32* %4
br label %55
52: ; preds = %42
%53 = load i32, i32* %6
%54 = sub nsw i32 %53, 1
store i32 %54, i32* %5
br label %55
55: ; preds = %52, %49
br label %56
56: ; preds = %55, %37
br label %22
57: ; preds = %22
ret void
}

LLVM IR (-O2):
@.str = [49 x i8] c"Digite um inteiro multiplo de 3 entre 0 e 1495: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [48 x i8] c"Valor encontrado! Posicao de P no vetor A: %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 ([49 x i8], [49 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)
%34 = load i32, i32* %2
br label %35
35: ; preds = %27, %46
%36 = phi i32 [ 499, %27 ], [ %51, %46 ]
%37 = phi i32 [ 0, %27 ], [ %50, %46 ]
%38 = add nsw i32 %36, %37
%39 = sdiv i32 %38, 2
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds [500 x i32], [500 x i32]* %1, i64 0, i64 %40
%42 = load i32, i32* %41
%43 = icmp eq i32 %42, %34
br i1 %43, label %44, label %46
44: ; preds = %35
%45 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([48 x i8], [48 x i8]* @.str.2, i64 0, i64 0), i32 %39)
br label %53
46: ; preds = %35
%47 = icmp slt i32 %42, %34
%48 = add nsw i32 %39, 1
%49 = add nsw i32 %39, -1
%50 = select i1 %47, i32 %48, i32 %37
%51 = select i1 %47, i32 %36, i32 %49
%52 = icmp sgt i32 %50, %51
br i1 %52, label %53, label %35
53: ; preds = %46, %44
ret void
}