#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 /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ assert(int);
int atoi(char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ free(int *);
int *malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sort(int *, int);
int main(int argc, char **argv) {
  int *vals;
  int i;
  char buf[32];
  FILE *fp = 0;
  int num;
  if (argc < 2) {
    printf("usage: %s <file>\n", argv[0]);
    printf("  first line of <file> contains # of integers in file, one per "
           "line.\n");
    exit(-1);
  }
  fp = fopen(argv[1], "r");
  fgets((char *)&buf, 32, fp);
  num = atoi(buf);
  vals = malloc(num * sizeof(int *));
  for (i = 0; i < num; i++) {
    fgets((char *)&buf, 32, fp);
    vals[i] = atoi(buf);
  }
  fclose(fp);
  sort(vals, num);
  for (i = 0; i < num - 1; i++) {
    assert(vals[i] <= vals[i + 1]);
  }
  free(vals);
  printf("Integers properly sorted.\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x48(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    11f5 <main+0x55>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe2a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe2e(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0xffffffff,%edi
call   10c0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe54(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x48(%rbp)
lea    -0x40(%rbp),%rdi
mov    -0x48(%rbp),%rdx
mov    $0x20,%esi
call   1070 <fgets@plt>
lea    -0x40(%rbp),%rdi
call   10b0 <atoi@plt>
mov    %eax,-0x4c(%rbp)
movslq -0x4c(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1090 <malloc@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x4c(%rbp),%eax
jge    1287 <main+0xe7>
lea    -0x40(%rbp),%rdi
mov    -0x48(%rbp),%rdx
mov    $0x20,%esi
call   1070 <fgets@plt>
lea    -0x40(%rbp),%rdi
call   10b0 <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    1245 <main+0xa5>
mov    -0x48(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x18(%rbp),%rdi
mov    -0x4c(%rbp),%esi
call   1060 <sort@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    -0x4c(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    12ea <main+0x14a>
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    -0x18(%rbp),%rcx
mov    -0x1c(%rbp),%edx
add    $0x1,%edx
movslq %edx,%rdx
cmp    (%rcx,%rdx,4),%eax
setle  %al
and    $0x1,%al
movzbl %al,%edi
call   1080 <assert@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    12a3 <main+0x103>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
lea    0xd60(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
cmp    $0x1,%edi
jle    12b3 <main+0x103>
mov    0x8(%rsi),%rdi
lea    0xe40(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,%r15
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x20,%esi
mov    %rax,%rdx
call   1080 <fgets@plt>
mov    %rbx,%rdi
call   10c0 <atoi@plt>
mov    %eax,%r14d
lea    0x0(,%r14,8),%edi
call   10a0 <malloc@plt>
mov    %rax,%rbx
test   %r14d,%r14d
jle    1244 <main+0x94>
mov    %r14d,%r13d
xor    %ebp,%ebp
mov    %rsp,%r12
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r12,%rdi
mov    $0x20,%esi
mov    %r15,%rdx
call   1080 <fgets@plt>
mov    %r12,%rdi
call   10c0 <atoi@plt>
mov    %eax,(%rbx,%rbp,4)
add    $0x1,%rbp
cmp    %rbp,%r13
jne    1220 <main+0x70>
mov    %r15,%rdi
call   1050 <fclose@plt>
mov    %rbx,%rdi
mov    %r14d,%esi
call   1070 <sort@plt>
cmp    $0x2,%r14d
jl     128e <main+0xde>
add    $0xffffffff,%r14d
xor    %eax,%eax
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    (%rbx,%rax,4),%ecx
lea    0x1(%rax),%rbp
xor    %edi,%edi
cmp    0x4(%rbx,%rax,4),%ecx
setle  %dil
call   1090 <assert@plt>
mov    %rbp,%rax
cmp    %rbp,%r14
jne    1270 <main+0xc0>
mov    %rbx,%rdi
call   1030 <free@plt>
lea    0xd77(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    (%rsi),%rsi
lea    0xd43(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xd63(%rip),%rdi
call   1040 <puts@plt>
mov    $0xffffffff,%edi
call   10d0 <exit@plt>

LLVM IR (-O0):
@.str = [18 x i8] c"usage: %s <file>\0A\00"
@.str.1 = [70 x i8] c" first line of <file> contains # of integers in file, one per line.\0A\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [27 x i8] c"Integers properly sorted.\0A\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 [32 x i8]
%9 = alloca i32*
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32* null, i32** %9
%11 = load i32, i32* %4
%12 = icmp slt i32 %11, 2
br i1 %12, label %13, label %20
13: ; preds = %2
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 0
%16 = load i8*, i8** %15
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %16)
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([70 x i8], [70 x i8]* @.str.1, i64 0, i64 0))
%19 = call i32 @exit(i32 -1)
unreachable
20: ; preds = %2
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 1
%23 = load i8*, i8** %22
%24 = call i32* @fopen(i8* %23, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %24, i32** %9
%25 = bitcast [32 x i8]* %8 to i8*
%26 = load i32*, i32** %9
%27 = call i32 @fgets(i8* %25, i32 32, i32* %26)
%28 = getelementptr inbounds [32 x i8], [32 x i8]* %8, i64 0, i64 0
%29 = call i32 @atoi(i8* %28)
store i32 %29, i32* %10
%30 = load i32, i32* %10
%31 = sext i32 %30 to i64
%32 = mul i64 %31, 8
%33 = trunc i64 %32 to i32
%34 = call i32* @malloc(i32 %33)
store i32* %34, i32** %6
store i32 0, i32* %7
br label %35
35: ; preds = %49, %20
%36 = load i32, i32* %7
%37 = load i32, i32* %10
%38 = icmp slt i32 %36, %37
br i1 %38, label %39, label %52
39: ; preds = %35
%40 = bitcast [32 x i8]* %8 to i8*
%41 = load i32*, i32** %9
%42 = call i32 @fgets(i8* %40, i32 32, i32* %41)
%43 = getelementptr inbounds [32 x i8], [32 x i8]* %8, i64 0, i64 0
%44 = call i32 @atoi(i8* %43)
%45 = load i32*, i32** %6
%46 = load i32, i32* %7
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds i32, i32* %45, i64 %47
store i32 %44, i32* %48
br label %49
49: ; preds = %39
%50 = load i32, i32* %7
%51 = add nsw i32 %50, 1
store i32 %51, i32* %7
br label %35
52: ; preds = %35
%53 = load i32*, i32** %9
%54 = call i32 @fclose(i32* %53)
%55 = load i32*, i32** %6
%56 = load i32, i32* %10
%57 = call i32 @sort(i32* %55, i32 %56)
store i32 0, i32* %7
br label %58
58: ; preds = %78, %52
%59 = load i32, i32* %7
%60 = load i32, i32* %10
%61 = sub nsw i32 %60, 1
%62 = icmp slt i32 %59, %61
br i1 %62, label %63, label %81
63: ; preds = %58
%64 = load i32*, i32** %6
%65 = load i32, i32* %7
%66 = sext i32 %65 to i64
%67 = getelementptr inbounds i32, i32* %64, i64 %66
%68 = load i32, i32* %67
%69 = load i32*, i32** %6
%70 = load i32, i32* %7
%71 = add nsw i32 %70, 1
%72 = sext i32 %71 to i64
%73 = getelementptr inbounds i32, i32* %69, i64 %72
%74 = load i32, i32* %73
%75 = icmp sle i32 %68, %74
%76 = zext i1 %75 to i32
%77 = call i32 @assert(i32 %76)
br label %78
78: ; preds = %63
%79 = load i32, i32* %7
%80 = add nsw i32 %79, 1
store i32 %80, i32* %7
br label %58
81: ; preds = %58
%82 = load i32*, i32** %6
%83 = call i32 @free(i32* %82)
%84 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str = [18 x i8] c"usage: %s <file>\0A\00"
@.str.2 = [2 x i8] c"r\00"
@str = [26 x i8] c"Integers properly sorted.\00"
@str.4 = [69 x i8] c" first line of <file> contains # of integers in file, one per line.\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [32 x i8]
%4 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 0
%5 = icmp slt i32 %0, 2
br i1 %5, label %6, label %11
6: ; preds = %2
%7 = load i8*, i8** %1
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %7)
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([69 x i8], [69 x i8]* @str.4, i64 0, i64 0))
%10 = tail call i32 @exit(i32 -1)
unreachable
11: ; preds = %2
%12 = getelementptr inbounds i8*, i8** %1, i64 1
%13 = load i8*, i8** %12
%14 = tail call i32* @fopen(i8* %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%15 = call i32 @fgets(i8* %4, i32 32, i32* %14)
%16 = call i32 @atoi(i8* %4)
%17 = shl i32 %16, 3
%18 = call i32* @malloc(i32 %17)
%19 = icmp sgt i32 %16, 0
br i1 %19, label %20, label %29
20: ; preds = %11
%21 = zext i32 %16 to i64
br label %22
22: ; preds = %20, %22
%23 = phi i64 [ 0, %20 ], [ %27, %22 ]
%24 = call i32 @fgets(i8* %4, i32 32, i32* %14)
%25 = call i32 @atoi(i8* %4)
%26 = getelementptr inbounds i32, i32* %18, i64 %23
store i32 %25, i32* %26
%27 = add nuw nsw i64 %23, 1
%28 = icmp eq i64 %27, %21
br i1 %28, label %29, label %22
29: ; preds = %22, %11
%30 = call i32 @fclose(i32* %14)
%31 = call i32 @sort(i32* %18, i32 %16)
%32 = icmp sgt i32 %16, 1
br i1 %32, label %33, label %47
33: ; preds = %29
%34 = add nsw i32 %16, -1
%35 = zext i32 %34 to i64
br label %36
36: ; preds = %33, %36
%37 = phi i64 [ 0, %33 ], [ %40, %36 ]
%38 = getelementptr inbounds i32, i32* %18, i64 %37
%39 = load i32, i32* %38
%40 = add nuw nsw i64 %37, 1
%41 = getelementptr inbounds i32, i32* %18, i64 %40
%42 = load i32, i32* %41
%43 = icmp sle i32 %39, %42
%44 = zext i1 %43 to i32
%45 = call i32 @assert(i32 %44)
%46 = icmp eq i64 %40, %35
br i1 %46, label %47, label %36
47: ; preds = %36, %29
%48 = call i32 @free(i32* %18)
%49 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str, i64 0, i64 0))
ret i32 0
}