#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);
int /*<<< orphan*/ closestpair(int *, int);
int /*<<< orphan*/ free(int *);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ scanf(char *, int *);
int main() {
  int i, n, *vet;
  printf("Quantos numeros serao entrados?\n");
  scanf("%d", &n);
  while (n < 2) {
    printf("Favor digitar um numero maior que 1.\n");
    scanf("%d", &n);
  }
  vet = (int *)malloc(n * sizeof(int));
  printf("Digite os numeros: ");
  for (i = 0; i < n; i++)
    scanf("%d", &vet[i]);
  bubble(vet, n);
  printf("\nOs dois elementos com a menor diferenca sao:\n");
  closestpair(vet, n);
  free(vet);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe8a(%rip),%rdi
call   1050 <printf@plt>
lea    0xe9f(%rip),%rdi
lea    -0xc(%rbp),%rsi
call   1070 <scanf@plt>
cmpl   $0x2,-0xc(%rbp)
jge    11b6 <main+0x56>
lea    0xe88(%rip),%rdi
call   1050 <printf@plt>
lea    0xe79(%rip),%rdi
lea    -0xc(%rbp),%rsi
call   1070 <scanf@plt>
jmp    118b <main+0x2b>
movslq -0xc(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x18(%rbp)
lea    0xe7a(%rip),%rdi
call   1050 <printf@plt>
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1211 <main+0xb1>
mov    -0x18(%rbp),%rsi
movslq -0x8(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe23(%rip),%rdi
call   1070 <scanf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    11dc <main+0x7c>
mov    -0x18(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1040 <bubble@plt>
lea    0xe3a(%rip),%rdi
call   1050 <printf@plt>
mov    -0x18(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1080 <closestpair@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
lea    0xe98(%rip),%rdi
call   1040 <puts@plt>
lea    0xe75(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1080 <scanf@plt>
mov    0x4(%rsp),%edi
cmp    $0x1,%edi
jg     11dc <main+0x6c>
lea    0xec0(%rip),%r14
lea    0xe54(%rip),%r15
lea    0x4(%rsp),%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
call   1040 <puts@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1080 <scanf@plt>
mov    0x4(%rsp),%edi
cmp    $0x2,%edi
jl     11c0 <main+0x50>
shl    $0x2,%edi
call   1070 <malloc@plt>
mov    %rax,%r14
lea    0xe15(%rip),%rdi
call   1060 <printf@plt>
mov    0x4(%rsp),%esi
test   %esi,%esi
jle    122d <main+0xbd>
xor    %r12d,%r12d
lea    0xdfb(%rip),%r15
mov    %r14,%rbx
nopl   0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    %rbx,%rsi
call   1080 <scanf@plt>
add    $0x1,%r12
movslq 0x4(%rsp),%rsi
add    $0x4,%rbx
cmp    %rsi,%r12
jl     1210 <main+0xa0>
mov    %r14,%rdi
call   1050 <bubble@plt>
lea    0xdfb(%rip),%rdi
call   1040 <puts@plt>
mov    0x4(%rsp),%esi
mov    %r14,%rdi
call   1090 <closestpair@plt>
mov    %r14,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [33 x i8] c"Quantos numeros serao entrados?\0A\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [38 x i8] c"Favor digitar um numero maior que 1.\0A\00"
@.str.3 = [20 x i8] c"Digite os numeros: \00"
@.str.4 = [47 x i8] c"\0AOs dois elementos com a menor diferenca sao:\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32*
store i32 0, i32* %1
%5 = call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
%6 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
br label %7
7: ; preds = %10, %0
%8 = load i32, i32* %3
%9 = icmp slt i32 %8, 2
br i1 %9, label %10, label %13
10: ; preds = %7
%11 = call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0))
%12 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
br label %7
13: ; preds = %7
%14 = load i32, i32* %3
%15 = sext i32 %14 to i64
%16 = mul i64 %15, 4
%17 = trunc i64 %16 to i32
%18 = call i64 @malloc(i32 %17)
%19 = inttoptr i64 %18 to i32*
store i32* %19, i32** %4
%20 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %2
br label %21
21: ; preds = %31, %13
%22 = load i32, i32* %2
%23 = load i32, i32* %3
%24 = icmp slt i32 %22, %23
br i1 %24, label %25, label %34
25: ; preds = %21
%26 = load i32*, i32** %4
%27 = load i32, i32* %2
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i32, i32* %26, i64 %28
%30 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %29)
br label %31
31: ; preds = %25
%32 = load i32, i32* %2
%33 = add nsw i32 %32, 1
store i32 %33, i32* %2
br label %21
34: ; preds = %21
%35 = load i32*, i32** %4
%36 = load i32, i32* %3
%37 = call i32 @bubble(i32* %35, i32 %36)
%38 = call i32 @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.4, i64 0, i64 0))
%39 = load i32*, i32** %4
%40 = load i32, i32* %3
%41 = call i32 @closestpair(i32* %39, i32 %40)
%42 = load i32*, i32** %4
%43 = call i32 @free(i32* %42)
%44 = load i32, i32* %1
ret i32 %44
}

LLVM IR (-O2):
@.str.1 = [3 x i8] c"%d\00"
@.str.3 = [20 x i8] c"Digite os numeros: \00"
@str = [32 x i8] c"Quantos numeros serao entrados?\00"
@str.5 = [46 x i8] c"\0AOs dois elementos com a menor diferenca sao:\00"
@str.6 = [37 x i8] c"Favor digitar um numero maior que 1.\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @str, i64 0, i64 0))
%4 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%5 = load i32, i32* %1
%6 = icmp slt i32 %5, 2
br i1 %6, label %7, label %12
7: ; preds = %0, %7
%8 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @str.6, i64 0, i64 0))
%9 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%10 = load i32, i32* %1
%11 = icmp slt i32 %10, 2
br i1 %11, label %7, label %12
12: ; preds = %7, %0
%13 = phi i32 [ %5, %0 ], [ %10, %7 ]
%14 = shl i32 %13, 2
%15 = call i64 @malloc(i32 %14)
%16 = inttoptr i64 %15 to i32*
%17 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
%18 = load i32, i32* %1
%19 = icmp sgt i32 %18, 0
br i1 %19, label %20, label %28
20: ; preds = %12, %20
%21 = phi i64 [ %24, %20 ], [ 0, %12 ]
%22 = getelementptr inbounds i32, i32* %16, i64 %21
%23 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %22)
%24 = add nuw nsw i64 %21, 1
%25 = load i32, i32* %1
%26 = sext i32 %25 to i64
%27 = icmp slt i64 %24, %26
br i1 %27, label %20, label %28
28: ; preds = %20, %12
%29 = phi i32 [ %18, %12 ], [ %25, %20 ]
%30 = call i32 @bubble(i32* %16, i32 %29)
%31 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([46 x i8], [46 x i8]* @str.5, i64 0, i64 0))
%32 = load i32, i32* %1
%33 = call i32 @closestpair(i32* %16, i32 %32)
%34 = call i32 @free(i32* %16)
ret i32 0
}