#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 atoi(char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ free(int *);
int *malloc(int);
int /*<<< orphan*/ output(int *, int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ sort(int *, int);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  int *a = NULL;
  int i;
  int size;
  if (argc < 2) {
    fprintf(stderr, "no number input\n");
    exit(2);
  }
  size = argc - 1;
  a = malloc(sizeof(*a) * size);
  if (!a) {
    fprintf(stderr, "oom: want: %lu(num: %d)\n", sizeof(*a) * size, size);
    exit(2);
  }
  for (i = 0; i < size; i++) {
    a[i] = atoi(argv[i + 1]);
  }
  printf("before sort: ");
  output(a, size);
  sort(a, size);
  printf("after sort: ");
  output(a, size);
  free(a);
  a = NULL;
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    11c9 <main+0x49>
mov    0x2e31(%rip),%rax
mov    (%rax),%edi
lea    0xe48(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    $0x2,%edi
call   10a0 <exit@plt>
mov    -0x8(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x20(%rbp)
movslq -0x20(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1080 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    121c <main+0x9c>
mov    0x2de9(%rip),%rax
mov    (%rax),%edi
movslq -0x20(%rbp),%rdx
shl    $0x2,%rdx
mov    -0x20(%rbp),%ecx
lea    0xe06(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    $0x2,%edi
call   10a0 <exit@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x20(%rbp),%eax
jge    1260 <main+0xe0>
mov    -0x10(%rbp),%rax
mov    -0x1c(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rdi
call   1090 <atoi@plt>
mov    %eax,%edx
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1223 <main+0xa3>
lea    0xdc3(%rip),%rdi
call   1050 <printf@plt>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%esi
call   1040 <output@plt>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%esi
call   1060 <sort@plt>
lea    0xdad(%rip),%rdi
call   1050 <printf@plt>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%esi
call   1040 <output@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x18(%rbp)
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
cmp    $0x1,%edi
jle    1227 <main+0xa7>
mov    %rsi,%r13
mov    %edi,%r14d
add    $0xffffffff,%r14d
lea    0x0(,%r14,4),%r12
mov    %r12d,%edi
call   1080 <malloc@plt>
test   %rax,%rax
je     1248 <main+0xc8>
mov    %rax,%r15
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
lea    0x1(%rbx),%r12
mov    0x8(%r13,%rbx,8),%rdi
call   1090 <atoi@plt>
mov    %eax,(%r15,%rbx,4)
mov    %r12,%rbx
cmp    %r12,%r14
jne    11c0 <main+0x40>
lea    0xe49(%rip),%rdi
call   1050 <printf@plt>
mov    %r15,%rdi
mov    %r14d,%esi
call   1040 <output@plt>
mov    %r15,%rdi
mov    %r14d,%esi
call   1060 <sort@plt>
lea    0xe35(%rip),%rdi
call   1050 <printf@plt>
mov    %r15,%rdi
mov    %r14d,%esi
call   1040 <output@plt>
mov    %r15,%rdi
call   1030 <free@plt>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
mov    0x2db2(%rip),%rax
mov    (%rax),%edi
lea    0xdc9(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    $0x2,%edi
call   10a0 <exit@plt>
mov    0x2d91(%rip),%rax
mov    (%rax),%edi
lea    0xdb9(%rip),%rsi
mov    %r12,%rdx
mov    %r14d,%ecx
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    $0x2,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [17 x i8] c"no number input\0A\00"
@.str.1 = [25 x i8] c"oom: want: %lu(num: %d)\0A\00"
@.str.2 = [14 x i8] c"before sort: \00"
@.str.3 = [13 x i8] c"after sort: \00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32* null, i32** %6
%9 = load i32, i32* %4
%10 = icmp slt i32 %9, 2
br i1 %10, label %11, label %15
11: ; preds = %2
%12 = load i32, i32* @stderr
%13 = call i32 (i32, i8*, ...) @fprintf(i32 %12, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%14 = call i32 @exit(i32 2)
unreachable
15: ; preds = %2
%16 = load i32, i32* %4
%17 = sub nsw i32 %16, 1
store i32 %17, i32* %8
%18 = load i32, i32* %8
%19 = sext i32 %18 to i64
%20 = mul i64 4, %19
%21 = trunc i64 %20 to i32
%22 = call i32* @malloc(i32 %21)
store i32* %22, i32** %6
%23 = load i32*, i32** %6
%24 = icmp ne i32* %23, null
br i1 %24, label %33, label %25
25: ; preds = %15
%26 = load i32, i32* @stderr
%27 = load i32, i32* %8
%28 = sext i32 %27 to i64
%29 = mul i64 4, %28
%30 = load i32, i32* %8
%31 = call i32 (i32, i8*, ...) @fprintf(i32 %26, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i64 %29, i32 %30)
%32 = call i32 @exit(i32 2)
unreachable
33: ; preds = %15
store i32 0, i32* %7
br label %34
34: ; preds = %50, %33
%35 = load i32, i32* %7
%36 = load i32, i32* %8
%37 = icmp slt i32 %35, %36
br i1 %37, label %38, label %53
38: ; preds = %34
%39 = load i8**, i8*** %5
%40 = load i32, i32* %7
%41 = add nsw i32 %40, 1
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds i8*, i8** %39, i64 %42
%44 = load i8*, i8** %43
%45 = call i32 @atoi(i8* %44)
%46 = load i32*, i32** %6
%47 = load i32, i32* %7
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds i32, i32* %46, i64 %48
store i32 %45, i32* %49
br label %50
50: ; preds = %38
%51 = load i32, i32* %7
%52 = add nsw i32 %51, 1
store i32 %52, i32* %7
br label %34
53: ; preds = %34
%54 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%55 = load i32*, i32** %6
%56 = load i32, i32* %8
%57 = call i32 @output(i32* %55, i32 %56)
%58 = load i32*, i32** %6
%59 = load i32, i32* %8
%60 = call i32 @sort(i32* %58, i32 %59)
%61 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
%62 = load i32*, i32** %6
%63 = load i32, i32* %8
%64 = call i32 @output(i32* %62, i32 %63)
%65 = load i32*, i32** %6
%66 = call i32 @free(i32* %65)
store i32* null, i32** %6
ret i32 0
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [17 x i8] c"no number input\0A\00"
@.str.1 = [25 x i8] c"oom: want: %lu(num: %d)\0A\00"
@.str.2 = [14 x i8] c"before sort: \00"
@.str.3 = [13 x i8] c"after sort: \00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 2
br i1 %3, label %4, label %8
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = tail call i32 (i32, i8*, ...) @fprintf(i32 %5, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%7 = tail call i32 @exit(i32 2)
unreachable
8: ; preds = %2
%9 = add nsw i32 %0, -1
%10 = zext i32 %9 to i64
%11 = shl nuw nsw i64 %10, 2
%12 = trunc i64 %11 to i32
%13 = tail call i32* @malloc(i32 %12)
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %19
15: ; preds = %8
%16 = load i32, i32* @stderr
%17 = tail call i32 (i32, i8*, ...) @fprintf(i32 %16, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i64 %11, i32 %9)
%18 = tail call i32 @exit(i32 2)
unreachable
19: ; preds = %8, %19
%20 = phi i64 [ %21, %19 ], [ 0, %8 ]
%21 = add nuw nsw i64 %20, 1
%22 = getelementptr inbounds i8*, i8** %1, i64 %21
%23 = load i8*, i8** %22
%24 = tail call i32 @atoi(i8* %23)
%25 = getelementptr inbounds i32, i32* %13, i64 %20
store i32 %24, i32* %25
%26 = icmp eq i64 %21, %10
br i1 %26, label %27, label %19
27: ; preds = %19
%28 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%29 = tail call i32 @output(i32* %13, i32 %9)
%30 = tail call i32 @sort(i32* %13, i32 %9)
%31 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
%32 = tail call i32 @output(i32* %13, i32 %9)
%33 = tail call i32 @free(i32* %13)
ret i32 0
}