#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*/ bubblesort(int *, int);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ insere_lista_auto(int *, int);
int /*<<< orphan*/ mostra_lista(int *, int);
int pesquisaBinaria(int *, int, int);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ removeRepetido(int *, int);
int repitido(int *, int);
int /*<<< orphan*/ scanf(char *, int *);
int /*<<< orphan*/ stdin;
void question_five() {
  int tam_vetor, aux, busca;
  printf("\n------------- Questao 5 -------------\n");
  printf("Entre com o tamanho do vetor: ");
  scanf("%d", &tam_vetor);
  int vetor[tam_vetor];
  insere_lista_auto(vetor, tam_vetor);
  aux = repitido(vetor, tam_vetor);
  if (aux) {
    printf("existe elementos repetidos\n");
    tam_vetor -= removeRepetido(vetor, tam_vetor);
  } else
    printf("OK\n");
  bubblesort(vetor, tam_vetor);
  mostra_lista(vetor, tam_vetor);
  printf("valor da busca: ");
  fflush(stdin);
  scanf("%d", &busca);
  busca = pesquisaBinaria(vetor, tam_vetor, busca);
  if (busca >= 0)
    printf("O valor se encontra na posicao: %d\n", busca);
  else
    printf("Valor nao enontrado\n");
}


x86 assembly (clang, -O0):
<question_five>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
lea    0xe61(%rip),%rdi
xor    %eax,%eax
mov    %al,-0x29(%rbp)
call   1030 <printf@plt>
mov    -0x29(%rbp),%al
lea    0xe75(%rip),%rdi
call   1030 <printf@plt>
lea    0xe88(%rip),%rdi
lea    -0x4(%rbp),%rsi
call   1090 <scanf@plt>
mov    -0x4(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
lea    0xf(,%rax,4),%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x28(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x20(%rbp)
mov    -0x4(%rbp),%esi
call   10b0 <insere_lista_auto@plt>
mov    -0x28(%rbp),%rdi
mov    -0x4(%rbp),%esi
call   1040 <repitido@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     123c <question_five+0xac>
lea    0xe33(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x28(%rbp),%rdi
mov    -0x4(%rbp),%esi
call   1060 <removeRepetido@plt>
mov    %rax,%rcx
movslq -0x4(%rbp),%rax
sub    %rcx,%rax
mov    %eax,-0x4(%rbp)
jmp    124a <question_five+0xba>
lea    0xe23(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x28(%rbp),%rdi
mov    -0x4(%rbp),%esi
call   10a0 <bubblesort@plt>
mov    -0x28(%rbp),%rdi
mov    -0x4(%rbp),%esi
call   1070 <mostra_lista@plt>
lea    0xe01(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2d71(%rip),%rax
mov    (%rax),%edi
call   1080 <fflush@plt>
lea    0xdc2(%rip),%rdi
lea    -0xc(%rbp),%rsi
call   1090 <scanf@plt>
mov    -0x28(%rbp),%rdi
mov    -0x4(%rbp),%esi
mov    -0xc(%rbp),%edx
call   1050 <pesquisaBinaria@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jl     12c0 <question_five+0x130>
mov    -0xc(%rbp),%esi
lea    0xdc7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    12ce <question_five+0x13e>
lea    0xdd8(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<question_five>:
push   %rbp
mov    %rsp,%rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
lea    0xea5(%rip),%rdi
call   1030 <puts@plt>
lea    0xe42(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe53(%rip),%rdi
lea    -0x14(%rbp),%rsi
call   10a0 <scanf@plt>
mov    %rsp,%r14
mov    -0x14(%rbp),%eax
mov    %rsp,%rbx
lea    0xf(,%rax,4),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    -0x14(%rbp),%esi
mov    %rbx,%rdi
call   10c0 <insere_lista_auto@plt>
mov    -0x14(%rbp),%esi
mov    %rbx,%rdi
call   1050 <repitido@plt>
test   %eax,%eax
je     122b <question_five+0x8b>
lea    0xe84(%rip),%rdi
call   1030 <puts@plt>
mov    -0x14(%rbp),%esi
mov    %rbx,%rdi
call   1070 <removeRepetido@plt>
mov    -0x14(%rbp),%esi
sub    %eax,%esi
mov    %esi,-0x14(%rbp)
jmp    123a <question_five+0x9a>
lea    0xe4c(%rip),%rdi
call   1030 <puts@plt>
mov    -0x14(%rbp),%esi
mov    %rbx,%rdi
call   10b0 <bubblesort@plt>
mov    -0x14(%rbp),%esi
mov    %rbx,%rdi
call   1080 <mostra_lista@plt>
lea    0xdce(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x2d86(%rip),%rax
mov    (%rax),%edi
call   1090 <fflush@plt>
lea    0xdaf(%rip),%rdi
lea    -0x18(%rbp),%rsi
call   10a0 <scanf@plt>
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
mov    %rbx,%rdi
call   1060 <pesquisaBinaria@plt>
mov    %eax,-0x18(%rbp)
test   %eax,%eax
js     12a0 <question_five+0x100>
lea    0xd9e(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    12ac <question_five+0x10c>
lea    0xdda(%rip),%rdi
call   1030 <puts@plt>
mov    %r14,%rsp
lea    -0x10(%rbp),%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [40 x i8] c"\0A------------- Questao 5 -------------\0A\00"
@.str.1 = [31 x i8] c"Entre com o tamanho do vetor: \00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [28 x i8] c"existe elementos repetidos\0A\00"
@.str.4 = [4 x i8] c"OK\0A\00"
@.str.5 = [17 x i8] c"valor da busca: \00"
@stdin = global i32 0
@.str.6 = [36 x i8] c"O valor se encontra na posicao: %d\0A\00"
@.str.7 = [21 x i8] c"Valor nao enontrado\0A\00"
define void @question_five() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i64
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0))
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0))
%8 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %1)
%9 = load i32, i32* %1
%10 = zext i32 %9 to i64
%11 = call i8* @llvm.stacksave()
store i8* %11, i8** %4
%12 = alloca i32, i64 %10
store i64 %10, i64* %5
%13 = load i32, i32* %1
%14 = call i32 @insere_lista_auto(i32* %12, i32 %13)
%15 = load i32, i32* %1
%16 = call i32 @repitido(i32* %12, i32 %15)
store i32 %16, i32* %2
%17 = load i32, i32* %2
%18 = icmp ne i32 %17, 0
br i1 %18, label %19, label %27
19: ; preds = %0
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0))
%21 = load i32, i32* %1
%22 = call i64 @removeRepetido(i32* %12, i32 %21)
%23 = load i32, i32* %1
%24 = sext i32 %23 to i64
%25 = sub nsw i64 %24, %22
%26 = trunc i64 %25 to i32
store i32 %26, i32* %1
br label %29
27: ; preds = %0
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0))
br label %29
29: ; preds = %27, %19
%30 = load i32, i32* %1
%31 = call i32 @bubblesort(i32* %12, i32 %30)
%32 = load i32, i32* %1
%33 = call i32 @mostra_lista(i32* %12, i32 %32)
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0))
%35 = load i32, i32* @stdin
%36 = call i32 @fflush(i32 %35)
%37 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %3)
%38 = load i32, i32* %1
%39 = load i32, i32* %3
%40 = call i32 @pesquisaBinaria(i32* %12, i32 %38, i32 %39)
store i32 %40, i32* %3
%41 = load i32, i32* %3
%42 = icmp sge i32 %41, 0
br i1 %42, label %43, label %46
43: ; preds = %29
%44 = load i32, i32* %3
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.6, i64 0, i64 0), i32 %44)
br label %48
46: ; preds = %29
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.7, i64 0, i64 0))
br label %48
48: ; preds = %46, %43
%49 = load i8*, i8** %4
ret void
}

LLVM IR (-O2):
@.str.1 = [31 x i8] c"Entre com o tamanho do vetor: \00"
@.str.2 = [3 x i8] c"%d\00"
@.str.5 = [17 x i8] c"valor da busca: \00"
@stdin = global i32 0
@.str.6 = [36 x i8] c"O valor se encontra na posicao: %d\0A\00"
@str = [39 x i8] c"\0A------------- Questao 5 -------------\00"
@str.8 = [3 x i8] c"OK\00"
@str.9 = [20 x i8] c"Valor nao enontrado\00"
@str.10 = [27 x i8] c"existe elementos repetidos\00"
define void @question_five() {
%1 = alloca i32
%2 = alloca i32
%3 = bitcast i32* %1 to i8*
%4 = bitcast i32* %2 to i8*
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @str, i64 0, i64 0))
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0))
%7 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %1)
%8 = load i32, i32* %1
%9 = zext i32 %8 to i64
%10 = call i8* @llvm.stacksave()
%11 = alloca i32, i64 %9
%12 = load i32, i32* %1
%13 = call i32 @insere_lista_auto(i32* %11, i32 %12)
%14 = load i32, i32* %1
%15 = call i32 @repitido(i32* %11, i32 %14)
%16 = icmp eq i32 %15, 0
br i1 %16, label %24, label %17
17: ; preds = %0
%18 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str.10, i64 0, i64 0))
%19 = load i32, i32* %1
%20 = call i64 @removeRepetido(i32* %11, i32 %19)
%21 = load i32, i32* %1
%22 = trunc i64 %20 to i32
%23 = sub i32 %21, %22
store i32 %23, i32* %1
br label %27
24: ; preds = %0
%25 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @str.8, i64 0, i64 0))
%26 = load i32, i32* %1
br label %27
27: ; preds = %24, %17
%28 = phi i32 [ %26, %24 ], [ %23, %17 ]
%29 = call i32 @bubblesort(i32* %11, i32 %28)
%30 = load i32, i32* %1
%31 = call i32 @mostra_lista(i32* %11, i32 %30)
%32 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0))
%33 = load i32, i32* @stdin
%34 = call i32 @fflush(i32 %33)
%35 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %2)
%36 = load i32, i32* %1
%37 = load i32, i32* %2
%38 = call i32 @pesquisaBinaria(i32* %11, i32 %36, i32 %37)
store i32 %38, i32* %2
%39 = icmp sgt i32 %38, -1
br i1 %39, label %40, label %42
40: ; preds = %27
%41 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.6, i64 0, i64 0), i32 %38)
br label %44
42: ; preds = %27
%43 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str.9, i64 0, i64 0))
br label %44
44: ; preds = %42, %40
ret void
}