#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;
int /*<<< orphan*/ error(char *, ...);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int fread(unsigned char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int, int /*<<< orphan*/);
int ftell(int /*<<< orphan*/ *);
int fwrite(unsigned char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
unsigned long read4FromEco(unsigned char *);
scalar_t__ strcmp(char *, char *);
int strtoul(char *, char **, int);
int /*<<< orphan*/ usage(char *);
int main(int argc, char *argv[]) {
  int i;
  char *bootName;
  FILE *bootFile;
  int bootSize;
  char *diskName;
  FILE *diskFile;
  unsigned long sliceStart;
  unsigned long sliceSize;
  int part;
  char *endptr;
  unsigned char partTable[512];
  unsigned char *ptptr;
  unsigned long partType;
  unsigned char bootCode[8192];
  unsigned char diskLabel[512];
  if (argc != 4) {
    usage(argv[0]);
    exit(1);
  }
  for (i = 0; i < 8192; i++) {
    bootCode[i] = 0;
  }
  bootName = argv[1];
  bootFile = fopen(bootName, "rb");
  if (bootFile == NULL) {
    error("cannot open bootblock '%s'", bootName);
  }
  fseek(bootFile, 0, SEEK_END);
  bootSize = ftell(bootFile);
  fseek(bootFile, 0, SEEK_SET);
  if (bootSize > 8192) {
    error("bootblock '%s' too big", bootName);
  }
  if (fread(bootCode, 1, bootSize, bootFile) != bootSize) {
    error("cannot read bootblock '%s'", bootName);
  }
  fclose(bootFile);
  printf("Bootblock '%s' read, %d bytes.\n", bootName, bootSize);
  diskName = argv[2];
  diskFile = fopen(diskName, "r+b");
  if (diskFile == NULL) {
    error("cannot open disk image '%s'", diskName);
  }
  if (strcmp(argv[3], "*") == 0) {
    sliceStart = 0;
    fseek(diskFile, 0, SEEK_END);
    sliceSize = ftell(diskFile) / 512;
  } else {
    part = strtoul(argv[3], &endptr, 10);
    if (*endptr != '\0' || part < 0 || part > 15) {
      error("illegal partition number '%s'", argv[3]);
    }
    fseek(diskFile, 1 * 512, SEEK_SET);
    if (fread(partTable, 1, 512, diskFile) != 512) {
      error("cannot read partition table of disk '%s'", diskName);
    }
    ptptr = partTable + part * 32;
    partType = read4FromEco(ptptr + 0);
    if ((partType & 0x7FFFFFFF) != 0x000000A9) {
      error("partition %d of disk '%s' is not a NetBSD slice", part, diskName);
    }
    sliceStart = read4FromEco(ptptr + 4);
    sliceSize = read4FromEco(ptptr + 8);
  }
  printf("Slice size is %lu (0x%lX) sectors of %d bytes each.\n", sliceSize,
         sliceSize, 512);
  fseek(diskFile, (sliceStart + 1) * 512, SEEK_SET);
  if (fread(diskLabel, 1, 512, diskFile) != 512) {
    error("cannot read disklabel of disk '%s'", diskName);
  }
  printf("Disklabel read from disk '%s', %d bytes\n", diskName, 512);
  for (i = 0; i < 512; i++) {
    bootCode[512 + i] = diskLabel[i];
  }
  fseek(diskFile, (sliceStart + 0) * 512, SEEK_SET);
  if (fwrite(bootCode, 1, bootSize, diskFile) != bootSize) {
    error("cannot write bootblock to disk '%s'", diskName);
  }
  printf("Bootblock written to disk '%s', %d bytes\n", diskName, bootSize);
  fclose(diskFile);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2470,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x4,-0x8(%rbp)
je     1209 <main+0x39>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1090 <usage@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
movl   $0x0,-0x14(%rbp)
cmpl   $0x2000,-0x14(%rbp)
jge    1237 <main+0x67>
movslq -0x14(%rbp),%rax
movb   $0x0,-0x2270(%rbp,%rax,1)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1210 <main+0x40>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xdb2(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1274 <main+0xa4>
mov    -0x20(%rbp),%rsi
lea    0xd96(%rip),%rdi
mov    $0x0,%al
call   10a0 <error@plt>
mov    -0x28(%rbp),%rdi
mov    0x2d69(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1080 <fseek@plt>
mov    -0x28(%rbp),%rdi
call   1070 <ftell@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x28(%rbp),%rdi
mov    0x2d39(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1080 <fseek@plt>
cmpl   $0x2000,-0x2c(%rbp)
jle    12c7 <main+0xf7>
mov    -0x20(%rbp),%rsi
lea    0xd5e(%rip),%rdi
mov    $0x0,%al
call   10a0 <error@plt>
lea    -0x2270(%rbp),%rdi
mov    -0x2c(%rbp),%edx
mov    -0x28(%rbp),%rcx
mov    $0x1,%esi
call   1030 <fread@plt>
cmp    -0x2c(%rbp),%eax
je     12fa <main+0x12a>
mov    -0x20(%rbp),%rsi
lea    0xd42(%rip),%rdi
mov    $0x0,%al
call   10a0 <error@plt>
mov    -0x28(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x20(%rbp),%rsi
mov    -0x2c(%rbp),%edx
lea    0xd3f(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
lea    0xd41(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
jne    1355 <main+0x185>
mov    -0x38(%rbp),%rsi
lea    0xd26(%rip),%rdi
mov    $0x0,%al
call   10a0 <error@plt>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
lea    0xd2c(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    13ab <main+0x1db>
movq   $0x0,-0x48(%rbp)
mov    -0x40(%rbp),%rdi
mov    0x2c62(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1080 <fseek@plt>
mov    -0x40(%rbp),%rdi
call   1070 <ftell@plt>
mov    $0x200,%ecx
cltd
idiv   %ecx
cltq
mov    %rax,-0x50(%rbp)
jmp    14cf <main+0x2ff>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
lea    -0x60(%rbp),%rsi
mov    $0xa,%edx
call   10d0 <strtoul@plt>
mov    %eax,-0x54(%rbp)
mov    -0x60(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    13e8 <main+0x218>
cmpl   $0x0,-0x54(%rbp)
jl     13e8 <main+0x218>
cmpl   $0xf,-0x54(%rbp)
jle    13fe <main+0x22e>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rsi
lea    0xc9b(%rip),%rdi
mov    $0x0,%al
call   10a0 <error@plt>
mov    -0x40(%rbp),%rdi
mov    0x2bcf(%rip),%rax
mov    (%rax),%edx
mov    $0x200,%esi
call   1080 <fseek@plt>
lea    -0x260(%rbp),%rdi
mov    -0x40(%rbp),%rcx
mov    $0x1,%esi
mov    $0x200,%edx
call   1030 <fread@plt>
cmp    $0x200,%eax
je     144c <main+0x27c>
mov    -0x38(%rbp),%rsi
lea    0xc6b(%rip),%rdi
mov    $0x0,%al
call   10a0 <error@plt>
lea    -0x260(%rbp),%rax
mov    -0x54(%rbp),%ecx
shl    $0x5,%ecx
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x268(%rbp)
mov    -0x268(%rbp),%rdi
call   10b0 <read4FromEco@plt>
mov    %rax,-0x270(%rbp)
mov    -0x270(%rbp),%rax
and    $0x7fffffff,%rax
cmp    $0xa9,%rax
je     14a7 <main+0x2d7>
mov    -0x54(%rbp),%esi
mov    -0x38(%rbp),%rdx
lea    0xc39(%rip),%rdi
mov    $0x0,%al
call   10a0 <error@plt>
mov    -0x268(%rbp),%rdi
add    $0x4,%rdi
call   10b0 <read4FromEco@plt>
mov    %rax,-0x48(%rbp)
mov    -0x268(%rbp),%rdi
add    $0x8,%rdi
call   10b0 <read4FromEco@plt>
mov    %rax,-0x50(%rbp)
mov    -0x50(%rbp),%rsi
mov    -0x50(%rbp),%rdx
lea    0xc2b(%rip),%rdi
mov    $0x200,%ecx
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x40(%rbp),%rdi
mov    -0x48(%rbp),%rax
add    $0x1,%rax
shl    $0x9,%rax
mov    %eax,%esi
mov    0x2ad5(%rip),%rax
mov    (%rax),%edx
call   1080 <fseek@plt>
lea    -0x2470(%rbp),%rdi
mov    -0x40(%rbp),%rcx
mov    $0x1,%esi
mov    $0x200,%edx
call   1030 <fread@plt>
cmp    $0x200,%eax
je     1541 <main+0x371>
mov    -0x38(%rbp),%rsi
lea    0xc04(%rip),%rdi
mov    $0x0,%al
call   10a0 <error@plt>
mov    -0x38(%rbp),%rsi
lea    0xc15(%rip),%rdi
mov    $0x200,%edx
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x14(%rbp)
cmpl   $0x200,-0x14(%rbp)
jge    1596 <main+0x3c6>
movslq -0x14(%rbp),%rax
mov    -0x2470(%rbp,%rax,1),%cl
mov    -0x14(%rbp),%eax
add    $0x200,%eax
cltq
mov    %cl,-0x2270(%rbp,%rax,1)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    155f <main+0x38f>
mov    -0x40(%rbp),%rdi
mov    -0x48(%rbp),%rax
add    $0x0,%rax
shl    $0x9,%rax
mov    %eax,%esi
mov    0x2a29(%rip),%rax
mov    (%rax),%edx
call   1080 <fseek@plt>
lea    -0x2270(%rbp),%rdi
mov    -0x2c(%rbp),%edx
mov    -0x40(%rbp),%rcx
mov    $0x1,%esi
call   10f0 <fwrite@plt>
cmp    -0x2c(%rbp),%eax
je     15e9 <main+0x419>
mov    -0x38(%rbp),%rsi
lea    0xba8(%rip),%rdi
mov    $0x0,%al
call   10a0 <error@plt>
mov    -0x38(%rbp),%rsi
mov    -0x2c(%rbp),%edx
lea    0xbb7(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x40(%rbp),%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x2470,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x2418,%rsp
mov    %rsi,%r13
cmp    $0x4,%edi
jne    1531 <main+0x341>
lea    0x410(%rsp),%rdi
mov    $0x2000,%edx
xor    %esi,%esi
call   1060 <memset@plt>
mov    0x8(%r13),%rbx
lea    0xdd4(%rip),%rsi
mov    %rbx,%rdi
call   10e0 <fopen@plt>
mov    %rax,%rbp
test   %rax,%rax
jne    124d <main+0x5d>
lea    0xdc0(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   10c0 <error@plt>
mov    0x2d94(%rip),%r12
mov    (%r12),%edx
mov    %rbp,%rdi
xor    %esi,%esi
call   10a0 <fseek@plt>
mov    %rbp,%rdi
call   1080 <ftell@plt>
mov    %eax,%r15d
mov    0x2d64(%rip),%rax
mov    (%rax),%edx
mov    %rbp,%rdi
xor    %esi,%esi
call   10a0 <fseek@plt>
cmp    $0x2001,%r15d
jl     129a <main+0xaa>
lea    0xd8e(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   10c0 <error@plt>
lea    0x410(%rsp),%rdi
mov    $0x1,%esi
mov    %r15d,%edx
mov    %rbp,%rcx
call   1030 <fread@plt>
cmp    %r15d,%eax
je     12c8 <main+0xd8>
lea    0xd77(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   10c0 <error@plt>
mov    %rbp,%rdi
call   1040 <fclose@plt>
lea    0xd79(%rip),%rdi
mov    %rbx,%rsi
mov    %r15d,%edx
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x10(%r13),%rbx
lea    0xd81(%rip),%rsi
mov    %rbx,%rdi
call   10e0 <fopen@plt>
mov    %rax,%r14
test   %rax,%rax
jne    1310 <main+0x120>
lea    0xd6e(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   10c0 <error@plt>
mov    0x18(%r13),%rdi
lea    0xd75(%rip),%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
je     1411 <main+0x221>
mov    0x18(%r13),%rdi
lea    0x8(%rsp),%rsi
mov    $0xa,%edx
call   10f0 <strtoul@plt>
mov    %eax,%r12d
mov    0x8(%rsp),%rax
cmpb   $0x0,(%rax)
jne    1354 <main+0x164>
test   %r12d,%r12d
js     1354 <main+0x164>
cmp    $0x10,%r12d
jl     1366 <main+0x176>
mov    0x18(%r13),%rsi
lea    0xd33(%rip),%rdi
xor    %eax,%eax
call   10c0 <error@plt>
mov    0x2c6b(%rip),%r13
mov    0x0(%r13),%edx
mov    %r14,%rdi
mov    $0x200,%esi
call   10a0 <fseek@plt>
lea    0x210(%rsp),%rdi
mov    $0x1,%esi
mov    $0x200,%edx
mov    %r14,%rcx
call   1030 <fread@plt>
cmp    $0x200,%eax
je     13b0 <main+0x1c0>
lea    0xd0a(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   10c0 <error@plt>
mov    %rbx,%r13
mov    %r12d,%eax
shl    $0x5,%eax
cltq
lea    (%rsp,%rax,1),%rbx
add    $0x210,%rbx
mov    %rbx,%rdi
call   10d0 <read4FromEco@plt>
and    $0x7fffffff,%eax
cmp    $0xa9,%eax
je     13ee <main+0x1fe>
lea    0xcf8(%rip),%rdi
mov    %r12d,%esi
mov    %r13,%rdx
xor    %eax,%eax
call   10c0 <error@plt>
lea    0x4(%rbx),%rdi
call   10d0 <read4FromEco@plt>
mov    %rax,%rbp
add    $0x8,%rbx
mov    %rbx,%rdi
call   10d0 <read4FromEco@plt>
mov    %rax,%rdx
shl    $0x9,%ebp
mov    %r13,%rbx
jmp    143a <main+0x24a>
mov    (%r12),%edx
xor    %ebp,%ebp
mov    %r14,%rdi
xor    %esi,%esi
call   10a0 <fseek@plt>
mov    %r14,%rdi
call   1080 <ftell@plt>
lea    0x1ff(%rax),%ecx
test   %eax,%eax
cmovns %eax,%ecx
sar    $0x9,%ecx
movslq %ecx,%rdx
mov    0x2b97(%rip),%r13
lea    0xcc1(%rip),%rdi
mov    %rdx,%rsi
mov    $0x200,%ecx
xor    %eax,%eax
call   1050 <printf@plt>
lea    0x200(%rbp),%esi
mov    0x0(%r13),%edx
mov    %r14,%rdi
call   10a0 <fseek@plt>
lea    0x10(%rsp),%rdi
mov    $0x1,%esi
mov    $0x200,%edx
mov    %r14,%rcx
call   1030 <fread@plt>
cmp    $0x200,%eax
je     1498 <main+0x2a8>
lea    0xcb0(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   10c0 <error@plt>
lea    0xcc2(%rip),%rdi
mov    %rbx,%rsi
mov    $0x200,%edx
xor    %eax,%eax
call   1050 <printf@plt>
lea    0x610(%rsp),%rdi
lea    0x10(%rsp),%rsi
mov    $0x200,%edx
call   1090 <memcpy@plt>
mov    0x0(%r13),%edx
mov    %r14,%rdi
mov    %ebp,%esi
call   10a0 <fseek@plt>
lea    0x410(%rsp),%rdi
mov    $0x1,%esi
mov    %r15d,%edx
mov    %r14,%rcx
call   1110 <fwrite@plt>
cmp    %r15d,%eax
je     1501 <main+0x311>
lea    0xc93(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   10c0 <error@plt>
lea    0xca6(%rip),%rdi
mov    %rbx,%rsi
mov    %r15d,%edx
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r14,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x2418,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x0(%r13),%rdi
call   10b0 <usage@plt>
mov    $0x1,%edi
call   1100 <exit@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
@.str.1 = [27 x i8] c"cannot open bootblock '%s'\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@.str.2 = [23 x i8] c"bootblock '%s' too big\00"
@.str.3 = [27 x i8] c"cannot read bootblock '%s'\00"
@.str.4 = [32 x i8] c"Bootblock '%s' read, %d bytes.\0A\00"
@.str.5 = [4 x i8] c"r+b\00"
@.str.6 = [28 x i8] c"cannot open disk image '%s'\00"
@.str.7 = [2 x i8] c"*\00"
@.str.8 = [30 x i8] c"illegal partition number '%s'\00"
@.str.9 = [41 x i8] c"cannot read partition table of disk '%s'\00"
@.str.10 = [48 x i8] c"partition %d of disk '%s' is not a NetBSD slice\00"
@.str.11 = [53 x i8] c"Slice size is %lu (0x%lX) sectors of %d bytes each.\0A\00"
@.str.12 = [35 x i8] c"cannot read disklabel of disk '%s'\00"
@.str.13 = [41 x i8] c"Disklabel read from disk '%s', %d bytes\0A\00"
@.str.14 = [36 x i8] c"cannot write bootblock to disk '%s'\00"
@.str.15 = [42 x i8] c"Bootblock written to disk '%s', %d bytes\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32*
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i32*
%12 = alloca i64
%13 = alloca i64
%14 = alloca i32
%15 = alloca i8*
%16 = alloca [512 x i8]
%17 = alloca i8*
%18 = alloca i64
%19 = alloca [8192 x i8]
%20 = alloca [512 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%21 = load i32, i32* %4
%22 = icmp ne i32 %21, 4
br i1 %22, label %23, label %29
23: ; preds = %2
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 0
%26 = load i8*, i8** %25
%27 = call i32 @usage(i8* %26)
%28 = call i32 @exit(i32 1)
unreachable
29: ; preds = %2
store i32 0, i32* %6
br label %30
30: ; preds = %37, %29
%31 = load i32, i32* %6
%32 = icmp slt i32 %31, 8192
br i1 %32, label %33, label %40
33: ; preds = %30
%34 = load i32, i32* %6
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds [8192 x i8], [8192 x i8]* %19, i64 0, i64 %35
store i8 0, i8* %36
br label %37
37: ; preds = %33
%38 = load i32, i32* %6
%39 = add nsw i32 %38, 1
store i32 %39, i32* %6
br label %30
40: ; preds = %30
%41 = load i8**, i8*** %5
%42 = getelementptr inbounds i8*, i8** %41, i64 1
%43 = load i8*, i8** %42
store i8* %43, i8** %7
%44 = load i8*, i8** %7
%45 = call i32* @fopen(i8* %44, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %45, i32** %8
%46 = load i32*, i32** %8
%47 = icmp eq i32* %46, null
br i1 %47, label %48, label %51
48: ; preds = %40
%49 = load i8*, i8** %7
%50 = call i32 (i8*, ...) @error(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8* %49)
br label %51
51: ; preds = %48, %40
%52 = load i32*, i32** %8
%53 = load i32, i32* @SEEK_END
%54 = call i32 @fseek(i32* %52, i32 0, i32 %53)
%55 = load i32*, i32** %8
%56 = call i32 @ftell(i32* %55)
store i32 %56, i32* %9
%57 = load i32*, i32** %8
%58 = load i32, i32* @SEEK_SET
%59 = call i32 @fseek(i32* %57, i32 0, i32 %58)
%60 = load i32, i32* %9
%61 = icmp sgt i32 %60, 8192
br i1 %61, label %62, label %65
62: ; preds = %51
%63 = load i8*, i8** %7
%64 = call i32 (i8*, ...) @error(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i8* %63)
br label %65
65: ; preds = %62, %51
%66 = getelementptr inbounds [8192 x i8], [8192 x i8]* %19, i64 0, i64 0
%67 = load i32, i32* %9
%68 = load i32*, i32** %8
%69 = call i32 @fread(i8* %66, i32 1, i32 %67, i32* %68)
%70 = load i32, i32* %9
%71 = icmp ne i32 %69, %70
br i1 %71, label %72, label %75
72: ; preds = %65
%73 = load i8*, i8** %7
%74 = call i32 (i8*, ...) @error(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0), i8* %73)
br label %75
75: ; preds = %72, %65
%76 = load i32*, i32** %8
%77 = call i32 @fclose(i32* %76)
%78 = load i8*, i8** %7
%79 = load i32, i32* %9
%80 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.4, i64 0, i64 0), i8* %78, i32 %79)
%81 = load i8**, i8*** %5
%82 = getelementptr inbounds i8*, i8** %81, i64 2
%83 = load i8*, i8** %82
store i8* %83, i8** %10
%84 = load i8*, i8** %10
%85 = call i32* @fopen(i8* %84, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0))
store i32* %85, i32** %11
%86 = load i32*, i32** %11
%87 = icmp eq i32* %86, null
br i1 %87, label %88, label %91
88: ; preds = %75
%89 = load i8*, i8** %10
%90 = call i32 (i8*, ...) @error(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.6, i64 0, i64 0), i8* %89)
br label %91
91: ; preds = %88, %75
%92 = load i8**, i8*** %5
%93 = getelementptr inbounds i8*, i8** %92, i64 3
%94 = load i8*, i8** %93
%95 = call i64 @strcmp(i8* %94, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
%96 = icmp eq i64 %95, 0
br i1 %96, label %97, label %105
97: ; preds = %91
store i64 0, i64* %12
%98 = load i32*, i32** %11
%99 = load i32, i32* @SEEK_END
%100 = call i32 @fseek(i32* %98, i32 0, i32 %99)
%101 = load i32*, i32** %11
%102 = call i32 @ftell(i32* %101)
%103 = sdiv i32 %102, 512
%104 = sext i32 %103 to i64
store i64 %104, i64* %13
br label %159
105: ; preds = %91
%106 = load i8**, i8*** %5
%107 = getelementptr inbounds i8*, i8** %106, i64 3
%108 = load i8*, i8** %107
%109 = call i32 @strtoul(i8* %108, i8** %15, i32 10)
store i32 %109, i32* %14
%110 = load i8*, i8** %15
%111 = load i8, i8* %110
%112 = sext i8 %111 to i32
%113 = icmp ne i32 %112, 0
br i1 %113, label %120, label %114
114: ; preds = %105
%115 = load i32, i32* %14
%116 = icmp slt i32 %115, 0
br i1 %116, label %120, label %117
117: ; preds = %114
%118 = load i32, i32* %14
%119 = icmp sgt i32 %118, 15
br i1 %119, label %120, label %125
120: ; preds = %117, %114, %105
%121 = load i8**, i8*** %5
%122 = getelementptr inbounds i8*, i8** %121, i64 3
%123 = load i8*, i8** %122
%124 = call i32 (i8*, ...) @error(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.8, i64 0, i64 0), i8* %123)
br label %125
125: ; preds = %120, %117
%126 = load i32*, i32** %11
%127 = load i32, i32* @SEEK_SET
%128 = call i32 @fseek(i32* %126, i32 512, i32 %127)
%129 = getelementptr inbounds [512 x i8], [512 x i8]* %16, i64 0, i64 0
%130 = load i32*, i32** %11
%131 = call i32 @fread(i8* %129, i32 1, i32 512, i32* %130)
%132 = icmp ne i32 %131, 512
br i1 %132, label %133, label %136
133: ; preds = %125
%134 = load i8*, i8** %10
%135 = call i32 (i8*, ...) @error(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.9, i64 0, i64 0), i8* %134)
br label %136
136: ; preds = %133, %125
%137 = getelementptr inbounds [512 x i8], [512 x i8]* %16, i64 0, i64 0
%138 = load i32, i32* %14
%139 = mul nsw i32 %138, 32
%140 = sext i32 %139 to i64
%141 = getelementptr inbounds i8, i8* %137, i64 %140
store i8* %141, i8** %17
%142 = load i8*, i8** %17
%143 = getelementptr inbounds i8, i8* %142, i64 0
%144 = call i64 @read4FromEco(i8* %143)
store i64 %144, i64* %18
%145 = load i64, i64* %18
%146 = and i64 %145, 2147483647
%147 = icmp ne i64 %146, 169
br i1 %147, label %148, label %152
148: ; preds = %136
%149 = load i32, i32* %14
%150 = load i8*, i8** %10
%151 = call i32 (i8*, ...) @error(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.10, i64 0, i64 0), i32 %149, i8* %150)
br label %152
152: ; preds = %148, %136
%153 = load i8*, i8** %17
%154 = getelementptr inbounds i8, i8* %153, i64 4
%155 = call i64 @read4FromEco(i8* %154)
store i64 %155, i64* %12
%156 = load i8*, i8** %17
%157 = getelementptr inbounds i8, i8* %156, i64 8
%158 = call i64 @read4FromEco(i8* %157)
store i64 %158, i64* %13
br label %159
159: ; preds = %152, %97
%160 = load i64, i64* %13
%161 = load i64, i64* %13
%162 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.11, i64 0, i64 0), i64 %160, i64 %161, i32 512)
%163 = load i32*, i32** %11
%164 = load i64, i64* %12
%165 = add i64 %164, 1
%166 = mul i64 %165, 512
%167 = trunc i64 %166 to i32
%168 = load i32, i32* @SEEK_SET
%169 = call i32 @fseek(i32* %163, i32 %167, i32 %168)
%170 = getelementptr inbounds [512 x i8], [512 x i8]* %20, i64 0, i64 0
%171 = load i32*, i32** %11
%172 = call i32 @fread(i8* %170, i32 1, i32 512, i32* %171)
%173 = icmp ne i32 %172, 512
br i1 %173, label %174, label %177
174: ; preds = %159
%175 = load i8*, i8** %10
%176 = call i32 (i8*, ...) @error(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.12, i64 0, i64 0), i8* %175)
br label %177
177: ; preds = %174, %159
%178 = load i8*, i8** %10
%179 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.13, i64 0, i64 0), i8* %178, i32 512)
store i32 0, i32* %6
br label %180
180: ; preds = %192, %177
%181 = load i32, i32* %6
%182 = icmp slt i32 %181, 512
br i1 %182, label %183, label %195
183: ; preds = %180
%184 = load i32, i32* %6
%185 = sext i32 %184 to i64
%186 = getelementptr inbounds [512 x i8], [512 x i8]* %20, i64 0, i64 %185
%187 = load i8, i8* %186
%188 = load i32, i32* %6
%189 = add nsw i32 512, %188
%190 = sext i32 %189 to i64
%191 = getelementptr inbounds [8192 x i8], [8192 x i8]* %19, i64 0, i64 %190
store i8 %187, i8* %191
br label %192
192: ; preds = %183
%193 = load i32, i32* %6
%194 = add nsw i32 %193, 1
store i32 %194, i32* %6
br label %180
195: ; preds = %180
%196 = load i32*, i32** %11
%197 = load i64, i64* %12
%198 = add i64 %197, 0
%199 = mul i64 %198, 512
%200 = trunc i64 %199 to i32
%201 = load i32, i32* @SEEK_SET
%202 = call i32 @fseek(i32* %196, i32 %200, i32 %201)
%203 = getelementptr inbounds [8192 x i8], [8192 x i8]* %19, i64 0, i64 0
%204 = load i32, i32* %9
%205 = load i32*, i32** %11
%206 = call i32 @fwrite(i8* %203, i32 1, i32 %204, i32* %205)
%207 = load i32, i32* %9
%208 = icmp ne i32 %206, %207
br i1 %208, label %209, label %212
209: ; preds = %195
%210 = load i8*, i8** %10
%211 = call i32 (i8*, ...) @error(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.14, i64 0, i64 0), i8* %210)
br label %212
212: ; preds = %209, %195
%213 = load i8*, i8** %10
%214 = load i32, i32* %9
%215 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.15, i64 0, i64 0), i8* %213, i32 %214)
%216 = load i32*, i32** %11
%217 = call i32 @fclose(i32* %216)
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
@.str.1 = [27 x i8] c"cannot open bootblock '%s'\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@.str.2 = [23 x i8] c"bootblock '%s' too big\00"
@.str.3 = [27 x i8] c"cannot read bootblock '%s'\00"
@.str.4 = [32 x i8] c"Bootblock '%s' read, %d bytes.\0A\00"
@.str.5 = [4 x i8] c"r+b\00"
@.str.6 = [28 x i8] c"cannot open disk image '%s'\00"
@.str.7 = [2 x i8] c"*\00"
@.str.8 = [30 x i8] c"illegal partition number '%s'\00"
@.str.9 = [41 x i8] c"cannot read partition table of disk '%s'\00"
@.str.10 = [48 x i8] c"partition %d of disk '%s' is not a NetBSD slice\00"
@.str.11 = [53 x i8] c"Slice size is %lu (0x%lX) sectors of %d bytes each.\0A\00"
@.str.12 = [35 x i8] c"cannot read disklabel of disk '%s'\00"
@.str.13 = [41 x i8] c"Disklabel read from disk '%s', %d bytes\0A\00"
@.str.14 = [36 x i8] c"cannot write bootblock to disk '%s'\00"
@.str.15 = [42 x i8] c"Bootblock written to disk '%s', %d bytes\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i8*
%4 = alloca [512 x i8]
%5 = alloca [8192 x i8]
%6 = alloca [512 x i8]
%7 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%8 = bitcast i8** %3 to i8*
%9 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 0
%10 = getelementptr inbounds [8192 x i8], [8192 x i8]* %5, i64 0, i64 0
%11 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%12 = icmp eq i32 %0, 4
br i1 %12, label %13, label %19
13: ; preds = %2
%14 = getelementptr inbounds [8192 x i8], [8192 x i8]* %5, i64 0, i64 0
%15 = getelementptr inbounds i8*, i8** %1, i64 1
%16 = load i8*, i8** %15
%17 = tail call i32* @fopen(i8* %16, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%18 = icmp eq i32* %17, null
br i1 %18, label %23, label %25
19: ; preds = %2
%20 = load i8*, i8** %1
%21 = tail call i32 @usage(i8* %20)
%22 = tail call i32 @exit(i32 1)
unreachable
23: ; preds = %13
%24 = tail call i32 (i8*, ...) @error(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8* %16)
br label %25
25: ; preds = %23, %13
%26 = load i32, i32* @SEEK_END
%27 = tail call i32 @fseek(i32* %17, i32 0, i32 %26)
%28 = tail call i32 @ftell(i32* %17)
%29 = load i32, i32* @SEEK_SET
%30 = tail call i32 @fseek(i32* %17, i32 0, i32 %29)
%31 = icmp sgt i32 %28, 8192
br i1 %31, label %32, label %34
32: ; preds = %25
%33 = tail call i32 (i8*, ...) @error(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i8* %16)
br label %34
34: ; preds = %32, %25
%35 = call i32 @fread(i8* %10, i32 1, i32 %28, i32* %17)
%36 = icmp eq i32 %35, %28
br i1 %36, label %39, label %37
37: ; preds = %34
%38 = tail call i32 (i8*, ...) @error(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0), i8* %16)
br label %39
39: ; preds = %37, %34
%40 = tail call i32 @fclose(i32* %17)
%41 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.4, i64 0, i64 0), i8* %16, i32 %28)
%42 = getelementptr inbounds i8*, i8** %1, i64 2
%43 = load i8*, i8** %42
%44 = tail call i32* @fopen(i8* %43, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0))
%45 = icmp eq i32* %44, null
br i1 %45, label %46, label %48
46: ; preds = %39
%47 = tail call i32 (i8*, ...) @error(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.6, i64 0, i64 0), i8* %43)
br label %48
48: ; preds = %46, %39
%49 = getelementptr inbounds i8*, i8** %1, i64 3
%50 = load i8*, i8** %49
%51 = tail call i64 @strcmp(i8* %50, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
%52 = icmp eq i64 %51, 0
br i1 %52, label %53, label %59
53: ; preds = %48
%54 = load i32, i32* @SEEK_END
%55 = tail call i32 @fseek(i32* %44, i32 0, i32 %54)
%56 = tail call i32 @ftell(i32* %44)
%57 = sdiv i32 %56, 512
%58 = sext i32 %57 to i64
br label %95
59: ; preds = %48
%60 = load i8*, i8** %49
%61 = call i32 @strtoul(i8* %60, i8** %3, i32 10)
%62 = load i8*, i8** %3
%63 = load i8, i8* %62
%64 = icmp ne i8 %63, 0
%65 = icmp slt i32 %61, 0
%66 = select i1 %64, i1 true, i1 %65
%67 = icmp sgt i32 %61, 15
%68 = select i1 %66, i1 true, i1 %67
br i1 %68, label %69, label %72
69: ; preds = %59
%70 = load i8*, i8** %49
%71 = tail call i32 (i8*, ...) @error(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.8, i64 0, i64 0), i8* %70)
br label %72
72: ; preds = %59, %69
%73 = load i32, i32* @SEEK_SET
%74 = tail call i32 @fseek(i32* %44, i32 512, i32 %73)
%75 = call i32 @fread(i8* %9, i32 1, i32 512, i32* %44)
%76 = icmp eq i32 %75, 512
br i1 %76, label %79, label %77
77: ; preds = %72
%78 = tail call i32 (i8*, ...) @error(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.9, i64 0, i64 0), i8* %43)
br label %79
79: ; preds = %77, %72
%80 = shl nsw i32 %61, 5
%81 = sext i32 %80 to i64
%82 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 %81
%83 = call i64 @read4FromEco(i8* %82)
%84 = and i64 %83, 2147483647
%85 = icmp eq i64 %84, 169
br i1 %85, label %88, label %86
86: ; preds = %79
%87 = call i32 (i8*, ...) @error(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.10, i64 0, i64 0), i32 %61, i8* %43)
br label %88
88: ; preds = %86, %79
%89 = getelementptr inbounds i8, i8* %82, i64 4
%90 = call i64 @read4FromEco(i8* %89)
%91 = getelementptr inbounds i8, i8* %82, i64 8
%92 = call i64 @read4FromEco(i8* %91)
%93 = trunc i64 %90 to i32
%94 = shl i32 %93, 9
br label %95
95: ; preds = %88, %53
%96 = phi i64 [ %58, %53 ], [ %92, %88 ]
%97 = phi i32 [ 0, %53 ], [ %94, %88 ]
%98 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([53 x i8], [53 x i8]* @.str.11, i64 0, i64 0), i64 %96, i64 %96, i32 512)
%99 = add i32 %97, 512
%100 = load i32, i32* @SEEK_SET
%101 = call i32 @fseek(i32* %44, i32 %99, i32 %100)
%102 = call i32 @fread(i8* %11, i32 1, i32 512, i32* %44)
%103 = icmp eq i32 %102, 512
br i1 %103, label %106, label %104
104: ; preds = %95
%105 = call i32 (i8*, ...) @error(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.12, i64 0, i64 0), i8* %43)
br label %106
106: ; preds = %104, %95
%107 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @.str.13, i64 0, i64 0), i8* %43, i32 512)
%108 = getelementptr inbounds [8192 x i8], [8192 x i8]* %5, i64 0, i64 512
%109 = load i32, i32* @SEEK_SET
%110 = call i32 @fseek(i32* %44, i32 %97, i32 %109)
%111 = call i32 @fwrite(i8* %10, i32 1, i32 %28, i32* %44)
%112 = icmp eq i32 %111, %28
br i1 %112, label %115, label %113
113: ; preds = %106
%114 = call i32 (i8*, ...) @error(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.14, i64 0, i64 0), i8* %43)
br label %115
115: ; preds = %113, %106
%116 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str.15, i64 0, i64 0), i8* %43, i32 %28)
%117 = call i32 @fclose(i32* %44)
ret i32 0
}