#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*/ uint8_t;

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int lseek(int, int, int /*<<< orphan*/);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int read(int, int /*<<< orphan*/ *, int);
void load_bank_at(uint8_t *p, char *name, int offset) {
  int fd = open(name, O_RDONLY);
  if (fd == -1) {
    perror(name);
    exit(1);
  }
  if (lseek(fd, offset, SEEK_SET) != offset) {
    perror("lseek");
    exit(1);
  }
  if (read(fd, p, 16384) < 1) {
    perror(name);
    exit(1);
  }
  close(fd);
}


x86 assembly (clang, -O0):
<load_bank_at>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e6a(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jne    11a5 <load_bank_at+0x45>
mov    -0x10(%rbp),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x18(%rbp),%edi
mov    -0x14(%rbp),%esi
mov    0x2e26(%rip),%rax
mov    (%rax),%edx
call   1030 <lseek@plt>
cmp    -0x14(%rbp),%eax
je     11d8 <load_bank_at+0x78>
lea    0xe37(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x18(%rbp),%edi
mov    -0x8(%rbp),%rsi
mov    $0x4000,%edx
call   1050 <read@plt>
cmp    $0x1,%eax
jge    1205 <load_bank_at+0xa5>
mov    -0x10(%rbp),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x18(%rbp),%edi
call   1040 <close@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<load_bank_at>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%ebx
mov    %rsi,%r14
mov    %rdi,%r15
mov    0x2e72(%rip),%rax
mov    (%rax),%esi
mov    %r14,%rdi
call   1060 <open@plt>
cmp    $0xffffffff,%eax
je     11c1 <load_bank_at+0x61>
mov    %eax,%ebp
mov    0x2e4a(%rip),%rax
mov    (%rax),%edx
mov    %ebp,%edi
mov    %ebx,%esi
call   1030 <lseek@plt>
cmp    %ebx,%eax
jne    11c6 <load_bank_at+0x66>
mov    %ebp,%edi
mov    %r15,%rsi
mov    $0x4000,%edx
call   1050 <read@plt>
test   %eax,%eax
jle    11c1 <load_bank_at+0x61>
mov    %ebp,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <close@plt>
mov    %r14,%rdi
jmp    11cd <load_bank_at+0x6d>
lea    0xe33(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@O_RDONLY = global i32 0
@SEEK_SET = global i32 0
@.str = [6 x i8] c"lseek\00"
define void @load_bank_at(i32* %0, i8* %1, i32 %2) {
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
store i32* %0, i32** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%8 = load i8*, i8** %5
%9 = load i32, i32* @O_RDONLY
%10 = call i32 @open(i8* %8, i32 %9)
store i32 %10, i32* %7
%11 = load i32, i32* %7
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %17
13: ; preds = %3
%14 = load i8*, i8** %5
%15 = call i32 @perror(i8* %14)
%16 = call i32 @exit(i32 1)
unreachable
17: ; preds = %3
%18 = load i32, i32* %7
%19 = load i32, i32* %6
%20 = load i32, i32* @SEEK_SET
%21 = call i32 @lseek(i32 %18, i32 %19, i32 %20)
%22 = load i32, i32* %6
%23 = icmp ne i32 %21, %22
br i1 %23, label %24, label %27
24: ; preds = %17
%25 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%26 = call i32 @exit(i32 1)
unreachable
27: ; preds = %17
%28 = load i32, i32* %7
%29 = load i32*, i32** %4
%30 = call i32 @read(i32 %28, i32* %29, i32 16384)
%31 = icmp slt i32 %30, 1
br i1 %31, label %32, label %36
32: ; preds = %27
%33 = load i8*, i8** %5
%34 = call i32 @perror(i8* %33)
%35 = call i32 @exit(i32 1)
unreachable
36: ; preds = %27
%37 = load i32, i32* %7
%38 = call i32 @close(i32 %37)
ret void
}

LLVM IR (-O2):
@O_RDONLY = global i32 0
@SEEK_SET = global i32 0
@.str = [6 x i8] c"lseek\00"
define void @load_bank_at(i32* nocapture %0, i8* nocapture %1, i32 %2) {
%4 = load i32, i32* @O_RDONLY
%5 = tail call i32 @open(i8* %1, i32 %4)
%6 = icmp eq i32 %5, -1
br i1 %6, label %7, label %10
7: ; preds = %3
%8 = tail call i32 @perror(i8* %1)
%9 = tail call i32 @exit(i32 1)
unreachable
10: ; preds = %3
%11 = load i32, i32* @SEEK_SET
%12 = tail call i32 @lseek(i32 %5, i32 %2, i32 %11)
%13 = icmp eq i32 %12, %2
br i1 %13, label %17, label %14
14: ; preds = %10
%15 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%16 = tail call i32 @exit(i32 1)
unreachable
17: ; preds = %10
%18 = tail call i32 @read(i32 %5, i32* %0, i32 16384)
%19 = icmp slt i32 %18, 1
br i1 %19, label %20, label %23
20: ; preds = %17
%21 = tail call i32 @perror(i8* %1)
%22 = tail call i32 @exit(i32 1)
unreachable
23: ; preds = %17
%24 = tail call i32 @close(i32 %5)
ret void
}