#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*/ EXIT_FAILURE;
int /*<<< orphan*/ RadixSort(int *, int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, int *);
int *malloc(int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ print(int *, int);
int /*<<< orphan*/ printf(char *);
int main() {
  int i, TotalNumbers;
  FILE *f;
  f = fopen("numbers.txt", "r");
  if (f == NULL) {
    perror("Error while opening the file\n");
    exit(EXIT_FAILURE);
  }
  fscanf(f, "%d\n", &TotalNumbers);
  int *numbers = malloc(TotalNumbers * sizeof(int));
  for (i = 0; i < TotalNumbers; i++) {
    fscanf(f, "%d", numbers + i);
  }
  printf("\nThe unsorted numbers are  : ");
  print(numbers, TotalNumbers);
  RadixSort(numbers, TotalNumbers);
  printf("\n\nThe sorted numbers : ");
  print(&numbers[0], TotalNumbers);
  printf("\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe6a(%rip),%rdi
lea    0xe6f(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11cb <main+0x4b>
lea    0xe56(%rip),%rdi
call   1090 <perror@plt>
mov    0x2e1c(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
mov    -0x18(%rbp),%rdi
lea    0xe56(%rip),%rsi
lea    -0xc(%rbp),%rdx
call   1040 <fscanf@plt>
movslq -0xc(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1232 <main+0xb2>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rdx
movslq -0x8(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rdx
lea    0xe11(%rip),%rsi
call   1040 <fscanf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    11f9 <main+0x79>
lea    0xdfa(%rip),%rdi
call   1030 <printf@plt>
mov    -0x20(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1050 <print@plt>
mov    -0x20(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1070 <RadixSort@plt>
lea    0xdf4(%rip),%rdi
call   1030 <printf@plt>
mov    -0x20(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1050 <print@plt>
lea    0xdb9(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
lea    0xe5c(%rip),%rdi
lea    0xe61(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     1276 <main+0xe6>
mov    %rax,%r12
lea    0xe69(%rip),%rsi
lea    0xc(%rsp),%rdx
mov    %rax,%rdi
call   1050 <fscanf@plt>
mov    0xc(%rsp),%ebx
lea    0x0(,%rbx,4),%edi
call   1070 <malloc@plt>
mov    %rax,%r14
test   %ebx,%ebx
jle    1220 <main+0x90>
xor    %r13d,%r13d
lea    0xe3f(%rip),%r15
mov    %r14,%rbx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r12,%rdi
mov    %r15,%rsi
mov    %rbx,%rdx
call   1050 <fscanf@plt>
add    $0x1,%r13
movslq 0xc(%rsp),%rax
add    $0x4,%rbx
cmp    %rax,%r13
jl     1200 <main+0x70>
lea    0xe0c(%rip),%rdi
call   1040 <printf@plt>
mov    0xc(%rsp),%esi
mov    %r14,%rdi
call   1060 <print@plt>
mov    0xc(%rsp),%esi
mov    %r14,%rdi
call   1080 <RadixSort@plt>
lea    0xe06(%rip),%rdi
call   1040 <printf@plt>
mov    0xc(%rsp),%esi
mov    %r14,%rdi
call   1060 <print@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
lea    0xd91(%rip),%rdi
call   10a0 <perror@plt>
mov    0x2d57(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@.str = [12 x i8] c"numbers.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [30 x i8] c"Error while opening the file\0A\00"
@EXIT_FAILURE = global i32 0
@.str.3 = [4 x i8] c"%d\0A\00"
@.str.4 = [3 x i8] c"%d\00"
@.str.5 = [30 x i8] c"\0AThe unsorted numbers are : \00"
@.str.6 = [24 x i8] c"\0A\0AThe sorted numbers : \00"
@.str.7 = [2 x i8] c"\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32*
store i32 0, i32* %1
%6 = call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %6, i32** %4
%7 = load i32*, i32** %4
%8 = icmp eq i32* %7, null
br i1 %8, label %9, label %13
9: ; preds = %0
%10 = call i32 @perror(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0))
%11 = load i32, i32* @EXIT_FAILURE
%12 = call i32 @exit(i32 %11)
unreachable
13: ; preds = %0
%14 = load i32*, i32** %4
%15 = call i32 @fscanf(i32* %14, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32* %3)
%16 = load i32, i32* %3
%17 = sext i32 %16 to i64
%18 = mul i64 %17, 4
%19 = trunc i64 %18 to i32
%20 = call i32* @malloc(i32 %19)
store i32* %20, i32** %5
store i32 0, i32* %2
br label %21
21: ; preds = %32, %13
%22 = load i32, i32* %2
%23 = load i32, i32* %3
%24 = icmp slt i32 %22, %23
br i1 %24, label %25, label %35
25: ; preds = %21
%26 = load i32*, i32** %4
%27 = load i32*, i32** %5
%28 = load i32, i32* %2
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i32, i32* %27, i64 %29
%31 = call i32 @fscanf(i32* %26, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32* %30)
br label %32
32: ; preds = %25
%33 = load i32, i32* %2
%34 = add nsw i32 %33, 1
store i32 %34, i32* %2
br label %21
35: ; preds = %21
%36 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.5, i64 0, i64 0))
%37 = load i32*, i32** %5
%38 = load i32, i32* %3
%39 = call i32 @print(i32* %37, i32 %38)
%40 = load i32*, i32** %5
%41 = load i32, i32* %3
%42 = call i32 @RadixSort(i32* %40, i32 %41)
%43 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.6, i64 0, i64 0))
%44 = load i32*, i32** %5
%45 = getelementptr inbounds i32, i32* %44, i64 0
%46 = load i32, i32* %3
%47 = call i32 @print(i32* %45, i32 %46)
%48 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str = [12 x i8] c"numbers.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [30 x i8] c"Error while opening the file\0A\00"
@EXIT_FAILURE = global i32 0
@.str.3 = [4 x i8] c"%d\0A\00"
@.str.4 = [3 x i8] c"%d\00"
@.str.5 = [30 x i8] c"\0AThe unsorted numbers are : \00"
@.str.6 = [24 x i8] c"\0A\0AThe sorted numbers : \00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %5, label %9
5: ; preds = %0
%6 = tail call i32 @perror(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0))
%7 = load i32, i32* @EXIT_FAILURE
%8 = tail call i32 @exit(i32 %7)
unreachable
9: ; preds = %0
%10 = call i32 @fscanf(i32* %3, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32* %1)
%11 = load i32, i32* %1
%12 = shl i32 %11, 2
%13 = call i32* @malloc(i32 %12)
%14 = icmp sgt i32 %11, 0
br i1 %14, label %15, label %23
15: ; preds = %9, %15
%16 = phi i64 [ %19, %15 ], [ 0, %9 ]
%17 = getelementptr inbounds i32, i32* %13, i64 %16
%18 = call i32 @fscanf(i32* %3, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32* %17)
%19 = add nuw nsw i64 %16, 1
%20 = load i32, i32* %1
%21 = sext i32 %20 to i64
%22 = icmp slt i64 %19, %21
br i1 %22, label %15, label %23
23: ; preds = %15, %9
%24 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.5, i64 0, i64 0))
%25 = load i32, i32* %1
%26 = call i32 @print(i32* %13, i32 %25)
%27 = load i32, i32* %1
%28 = call i32 @RadixSort(i32* %13, i32 %27)
%29 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.6, i64 0, i64 0))
%30 = load i32, i32* %1
%31 = call i32 @print(i32* %13, i32 %30)
%32 = call i32 @putchar(i32 10)
ret i32 0
}