#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 */
struct pci_device {
  int vendor_id;
  int rom_size;
};

/* Variables and functions */
int O_CREAT;
int O_RDWR;
int O_TRUNC;
int S_IRGRP;
int S_IROTH;
int S_IRUSR;
int S_IWGRP;
int S_IWOTH;
int S_IWUSR;
int /*<<< orphan*/ close(int);
int errno;
int /*<<< orphan*/ errx(int, char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
void *malloc(int);
int open(char *, int, int);
struct pci_device *pci_device_find_by_slot(int /*<<< orphan*/,
                                           int /*<<< orphan*/, int,
                                           int /*<<< orphan*/);
int pci_device_probe(struct pci_device *);
int pci_device_read_rom(struct pci_device *, void *);
int /*<<< orphan*/ pci_system_cleanup();
int pci_system_init();
int /*<<< orphan*/ stderr;
char *strerror(int);
int /*<<< orphan*/ usage();
int write(int, void *, int);
int main(int argc, char **argv) {
  struct pci_device *dev;
  void *bios;
  int error, fd;
  if (argc != 2)
    usage();
  error = pci_system_init();
  if (error != 0) {
    fprintf(stderr, "Couldn't initialize PCI system: %s\n", strerror(error));
    exit(1);
  }
  dev = pci_device_find_by_slot(0, 0, 2, 0);
  if (dev == NULL)
    errx(1, "Couldn't find graphics card");
  error = pci_device_probe(dev);
  if (error != 0) {
    fprintf(stderr, "Couldn't probe graphics card: %s\n", strerror(error));
    exit(1);
  }
  if (dev->vendor_id != 0x8086)
    errx(1, "Graphics card is non-intel");
  if (dev->rom_size == 0)
    dev->rom_size = 64 * 1024;
  bios = malloc(dev->rom_size);
  if (bios == NULL)
    errx(1, "Couldn't allocate memory for BIOS data\n");
  error = pci_device_read_rom(dev, bios);
  if (error != 0) {
    fprintf(stderr, "Couldn't read graphics card ROM: %s\n", strerror(error));
    exit(1);
  }
  fd = open(argv[1], O_RDWR | O_CREAT | O_TRUNC,
            (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH));
  if (fd < 0) {
    fprintf(stderr, "Couldn't open output: %s\n", strerror(errno));
    exit(1);
  }
  if (write(fd, bios, dev->rom_size) < dev->rom_size) {
    fprintf(stderr, "Couldn't write BIOS data: %s\n", strerror(errno));
    exit(1);
  }
  close(fd);
  pci_system_cleanup();
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     1207 <main+0x27>
mov    $0x0,%al
call   10b0 <usage@plt>
mov    $0x0,%al
call   1100 <pci_system_init@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
je     124b <main+0x6b>
mov    0x2d96(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x24(%rbp),%edi
call   10f0 <strerror@plt>
mov    -0x2c(%rbp),%edi
mov    %rax,%rdx
lea    0xdc4(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
xor    %ecx,%ecx
mov    $0x2,%edx
mov    %ecx,%edi
mov    %ecx,%esi
call   1070 <pci_device_find_by_slot@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    127b <main+0x9b>
mov    $0x1,%edi
lea    0xdae(%rip),%rsi
call   1040 <errx@plt>
mov    -0x18(%rbp),%rdi
call   1090 <pci_device_probe@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
je     12c1 <main+0xe1>
mov    0x2d20(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
mov    -0x24(%rbp),%edi
call   10f0 <strerror@plt>
mov    -0x30(%rbp),%edi
mov    %rax,%rdx
lea    0xd8e(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
mov    -0x18(%rbp),%rax
cmpl   $0x8086,(%rax)
je     12e2 <main+0x102>
mov    $0x1,%edi
lea    0xd85(%rip),%rsi
call   1040 <errx@plt>
mov    -0x18(%rbp),%rax
cmpl   $0x0,0x4(%rax)
jne    12fb <main+0x11b>
mov    -0x18(%rbp),%rax
movl   $0x10000,0x4(%rax)
mov    -0x18(%rbp),%rax
mov    0x4(%rax),%edi
call   10a0 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1327 <main+0x147>
mov    $0x1,%edi
lea    0xd5b(%rip),%rsi
call   1040 <errx@plt>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1080 <pci_device_read_rom@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
je     1371 <main+0x191>
mov    0x2c70(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
mov    -0x24(%rbp),%edi
call   10f0 <strerror@plt>
mov    -0x34(%rbp),%edi
mov    %rax,%rdx
lea    0xd43(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2c58(%rip),%rax
mov    (%rax),%esi
mov    0x2c6f(%rip),%rax
or     (%rax),%esi
mov    0x2c5e(%rip),%rax
or     (%rax),%esi
mov    0x2bfd(%rip),%rax
mov    (%rax),%edx
mov    0x2c24(%rip),%rax
or     (%rax),%edx
mov    0x2bfb(%rip),%rax
or     (%rax),%edx
mov    0x2c1a(%rip),%rax
or     (%rax),%edx
mov    0x2be1(%rip),%rax
or     (%rax),%edx
mov    0x2bc0(%rip),%rax
or     (%rax),%edx
call   10c0 <open@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
jge    1412 <main+0x232>
mov    0x2bd5(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x38(%rbp)
mov    0x2bc1(%rip),%rax
mov    (%rax),%edi
call   10f0 <strerror@plt>
mov    -0x38(%rbp),%edi
mov    %rax,%rdx
lea    0xcc7(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
mov    -0x28(%rbp),%edi
mov    -0x20(%rbp),%rsi
mov    -0x18(%rbp),%rax
mov    0x4(%rax),%edx
call   1030 <write@plt>
mov    -0x18(%rbp),%rcx
cmp    0x4(%rcx),%eax
jge    1468 <main+0x288>
mov    0x2b7f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x3c(%rbp)
mov    0x2b6b(%rip),%rax
mov    (%rax),%edi
call   10f0 <strerror@plt>
mov    -0x3c(%rbp),%edi
mov    %rax,%rdx
lea    0xc8b(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
mov    -0x28(%rbp),%edi
call   1050 <close@plt>
mov    $0x0,%al
call   10d0 <pci_system_cleanup@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
cmp    $0x2,%edi
je     11f6 <main+0x16>
xor    %eax,%eax
call   10b0 <usage@plt>
xor    %eax,%eax
call   1100 <pci_system_init@plt>
test   %eax,%eax
jne    132c <main+0x14c>
xor    %edi,%edi
xor    %esi,%esi
mov    $0x2,%edx
xor    %ecx,%ecx
call   1070 <pci_device_find_by_slot@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    122e <main+0x4e>
lea    0xe00(%rip),%rsi
mov    $0x1,%edi
call   1040 <errx@plt>
mov    %rbx,%rdi
call   1090 <pci_device_probe@plt>
test   %eax,%eax
jne    1345 <main+0x165>
cmpl   $0x8086,(%rbx)
je     1257 <main+0x77>
lea    0xe15(%rip),%rsi
mov    $0x1,%edi
call   1040 <errx@plt>
mov    0x4(%rbx),%edi
test   %edi,%edi
jne    126a <main+0x8a>
movl   $0x10000,0x4(%rbx)
mov    $0x10000,%edi
call   10a0 <malloc@plt>
mov    %rax,%r15
test   %rax,%rax
jne    1288 <main+0xa8>
lea    0xdff(%rip),%rsi
mov    $0x1,%edi
call   1040 <errx@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1080 <pci_device_read_rom@plt>
test   %eax,%eax
jne    135e <main+0x17e>
mov    0x2d36(%rip),%rax
mov    0x2d4f(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2d3c(%rip),%rax
or     (%rax),%esi
mov    0x2cdb(%rip),%rax
mov    0x2d04(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    0x2cd9(%rip),%rax
or     (%rax),%edx
mov    0x2cf8(%rip),%rax
or     (%rax),%edx
mov    0x2cbf(%rip),%rax
or     (%rax),%edx
mov    0x8(%r14),%rdi
mov    0x2c9a(%rip),%rax
or     (%rax),%edx
call   10c0 <open@plt>
test   %eax,%eax
js     1377 <main+0x197>
mov    %eax,%ebp
mov    0x4(%rbx),%edx
mov    %eax,%edi
mov    %r15,%rsi
call   1030 <write@plt>
cmp    0x4(%rbx),%eax
jl     1397 <main+0x1b7>
mov    %ebp,%edi
call   1050 <close@plt>
xor    %eax,%eax
call   10d0 <pci_system_cleanup@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2c85(%rip),%rcx
mov    (%rcx),%ebx
mov    %eax,%edi
call   10f0 <strerror@plt>
lea    0xcbd(%rip),%rsi
jmp    13b5 <main+0x1d5>
mov    0x2c6c(%rip),%rcx
mov    (%rcx),%ebx
mov    %eax,%edi
call   10f0 <strerror@plt>
lea    0xce4(%rip),%rsi
jmp    13b5 <main+0x1d5>
mov    0x2c53(%rip),%rcx
mov    (%rcx),%ebx
mov    %eax,%edi
call   10f0 <strerror@plt>
lea    0xd30(%rip),%rsi
jmp    13b5 <main+0x1d5>
mov    0x2c3a(%rip),%rax
mov    (%rax),%ebx
mov    0x2c29(%rip),%rax
mov    (%rax),%edi
call   10f0 <strerror@plt>
lea    0xd35(%rip),%rsi
jmp    13b5 <main+0x1d5>
mov    0x2c1a(%rip),%rax
mov    (%rax),%ebx
mov    0x2c09(%rip),%rax
mov    (%rax),%edi
call   10f0 <strerror@plt>
lea    0xd2f(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>

LLVM IR (-O0):
%struct.pci_device = type { i32, i32 }
@stderr = global i32 0
@.str = [36 x i8] c"Couldn't initialize PCI system: %s\0A\00"
@.str.1 = [28 x i8] c"Couldn't find graphics card\00"
@.str.2 = [34 x i8] c"Couldn't probe graphics card: %s\0A\00"
@.str.3 = [27 x i8] c"Graphics card is non-intel\00"
@.str.4 = [40 x i8] c"Couldn't allocate memory for BIOS data\0A\00"
@.str.5 = [37 x i8] c"Couldn't read graphics card ROM: %s\0A\00"
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@S_IRGRP = global i32 0
@S_IWGRP = global i32 0
@S_IROTH = global i32 0
@S_IWOTH = global i32 0
@.str.6 = [26 x i8] c"Couldn't open output: %s\0A\00"
@errno = global i32 0
@.str.7 = [30 x i8] c"Couldn't write BIOS data: %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.pci_device*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp ne i32 %10, 2
br i1 %11, label %12, label %14
12: ; preds = %2
%13 = call i32 (...) @usage()
br label %14
14: ; preds = %12, %2
%15 = call i32 (...) @pci_system_init()
store i32 %15, i32* %8
%16 = load i32, i32* %8
%17 = icmp ne i32 %16, 0
br i1 %17, label %18, label %24
18: ; preds = %14
%19 = load i32, i32* @stderr
%20 = load i32, i32* %8
%21 = call i8* @strerror(i32 %20)
%22 = call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i8* %21)
%23 = call i32 @exit(i32 1)
unreachable
24: ; preds = %14
%25 = call %struct.pci_device* @pci_device_find_by_slot(i32 0, i32 0, i32 2, i32 0)
store %struct.pci_device* %25, %struct.pci_device** %6
%26 = load %struct.pci_device*, %struct.pci_device** %6
%27 = icmp eq %struct.pci_device* %26, null
br i1 %27, label %28, label %30
28: ; preds = %24
%29 = call i32 @errx(i32 1, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
br label %30
30: ; preds = %28, %24
%31 = load %struct.pci_device*, %struct.pci_device** %6
%32 = call i32 @pci_device_probe(%struct.pci_device* %31)
store i32 %32, i32* %8
%33 = load i32, i32* %8
%34 = icmp ne i32 %33, 0
br i1 %34, label %35, label %41
35: ; preds = %30
%36 = load i32, i32* @stderr
%37 = load i32, i32* %8
%38 = call i8* @strerror(i32 %37)
%39 = call i32 @fprintf(i32 %36, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0), i8* %38)
%40 = call i32 @exit(i32 1)
unreachable
41: ; preds = %30
%42 = load %struct.pci_device*, %struct.pci_device** %6
%43 = getelementptr inbounds %struct.pci_device, %struct.pci_device* %42, i32 0, i32 0
%44 = load i32, i32* %43
%45 = icmp ne i32 %44, 32902
br i1 %45, label %46, label %48
46: ; preds = %41
%47 = call i32 @errx(i32 1, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0))
br label %48
48: ; preds = %46, %41
%49 = load %struct.pci_device*, %struct.pci_device** %6
%50 = getelementptr inbounds %struct.pci_device, %struct.pci_device* %49, i32 0, i32 1
%51 = load i32, i32* %50
%52 = icmp eq i32 %51, 0
br i1 %52, label %53, label %56
53: ; preds = %48
%54 = load %struct.pci_device*, %struct.pci_device** %6
%55 = getelementptr inbounds %struct.pci_device, %struct.pci_device* %54, i32 0, i32 1
store i32 65536, i32* %55
br label %56
56: ; preds = %53, %48
%57 = load %struct.pci_device*, %struct.pci_device** %6
%58 = getelementptr inbounds %struct.pci_device, %struct.pci_device* %57, i32 0, i32 1
%59 = load i32, i32* %58
%60 = call i8* @malloc(i32 %59)
store i8* %60, i8** %7
%61 = load i8*, i8** %7
%62 = icmp eq i8* %61, null
br i1 %62, label %63, label %65
63: ; preds = %56
%64 = call i32 @errx(i32 1, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.4, i64 0, i64 0))
br label %65
65: ; preds = %63, %56
%66 = load %struct.pci_device*, %struct.pci_device** %6
%67 = load i8*, i8** %7
%68 = call i32 @pci_device_read_rom(%struct.pci_device* %66, i8* %67)
store i32 %68, i32* %8
%69 = load i32, i32* %8
%70 = icmp ne i32 %69, 0
br i1 %70, label %71, label %77
71: ; preds = %65
%72 = load i32, i32* @stderr
%73 = load i32, i32* %8
%74 = call i8* @strerror(i32 %73)
%75 = call i32 @fprintf(i32 %72, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.5, i64 0, i64 0), i8* %74)
%76 = call i32 @exit(i32 1)
unreachable
77: ; preds = %65
%78 = load i8**, i8*** %5
%79 = getelementptr inbounds i8*, i8** %78, i64 1
%80 = load i8*, i8** %79
%81 = load i32, i32* @O_RDWR
%82 = load i32, i32* @O_CREAT
%83 = or i32 %81, %82
%84 = load i32, i32* @O_TRUNC
%85 = or i32 %83, %84
%86 = load i32, i32* @S_IRUSR
%87 = load i32, i32* @S_IWUSR
%88 = or i32 %86, %87
%89 = load i32, i32* @S_IRGRP
%90 = or i32 %88, %89
%91 = load i32, i32* @S_IWGRP
%92 = or i32 %90, %91
%93 = load i32, i32* @S_IROTH
%94 = or i32 %92, %93
%95 = load i32, i32* @S_IWOTH
%96 = or i32 %94, %95
%97 = call i32 @open(i8* %80, i32 %85, i32 %96)
store i32 %97, i32* %9
%98 = load i32, i32* %9
%99 = icmp slt i32 %98, 0
br i1 %99, label %100, label %106
100: ; preds = %77
%101 = load i32, i32* @stderr
%102 = load i32, i32* @errno
%103 = call i8* @strerror(i32 %102)
%104 = call i32 @fprintf(i32 %101, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.6, i64 0, i64 0), i8* %103)
%105 = call i32 @exit(i32 1)
unreachable
106: ; preds = %77
%107 = load i32, i32* %9
%108 = load i8*, i8** %7
%109 = load %struct.pci_device*, %struct.pci_device** %6
%110 = getelementptr inbounds %struct.pci_device, %struct.pci_device* %109, i32 0, i32 1
%111 = load i32, i32* %110
%112 = call i32 @write(i32 %107, i8* %108, i32 %111)
%113 = load %struct.pci_device*, %struct.pci_device** %6
%114 = getelementptr inbounds %struct.pci_device, %struct.pci_device* %113, i32 0, i32 1
%115 = load i32, i32* %114
%116 = icmp slt i32 %112, %115
br i1 %116, label %117, label %123
117: ; preds = %106
%118 = load i32, i32* @stderr
%119 = load i32, i32* @errno
%120 = call i8* @strerror(i32 %119)
%121 = call i32 @fprintf(i32 %118, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.7, i64 0, i64 0), i8* %120)
%122 = call i32 @exit(i32 1)
unreachable
123: ; preds = %106
%124 = load i32, i32* %9
%125 = call i32 @close(i32 %124)
%126 = call i32 (...) @pci_system_cleanup()
ret i32 0
}

LLVM IR (-O2):
%struct.pci_device = type { i32, i32 }
@stderr = global i32 0
@.str = [36 x i8] c"Couldn't initialize PCI system: %s\0A\00"
@.str.1 = [28 x i8] c"Couldn't find graphics card\00"
@.str.2 = [34 x i8] c"Couldn't probe graphics card: %s\0A\00"
@.str.3 = [27 x i8] c"Graphics card is non-intel\00"
@.str.4 = [40 x i8] c"Couldn't allocate memory for BIOS data\0A\00"
@.str.5 = [37 x i8] c"Couldn't read graphics card ROM: %s\0A\00"
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@S_IRGRP = global i32 0
@S_IWGRP = global i32 0
@S_IROTH = global i32 0
@S_IWOTH = global i32 0
@.str.6 = [26 x i8] c"Couldn't open output: %s\0A\00"
@errno = global i32 0
@.str.7 = [30 x i8] c"Couldn't write BIOS data: %s\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 2
br i1 %3, label %6, label %4
4: ; preds = %2
%5 = tail call i32 (...) @usage()
br label %6
6: ; preds = %4, %2
%7 = tail call i32 (...) @pci_system_init()
%8 = icmp eq i32 %7, 0
br i1 %8, label %14, label %9
9: ; preds = %6
%10 = load i32, i32* @stderr
%11 = tail call i8* @strerror(i32 %7)
%12 = tail call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i8* %11)
%13 = tail call i32 @exit(i32 1)
unreachable
14: ; preds = %6
%15 = tail call %struct.pci_device* @pci_device_find_by_slot(i32 0, i32 0, i32 2, i32 0)
%16 = icmp eq %struct.pci_device* %15, null
br i1 %16, label %17, label %19
17: ; preds = %14
%18 = tail call i32 @errx(i32 1, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
br label %19
19: ; preds = %17, %14
%20 = tail call i32 @pci_device_probe(%struct.pci_device* %15)
%21 = icmp eq i32 %20, 0
br i1 %21, label %27, label %22
22: ; preds = %19
%23 = load i32, i32* @stderr
%24 = tail call i8* @strerror(i32 %20)
%25 = tail call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0), i8* %24)
%26 = tail call i32 @exit(i32 1)
unreachable
27: ; preds = %19
%28 = getelementptr inbounds %struct.pci_device, %struct.pci_device* %15, i64 0, i32 0
%29 = load i32, i32* %28
%30 = icmp eq i32 %29, 32902
br i1 %30, label %33, label %31
31: ; preds = %27
%32 = tail call i32 @errx(i32 1, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0))
br label %33
33: ; preds = %31, %27
%34 = getelementptr inbounds %struct.pci_device, %struct.pci_device* %15, i64 0, i32 1
%35 = load i32, i32* %34
%36 = icmp eq i32 %35, 0
br i1 %36, label %37, label %38
37: ; preds = %33
store i32 65536, i32* %34
br label %38
38: ; preds = %37, %33
%39 = phi i32 [ 65536, %37 ], [ %35, %33 ]
%40 = tail call i8* @malloc(i32 %39)
%41 = icmp eq i8* %40, null
br i1 %41, label %42, label %44
42: ; preds = %38
%43 = tail call i32 @errx(i32 1, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.4, i64 0, i64 0))
br label %44
44: ; preds = %42, %38
%45 = tail call i32 @pci_device_read_rom(%struct.pci_device* %15, i8* %40)
%46 = icmp eq i32 %45, 0
br i1 %46, label %52, label %47
47: ; preds = %44
%48 = load i32, i32* @stderr
%49 = tail call i8* @strerror(i32 %45)
%50 = tail call i32 @fprintf(i32 %48, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.5, i64 0, i64 0), i8* %49)
%51 = tail call i32 @exit(i32 1)
unreachable
52: ; preds = %44
%53 = getelementptr inbounds i8*, i8** %1, i64 1
%54 = load i8*, i8** %53
%55 = load i32, i32* @O_RDWR
%56 = load i32, i32* @O_CREAT
%57 = or i32 %56, %55
%58 = load i32, i32* @O_TRUNC
%59 = or i32 %57, %58
%60 = load i32, i32* @S_IRUSR
%61 = load i32, i32* @S_IWUSR
%62 = or i32 %61, %60
%63 = load i32, i32* @S_IRGRP
%64 = or i32 %62, %63
%65 = load i32, i32* @S_IWGRP
%66 = or i32 %64, %65
%67 = load i32, i32* @S_IROTH
%68 = or i32 %66, %67
%69 = load i32, i32* @S_IWOTH
%70 = or i32 %68, %69
%71 = tail call i32 @open(i8* %54, i32 %59, i32 %70)
%72 = icmp slt i32 %71, 0
br i1 %72, label %73, label %79
73: ; preds = %52
%74 = load i32, i32* @stderr
%75 = load i32, i32* @errno
%76 = tail call i8* @strerror(i32 %75)
%77 = tail call i32 @fprintf(i32 %74, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.6, i64 0, i64 0), i8* %76)
%78 = tail call i32 @exit(i32 1)
unreachable
79: ; preds = %52
%80 = load i32, i32* %34
%81 = tail call i32 @write(i32 %71, i8* %40, i32 %80)
%82 = load i32, i32* %34
%83 = icmp slt i32 %81, %82
br i1 %83, label %84, label %90
84: ; preds = %79
%85 = load i32, i32* @stderr
%86 = load i32, i32* @errno
%87 = tail call i8* @strerror(i32 %86)
%88 = tail call i32 @fprintf(i32 %85, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.7, i64 0, i64 0), i8* %87)
%89 = tail call i32 @exit(i32 1)
unreachable
90: ; preds = %79
%91 = tail call i32 @close(i32 %71)
%92 = tail call i32 (...) @pci_system_cleanup()
ret i32 0
}