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


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30d70,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xea7(%rip),%rdi
lea    0xeae(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1195 <main+0x55>
mov    0x2e5d(%rip),%rax
mov    (%rax),%edi
lea    0xe8c(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1227 <main+0xe7>
movl   $0x0,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe77(%rip),%rsi
lea    -0x14(%rbp),%rdx
call   1030 <fscanf@plt>
mov    %rax,%rcx
xor    %eax,%eax
mov    0x2e2c(%rip),%rdx
cmp    (%rdx),%rcx
mov    %al,-0x30d61(%rbp)
je     11db <main+0x9b>
cmpl   $0xc350,-0x18(%rbp)
setl   %al
mov    %al,-0x30d61(%rbp)
mov    -0x30d61(%rbp),%al
test   $0x1,%al
jne    11ee <main+0xae>
jmp    120a <main+0xca>
mov    -0x14(%rbp),%ecx
movslq -0x18(%rbp),%rax
mov    %ecx,-0x30d60(%rbp,%rax,4)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    119c <main+0x5c>
movl   $0x0,-0x14(%rbp)
lea    -0x30d60(%rbp),%rdi
mov    -0x18(%rbp),%esi
call   1060 <bubbles@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30d70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x30d58,%rsp
lea    0xea8(%rip),%rdi
lea    0xeaf(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     11f5 <main+0xb5>
mov    %rax,%rbx
lea    0xea7(%rip),%rsi
lea    0xc(%rsp),%rdx
mov    %rax,%rdi
call   1030 <fscanf@plt>
mov    0x2e5d(%rip),%r13
xor    %ebp,%ebp
mov    $0x0,%r14d
cmp    0x0(%r13),%rax
je     11de <main+0x9e>
xor    %ebp,%ebp
lea    0xe7c(%rip),%r15
lea    0xc(%rsp),%r12
nopw   0x0(%rax,%rax,1)
mov    0xc(%rsp),%eax
mov    %eax,0x10(%rsp,%rbp,4)
lea    0x1(%rbp),%r14
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
call   1030 <fscanf@plt>
cmp    0x0(%r13),%rax
je     11dc <main+0x9c>
cmp    $0xc34f,%rbp
mov    %r14,%rbp
jb     11b0 <main+0x70>
xor    %ebp,%ebp
movl   $0x0,0xc(%rsp)
lea    0x10(%rsp),%rdi
mov    %r14d,%esi
call   1060 <bubbles@plt>
jmp    120f <main+0xcf>
mov    0x2ddc(%rip),%rax
mov    (%rax),%edi
lea    0xe0b(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
add    $0x30d58,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [14 x i8] c"c06-50000.dat\00"
@.str.1 = [2 x i8] c"r\00"
@stderr = global i32 0
@.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() {
%1 = alloca i32
%2 = alloca [50000 x i32]
%3 = bitcast i32* %1 to i8*
%4 = bitcast [50000 x i32]* %2 to i8*
%5 = tail call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %11, label %7
7: ; preds = %0
%8 = call i64 @fscanf(i32* %5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %1)
%9 = load i64, i64* @EOF
%10 = icmp eq i64 %8, %9
br i1 %10, label %26, label %14
11: ; preds = %0
%12 = load i32, i32* @stderr
%13 = tail call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
br label %30
14: ; preds = %7, %14
%15 = phi i64 [ %18, %14 ], [ 0, %7 ]
%16 = load i32, i32* %1
%17 = getelementptr inbounds [50000 x i32], [50000 x i32]* %2, i64 0, i64 %15
store i32 %16, i32* %17
%18 = add nuw nsw i64 %15, 1
%19 = call i64 @fscanf(i32* %5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %1)
%20 = load i64, i64* @EOF
%21 = icmp ne i64 %19, %20
%22 = icmp ult i64 %15, 49999
%23 = select i1 %21, i1 %22, i1 false
br i1 %23, label %14, label %24
24: ; preds = %14
%25 = trunc i64 %18 to i32
br label %26
26: ; preds = %24, %7
%27 = phi i32 [ 0, %7 ], [ %25, %24 ]
store i32 0, i32* %1
%28 = getelementptr inbounds [50000 x i32], [50000 x i32]* %2, i64 0, i64 0
%29 = call i32 @bubbles(i32* %28, i32 %27)
br label %30
30: ; preds = %26, %11
%31 = phi i32 [ -1, %11 ], [ 0, %26 ]
ret i32 %31
}