#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 */
struct nodo {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ Imprime(struct nodo **);
int /*<<< orphan*/ InsereDireita(struct nodo **, int);
int /*<<< orphan*/ InsereEsquerda(struct nodo **, int);
int InsereNodoDepois(struct nodo **, int, int);
int PesquisaValor(struct nodo **, int);
int /*<<< orphan*/ printf(char *, ...);
int rand();
int /*<<< orphan*/ scanf(char *, int *);
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int main() {
  int i;
  struct nodo *ptr = NULL;
  srand(time(NULL));
  for (i = 0; i < 20; i++) {
    int rnd = rand() % 101;
    if (rnd % 2 == 0) {
      InsereDireita(&ptr, rnd);
    } else {
      InsereEsquerda(&ptr, rnd);
    }
  }
  printf("Lista de nodos:\n\t");
  Imprime(&ptr);
  int val;
  printf("Digite o valor de um nodo a ser inserido: ");
  scanf("%i", &val);
  int inseridoDepois = InsereNodoDepois(&ptr, (val * val), val);
  printf("Foram inseridos %i nodos com o valor indormado.\n", inseridoDepois);
  printf("Lista de nodos:\n\t");
  Imprime(&ptr);
  int valorSorteado = rand() % 101;
  int existe = PesquisaValor(&ptr, valorSorteado);
  if (existe == -1) {
    printf("O valor sorteado %i não foi encontrado na lista.\n", valorSorteado);
  } else {
    printf("O valor sorteado %i foi encontrado na posição %i da lista.\n",
           valorSorteado, existe);
  }
  printf("Lista de nodos:\n\t");
  Imprime(&ptr);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x0,-0x10(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1070 <time@plt>
mov    %eax,%edi
call   1050 <srand@plt>
movl   $0x0,-0x8(%rbp)
cmpl   $0x14,-0x8(%rbp)
jge    122e <main+0x8e>
mov    $0x0,%al
call   10c0 <rand@plt>
mov    $0x65,%ecx
cltd
idiv   %ecx
mov    %edx,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    120f <main+0x6f>
mov    -0x14(%rbp),%esi
lea    -0x10(%rbp),%rdi
call   1090 <InsereDireita@plt>
jmp    121b <main+0x7b>
mov    -0x14(%rbp),%esi
lea    -0x10(%rbp),%rdi
call   1040 <InsereEsquerda@plt>
jmp    1220 <main+0x80>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    11ce <main+0x2e>
lea    0xdcb(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x10(%rbp),%rdi
call   10a0 <Imprime@plt>
lea    0xdc6(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xde3(%rip),%rdi
lea    -0x18(%rbp),%rsi
call   1080 <scanf@plt>
mov    -0x18(%rbp),%esi
imul   -0x18(%rbp),%esi
mov    -0x18(%rbp),%edx
lea    -0x10(%rbp),%rdi
call   1060 <InsereNodoDepois@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%esi
lea    0xdbd(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xd6f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x10(%rbp),%rdi
call   10a0 <Imprime@plt>
mov    $0x0,%al
call   10c0 <rand@plt>
mov    $0x65,%ecx
cltd
idiv   %ecx
mov    %edx,-0x20(%rbp)
mov    -0x20(%rbp),%esi
lea    -0x10(%rbp),%rdi
call   10b0 <PesquisaValor@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0xffffffff,-0x24(%rbp)
jne    12e2 <main+0x142>
mov    -0x20(%rbp),%esi
lea    0xd9b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    12f6 <main+0x156>
mov    -0x20(%rbp),%esi
mov    -0x24(%rbp),%edx
lea    0xdb5(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xd03(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x10(%rbp),%rdi
call   10a0 <Imprime@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
movq   $0x0,0x8(%rsp)
xor    %edi,%edi
call   1070 <time@plt>
mov    %eax,%edi
call   1050 <srand@plt>
mov    $0x14,%ebp
lea    0x8(%rsp),%rbx
jmp    11da <main+0x3a>
nopl   (%rax)
call   1040 <InsereEsquerda@plt>
add    $0xffffffff,%ebp
je     1210 <main+0x70>
xor    %eax,%eax
call   10c0 <rand@plt>
movslq %eax,%rsi
imul   $0x288df0cb,%rsi,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x24,%rax
add    %ecx,%eax
imul   $0x65,%eax,%eax
sub    %eax,%esi
mov    %rbx,%rdi
test   $0x1,%sil
jne    11d0 <main+0x30>
call   1090 <InsereDireita@plt>
add    $0xffffffff,%ebp
jne    11da <main+0x3a>
lea    0xde9(%rip),%r14
mov    %r14,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0x8(%rsp),%r15
mov    %r15,%rdi
call   10a0 <Imprime@plt>
lea    0xddd(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xdfa(%rip),%rdi
lea    0x14(%rsp),%rsi
call   1080 <scanf@plt>
mov    0x14(%rsp),%edx
mov    %edx,%esi
imul   %edx,%esi
mov    %r15,%rdi
call   1060 <InsereNodoDepois@plt>
lea    0xddb(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %r14,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %r15,%rdi
call   10a0 <Imprime@plt>
xor    %eax,%eax
call   10c0 <rand@plt>
movslq %eax,%rbx
imul   $0x288df0cb,%rbx,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x24,%rax
add    %ecx,%eax
imul   $0x65,%eax,%eax
sub    %eax,%ebx
mov    %r15,%rdi
mov    %ebx,%esi
call   10b0 <PesquisaValor@plt>
cmp    $0xffffffff,%eax
je     12c6 <main+0x126>
lea    0xdeb(%rip),%rdi
mov    %ebx,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1030 <printf@plt>
jmp    12d6 <main+0x136>
lea    0xda4(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xd23(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0x8(%rsp),%rdi
call   10a0 <Imprime@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.nodo = type { i32 }
@.str = [18 x i8] c"Lista de nodos:\0A\09\00"
@.str.1 = [43 x i8] c"Digite o valor de um nodo a ser inserido: \00"
@.str.2 = [3 x i8] c"%i\00"
@.str.3 = [49 x i8] c"Foram inseridos %i nodos com o valor indormado.\0A\00"
@.str.4 = [51 x i8] c"O valor sorteado %i n\C3\A3o foi encontrado na lista.\0A\00"
@.str.5 = [62 x i8] c"O valor sorteado %i foi encontrado na posi\C3\A7\C3\A3o %i da lista.\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca %struct.nodo*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %1
store %struct.nodo* null, %struct.nodo** %3
%9 = call i32 @time(i32* null)
%10 = call i32 @srand(i32 %9)
store i32 0, i32* %2
br label %11
11: ; preds = %27, %0
%12 = load i32, i32* %2
%13 = icmp slt i32 %12, 20
br i1 %13, label %14, label %30
14: ; preds = %11
%15 = call i32 (...) @rand()
%16 = srem i32 %15, 101
store i32 %16, i32* %4
%17 = load i32, i32* %4
%18 = srem i32 %17, 2
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %23
20: ; preds = %14
%21 = load i32, i32* %4
%22 = call i32 @InsereDireita(%struct.nodo** %3, i32 %21)
br label %26
23: ; preds = %14
%24 = load i32, i32* %4
%25 = call i32 @InsereEsquerda(%struct.nodo** %3, i32 %24)
br label %26
26: ; preds = %23, %20
br label %27
27: ; preds = %26
%28 = load i32, i32* %2
%29 = add nsw i32 %28, 1
store i32 %29, i32* %2
br label %11
30: ; preds = %11
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%32 = call i32 @Imprime(%struct.nodo** %3)
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.1, i64 0, i64 0))
%34 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %5)
%35 = load i32, i32* %5
%36 = load i32, i32* %5
%37 = mul nsw i32 %35, %36
%38 = load i32, i32* %5
%39 = call i32 @InsereNodoDepois(%struct.nodo** %3, i32 %37, i32 %38)
store i32 %39, i32* %6
%40 = load i32, i32* %6
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.3, i64 0, i64 0), i32 %40)
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%43 = call i32 @Imprime(%struct.nodo** %3)
%44 = call i32 (...) @rand()
%45 = srem i32 %44, 101
store i32 %45, i32* %7
%46 = load i32, i32* %7
%47 = call i32 @PesquisaValor(%struct.nodo** %3, i32 %46)
store i32 %47, i32* %8
%48 = load i32, i32* %8
%49 = icmp eq i32 %48, -1
br i1 %49, label %50, label %53
50: ; preds = %30
%51 = load i32, i32* %7
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.4, i64 0, i64 0), i32 %51)
br label %57
53: ; preds = %30
%54 = load i32, i32* %7
%55 = load i32, i32* %8
%56 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([62 x i8], [62 x i8]* @.str.5, i64 0, i64 0), i32 %54, i32 %55)
br label %57
57: ; preds = %53, %50
%58 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%59 = call i32 @Imprime(%struct.nodo** %3)
ret i32 0
}

LLVM IR (-O2):
%struct.nodo = type { i32 }
@.str = [18 x i8] c"Lista de nodos:\0A\09\00"
@.str.1 = [43 x i8] c"Digite o valor de um nodo a ser inserido: \00"
@.str.2 = [3 x i8] c"%i\00"
@.str.3 = [49 x i8] c"Foram inseridos %i nodos com o valor indormado.\0A\00"
@.str.4 = [51 x i8] c"O valor sorteado %i n\C3\A3o foi encontrado na lista.\0A\00"
@.str.5 = [62 x i8] c"O valor sorteado %i foi encontrado na posi\C3\A7\C3\A3o %i da lista.\0A\00"
define i32 @main() {
%1 = alloca %struct.nodo*
%2 = alloca i32
%3 = bitcast %struct.nodo** %1 to i8*
store %struct.nodo* null, %struct.nodo** %1
%4 = tail call i32 @time(i32* null)
%5 = tail call i32 @srand(i32 %4)
br label %6
6: ; preds = %0, %16
%7 = phi i32 [ 0, %0 ], [ %17, %16 ]
%8 = call i32 (...) @rand()
%9 = srem i32 %8, 101
%10 = and i32 %9, 1
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %6
%13 = call i32 @InsereDireita(%struct.nodo** %1, i32 %9)
br label %16
14: ; preds = %6
%15 = call i32 @InsereEsquerda(%struct.nodo** %1, i32 %9)
br label %16
16: ; preds = %14, %12
%17 = add nuw nsw i32 %7, 1
%18 = icmp eq i32 %17, 20
br i1 %18, label %19, label %6
19: ; preds = %16
%20 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%21 = call i32 @Imprime(%struct.nodo** %1)
%22 = bitcast i32* %2 to i8*
%23 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @.str.1, i64 0, i64 0))
%24 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %2)
%25 = load i32, i32* %2
%26 = mul nsw i32 %25, %25
%27 = call i32 @InsereNodoDepois(%struct.nodo** %1, i32 %26, i32 %25)
%28 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([49 x i8], [49 x i8]* @.str.3, i64 0, i64 0), i32 %27)
%29 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%30 = call i32 @Imprime(%struct.nodo** %1)
%31 = call i32 (...) @rand()
%32 = srem i32 %31, 101
%33 = call i32 @PesquisaValor(%struct.nodo** %1, i32 %32)
%34 = icmp eq i32 %33, -1
br i1 %34, label %35, label %37
35: ; preds = %19
%36 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([51 x i8], [51 x i8]* @.str.4, i64 0, i64 0), i32 %32)
br label %39
37: ; preds = %19
%38 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([62 x i8], [62 x i8]* @.str.5, i64 0, i64 0), i32 %32, i32 %33)
br label %39
39: ; preds = %37, %35
%40 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%41 = call i32 @Imprime(%struct.nodo** %1)
ret i32 0
}