#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 *bubblesort(int *, int);
int busqueda_binaria(int *, int /*<<< orphan*/, int, int);
int /*<<< orphan*/ free(int *);
int *malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ quicksort(int *, int /*<<< orphan*/, int);
int rand();
int /*<<< orphan*/ scanf(char *, int *);
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int main() {
  srand(time(NULL));
  int i, num;
  int dim = 1000;
  int *arreglo;
  arreglo = malloc(dim * sizeof(int));
  for (i = 0; i < dim; i++) {
    arreglo[i] = rand() % dim;
  }
  int num_search = 500;
  num = rand() % dim;
  arreglo[num] = num_search;
  printf("\nArreglo desordenado:\n\n");
  for (i = 0; i < dim; i++) {
    printf("%d, ", arreglo[i]);
  }
  printf("\n");
  printf("Ingrese 0 para bubblesort.\nIngrese 1 para quicksort\n");
  int opcion;
  scanf(" %d", &opcion);
  if (opcion == 0) {
    arreglo = bubblesort(arreglo, dim);
  } else if (opcion == 1) {
    quicksort(arreglo, 0, dim - 1);
  }
  printf("\nArreglo ordenado:\n\n");
  for (i = 0; i < dim; i++) {
    printf("%d, ", arreglo[i]);
  }
  printf("\n");
  printf("\nBúsqueda binaria:\n");
  int pos = busqueda_binaria(arreglo, 0, dim - 1, num_search);
  if (pos < 0) {
    printf("Número no encontrado\n");
  } else {
    printf("El índice del número es %d\n", pos);
    printf("Verificación:\tarreglo[%d]=%d\n", pos, arreglo[pos]);
  }
  free(arreglo);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1070 <time@plt>
mov    %eax,%edi
call   1060 <srand@plt>
movl   $0x3e8,-0x10(%rbp)
movslq -0x10(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1080 <malloc@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    1210 <main+0x70>
mov    $0x0,%al
call   10c0 <rand@plt>
cltd
idivl  -0x10(%rbp)
mov    -0x18(%rbp),%rax
movslq -0x8(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    11e0 <main+0x40>
movl   $0x1f4,-0x1c(%rbp)
mov    $0x0,%al
call   10c0 <rand@plt>
cltd
idivl  -0x10(%rbp)
mov    %edx,-0xc(%rbp)
mov    -0x1c(%rbp),%edx
mov    -0x18(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
lea    0xdc6(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    127b <main+0xdb>
mov    -0x18(%rbp),%rax
movslq -0x8(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xdb2(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1248 <main+0xa8>
lea    0xde7(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xd8d(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xdb4(%rip),%rdi
lea    -0x20(%rbp),%rsi
call   10a0 <scanf@plt>
cmpl   $0x0,-0x20(%rbp)
jne    12c6 <main+0x126>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%esi
call   10b0 <bubblesort@plt>
mov    %rax,-0x18(%rbp)
jmp    12e6 <main+0x146>
cmpl   $0x1,-0x20(%rbp)
jne    12e1 <main+0x141>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%edx
sub    $0x1,%edx
xor    %esi,%esi
call   1040 <quicksort@plt>
jmp    12e6 <main+0x146>
lea    0xd69(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    132e <main+0x18e>
mov    -0x18(%rbp),%rax
movslq -0x8(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xcff(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    12fb <main+0x15b>
lea    0xd34(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xd28(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%edx
sub    $0x1,%edx
mov    -0x1c(%rbp),%ecx
xor    %esi,%esi
call   1090 <busqueda_binaria@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    137e <main+0x1de>
lea    0xd0e(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    13ab <main+0x20b>
mov    -0x24(%rbp),%esi
lea    0xd0f(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x24(%rbp),%esi
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
lea    0xd11(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
xor    %edi,%edi
call   1090 <time@plt>
mov    %eax,%edi
call   1080 <srand@plt>
mov    $0xfa0,%edi
call   10a0 <malloc@plt>
mov    %rax,%rbx
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nop
xor    %eax,%eax
call   10e0 <rand@plt>
cltq
imul   $0x10624dd3,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x26,%rcx
add    %edx,%ecx
imul   $0x3e8,%ecx,%ecx
sub    %ecx,%eax
mov    %eax,(%rbx,%rbp,4)
add    $0x1,%rbp
cmp    $0x3e8,%rbp
jne    11f0 <main+0x30>
xor    %eax,%eax
call   10e0 <rand@plt>
cltq
imul   $0x10624dd3,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x26,%rcx
add    %edx,%ecx
imul   $0x3e8,%ecx,%ecx
sub    %ecx,%eax
cltq
movl   $0x1f4,(%rbx,%rax,4)
lea    0xdec(%rip),%rdi
call   1050 <puts@plt>
lea    0xd9a(%rip),%r14
xor    %ebp,%ebp
nopl   0x0(%rax,%rax,1)
mov    (%rbx,%rbp,4),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1070 <printf@plt>
add    $0x1,%rbp
cmp    $0x3e8,%rbp
jne    1270 <main+0xb0>
mov    $0xa,%edi
call   1040 <putchar@plt>
lea    0xdc2(%rip),%rdi
call   1050 <puts@plt>
lea    0xd5e(%rip),%rdi
lea    0xc(%rsp),%rsi
call   10c0 <scanf@plt>
mov    0xc(%rsp),%eax
test   %eax,%eax
je     12cf <main+0x10f>
cmp    $0x1,%eax
jne    12df <main+0x11f>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x3e7,%edx
call   1060 <quicksort@plt>
jmp    12df <main+0x11f>
mov    %rbx,%rdi
mov    $0x3e8,%esi
call   10d0 <bubblesort@plt>
mov    %rax,%rbx
lea    0xdab(%rip),%rdi
call   1050 <puts@plt>
lea    0xd0e(%rip),%r14
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    (%rbx,%rbp,4),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1070 <printf@plt>
add    $0x1,%rbp
cmp    $0x3e8,%rbp
jne    1300 <main+0x140>
mov    $0xa,%edi
call   1040 <putchar@plt>
lea    0xd7a(%rip),%rdi
call   1050 <puts@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x3e7,%edx
mov    $0x1f4,%ecx
call   10b0 <busqueda_binaria@plt>
test   %eax,%eax
js     1371 <main+0x1b1>
mov    %eax,%ebp
lea    0xcb8(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %ebp,%eax
mov    (%rbx,%rax,4),%edx
lea    0xcc1(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1070 <printf@plt>
jmp    137d <main+0x1bd>
lea    0xd41(%rip),%rdi
call   1050 <puts@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [24 x i8] c"\0AArreglo desordenado:\0A\0A\00"
@.str.1 = [5 x i8] c"%d, \00"
@.str.2 = [2 x i8] c"\0A\00"
@.str.3 = [53 x i8] c"Ingrese 0 para bubblesort.\0AIngrese 1 para quicksort\0A\00"
@.str.4 = [4 x i8] c" %d\00"
@.str.5 = [21 x i8] c"\0AArreglo ordenado:\0A\0A\00"
@.str.6 = [21 x i8] c"\0AB\C3\BAsqueda binaria:\0A\00"
@.str.7 = [23 x i8] c"N\C3\BAmero no encontrado\0A\00"
@.str.8 = [30 x i8] c"El \C3\ADndice del n\C3\BAmero es %d\0A\00"
@.str.9 = [31 x i8] c"Verificaci\C3\B3n:\09arreglo[%d]=%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %1
%9 = call i32 @time(i32* null)
%10 = call i32 @srand(i32 %9)
store i32 1000, i32* %4
%11 = load i32, i32* %4
%12 = sext i32 %11 to i64
%13 = mul i64 %12, 4
%14 = trunc i64 %13 to i32
%15 = call i32* @malloc(i32 %14)
store i32* %15, i32** %5
store i32 0, i32* %2
br label %16
16: ; preds = %28, %0
%17 = load i32, i32* %2
%18 = load i32, i32* %4
%19 = icmp slt i32 %17, %18
br i1 %19, label %20, label %31
20: ; preds = %16
%21 = call i32 (...) @rand()
%22 = load i32, i32* %4
%23 = srem i32 %21, %22
%24 = load i32*, i32** %5
%25 = load i32, i32* %2
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i32, i32* %24, i64 %26
store i32 %23, i32* %27
br label %28
28: ; preds = %20
%29 = load i32, i32* %2
%30 = add nsw i32 %29, 1
store i32 %30, i32* %2
br label %16
31: ; preds = %16
store i32 500, i32* %6
%32 = call i32 (...) @rand()
%33 = load i32, i32* %4
%34 = srem i32 %32, %33
store i32 %34, i32* %3
%35 = load i32, i32* %6
%36 = load i32*, i32** %5
%37 = load i32, i32* %3
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i32, i32* %36, i64 %38
store i32 %35, i32* %39
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %2
br label %41
41: ; preds = %52, %31
%42 = load i32, i32* %2
%43 = load i32, i32* %4
%44 = icmp slt i32 %42, %43
br i1 %44, label %45, label %55
45: ; preds = %41
%46 = load i32*, i32** %5
%47 = load i32, i32* %2
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds i32, i32* %46, i64 %48
%50 = load i32, i32* %49
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %50)
br label %52
52: ; preds = %45
%53 = load i32, i32* %2
%54 = add nsw i32 %53, 1
store i32 %54, i32* %2
br label %41
55: ; preds = %41
%56 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%57 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.3, i64 0, i64 0))
%58 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32* %7)
%59 = load i32, i32* %7
%60 = icmp eq i32 %59, 0
br i1 %60, label %61, label %65
61: ; preds = %55
%62 = load i32*, i32** %5
%63 = load i32, i32* %4
%64 = call i32* @bubblesort(i32* %62, i32 %63)
store i32* %64, i32** %5
br label %74
65: ; preds = %55
%66 = load i32, i32* %7
%67 = icmp eq i32 %66, 1
br i1 %67, label %68, label %73
68: ; preds = %65
%69 = load i32*, i32** %5
%70 = load i32, i32* %4
%71 = sub nsw i32 %70, 1
%72 = call i32 @quicksort(i32* %69, i32 0, i32 %71)
br label %73
73: ; preds = %68, %65
br label %74
74: ; preds = %73, %61
%75 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0))
store i32 0, i32* %2
br label %76
76: ; preds = %87, %74
%77 = load i32, i32* %2
%78 = load i32, i32* %4
%79 = icmp slt i32 %77, %78
br i1 %79, label %80, label %90
80: ; preds = %76
%81 = load i32*, i32** %5
%82 = load i32, i32* %2
%83 = sext i32 %82 to i64
%84 = getelementptr inbounds i32, i32* %81, i64 %83
%85 = load i32, i32* %84
%86 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %85)
br label %87
87: ; preds = %80
%88 = load i32, i32* %2
%89 = add nsw i32 %88, 1
store i32 %89, i32* %2
br label %76
90: ; preds = %76
%91 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%92 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.6, i64 0, i64 0))
%93 = load i32*, i32** %5
%94 = load i32, i32* %4
%95 = sub nsw i32 %94, 1
%96 = load i32, i32* %6
%97 = call i32 @busqueda_binaria(i32* %93, i32 0, i32 %95, i32 %96)
store i32 %97, i32* %8
%98 = load i32, i32* %8
%99 = icmp slt i32 %98, 0
br i1 %99, label %100, label %102
100: ; preds = %90
%101 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.7, i64 0, i64 0))
br label %112
102: ; preds = %90
%103 = load i32, i32* %8
%104 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.8, i64 0, i64 0), i32 %103)
%105 = load i32, i32* %8
%106 = load i32*, i32** %5
%107 = load i32, i32* %8
%108 = sext i32 %107 to i64
%109 = getelementptr inbounds i32, i32* %106, i64 %108
%110 = load i32, i32* %109
%111 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.9, i64 0, i64 0), i32 %105, i32 %110)
br label %112
112: ; preds = %102, %100
%113 = load i32*, i32** %5
%114 = call i32 @free(i32* %113)
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [5 x i8] c"%d, \00"
@.str.4 = [4 x i8] c" %d\00"
@.str.8 = [30 x i8] c"El \C3\ADndice del n\C3\BAmero es %d\0A\00"
@.str.9 = [31 x i8] c"Verificaci\C3\B3n:\09arreglo[%d]=%d\0A\00"
@str = [23 x i8] c"\0AArreglo desordenado:\0A\00"
@str.10 = [52 x i8] c"Ingrese 0 para bubblesort.\0AIngrese 1 para quicksort\00"
@str.11 = [20 x i8] c"\0AArreglo ordenado:\0A\00"
@str.12 = [20 x i8] c"\0AB\C3\BAsqueda binaria:\00"
@str.13 = [22 x i8] c"N\C3\BAmero no encontrado\00"
define i32 @main() {
%1 = alloca i32
%2 = tail call i32 @time(i32* null)
%3 = tail call i32 @srand(i32 %2)
%4 = tail call i32* @malloc(i32 4000)
br label %5
5: ; preds = %0, %5
%6 = phi i64 [ 0, %0 ], [ %10, %5 ]
%7 = tail call i32 (...) @rand()
%8 = srem i32 %7, 1000
%9 = getelementptr inbounds i32, i32* %4, i64 %6
store i32 %8, i32* %9
%10 = add nuw nsw i64 %6, 1
%11 = icmp eq i64 %10, 1000
br i1 %11, label %12, label %5
12: ; preds = %5
%13 = tail call i32 (...) @rand()
%14 = srem i32 %13, 1000
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds i32, i32* %4, i64 %15
store i32 500, i32* %16
%17 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str, i64 0, i64 0))
br label %18
18: ; preds = %12, %18
%19 = phi i64 [ 0, %12 ], [ %23, %18 ]
%20 = getelementptr inbounds i32, i32* %4, i64 %19
%21 = load i32, i32* %20
%22 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %21)
%23 = add nuw nsw i64 %19, 1
%24 = icmp eq i64 %23, 1000
br i1 %24, label %25, label %18
25: ; preds = %18
%26 = tail call i32 @putchar(i32 10)
%27 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([52 x i8], [52 x i8]* @str.10, i64 0, i64 0))
%28 = bitcast i32* %1 to i8*
%29 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32* %1)
%30 = load i32, i32* %1
switch i32 %30, label %35 [
i32 0, label %31
i32 1, label %33
]
31: ; preds = %25
%32 = call i32* @bubblesort(i32* %4, i32 1000)
br label %35
33: ; preds = %25
%34 = call i32 @quicksort(i32* %4, i32 0, i32 999)
br label %35
35: ; preds = %25, %33, %31
%36 = phi i32* [ %32, %31 ], [ %4, %33 ], [ %4, %25 ]
%37 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str.11, i64 0, i64 0))
br label %38
38: ; preds = %35, %38
%39 = phi i64 [ 0, %35 ], [ %43, %38 ]
%40 = getelementptr inbounds i32, i32* %36, i64 %39
%41 = load i32, i32* %40
%42 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %41)
%43 = add nuw nsw i64 %39, 1
%44 = icmp eq i64 %43, 1000
br i1 %44, label %45, label %38
45: ; preds = %38
%46 = call i32 @putchar(i32 10)
%47 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str.12, i64 0, i64 0))
%48 = call i32 @busqueda_binaria(i32* %36, i32 0, i32 999, i32 500)
%49 = icmp slt i32 %48, 0
br i1 %49, label %50, label %52
50: ; preds = %45
%51 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str.13, i64 0, i64 0))
br label %58
52: ; preds = %45
%53 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.8, i64 0, i64 0), i32 %48)
%54 = zext i32 %48 to i64
%55 = getelementptr inbounds i32, i32* %36, i64 %54
%56 = load i32, i32* %55
%57 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.9, i64 0, i64 0), i32 %48, i32 %56)
br label %58
58: ; preds = %52, %50
%59 = call i32 @free(i32* %36)
ret i32 0
}