#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*/ bubble(int *);
int busca(int *, int, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, ...);
int rand();
int /*<<< orphan*/ scanf(char *, int *);
int main() {
  int vetor[100], i, val, res;
  for (i = 0; i < 100; i++)
    vetor[i] = rand() % 100;
  bubble(vetor);
  for (i = 0; i < 100; i++)
    printf("Posicao = %d ; Valor = %d\n", i, vetor[i]);
  printf("Entre com o valor a ser procurado: ");
  scanf("%d", &val);
  res = busca(vetor, val, 0, 99);
  if (res == -1)
    printf("Numero nao encontrado");
  else
    printf("Numero encontrado na posicao: %d", res);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1b0,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x1a4(%rbp)
cmpl   $0x64,-0x1a4(%rbp)
jge    11aa <main+0x5a>
mov    $0x0,%al
call   1070 <rand@plt>
mov    $0x64,%ecx
cltd
idiv   %ecx
movslq -0x1a4(%rbp),%rax
mov    %edx,-0x1a0(%rbp,%rax,4)
mov    -0x1a4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1a4(%rbp)
jmp    116c <main+0x1c>
lea    -0x1a0(%rbp),%rdi
call   1030 <bubble@plt>
movl   $0x0,-0x1a4(%rbp)
cmpl   $0x64,-0x1a4(%rbp)
jge    1203 <main+0xb3>
mov    -0x1a4(%rbp),%esi
movslq -0x1a4(%rbp),%rax
mov    -0x1a0(%rbp,%rax,4),%edx
lea    0xe18(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x1a4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1a4(%rbp)
jmp    11c0 <main+0x70>
lea    0xe11(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe5b(%rip),%rdi
lea    -0x1a8(%rbp),%rsi
call   1060 <scanf@plt>
lea    -0x1a0(%rbp),%rdi
mov    -0x1a8(%rbp),%esi
xor    %edx,%edx
mov    $0x63,%ecx
call   1050 <busca@plt>
mov    %eax,-0x1ac(%rbp)
cmpl   $0xffffffff,-0x1ac(%rbp)
jne    1263 <main+0x113>
lea    0xde8(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1277 <main+0x127>
mov    -0x1ac(%rbp),%esi
lea    0xde5(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x1b0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x1a8,%rsp
xor    %ebx,%ebx
nopl   0x0(%rax)
xor    %eax,%eax
call   1070 <rand@plt>
cltq
imul   $0x51eb851f,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x25,%rcx
add    %edx,%ecx
imul   $0x64,%ecx,%ecx
sub    %ecx,%eax
mov    %eax,0x10(%rsp,%rbx,4)
add    $0x1,%rbx
cmp    $0x64,%rbx
jne    1160 <main+0x10>
lea    0x10(%rsp),%rdi
call   1030 <bubble@plt>
lea    0xe5f(%rip),%r14
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    0x10(%rsp,%rbx,4),%edx
mov    %r14,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%rbx
cmp    $0x64,%rbx
jne    11b0 <main+0x60>
lea    0xe4a(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe94(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1060 <scanf@plt>
mov    0xc(%rsp),%esi
lea    0x10(%rsp),%rdi
xor    %edx,%edx
mov    $0x63,%ecx
call   1050 <busca@plt>
cmp    $0xffffffff,%eax
je     1215 <main+0xc5>
lea    0xe4b(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    1223 <main+0xd3>
lea    0xe23(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x1a8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [27 x i8] c"Posicao = %d ; Valor = %d\0A\00"
@.str.1 = [36 x i8] c"Entre com o valor a ser procurado: \00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [22 x i8] c"Numero nao encontrado\00"
@.str.4 = [33 x i8] c"Numero encontrado na posicao: %d\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [100 x i32]
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %3
br label %6
6: ; preds = %15, %0
%7 = load i32, i32* %3
%8 = icmp slt i32 %7, 100
br i1 %8, label %9, label %18
9: ; preds = %6
%10 = call i32 (...) @rand()
%11 = srem i32 %10, 100
%12 = load i32, i32* %3
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds [100 x i32], [100 x i32]* %2, i64 0, i64 %13
store i32 %11, i32* %14
br label %15
15: ; preds = %9
%16 = load i32, i32* %3
%17 = add nsw i32 %16, 1
store i32 %17, i32* %3
br label %6
18: ; preds = %6
%19 = getelementptr inbounds [100 x i32], [100 x i32]* %2, i64 0, i64 0
%20 = call i32 @bubble(i32* %19)
store i32 0, i32* %3
br label %21
21: ; preds = %31, %18
%22 = load i32, i32* %3
%23 = icmp slt i32 %22, 100
br i1 %23, label %24, label %34
24: ; preds = %21
%25 = load i32, i32* %3
%26 = load i32, i32* %3
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds [100 x i32], [100 x i32]* %2, i64 0, i64 %27
%29 = load i32, i32* %28
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i32 %25, i32 %29)
br label %31
31: ; preds = %24
%32 = load i32, i32* %3
%33 = add nsw i32 %32, 1
store i32 %33, i32* %3
br label %21
34: ; preds = %21
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0))
%36 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %4)
%37 = getelementptr inbounds [100 x i32], [100 x i32]* %2, i64 0, i64 0
%38 = load i32, i32* %4
%39 = call i32 @busca(i32* %37, i32 %38, i32 0, i32 99)
store i32 %39, i32* %5
%40 = load i32, i32* %5
%41 = icmp eq i32 %40, -1
br i1 %41, label %42, label %44
42: ; preds = %34
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0))
br label %47
44: ; preds = %34
%45 = load i32, i32* %5
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0), i32 %45)
br label %47
47: ; preds = %44, %42
ret i32 0
}

LLVM IR (-O2):
@.str = [27 x i8] c"Posicao = %d ; Valor = %d\0A\00"
@.str.1 = [36 x i8] c"Entre com o valor a ser procurado: \00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [22 x i8] c"Numero nao encontrado\00"
@.str.4 = [33 x i8] c"Numero encontrado na posicao: %d\00"
define i32 @main() {
%1 = alloca [100 x i32]
%2 = alloca i32
%3 = bitcast [100 x i32]* %1 to i8*
%4 = bitcast i32* %2 to i8*
br label %5
5: ; preds = %0, %5
%6 = phi i64 [ 0, %0 ], [ %10, %5 ]
%7 = tail call i32 (...) @rand()
%8 = srem i32 %7, 100
%9 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 %6
store i32 %8, i32* %9
%10 = add nuw nsw i64 %6, 1
%11 = icmp eq i64 %10, 100
br i1 %11, label %12, label %5
12: ; preds = %5
%13 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 0
%14 = call i32 @bubble(i32* %13)
br label %15
15: ; preds = %12, %15
%16 = phi i64 [ 0, %12 ], [ %21, %15 ]
%17 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 %16
%18 = load i32, i32* %17
%19 = trunc i64 %16 to i32
%20 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i32 %19, i32 %18)
%21 = add nuw nsw i64 %16, 1
%22 = icmp eq i64 %21, 100
br i1 %22, label %23, label %15
23: ; preds = %15
%24 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0))
%25 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %2)
%26 = load i32, i32* %2
%27 = call i32 @busca(i32* %13, i32 %26, i32 0, i32 99)
%28 = icmp eq i32 %27, -1
br i1 %28, label %29, label %31
29: ; preds = %23
%30 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0))
br label %33
31: ; preds = %23
%32 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0), i32 %27)
br label %33
33: ; preds = %31, %29
ret i32 0
}