#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 */
typedef int int64_t;

/* Variables and functions */
int input();
int *malloc(int);
int /*<<< orphan*/ output(int);
int sort(int *, int);
int64_t test(int64_t i2) {
  int64_t len = 0;
  int64_t *a;
  int64_t i = 0;
  int64_t y = 0;
  len = input();
  a = malloc(len * sizeof(int64_t));
  while (i < len) {
    int64_t y = input();
    a[i] = y;
    i = i + 1;
  }
  i = sort(a, len);
  i = 0;
  while (i < len) {
    int64_t y = a[i];
    output(y);
    i = i + 1;
  }
  return i;
}


x86 assembly (clang, -O0):
<test>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    $0x0,%al
call   1030 <input@plt>
mov    %eax,-0x8(%rbp)
movslq -0x8(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11af <test+0x6f>
mov    $0x0,%al
call   1030 <input@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%edx
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    117d <test+0x3d>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%esi
call   1050 <sort@plt>
mov    %eax,-0x14(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11f5 <test+0xb5>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%edi
call   1040 <output@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11c5 <test+0x85>
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
xor    %ebp,%ebp
xor    %eax,%eax
call   1030 <input@plt>
mov    %eax,%r14d
lea    0x0(,%r14,4),%edi
call   1060 <malloc@plt>
mov    %rax,%r15
test   %r14d,%r14d
jle    11b7 <test+0x77>
mov    %r14d,%ebp
xor    %ebx,%ebx
nopl   (%rax)
xor    %eax,%eax
call   1030 <input@plt>
mov    %eax,(%r15,%rbx,4)
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1170 <test+0x30>
mov    %r15,%rdi
mov    %r14d,%esi
call   1050 <sort@plt>
test   %r14d,%r14d
jle    11c4 <test+0x84>
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
mov    (%r15,%rbx,4),%edi
call   1040 <output@plt>
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    11a0 <test+0x60>
mov    %r14d,%ebp
jmp    11c6 <test+0x86>
mov    %r15,%rdi
mov    %r14d,%esi
call   1050 <sort@plt>
jmp    11c6 <test+0x86>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @test(i32 %0) {
%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* %2
store i32 0, i32* %3
store i32 0, i32* %5
store i32 0, i32* %6
%9 = call i32 (...) @input()
store i32 %9, i32* %3
%10 = load i32, i32* %3
%11 = sext i32 %10 to i64
%12 = mul i64 %11, 4
%13 = trunc i64 %12 to i32
%14 = call i32* @malloc(i32 %13)
store i32* %14, i32** %4
br label %15
15: ; preds = %19, %1
%16 = load i32, i32* %5
%17 = load i32, i32* %3
%18 = icmp slt i32 %16, %17
br i1 %18, label %19, label %28
19: ; preds = %15
%20 = call i32 (...) @input()
store i32 %20, i32* %7
%21 = load i32, i32* %7
%22 = load i32*, i32** %4
%23 = load i32, i32* %5
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i32, i32* %22, i64 %24
store i32 %21, i32* %25
%26 = load i32, i32* %5
%27 = add nsw i32 %26, 1
store i32 %27, i32* %5
br label %15
28: ; preds = %15
%29 = load i32*, i32** %4
%30 = load i32, i32* %3
%31 = call i32 @sort(i32* %29, i32 %30)
store i32 %31, i32* %5
store i32 0, i32* %5
br label %32
32: ; preds = %36, %28
%33 = load i32, i32* %5
%34 = load i32, i32* %3
%35 = icmp slt i32 %33, %34
br i1 %35, label %36, label %46
36: ; preds = %32
%37 = load i32*, i32** %4
%38 = load i32, i32* %5
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i32, i32* %37, i64 %39
%41 = load i32, i32* %40
store i32 %41, i32* %8
%42 = load i32, i32* %8
%43 = call i32 @output(i32 %42)
%44 = load i32, i32* %5
%45 = add nsw i32 %44, 1
store i32 %45, i32* %5
br label %32
46: ; preds = %32
%47 = load i32, i32* %5
ret i32 %47
}

LLVM IR (-O2):
define i32 @test(i32 %0) {
%2 = tail call i32 (...) @input()
%3 = shl i32 %2, 2
%4 = tail call i32* @malloc(i32 %3)
%5 = icmp sgt i32 %2, 0
br i1 %5, label %8, label %6
6: ; preds = %1
%7 = tail call i32 @sort(i32* %4, i32 %2)
br label %27
8: ; preds = %1
%9 = zext i32 %2 to i64
br label %10
10: ; preds = %8, %10
%11 = phi i64 [ 0, %8 ], [ %14, %10 ]
%12 = tail call i32 (...) @input()
%13 = getelementptr inbounds i32, i32* %4, i64 %11
store i32 %12, i32* %13
%14 = add nuw nsw i64 %11, 1
%15 = icmp eq i64 %14, %9
br i1 %15, label %16, label %10
16: ; preds = %10
%17 = tail call i32 @sort(i32* %4, i32 %2)
br i1 %5, label %18, label %27
18: ; preds = %16
%19 = zext i32 %2 to i64
br label %20
20: ; preds = %18, %20
%21 = phi i64 [ 0, %18 ], [ %25, %20 ]
%22 = getelementptr inbounds i32, i32* %4, i64 %21
%23 = load i32, i32* %22
%24 = tail call i32 @output(i32 %23)
%25 = add nuw nsw i64 %21, 1
%26 = icmp eq i64 %25, %19
br i1 %26, label %27, label %20
27: ; preds = %20, %6, %16
%28 = phi i32 [ 0, %16 ], [ 0, %6 ], [ %2, %20 ]
ret i32 %28
}