#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 */
scalar_t__ EOF;
int /*<<< orphan*/ bubbles(int *, int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
scalar_t__ fscanf(int /*<<< orphan*/ *, char *, int *);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  FILE *fp;
  int i, j;
  int n[50000];
  if (argc < 2) {
    fprintf(stderr, "Arguments\n");
    return -1;
  }
  fp = fopen(argv[1], "r");
  if (fp == NULL) {
    fprintf(stderr, "CAN NOT OPEN\n");
    return -1;
  }
  for (j = 0; j < 50000 && (fscanf(fp, "%d", &i) != EOF); j++)
    n[j] = i;
  fclose(fp);
  i = 0;
  bubbles(n, j);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30d70,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    1194 <main+0x44>
mov    0x2e5e(%rip),%rax
mov    (%rax),%edi
lea    0xe7d(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1270 <main+0x120>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe68(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11d8 <main+0x88>
mov    0x2e1a(%rip),%rax
mov    (%rax),%edi
lea    0xe46(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1270 <main+0x120>
movl   $0x0,-0x20(%rbp)
xor    %eax,%eax
cmpl   $0xc350,-0x20(%rbp)
mov    %al,-0x30d61(%rbp)
jge    121b <main+0xcb>
mov    -0x18(%rbp),%rdi
lea    0xe1c(%rip),%rsi
lea    -0x1c(%rbp),%rdx
call   1040 <fscanf@plt>
mov    0x2dd9(%rip),%rcx
cmp    (%rcx),%rax
setne  %al
mov    %al,-0x30d61(%rbp)
mov    -0x30d61(%rbp),%al
test   $0x1,%al
jne    122e <main+0xde>
jmp    124a <main+0xfa>
mov    -0x1c(%rbp),%ecx
movslq -0x20(%rbp),%rax
mov    %ecx,-0x30d60(%rbp,%rax,4)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    11df <main+0x8f>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x1c(%rbp)
lea    -0x30d60(%rbp),%rdi
mov    -0x20(%rbp),%esi
call   1070 <bubbles@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30d70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x30d50,%rsp
cmp    $0x1,%edi
jg     117a <main+0x2a>
mov    0x2e6c(%rip),%rax
mov    (%rax),%edi
lea    0xe8b(%rip),%rsi
jmp    120e <main+0xbe>
mov    0x8(%rsi),%rdi
lea    0xe86(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     11fe <main+0xae>
mov    %rax,%r14
xor    %ebx,%ebx
lea    0xe80(%rip),%r15
lea    0xc(%rsp),%r12
mov    0x2e41(%rip),%r13
nopw   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
call   1040 <fscanf@plt>
cmp    0x0(%r13),%rax
je     11de <main+0x8e>
mov    0xc(%rsp),%eax
mov    %eax,0x10(%rsp,%rbx,4)
add    $0x1,%rbx
cmp    $0xc350,%rbx
jne    11b0 <main+0x60>
mov    $0xc350,%ebx
mov    %r14,%rdi
call   1030 <fclose@plt>
movl   $0x0,0xc(%rsp)
lea    0x10(%rsp),%rdi
mov    %ebx,%esi
call   1070 <bubbles@plt>
xor    %eax,%eax
jmp    1218 <main+0xc8>
mov    0x2dd3(%rip),%rax
mov    (%rax),%edi
lea    0xdff(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0xffffffff,%eax
add    $0x30d50,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [11 x i8] c"Arguments\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [14 x i8] c"CAN NOT OPEN\0A\00"
@.str.3 = [3 x i8] c"%d\00"
@EOF = global i64 0
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
%9 = alloca [50000 x i32]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp slt i32 %10, 2
br i1 %11, label %12, label %15
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %50
15: ; preds = %2
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 1
%18 = load i8*, i8** %17
%19 = call i32* @fopen(i8* %18, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %19, i32** %6
%20 = load i32*, i32** %6
%21 = icmp eq i32* %20, null
br i1 %21, label %22, label %25
22: ; preds = %15
%23 = load i32, i32* @stderr
%24 = call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %3
br label %50
25: ; preds = %15
store i32 0, i32* %8
br label %26
26: ; preds = %41, %25
%27 = load i32, i32* %8
%28 = icmp slt i32 %27, 50000
br i1 %28, label %29, label %34
29: ; preds = %26
%30 = load i32*, i32** %6
%31 = call i64 @fscanf(i32* %30, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %7)
%32 = load i64, i64* @EOF
%33 = icmp ne i64 %31, %32
br label %34
34: ; preds = %29, %26
%35 = phi i1 [ false, %26 ], [ %33, %29 ]
br i1 %35, label %36, label %44
36: ; preds = %34
%37 = load i32, i32* %7
%38 = load i32, i32* %8
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds [50000 x i32], [50000 x i32]* %9, i64 0, i64 %39
store i32 %37, i32* %40
br label %41
41: ; preds = %36
%42 = load i32, i32* %8
%43 = add nsw i32 %42, 1
store i32 %43, i32* %8
br label %26
44: ; preds = %34
%45 = load i32*, i32** %6
%46 = call i32 @fclose(i32* %45)
store i32 0, i32* %7
%47 = getelementptr inbounds [50000 x i32], [50000 x i32]* %9, i64 0, i64 0
%48 = load i32, i32* %8
%49 = call i32 @bubbles(i32* %47, i32 %48)
store i32 0, i32* %3
br label %50
50: ; preds = %44, %22, %12
%51 = load i32, i32* %3
ret i32 %51
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [11 x i8] c"Arguments\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [14 x i8] c"CAN NOT OPEN\0A\00"
@.str.3 = [3 x i8] c"%d\00"
@EOF = global i64 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca [50000 x i32]
%5 = bitcast i32* %3 to i8*
%6 = bitcast [50000 x i32]* %4 to i8*
%7 = icmp slt i32 %0, 2
br i1 %7, label %8, label %11
8: ; preds = %2
%9 = load i32, i32* @stderr
%10 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
br label %36
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.1, i64 0, i64 0))
%15 = icmp eq i32* %14, null
br i1 %15, label %16, label %19
16: ; preds = %11
%17 = load i32, i32* @stderr
%18 = tail call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
br label %36
19: ; preds = %11, %24
%20 = phi i64 [ %27, %24 ], [ 0, %11 ]
%21 = call i64 @fscanf(i32* %14, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %3)
%22 = load i64, i64* @EOF
%23 = icmp eq i64 %21, %22
br i1 %23, label %29, label %24
24: ; preds = %19
%25 = load i32, i32* %3
%26 = getelementptr inbounds [50000 x i32], [50000 x i32]* %4, i64 0, i64 %20
store i32 %25, i32* %26
%27 = add nuw nsw i64 %20, 1
%28 = icmp eq i64 %27, 50000
br i1 %28, label %31, label %19
29: ; preds = %19
%30 = trunc i64 %20 to i32
br label %31
31: ; preds = %24, %29
%32 = phi i32 [ %30, %29 ], [ 50000, %24 ]
%33 = call i32 @fclose(i32* %14)
store i32 0, i32* %3
%34 = getelementptr inbounds [50000 x i32], [50000 x i32]* %4, i64 0, i64 0
%35 = call i32 @bubbles(i32* %34, i32 %32)
br label %36
36: ; preds = %31, %16, %8
%37 = phi i32 [ -1, %8 ], [ -1, %16 ], [ 0, %31 ]
ret i32 %37
}