#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 stat {
  int st_size;
};
typedef int /*<<< orphan*/ hdr;
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int /*<<< orphan*/ _LE(int, unsigned long *);
int /*<<< orphan*/ close(int);
int creat(char *, int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
scalar_t__ fstat(int, struct stat *);
int /*<<< orphan*/ lseek(int, int, int /*<<< orphan*/);
int open(char *, int /*<<< orphan*/);
int read(int, char *, int);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int write(int, ...);
int /*<<< orphan*/ write_prep_boot_partition(int);
main(int argc, char *argv[]) {
  int in_fd, out_fd, len, size;
  struct stat info;
  char buf[8192];
  struct hdr {
    unsigned long entry_point;
    unsigned long image_length;
  } hdr;
  if (argc != 3) {
    fprintf(stderr, "usage: mk_type41 <boot-file> <image>\n");
    exit(1);
  }
  if ((in_fd = open(argv[1], 0)) < 0) {
    fprintf(stderr, "Can't open input file: '%s': %s\n", argv[1],
            strerror(errno));
    exit(2);
  }
  if ((out_fd = creat(argv[2], 0666)) < 0) {
    fprintf(stderr, "Can't create output file: '%s': %s\n", argv[2],
            strerror(errno));
    exit(2);
  }
  if (fstat(in_fd, &info) < 0) {
    fprintf(stderr, "Can't get info on input file: %s\n", strerror(errno));
    exit(4);
  }
  write_prep_boot_partition(out_fd);
  _LE(0x400, &hdr.entry_point);
  _LE(info.st_size + 0x400, &hdr.image_length);
  lseek(out_fd, 0x200, 0);
  if (write(out_fd, &hdr, sizeof(hdr)) != sizeof(hdr)) {
    fprintf(stderr, "Can't write output file: %s\n", strerror(errno));
    exit(5);
  }
  lseek(out_fd, 0x400, 0);
  while ((len = read(in_fd, buf, sizeof(buf))) > 0) {
    if (write(out_fd, buf, len) != len) {
      fprintf(stderr, "Can't write output file: %s\n", strerror(errno));
      exit(5);
    }
  }
  if (len < 0) {
    fprintf(stderr, "Can't read input file: %s\n", strerror(errno));
    exit(6);
  }
  close(in_fd);
  close(out_fd);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2070,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     1204 <main+0x44>
mov    0x2df6(%rip),%rax
mov    (%rax),%edi
lea    0xe0d(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
xor    %esi,%esi
call   1090 <open@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    1273 <main+0xb3>
mov    0x2dba(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x204c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x2048(%rbp)
mov    0x2d94(%rip),%rax
mov    (%rax),%edi
call   10c0 <strerror@plt>
mov    -0x204c(%rbp),%edi
mov    -0x2048(%rbp),%rdx
mov    %rax,%rcx
lea    0xdc4(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    $0x2,%edi
call   10b0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
mov    $0x1b6,%esi
call   10a0 <creat@plt>
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
jge    12e5 <main+0x125>
mov    0x2d48(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x205c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x2058(%rbp)
mov    0x2d22(%rip),%rax
mov    (%rax),%edi
call   10c0 <strerror@plt>
mov    -0x205c(%rbp),%edi
mov    -0x2058(%rbp),%rdx
mov    %rax,%rcx
lea    0xd73(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    $0x2,%edi
call   10b0 <exit@plt>
mov    -0x14(%rbp),%edi
lea    -0x28(%rbp),%rsi
call   10d0 <fstat@plt>
cmp    $0x0,%rax
jge    1339 <main+0x179>
mov    0x2cde(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2060(%rbp)
mov    0x2cc7(%rip),%rax
mov    (%rax),%edi
call   10c0 <strerror@plt>
mov    -0x2060(%rbp),%edi
mov    %rax,%rdx
lea    0xd43(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    $0x4,%edi
call   10b0 <exit@plt>
mov    -0x18(%rbp),%edi
call   10e0 <write_prep_boot_partition@plt>
lea    -0x2040(%rbp),%rsi
mov    $0x400,%edi
call   1060 <_LE@plt>
mov    -0x28(%rbp),%edi
add    $0x400,%edi
lea    -0x2040(%rbp),%rsi
add    $0x8,%rsi
call   1060 <_LE@plt>
mov    -0x18(%rbp),%edi
mov    $0x200,%esi
xor    %edx,%edx
call   1040 <lseek@plt>
mov    -0x18(%rbp),%edi
lea    -0x2040(%rbp),%rsi
mov    $0x10,%edx
mov    $0x0,%al
call   1030 <write@plt>
cltq
cmp    $0x10,%rax
je     13da <main+0x21a>
mov    0x2c3d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2064(%rbp)
mov    0x2c26(%rip),%rax
mov    (%rax),%edi
call   10c0 <strerror@plt>
mov    -0x2064(%rbp),%edi
mov    %rax,%rdx
lea    0xcc4(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    $0x5,%edi
call   10b0 <exit@plt>
mov    -0x18(%rbp),%edi
mov    $0x400,%esi
xor    %edx,%edx
call   1040 <lseek@plt>
mov    -0x14(%rbp),%edi
lea    -0x2030(%rbp),%rsi
mov    $0x2000,%edx
call   1070 <read@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
jle    1469 <main+0x2a9>
mov    -0x18(%rbp),%edi
lea    -0x2030(%rbp),%rsi
mov    -0x1c(%rbp),%edx
mov    $0x0,%al
call   1030 <write@plt>
cmp    -0x1c(%rbp),%eax
je     1464 <main+0x2a4>
mov    0x2bb3(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2068(%rbp)
mov    0x2b9c(%rip),%rax
mov    (%rax),%edi
call   10c0 <strerror@plt>
mov    -0x2068(%rbp),%edi
mov    %rax,%rdx
lea    0xc3a(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    $0x5,%edi
call   10b0 <exit@plt>
jmp    13e9 <main+0x229>
cmpl   $0x0,-0x1c(%rbp)
jge    14b1 <main+0x2f1>
mov    0x2b66(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x206c(%rbp)
mov    0x2b4f(%rip),%rax
mov    (%rax),%edi
call   10c0 <strerror@plt>
mov    -0x206c(%rbp),%edi
mov    %rax,%rdx
lea    0xc0a(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    $0x6,%edi
call   10b0 <exit@plt>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
mov    -0x18(%rbp),%edi
call   1050 <close@plt>
mov    -0x4(%rbp),%eax
add    $0x2070,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x2020,%rsp
cmp    $0x3,%edi
jne    1315 <main+0x155>
mov    %rsi,%r14
mov    0x8(%rsi),%rdi
xor    %esi,%esi
call   1090 <open@plt>
test   %eax,%eax
js     1336 <main+0x176>
mov    %eax,%r15d
mov    0x10(%r14),%rdi
mov    $0x1b6,%esi
call   10a0 <creat@plt>
test   %eax,%eax
js     135a <main+0x19a>
mov    %eax,%r12d
lea    0x8(%rsp),%rsi
mov    %r15d,%edi
call   10d0 <fstat@plt>
test   %rax,%rax
js     1395 <main+0x1d5>
mov    %r12d,%edi
call   10e0 <write_prep_boot_partition@plt>
mov    $0x400,%ebx
lea    0x10(%rsp),%rbp
mov    $0x400,%edi
mov    %rbp,%rsi
call   1060 <_LE@plt>
add    0x8(%rsp),%ebx
lea    0x18(%rsp),%rsi
mov    %ebx,%edi
call   1060 <_LE@plt>
mov    %r12d,%edi
mov    $0x200,%esi
xor    %edx,%edx
call   1040 <lseek@plt>
mov    $0x10,%edx
mov    %r12d,%edi
mov    %rbp,%rsi
xor    %eax,%eax
call   1030 <write@plt>
cmp    $0x10,%eax
jne    12b9 <main+0xf9>
mov    %r12d,%edi
mov    $0x400,%esi
xor    %edx,%edx
call   1040 <lseek@plt>
lea    0x20(%rsp),%rbx
nopl   0x0(%rax)
mov    %r15d,%edi
mov    %rbx,%rsi
mov    $0x2000,%edx
call   1070 <read@plt>
test   %eax,%eax
jle    12ed <main+0x12d>
mov    %eax,%ebp
mov    %r12d,%edi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1030 <write@plt>
cmp    %ebp,%eax
je     1290 <main+0xd0>
mov    0x2d20(%rip),%rax
mov    (%rax),%ebx
mov    0x2d0f(%rip),%rax
mov    (%rax),%edi
call   10c0 <strerror@plt>
lea    0xdb6(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    $0x5,%edi
call   10b0 <exit@plt>
js     13c9 <main+0x209>
mov    %r15d,%edi
call   1050 <close@plt>
mov    %r12d,%edi
call   1050 <close@plt>
xor    %eax,%eax
add    $0x2020,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2cc4(%rip),%rax
mov    (%rax),%edi
lea    0xcdb(%rip),%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    0x2ca3(%rip),%rax
mov    (%rax),%ebx
mov    0x8(%r14),%rbp
mov    0x2c8e(%rip),%rax
mov    (%rax),%edi
call   10c0 <strerror@plt>
lea    0xcce(%rip),%rsi
jmp    137c <main+0x1bc>
mov    0x2c7f(%rip),%rax
mov    (%rax),%ebx
mov    0x10(%r14),%rbp
mov    0x2c6a(%rip),%rax
mov    (%rax),%edi
call   10c0 <strerror@plt>
lea    0xccb(%rip),%rsi
mov    %ebx,%edi
mov    %rbp,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    $0x2,%edi
call   10b0 <exit@plt>
mov    0x2c44(%rip),%rax
mov    (%rax),%ebx
mov    0x2c33(%rip),%rax
mov    (%rax),%edi
call   10c0 <strerror@plt>
lea    0xcb8(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    $0x4,%edi
call   10b0 <exit@plt>
mov    0x2c10(%rip),%rax
mov    (%rax),%ebx
mov    0x2bff(%rip),%rax
mov    (%rax),%edi
call   10c0 <strerror@plt>
lea    0xcc3(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    $0x6,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
%struct.stat = type { i32 }
%struct.hdr = type { i64, i64 }
@stderr = global i32 0
@.str = [38 x i8] c"usage: mk_type41 <boot-file> <image>\0A\00"
@.str.1 = [33 x i8] c"Can't open input file: '%s': %s\0A\00"
@errno = global i32 0
@.str.2 = [36 x i8] c"Can't create output file: '%s': %s\0A\00"
@.str.3 = [34 x i8] c"Can't get info on input file: %s\0A\00"
@.str.4 = [29 x i8] c"Can't write output file: %s\0A\00"
@.str.5 = [27 x i8] c"Can't read input file: %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca %struct.stat
%11 = alloca [8192 x i8]
%12 = alloca %struct.hdr
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%13 = load i32, i32* %4
%14 = icmp ne i32 %13, 3
br i1 %14, label %15, label %19
15: ; preds = %2
%16 = load i32, i32* @stderr
%17 = call i32 (i32, i8*, ...) @fprintf(i32 %16, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0))
%18 = call i32 @exit(i32 1)
unreachable
19: ; preds = %2
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
%23 = call i32 @open(i8* %22, i32 0)
store i32 %23, i32* %6
%24 = icmp slt i32 %23, 0
br i1 %24, label %25, label %34
25: ; preds = %19
%26 = load i32, i32* @stderr
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 1
%29 = load i8*, i8** %28
%30 = load i32, i32* @errno
%31 = call i8* @strerror(i32 %30)
%32 = call i32 (i32, i8*, ...) @fprintf(i32 %26, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), i8* %29, i8* %31)
%33 = call i32 @exit(i32 2)
unreachable
34: ; preds = %19
%35 = load i8**, i8*** %5
%36 = getelementptr inbounds i8*, i8** %35, i64 2
%37 = load i8*, i8** %36
%38 = call i32 @creat(i8* %37, i32 438)
store i32 %38, i32* %7
%39 = icmp slt i32 %38, 0
br i1 %39, label %40, label %49
40: ; preds = %34
%41 = load i32, i32* @stderr
%42 = load i8**, i8*** %5
%43 = getelementptr inbounds i8*, i8** %42, i64 2
%44 = load i8*, i8** %43
%45 = load i32, i32* @errno
%46 = call i8* @strerror(i32 %45)
%47 = call i32 (i32, i8*, ...) @fprintf(i32 %41, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0), i8* %44, i8* %46)
%48 = call i32 @exit(i32 2)
unreachable
49: ; preds = %34
%50 = load i32, i32* %6
%51 = call i64 @fstat(i32 %50, %struct.stat* %10)
%52 = icmp slt i64 %51, 0
br i1 %52, label %53, label %59
53: ; preds = %49
%54 = load i32, i32* @stderr
%55 = load i32, i32* @errno
%56 = call i8* @strerror(i32 %55)
%57 = call i32 (i32, i8*, ...) @fprintf(i32 %54, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.3, i64 0, i64 0), i8* %56)
%58 = call i32 @exit(i32 4)
unreachable
59: ; preds = %49
%60 = load i32, i32* %7
%61 = call i32 @write_prep_boot_partition(i32 %60)
%62 = getelementptr inbounds %struct.hdr, %struct.hdr* %12, i32 0, i32 0
%63 = call i32 @_LE(i32 1024, i64* %62)
%64 = getelementptr inbounds %struct.stat, %struct.stat* %10, i32 0, i32 0
%65 = load i32, i32* %64
%66 = add nsw i32 %65, 1024
%67 = getelementptr inbounds %struct.hdr, %struct.hdr* %12, i32 0, i32 1
%68 = call i32 @_LE(i32 %66, i64* %67)
%69 = load i32, i32* %7
%70 = call i32 @lseek(i32 %69, i32 512, i32 0)
%71 = load i32, i32* %7
%72 = call i32 (i32, ...) @write(i32 %71, %struct.hdr* %12, i64 16)
%73 = sext i32 %72 to i64
%74 = icmp ne i64 %73, 16
br i1 %74, label %75, label %81
75: ; preds = %59
%76 = load i32, i32* @stderr
%77 = load i32, i32* @errno
%78 = call i8* @strerror(i32 %77)
%79 = call i32 (i32, i8*, ...) @fprintf(i32 %76, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0), i8* %78)
%80 = call i32 @exit(i32 5)
unreachable
81: ; preds = %59
%82 = load i32, i32* %7
%83 = call i32 @lseek(i32 %82, i32 1024, i32 0)
br label %84
84: ; preds = %102, %81
%85 = load i32, i32* %6
%86 = getelementptr inbounds [8192 x i8], [8192 x i8]* %11, i64 0, i64 0
%87 = call i32 @read(i32 %85, i8* %86, i32 8192)
store i32 %87, i32* %8
%88 = icmp sgt i32 %87, 0
br i1 %88, label %89, label %103
89: ; preds = %84
%90 = load i32, i32* %7
%91 = getelementptr inbounds [8192 x i8], [8192 x i8]* %11, i64 0, i64 0
%92 = load i32, i32* %8
%93 = call i32 (i32, ...) @write(i32 %90, i8* %91, i32 %92)
%94 = load i32, i32* %8
%95 = icmp ne i32 %93, %94
br i1 %95, label %96, label %102
96: ; preds = %89
%97 = load i32, i32* @stderr
%98 = load i32, i32* @errno
%99 = call i8* @strerror(i32 %98)
%100 = call i32 (i32, i8*, ...) @fprintf(i32 %97, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0), i8* %99)
%101 = call i32 @exit(i32 5)
unreachable
102: ; preds = %89
br label %84
103: ; preds = %84
%104 = load i32, i32* %8
%105 = icmp slt i32 %104, 0
br i1 %105, label %106, label %112
106: ; preds = %103
%107 = load i32, i32* @stderr
%108 = load i32, i32* @errno
%109 = call i8* @strerror(i32 %108)
%110 = call i32 (i32, i8*, ...) @fprintf(i32 %107, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0), i8* %109)
%111 = call i32 @exit(i32 6)
unreachable
112: ; preds = %103
%113 = load i32, i32* %6
%114 = call i32 @close(i32 %113)
%115 = load i32, i32* %7
%116 = call i32 @close(i32 %115)
%117 = load i32, i32* %3
ret i32 %117
}

LLVM IR (-O2):
%struct.stat = type { i32 }
%struct.hdr = type { i64, i64 }
@stderr = global i32 0
@.str = [38 x i8] c"usage: mk_type41 <boot-file> <image>\0A\00"
@.str.1 = [33 x i8] c"Can't open input file: '%s': %s\0A\00"
@errno = global i32 0
@.str.2 = [36 x i8] c"Can't create output file: '%s': %s\0A\00"
@.str.3 = [34 x i8] c"Can't get info on input file: %s\0A\00"
@.str.4 = [29 x i8] c"Can't write output file: %s\0A\00"
@.str.5 = [27 x i8] c"Can't read input file: %s\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.stat
%4 = alloca [8192 x i8]
%5 = alloca %struct.hdr
%6 = bitcast %struct.stat* %3 to i8*
%7 = getelementptr inbounds [8192 x i8], [8192 x i8]* %4, i64 0, i64 0
%8 = bitcast %struct.hdr* %5 to i8*
%9 = icmp eq i32 %0, 3
br i1 %9, label %14, label %10
10: ; preds = %2
%11 = load i32, i32* @stderr
%12 = tail call i32 (i32, i8*, ...) @fprintf(i32 %11, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0))
%13 = tail call i32 @exit(i32 1)
unreachable
14: ; preds = %2
%15 = getelementptr inbounds i8*, i8** %1, i64 1
%16 = load i8*, i8** %15
%17 = tail call i32 @open(i8* %16, i32 0)
%18 = icmp slt i32 %17, 0
br i1 %18, label %19, label %26
19: ; preds = %14
%20 = load i32, i32* @stderr
%21 = load i8*, i8** %15
%22 = load i32, i32* @errno
%23 = tail call i8* @strerror(i32 %22)
%24 = tail call i32 (i32, i8*, ...) @fprintf(i32 %20, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), i8* %21, i8* %23)
%25 = tail call i32 @exit(i32 2)
unreachable
26: ; preds = %14
%27 = getelementptr inbounds i8*, i8** %1, i64 2
%28 = load i8*, i8** %27
%29 = tail call i32 @creat(i8* %28, i32 438)
%30 = icmp slt i32 %29, 0
br i1 %30, label %31, label %38
31: ; preds = %26
%32 = load i32, i32* @stderr
%33 = load i8*, i8** %27
%34 = load i32, i32* @errno
%35 = tail call i8* @strerror(i32 %34)
%36 = tail call i32 (i32, i8*, ...) @fprintf(i32 %32, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0), i8* %33, i8* %35)
%37 = tail call i32 @exit(i32 2)
unreachable
38: ; preds = %26
%39 = call i64 @fstat(i32 %17, %struct.stat* %3)
%40 = icmp slt i64 %39, 0
br i1 %40, label %41, label %47
41: ; preds = %38
%42 = load i32, i32* @stderr
%43 = load i32, i32* @errno
%44 = tail call i8* @strerror(i32 %43)
%45 = tail call i32 (i32, i8*, ...) @fprintf(i32 %42, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.3, i64 0, i64 0), i8* %44)
%46 = tail call i32 @exit(i32 4)
unreachable
47: ; preds = %38
%48 = tail call i32 @write_prep_boot_partition(i32 %29)
%49 = getelementptr inbounds %struct.hdr, %struct.hdr* %5, i64 0, i32 0
%50 = call i32 @_LE(i32 1024, i64* %49)
%51 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%52 = load i32, i32* %51
%53 = add nsw i32 %52, 1024
%54 = getelementptr inbounds %struct.hdr, %struct.hdr* %5, i64 0, i32 1
%55 = call i32 @_LE(i32 %53, i64* %54)
%56 = call i32 @lseek(i32 %29, i32 512, i32 0)
%57 = call i32 (i32, ...) @write(i32 %29, %struct.hdr* %5, i64 16)
%58 = icmp eq i32 %57, 16
br i1 %58, label %65, label %59
59: ; preds = %47
%60 = load i32, i32* @stderr
%61 = load i32, i32* @errno
%62 = call i8* @strerror(i32 %61)
%63 = call i32 (i32, i8*, ...) @fprintf(i32 %60, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0), i8* %62)
%64 = call i32 @exit(i32 5)
unreachable
65: ; preds = %47
%66 = call i32 @lseek(i32 %29, i32 1024, i32 0)
br label %67
67: ; preds = %70, %65
%68 = call i32 @read(i32 %17, i8* %7, i32 8192)
%69 = icmp sgt i32 %68, 0
br i1 %69, label %70, label %79
70: ; preds = %67
%71 = call i32 (i32, ...) @write(i32 %29, i8* %7, i32 %68)
%72 = icmp eq i32 %71, %68
br i1 %72, label %67, label %73
73: ; preds = %70
%74 = load i32, i32* @stderr
%75 = load i32, i32* @errno
%76 = call i8* @strerror(i32 %75)
%77 = call i32 (i32, i8*, ...) @fprintf(i32 %74, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0), i8* %76)
%78 = call i32 @exit(i32 5)
unreachable
79: ; preds = %67
%80 = icmp slt i32 %68, 0
br i1 %80, label %81, label %87
81: ; preds = %79
%82 = load i32, i32* @stderr
%83 = load i32, i32* @errno
%84 = call i8* @strerror(i32 %83)
%85 = call i32 (i32, i8*, ...) @fprintf(i32 %82, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0), i8* %84)
%86 = call i32 @exit(i32 6)
unreachable
87: ; preds = %79
%88 = call i32 @close(i32 %17)
%89 = call i32 @close(i32 %29)
ret i32 0
}