#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*/ SEEK_END;
int /*<<< orphan*/ SEEK_SET;
unsigned int *calloc(int, unsigned int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fread(unsigned int *, int, unsigned int,
                         int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
unsigned int ftell(int /*<<< orphan*/ *);
unsigned int *bread_file(char *filename) {
  unsigned int *rcode, size;
  FILE *fh = fopen(filename, "rb");
  fseek(fh, 0, SEEK_END);
  size = ftell(fh);
  fseek(fh, 0, SEEK_SET);
  rcode = calloc(sizeof *rcode, size / 4 + 1);
  rcode[0] = size / 4;
  fread(rcode + 1, 4, size / 4, fh);
  for (unsigned int i = 0; i < size / 4; i++)
    rcode[i] = ((rcode[i] >> 24) & 0x000000ff) |
               ((rcode[i] << 8) & 0x00ff0000) | ((rcode[i] >> 8) & 0x0000ff00) |
               ((rcode[i] << 24) & 0xff000000);
  fclose(fh);
  return rcode + 1;
}


x86 assembly (clang, -O0):
<bread_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe89(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    0x2e5d(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1070 <fseek@plt>
mov    -0x20(%rbp),%rdi
call   1060 <ftell@plt>
mov    %eax,-0x14(%rbp)
mov    -0x20(%rbp),%rdi
mov    0x2e2d(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1070 <fseek@plt>
mov    -0x14(%rbp),%esi
shr    $0x2,%esi
add    $0x1,%esi
mov    $0x4,%edi
call   1050 <calloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x14(%rbp),%ecx
shr    $0x2,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x10(%rbp),%rdi
add    $0x4,%rdi
mov    -0x14(%rbp),%edx
shr    $0x2,%edx
mov    -0x20(%rbp),%rcx
mov    $0x4,%esi
call   1030 <fread@plt>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    -0x14(%rbp),%ecx
shr    $0x2,%ecx
cmp    %ecx,%eax
jae    1272 <bread_file+0x112>
mov    -0x10(%rbp),%rax
mov    -0x24(%rbp),%ecx
mov    (%rax,%rcx,4),%edx
shr    $0x18,%edx
and    $0xff,%edx
mov    -0x10(%rbp),%rax
mov    -0x24(%rbp),%ecx
mov    (%rax,%rcx,4),%eax
shl    $0x8,%eax
and    $0xff0000,%eax
or     %eax,%edx
mov    -0x10(%rbp),%rax
mov    -0x24(%rbp),%ecx
mov    (%rax,%rcx,4),%eax
shr    $0x8,%eax
and    $0xff00,%eax
or     %eax,%edx
mov    -0x10(%rbp),%rax
mov    -0x24(%rbp),%ecx
mov    (%rax,%rcx,4),%eax
shl    $0x18,%eax
and    $0xff000000,%eax
or     %eax,%edx
mov    -0x10(%rbp),%rax
mov    -0x24(%rbp),%ecx
mov    %edx,(%rax,%rcx,4)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11fa <bread_file+0x9a>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x10(%rbp),%rax
add    $0x4,%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bread_file>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
lea    0xe91(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,%r15
mov    0x2e6a(%rip),%rax
mov    (%rax),%edx
mov    %r15,%rdi
xor    %esi,%esi
call   1070 <fseek@plt>
mov    %r15,%rdi
call   1060 <ftell@plt>
mov    %eax,%ebp
mov    0x2e3d(%rip),%rax
mov    (%rax),%edx
mov    %r15,%rdi
xor    %esi,%esi
call   1070 <fseek@plt>
mov    %ebp,%r12d
shr    $0x2,%r12d
lea    0x1(%r12),%esi
mov    $0x4,%edi
call   1050 <calloc@plt>
mov    %rax,%rbx
mov    %r12d,(%rax)
lea    0x4(%rax),%r14
mov    %r14,%rdi
mov    $0x4,%esi
mov    %r12d,%edx
mov    %r15,%rcx
call   1030 <fread@plt>
cmp    $0x4,%ebp
jb     1291 <bread_file+0x131>
cmp    $0x2,%r12d
mov    $0x1,%eax
cmovae %r12d,%eax
cmp    $0x8,%eax
jae    11fc <bread_file+0x9c>
xor    %ecx,%ecx
jmp    1280 <bread_file+0x120>
mov    %eax,%ecx
and    $0xfffffff8,%ecx
xor    %edx,%edx
pxor   %xmm0,%xmm0
nopw   0x0(%rax,%rax,1)
movdqu (%rbx,%rdx,4),%xmm1
movdqu 0x10(%rbx,%rdx,4),%xmm2
movdqa %xmm1,%xmm3
punpckhbw %xmm0,%xmm3
pshuflw $0x1b,%xmm3,%xmm3
pshufhw $0x1b,%xmm3,%xmm3
punpcklbw %xmm0,%xmm1
pshuflw $0x1b,%xmm1,%xmm1
pshufhw $0x1b,%xmm1,%xmm1
packuswb %xmm3,%xmm1
movdqa %xmm2,%xmm3
punpckhbw %xmm0,%xmm3
pshuflw $0x1b,%xmm3,%xmm3
pshufhw $0x1b,%xmm3,%xmm3
punpcklbw %xmm0,%xmm2
pshuflw $0x1b,%xmm2,%xmm2
pshufhw $0x1b,%xmm2,%xmm2
packuswb %xmm3,%xmm2
movdqu %xmm1,(%rbx,%rdx,4)
movdqu %xmm2,0x10(%rbx,%rdx,4)
add    $0x8,%rdx
cmp    %rdx,%rcx
jne    1210 <bread_file+0xb0>
cmp    %rax,%rcx
je     1291 <bread_file+0x131>
nopl   0x0(%rax)
mov    (%rbx,%rcx,4),%edx
bswap  %edx
mov    %edx,(%rbx,%rcx,4)
add    $0x1,%rcx
cmp    %rcx,%rax
jne    1280 <bread_file+0x120>
mov    %r15,%rdi
call   1040 <fclose@plt>
mov    %r14,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
define i32* @bread_file(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32
store i8* %0, i8** %2
%7 = load i8*, i8** %2
%8 = call i32* @fopen(i8* %7, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %8, i32** %5
%9 = load i32*, i32** %5
%10 = load i32, i32* @SEEK_END
%11 = call i32 @fseek(i32* %9, i32 0, i32 %10)
%12 = load i32*, i32** %5
%13 = call i32 @ftell(i32* %12)
store i32 %13, i32* %4
%14 = load i32*, i32** %5
%15 = load i32, i32* @SEEK_SET
%16 = call i32 @fseek(i32* %14, i32 0, i32 %15)
%17 = load i32, i32* %4
%18 = udiv i32 %17, 4
%19 = add i32 %18, 1
%20 = call i32* @calloc(i32 4, i32 %19)
store i32* %20, i32** %3
%21 = load i32, i32* %4
%22 = udiv i32 %21, 4
%23 = load i32*, i32** %3
%24 = getelementptr inbounds i32, i32* %23, i64 0
store i32 %22, i32* %24
%25 = load i32*, i32** %3
%26 = getelementptr inbounds i32, i32* %25, i64 1
%27 = load i32, i32* %4
%28 = udiv i32 %27, 4
%29 = load i32*, i32** %5
%30 = call i32 @fread(i32* %26, i32 4, i32 %28, i32* %29)
store i32 0, i32* %6
br label %31
31: ; preds = %72, %1
%32 = load i32, i32* %6
%33 = load i32, i32* %4
%34 = udiv i32 %33, 4
%35 = icmp ult i32 %32, %34
br i1 %35, label %36, label %75
36: ; preds = %31
%37 = load i32*, i32** %3
%38 = load i32, i32* %6
%39 = zext i32 %38 to i64
%40 = getelementptr inbounds i32, i32* %37, i64 %39
%41 = load i32, i32* %40
%42 = lshr i32 %41, 24
%43 = and i32 %42, 255
%44 = load i32*, i32** %3
%45 = load i32, i32* %6
%46 = zext i32 %45 to i64
%47 = getelementptr inbounds i32, i32* %44, i64 %46
%48 = load i32, i32* %47
%49 = shl i32 %48, 8
%50 = and i32 %49, 16711680
%51 = or i32 %43, %50
%52 = load i32*, i32** %3
%53 = load i32, i32* %6
%54 = zext i32 %53 to i64
%55 = getelementptr inbounds i32, i32* %52, i64 %54
%56 = load i32, i32* %55
%57 = lshr i32 %56, 8
%58 = and i32 %57, 65280
%59 = or i32 %51, %58
%60 = load i32*, i32** %3
%61 = load i32, i32* %6
%62 = zext i32 %61 to i64
%63 = getelementptr inbounds i32, i32* %60, i64 %62
%64 = load i32, i32* %63
%65 = shl i32 %64, 24
%66 = and i32 %65, -16777216
%67 = or i32 %59, %66
%68 = load i32*, i32** %3
%69 = load i32, i32* %6
%70 = zext i32 %69 to i64
%71 = getelementptr inbounds i32, i32* %68, i64 %70
store i32 %67, i32* %71
br label %72
72: ; preds = %36
%73 = load i32, i32* %6
%74 = add i32 %73, 1
store i32 %74, i32* %6
br label %31
75: ; preds = %31
%76 = load i32*, i32** %5
%77 = call i32 @fclose(i32* %76)
%78 = load i32*, i32** %3
%79 = getelementptr inbounds i32, i32* %78, i64 1
ret i32* %79
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
define noalias i32* @bread_file(i8* nocapture %0) {
%2 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%3 = load i32, i32* @SEEK_END
%4 = tail call i32 @fseek(i32* %2, i32 0, i32 %3)
%5 = tail call i32 @ftell(i32* %2)
%6 = load i32, i32* @SEEK_SET
%7 = tail call i32 @fseek(i32* %2, i32 0, i32 %6)
%8 = lshr i32 %5, 2
%9 = add nuw nsw i32 %8, 1
%10 = tail call i32* @calloc(i32 4, i32 %9)
store i32 %8, i32* %10
%11 = getelementptr inbounds i32, i32* %10, i64 1
%12 = tail call i32 @fread(i32* %11, i32 4, i32 %8, i32* %2)
%13 = icmp ult i32 %5, 4
br i1 %13, label %38, label %14
14: ; preds = %1
%15 = call i32 @llvm.umax.i32(i32 %8, i32 1)
%16 = zext i32 %15 to i64
%17 = icmp ult i32 %15, 8
br i1 %17, label %36, label %18
18: ; preds = %14
%19 = and i64 %16, 1073741816
br label %20
20: ; preds = %20, %18
%21 = phi i64 [ 0, %18 ], [ %32, %20 ]
%22 = getelementptr inbounds i32, i32* %10, i64 %21
%23 = bitcast i32* %22 to <4 x i32>*
%24 = load <4 x i32>, <4 x i32>* %23
%25 = getelementptr inbounds i32, i32* %22, i64 4
%26 = bitcast i32* %25 to <4 x i32>*
%27 = load <4 x i32>, <4 x i32>* %26
%28 = call <4 x i32> @llvm.bswap.v4i32(<4 x i32> %24)
%29 = call <4 x i32> @llvm.bswap.v4i32(<4 x i32> %27)
%30 = bitcast i32* %22 to <4 x i32>*
store <4 x i32> %28, <4 x i32>* %30
%31 = bitcast i32* %25 to <4 x i32>*
store <4 x i32> %29, <4 x i32>* %31
%32 = add nuw i64 %21, 8
%33 = icmp eq i64 %32, %19
br i1 %33, label %34, label %20
34: ; preds = %20
%35 = icmp eq i64 %19, %16
br i1 %35, label %38, label %36
36: ; preds = %14, %34
%37 = phi i64 [ 0, %14 ], [ %19, %34 ]
br label %40
38: ; preds = %40, %34, %1
%39 = tail call i32 @fclose(i32* %2)
ret i32* %11
40: ; preds = %36, %40
%41 = phi i64 [ %45, %40 ], [ %37, %36 ]
%42 = getelementptr inbounds i32, i32* %10, i64 %41
%43 = load i32, i32* %42
%44 = tail call i32 @llvm.bswap.i32(i32 %43)
store i32 %44, i32* %42
%45 = add nuw nsw i64 %41, 1
%46 = icmp eq i64 %45, %16
br i1 %46, label %38, label %40
}