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

/* Variables and functions */
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ ferror(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int fread(char **, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ guestStore(unsigned int, char);
void fillState(char *fileName, void *buf, unsigned int size) {
  FILE *fd;
  assert(size > 0);
  fd = fopen(fileName, "r");
  assert(fd != NULL);
  char word[4];
  unsigned int address = 0x0;
  while (fread(&word, sizeof(word), 1, fd) == 1 && !feof(fd) && !ferror(fd)) {
    guestStore(address, ((word[0] & 0xff) << 24) | ((word[1] & 0xff) << 16) |
                            ((word[2] & 0xff) << 8) | (word[3] & 0xff));
    address += 0x4;
    assert(address < size);
  }
  fclose(fd);
}


x86 assembly (clang, -O0):
<fillState>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
seta   %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
mov    -0x8(%rbp),%rdi
lea    0xe61(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
movl   $0x0,-0x28(%rbp)
lea    -0x24(%rbp),%rdi
mov    -0x20(%rbp),%rcx
mov    $0x4,%esi
mov    $0x1,%edx
call   1050 <fread@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x1,%ecx
mov    %al,-0x29(%rbp)
jne    1215 <fillState+0xa5>
mov    -0x20(%rbp),%rdi
call   1080 <feof@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x29(%rbp)
jne    1215 <fillState+0xa5>
mov    -0x20(%rbp),%rdi
call   1030 <ferror@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
mov    %al,-0x29(%rbp)
mov    -0x29(%rbp),%al
test   $0x1,%al
jne    1225 <fillState+0xb5>
jmp    1287 <fillState+0x117>
mov    -0x28(%rbp),%edi
movsbl -0x24(%rbp),%eax
and    $0xff,%eax
shl    $0x18,%eax
movsbl -0x23(%rbp),%ecx
and    $0xff,%ecx
shl    $0x10,%ecx
or     %ecx,%eax
movsbl -0x22(%rbp),%ecx
and    $0xff,%ecx
shl    $0x8,%ecx
or     %ecx,%eax
movsbl -0x21(%rbp),%ecx
and    $0xff,%ecx
or     %ecx,%eax
movsbl %al,%esi
call   1040 <guestStore@plt>
mov    -0x28(%rbp),%eax
add    $0x4,%eax
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x14(%rbp),%eax
setb   %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
jmp    11c1 <fillState+0x51>
mov    -0x20(%rbp),%rdi
call   1060 <fclose@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fillState>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%r14d
mov    %rdi,%rbx
xor    %edi,%edi
test   %edx,%edx
setne  %dil
call   1070 <assert@plt>
lea    0xe6f(%rip),%rsi
mov    %rbx,%rdi
call   1090 <fopen@plt>
mov    %rax,%rbx
xor    %edi,%edi
test   %rax,%rax
setne  %dil
call   1070 <assert@plt>
lea    0x4(%rsp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1050 <fread@plt>
cmp    $0x1,%eax
jne    121f <fillState+0xaf>
xor    %ebp,%ebp
lea    0x4(%rsp),%r15
nopl   (%rax)
mov    %rbx,%rdi
call   1080 <feof@plt>
test   %eax,%eax
jne    121f <fillState+0xaf>
mov    %rbx,%rdi
call   1030 <ferror@plt>
test   %eax,%eax
jne    121f <fillState+0xaf>
movsbl 0x7(%rsp),%esi
mov    %ebp,%edi
call   1040 <guestStore@plt>
add    $0x4,%ebp
xor    %edi,%edi
cmp    %r14d,%ebp
setb   %dil
call   1070 <assert@plt>
mov    %r15,%rdi
mov    $0x4,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1050 <fread@plt>
cmp    $0x1,%eax
je     11d0 <fillState+0x60>
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1060 <fclose@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
define void @fillState(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32*
%8 = alloca [4 x i8]
%9 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%10 = load i32, i32* %6
%11 = icmp ugt i32 %10, 0
%12 = zext i1 %11 to i32
%13 = call i32 @assert(i32 %12)
%14 = load i8*, i8** %4
%15 = call i32* @fopen(i8* %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %15, i32** %7
%16 = load i32*, i32** %7
%17 = icmp ne i32* %16, null
%18 = zext i1 %17 to i32
%19 = call i32 @assert(i32 %18)
store i32 0, i32* %9
br label %20
20: ; preds = %36, %3
%21 = bitcast [4 x i8]* %8 to i8**
%22 = load i32*, i32** %7
%23 = call i32 @fread(i8** %21, i32 4, i32 1, i32* %22)
%24 = icmp eq i32 %23, 1
br i1 %24, label %25, label %34
25: ; preds = %20
%26 = load i32*, i32** %7
%27 = call i32 @feof(i32* %26)
%28 = icmp ne i32 %27, 0
br i1 %28, label %34, label %29
29: ; preds = %25
%30 = load i32*, i32** %7
%31 = call i32 @ferror(i32* %30)
%32 = icmp ne i32 %31, 0
%33 = xor i1 %32, true
br label %34
34: ; preds = %29, %25, %20
%35 = phi i1 [ false, %25 ], [ false, %20 ], [ %33, %29 ]
br i1 %35, label %36, label %69
36: ; preds = %34
%37 = load i32, i32* %9
%38 = getelementptr inbounds [4 x i8], [4 x i8]* %8, i64 0, i64 0
%39 = load i8, i8* %38
%40 = sext i8 %39 to i32
%41 = and i32 %40, 255
%42 = shl i32 %41, 24
%43 = getelementptr inbounds [4 x i8], [4 x i8]* %8, i64 0, i64 1
%44 = load i8, i8* %43
%45 = sext i8 %44 to i32
%46 = and i32 %45, 255
%47 = shl i32 %46, 16
%48 = or i32 %42, %47
%49 = getelementptr inbounds [4 x i8], [4 x i8]* %8, i64 0, i64 2
%50 = load i8, i8* %49
%51 = sext i8 %50 to i32
%52 = and i32 %51, 255
%53 = shl i32 %52, 8
%54 = or i32 %48, %53
%55 = getelementptr inbounds [4 x i8], [4 x i8]* %8, i64 0, i64 3
%56 = load i8, i8* %55
%57 = sext i8 %56 to i32
%58 = and i32 %57, 255
%59 = or i32 %54, %58
%60 = trunc i32 %59 to i8
%61 = call i32 @guestStore(i32 %37, i8 signext %60)
%62 = load i32, i32* %9
%63 = add i32 %62, 4
store i32 %63, i32* %9
%64 = load i32, i32* %9
%65 = load i32, i32* %6
%66 = icmp ult i32 %64, %65
%67 = zext i1 %66 to i32
%68 = call i32 @assert(i32 %67)
br label %20
69: ; preds = %34
%70 = load i32*, i32** %7
%71 = call i32 @fclose(i32* %70)
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
define void @fillState(i8* nocapture %0, i8* nocapture readnone %1, i32 %2) {
%4 = alloca [4 x i8]
%5 = icmp ne i32 %2, 0
%6 = zext i1 %5 to i32
%7 = tail call i32 @assert(i32 %6)
%8 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%9 = icmp ne i32* %8, null
%10 = zext i1 %9 to i32
%11 = tail call i32 @assert(i32 %10)
%12 = getelementptr inbounds [4 x i8], [4 x i8]* %4, i64 0, i64 0
%13 = bitcast [4 x i8]* %4 to i8**
%14 = call i32 @fread(i8** %13, i32 4, i32 1, i32* %8)
%15 = icmp eq i32 %14, 1
br i1 %15, label %16, label %34
16: ; preds = %3
%17 = getelementptr inbounds [4 x i8], [4 x i8]* %4, i64 0, i64 3
br label %18
18: ; preds = %16, %25
%19 = phi i32 [ 0, %16 ], [ %28, %25 ]
%20 = tail call i32 @feof(i32* %8)
%21 = icmp eq i32 %20, 0
br i1 %21, label %22, label %34
22: ; preds = %18
%23 = tail call i32 @ferror(i32* %8)
%24 = icmp eq i32 %23, 0
br i1 %24, label %25, label %34
25: ; preds = %22
%26 = load i8, i8* %17
%27 = tail call i32 @guestStore(i32 %19, i8 signext %26)
%28 = add i32 %19, 4
%29 = icmp ult i32 %28, %2
%30 = zext i1 %29 to i32
%31 = tail call i32 @assert(i32 %30)
%32 = call i32 @fread(i8** %13, i32 4, i32 1, i32* %8)
%33 = icmp eq i32 %32, 1
br i1 %33, label %18, label %34
34: ; preds = %22, %18, %25, %3
%35 = tail call i32 @fclose(i32* %8)
ret void
}