#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 scalar_t__ uint32_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
int fread(scalar_t__ *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ quicksort(scalar_t__ *, int /*<<< orphan*/, int);
uint32_t fileBiggest(FILE *fp) {
  uint32_t a[(1024 * 1024)];
  int k, len;
  int size;
  uint32_t biggest = 0;
  size = sizeof(uint32_t);
  while (!feof(fp)) {
    len = fread(a, size, (1024 * 1024), fp);
    quicksort(a, 0, len - 1);
    if (biggest < a[len - 1])
      biggest = a[len - 1];
  }
  return biggest;
}


x86 assembly (clang, -O0):
<fileBiggest>:
push   %rbp
mov    %rsp,%rbp
sub    $0x800030,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x800028(%rbp)
movl   $0x8,-0x80001c(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1172 <fileBiggest+0x42>
jmp    11ea <fileBiggest+0xba>
lea    -0x800010(%rbp),%rdi
mov    -0x80001c(%rbp),%esi
mov    -0x8(%rbp),%rcx
mov    $0x100000,%edx
call   1030 <fread@plt>
mov    %eax,-0x800018(%rbp)
lea    -0x800010(%rbp),%rdi
mov    -0x800018(%rbp),%edx
sub    $0x1,%edx
xor    %esi,%esi
call   1040 <quicksort@plt>
mov    -0x800028(%rbp),%rax
mov    -0x800018(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
cmp    -0x800010(%rbp,%rcx,8),%rax
ff
jge    11e5 <fileBiggest+0xb5>
mov    -0x800018(%rbp),%eax
sub    $0x1,%eax
cltq
mov    -0x800010(%rbp,%rax,8),%rax
ff
mov    %rax,-0x800028(%rbp)
jmp    1154 <fileBiggest+0x24>
mov    -0x800028(%rbp),%rax
add    $0x800030,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fileBiggest>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x800008,%rsp
mov    %rdi,%r14
call   1050 <feof@plt>
xor    %ebx,%ebx
test   %eax,%eax
jne    1192 <fileBiggest+0x62>
mov    %rsp,%r15
nop
mov    %r15,%rdi
mov    $0x8,%esi
mov    $0x100000,%edx
mov    %r14,%rcx
call   1030 <fread@plt>
mov    %eax,%r12d
lea    -0x1(%r12),%edx
mov    %r15,%rdi
xor    %esi,%esi
call   1040 <quicksort@plt>
movslq %r12d,%rax
mov    -0x8(%rsp,%rax,8),%rax
cmp    %rax,%rbx
cmovl  %rax,%rbx
mov    %r14,%rdi
call   1050 <feof@plt>
test   %eax,%eax
je     1150 <fileBiggest+0x20>
mov    %rbx,%rax
add    $0x800008,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i64 @fileBiggest(i32* %0) {
%2 = alloca i32*
%3 = alloca [1048576 x i64]
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i64
store i32* %0, i32** %2
store i64 0, i64* %7
store i32 8, i32* %6
br label %8
8: ; preds = %35, %1
%9 = load i32*, i32** %2
%10 = call i32 @feof(i32* %9)
%11 = icmp ne i32 %10, 0
%12 = xor i1 %11, true
br i1 %12, label %13, label %36
13: ; preds = %8
%14 = getelementptr inbounds [1048576 x i64], [1048576 x i64]* %3, i64 0, i64 0
%15 = load i32, i32* %6
%16 = load i32*, i32** %2
%17 = call i32 @fread(i64* %14, i32 %15, i32 1048576, i32* %16)
store i32 %17, i32* %5
%18 = getelementptr inbounds [1048576 x i64], [1048576 x i64]* %3, i64 0, i64 0
%19 = load i32, i32* %5
%20 = sub nsw i32 %19, 1
%21 = call i32 @quicksort(i64* %18, i32 0, i32 %20)
%22 = load i64, i64* %7
%23 = load i32, i32* %5
%24 = sub nsw i32 %23, 1
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds [1048576 x i64], [1048576 x i64]* %3, i64 0, i64 %25
%27 = load i64, i64* %26
%28 = icmp slt i64 %22, %27
br i1 %28, label %29, label %35
29: ; preds = %13
%30 = load i32, i32* %5
%31 = sub nsw i32 %30, 1
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds [1048576 x i64], [1048576 x i64]* %3, i64 0, i64 %32
%34 = load i64, i64* %33
store i64 %34, i64* %7
br label %35
35: ; preds = %29, %13
br label %8
36: ; preds = %8
%37 = load i64, i64* %7
ret i64 %37
}

LLVM IR (-O2):
define i64 @fileBiggest(i32* nocapture %0) {
%2 = alloca [1048576 x i64]
%3 = bitcast [1048576 x i64]* %2 to i8*
%4 = call i32 @feof(i32* %0)
%5 = icmp eq i32 %4, 0
br i1 %5, label %6, label %20
6: ; preds = %1
%7 = getelementptr inbounds [1048576 x i64], [1048576 x i64]* %2, i64 0, i64 0
br label %8
8: ; preds = %6, %8
%9 = phi i64 [ 0, %6 ], [ %17, %8 ]
%10 = call i32 @fread(i64* %7, i32 8, i32 1048576, i32* %0)
%11 = add nsw i32 %10, -1
%12 = call i32 @quicksort(i64* %7, i32 0, i32 %11)
%13 = sext i32 %11 to i64
%14 = getelementptr inbounds [1048576 x i64], [1048576 x i64]* %2, i64 0, i64 %13
%15 = load i64, i64* %14
%16 = icmp slt i64 %9, %15
%17 = select i1 %16, i64 %15, i64 %9
%18 = call i32 @feof(i32* %0)
%19 = icmp eq i32 %18, 0
br i1 %19, label %8, label %20
20: ; preds = %8, %1
%21 = phi i64 [ 0, %1 ], [ %17, %8 ]
ret i64 %21
}