#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*/ *fopen(char *, char *);
int /*<<< orphan*/ print_arr(int *, int);
int /*<<< orphan*/ printf(char *);
int reading(int /*<<< orphan*/ *, int *, int *);
int /*<<< orphan*/ setbuf(int /*<<< orphan*/, int /*<<< orphan*/ *);
int /*<<< orphan*/ sort(int *, int);
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ writing(int /*<<< orphan*/ *, int *, int);
int main(int argc, char **argv) {
  setbuf(stdout, NULL);
  int arr[20];
  int size;
  FILE *f1, *f2;
  if (argc != 3) {
    printf("Incorrect args count");
    return -3;
  }
  f1 = fopen(argv[1], "r");
  f2 = fopen(argv[2], "w");
  if ((f1 == NULL) || (f2 == NULL)) {
    printf("Error when open files");
    return -2;
  }
  if (reading(f1, arr, &size) == -1) {
    printf("There are no numbers in the file");
    return -1;
  } else {
    print_arr(arr, size);
    sort(arr, size);
    writing(f2, arr, size);
    printf("Sorted array had been written in the second file\n");
    printf("The array after the sort:\n");
    print_arr(arr, size);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e50(%rip),%rax
mov    (%rax),%edi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <setbuf@plt>
cmpl   $0x3,-0x8(%rbp)
je     11bd <main+0x4d>
lea    0xe54(%rip),%rdi
call   1050 <printf@plt>
movl   $0xfffffffd,-0x4(%rbp)
jmp    12a0 <main+0x130>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe49(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x70(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe33(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x78(%rbp)
cmpq   $0x0,-0x70(%rbp)
je     1203 <main+0x93>
cmpq   $0x0,-0x78(%rbp)
jne    121b <main+0xab>
lea    0xe0f(%rip),%rdi
call   1050 <printf@plt>
movl   $0xfffffffe,-0x4(%rbp)
jmp    12a0 <main+0x130>
mov    -0x70(%rbp),%rdi
lea    -0x60(%rbp),%rsi
lea    -0x64(%rbp),%rdx
call   1070 <reading@plt>
cmp    $0xffffffff,%eax
jne    124d <main+0xdd>
lea    0xdf3(%rip),%rdi
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12a0 <main+0x130>
lea    -0x60(%rbp),%rdi
mov    -0x64(%rbp),%esi
call   1030 <print_arr@plt>
lea    -0x60(%rbp),%rdi
mov    -0x64(%rbp),%esi
call   1060 <sort@plt>
mov    -0x78(%rbp),%rdi
lea    -0x60(%rbp),%rsi
mov    -0x64(%rbp),%edx
call   1080 <writing@plt>
lea    0xdd4(%rip),%rdi
call   1050 <printf@plt>
lea    0xdfa(%rip),%rdi
call   1050 <printf@plt>
lea    -0x60(%rbp),%rdi
mov    -0x64(%rbp),%esi
call   1030 <print_arr@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x60,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
mov    0x2e4c(%rip),%rax
mov    (%rax),%edi
xor    %esi,%esi
call   1050 <setbuf@plt>
cmp    $0x3,%ebp
jne    1245 <main+0xc5>
mov    0x8(%rbx),%rdi
lea    0xe64(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,%r14
mov    0x10(%rbx),%rdi
lea    0xe53(%rip),%rsi
call   10a0 <fopen@plt>
test   %r14,%r14
je     1258 <main+0xd8>
mov    %rax,%rbx
test   %rax,%rax
je     1258 <main+0xd8>
lea    0x10(%rsp),%rsi
lea    0xc(%rsp),%rdx
mov    %r14,%rdi
call   1080 <reading@plt>
cmp    $0xffffffff,%eax
je     126b <main+0xeb>
mov    0xc(%rsp),%esi
lea    0x10(%rsp),%rbp
mov    %rbp,%rdi
call   1040 <print_arr@plt>
mov    0xc(%rsp),%esi
mov    %rbp,%rdi
call   1070 <sort@plt>
mov    0xc(%rsp),%edx
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1090 <writing@plt>
lea    0xe2c(%rip),%rdi
call   1030 <puts@plt>
lea    0xe51(%rip),%rdi
call   1030 <puts@plt>
mov    0xc(%rsp),%esi
mov    %rbp,%rdi
call   1040 <print_arr@plt>
xor    %eax,%eax
jmp    127c <main+0xfc>
lea    0xdb4(%rip),%rdi
call   1060 <printf@plt>
mov    $0xfffffffd,%eax
jmp    127c <main+0xfc>
lea    0xdba(%rip),%rdi
call   1060 <printf@plt>
mov    $0xfffffffe,%eax
jmp    127c <main+0xfc>
lea    0xdbd(%rip),%rdi
call   1060 <printf@plt>
mov    $0xffffffff,%eax
add    $0x60,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@stdout = global i32 0
@.str = [21 x i8] c"Incorrect args count\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [2 x i8] c"w\00"
@.str.3 = [22 x i8] c"Error when open files\00"
@.str.4 = [33 x i8] c"There are no numbers in the file\00"
@.str.5 = [50 x i8] c"Sorted array had been written in the second file\0A\00"
@.str.6 = [27 x i8] c"The array after the sort:\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [20 x i32]
%7 = alloca i32
%8 = alloca i32*
%9 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* @stdout
%11 = call i32 @setbuf(i32 %10, i32* null)
%12 = load i32, i32* %4
%13 = icmp ne i32 %12, 3
br i1 %13, label %14, label %16
14: ; preds = %2
%15 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
store i32 -3, i32* %3
br label %56
16: ; preds = %2
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
%20 = call i32* @fopen(i8* %19, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %20, i32** %8
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 2
%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 = load i32*, i32** %8
%26 = icmp eq i32* %25, null
br i1 %26, label %30, label %27
27: ; preds = %16
%28 = load i32*, i32** %9
%29 = icmp eq i32* %28, null
br i1 %29, label %30, label %32
30: ; preds = %27, %16
%31 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0))
store i32 -2, i32* %3
br label %56
32: ; preds = %27
%33 = load i32*, i32** %8
%34 = getelementptr inbounds [20 x i32], [20 x i32]* %6, i64 0, i64 0
%35 = call i32 @reading(i32* %33, i32* %34, i32* %7)
%36 = icmp eq i32 %35, -1
br i1 %36, label %37, label %39
37: ; preds = %32
%38 = call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0))
store i32 -1, i32* %3
br label %56
39: ; preds = %32
%40 = getelementptr inbounds [20 x i32], [20 x i32]* %6, i64 0, i64 0
%41 = load i32, i32* %7
%42 = call i32 @print_arr(i32* %40, i32 %41)
%43 = getelementptr inbounds [20 x i32], [20 x i32]* %6, i64 0, i64 0
%44 = load i32, i32* %7
%45 = call i32 @sort(i32* %43, i32 %44)
%46 = load i32*, i32** %9
%47 = getelementptr inbounds [20 x i32], [20 x i32]* %6, i64 0, i64 0
%48 = load i32, i32* %7
%49 = call i32 @writing(i32* %46, i32* %47, i32 %48)
%50 = call i32 @printf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.5, i64 0, i64 0))
%51 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.6, i64 0, i64 0))
%52 = getelementptr inbounds [20 x i32], [20 x i32]* %6, i64 0, i64 0
%53 = load i32, i32* %7
%54 = call i32 @print_arr(i32* %52, i32 %53)
br label %55
55: ; preds = %39
store i32 0, i32* %3
br label %56
56: ; preds = %55, %37, %30, %14
%57 = load i32, i32* %3
ret i32 %57
}

LLVM IR (-O2):
@stdout = global i32 0
@.str = [21 x i8] c"Incorrect args count\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [2 x i8] c"w\00"
@.str.3 = [22 x i8] c"Error when open files\00"
@.str.4 = [33 x i8] c"There are no numbers in the file\00"
@str = [49 x i8] c"Sorted array had been written in the second file\00"
@str.7 = [26 x i8] c"The array after the sort:\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [20 x i32]
%4 = alloca i32
%5 = load i32, i32* @stdout
%6 = tail call i32 @setbuf(i32 %5, i32* null)
%7 = bitcast [20 x i32]* %3 to i8*
%8 = bitcast i32* %4 to i8*
%9 = icmp eq i32 %0, 3
br i1 %9, label %12, label %10
10: ; preds = %2
%11 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
br label %41
12: ; preds = %2
%13 = getelementptr inbounds i8*, i8** %1, i64 1
%14 = load i8*, i8** %13
%15 = tail call i32* @fopen(i8* %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%16 = getelementptr inbounds i8*, i8** %1, i64 2
%17 = load i8*, i8** %16
%18 = tail call i32* @fopen(i8* %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%19 = icmp eq i32* %15, null
%20 = icmp eq i32* %18, null
%21 = or i1 %19, %20
br i1 %21, label %22, label %24
22: ; preds = %12
%23 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0))
br label %41
24: ; preds = %12
%25 = getelementptr inbounds [20 x i32], [20 x i32]* %3, i64 0, i64 0
%26 = call i32 @reading(i32* %15, i32* %25, i32* %4)
%27 = icmp eq i32 %26, -1
br i1 %27, label %28, label %30
28: ; preds = %24
%29 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0))
br label %41
30: ; preds = %24
%31 = load i32, i32* %4
%32 = call i32 @print_arr(i32* %25, i32 %31)
%33 = load i32, i32* %4
%34 = call i32 @sort(i32* %25, i32 %33)
%35 = load i32, i32* %4
%36 = call i32 @writing(i32* %18, i32* %25, i32 %35)
%37 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([49 x i8], [49 x i8]* @str, i64 0, i64 0))
%38 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str.7, i64 0, i64 0))
%39 = load i32, i32* %4
%40 = call i32 @print_arr(i32* %25, i32 %39)
br label %41
41: ; preds = %30, %28, %22, %10
%42 = phi i32 [ -3, %10 ], [ -2, %22 ], [ -1, %28 ], [ 0, %30 ]
ret i32 %42
}