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

/* Variables and functions */
int O_CREAT;
int O_RDONLY;
int O_TRUNC;
int O_WRONLY;
int S_IRUSR;
int S_IWUSR;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ free(char *);
int open(char const *, int, ...);
int pgheader_create_raw(char **, char const *, unsigned int *);
int pgheader_detect(char const *);
int read(int, char *, int);
int /*<<< orphan*/ strcmp(char const *, char const *);
int write(int, char *, int);
int pgheader_write(const char *header, const char *infile,
                   const char *outfile) {
  int fin, fout, i, ret;
  char c;
  char buf[16];
  char *raw_header;
  unsigned int size;
  if ((ret = pgheader_detect(infile))) {
    return ret;
  }
  if (!strcmp(infile, outfile)) {
    return 4;
  }
  fin = open(infile, O_RDONLY | 0x0);
  if (fin == -1) {
    return 1;
  }
  fout = open(outfile, O_WRONLY | O_CREAT | O_TRUNC | 0x0, S_IRUSR | S_IWUSR);
  if (fout == -1) {
    close(fin);
    return 1;
  }
  while (1) {
    int j, r;
    int zero;
    r = read(fin, buf, 16);
    if (r < 16) {
      close(fin);
      close(fout);
      return 2;
    }
    zero = 1;
    for (j = 0; j < 8; j++) {
      if (buf[j] != 0) {
        zero = 0;
      }
    }
    if (!zero) {
      break;
    }
  }
  if ((ret = pgheader_create_raw(&raw_header, header, &size))) {
    return ret;
  }
  for (i = 0; i < size; i++) {
    c = raw_header[i];
    if (write(fout, &c, 1) != 1) {
      close(fin);
      close(fout);
      return 1;
    }
  }
  free(raw_header);
  if (write(fout, buf, 16) != 16) {
    close(fin);
    close(fout);
    return 1;
  }
  while ((ret = read(fin, buf, 16)) == 16) {
    if (write(fout, buf, ret) != 16) {
      close(fin);
      close(fout);
      return 1;
    }
  };
  close(fin);
  close(fout);
  if (0 < ret && ret < 16) {
    return 2;
  } else if (ret == -1) {
    return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<pgheader_write>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1090 <pgheader_detect@plt>
mov    %eax,-0x30(%rbp)
cmp    $0x0,%eax
je     11b4 <pgheader_write+0x34>
mov    -0x30(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1478 <pgheader_write+0x2f8>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%eax
jne    11d6 <pgheader_write+0x56>
movl   $0x4,-0x4(%rbp)
jmp    1478 <pgheader_write+0x2f8>
mov    -0x18(%rbp),%rdi
mov    0x2df7(%rip),%rax
mov    (%rax),%esi
or     $0x0,%esi
mov    $0x0,%al
call   1080 <open@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0xffffffff,-0x24(%rbp)
jne    1206 <pgheader_write+0x86>
movl   $0x1,-0x4(%rbp)
jmp    1478 <pgheader_write+0x2f8>
mov    -0x20(%rbp),%rdi
mov    0x2d9f(%rip),%rax
mov    (%rax),%esi
mov    0x2dde(%rip),%rax
or     (%rax),%esi
mov    0x2dcd(%rip),%rax
or     (%rax),%esi
or     $0x0,%esi
mov    0x2d91(%rip),%rax
mov    (%rax),%edx
mov    0x2d98(%rip),%rax
or     (%rax),%edx
mov    $0x0,%al
call   1080 <open@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0xffffffff,-0x28(%rbp)
jne    1262 <pgheader_write+0xe2>
mov    -0x24(%rbp),%edi
call   1050 <close@plt>
movl   $0x1,-0x4(%rbp)
jmp    1478 <pgheader_write+0x2f8>
jmp    1267 <pgheader_write+0xe7>
mov    -0x24(%rbp),%edi
lea    -0x50(%rbp),%rsi
mov    $0x10,%edx
call   1060 <read@plt>
mov    %eax,-0x64(%rbp)
cmpl   $0x10,-0x64(%rbp)
jge    12a1 <pgheader_write+0x121>
mov    -0x24(%rbp),%edi
call   1050 <close@plt>
mov    -0x28(%rbp),%edi
call   1050 <close@plt>
movl   $0x2,-0x4(%rbp)
jmp    1478 <pgheader_write+0x2f8>
movl   $0x1,-0x68(%rbp)
movl   $0x0,-0x60(%rbp)
cmpl   $0x8,-0x60(%rbp)
jge    12e5 <pgheader_write+0x165>
movslq -0x60(%rbp),%rax
movsbl -0x50(%rbp,%rax,1),%eax
cmp    $0x0,%eax
je     12d2 <pgheader_write+0x152>
movl   $0x0,-0x68(%rbp)
jmp    12d7 <pgheader_write+0x157>
mov    -0x60(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x60(%rbp)
jmp    12af <pgheader_write+0x12f>
cmpl   $0x0,-0x68(%rbp)
jne    12f4 <pgheader_write+0x174>
jmp    12f9 <pgheader_write+0x179>
jmp    1267 <pgheader_write+0xe7>
mov    -0x10(%rbp),%rsi
lea    -0x58(%rbp),%rdi
lea    -0x5c(%rbp),%rdx
call   10a0 <pgheader_create_raw@plt>
mov    %eax,-0x30(%rbp)
cmp    $0x0,%eax
je     1321 <pgheader_write+0x1a1>
mov    -0x30(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1478 <pgheader_write+0x2f8>
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x5c(%rbp),%eax
jae    138b <pgheader_write+0x20b>
mov    -0x58(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x31(%rbp)
mov    -0x28(%rbp),%edi
lea    -0x31(%rbp),%rsi
mov    $0x1,%edx
call   1040 <write@plt>
cmp    $0x1,%eax
je     1378 <pgheader_write+0x1f8>
mov    -0x24(%rbp),%edi
call   1050 <close@plt>
mov    -0x28(%rbp),%edi
call   1050 <close@plt>
movl   $0x1,-0x4(%rbp)
jmp    1478 <pgheader_write+0x2f8>
jmp    137d <pgheader_write+0x1fd>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1328 <pgheader_write+0x1a8>
mov    -0x58(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%edi
lea    -0x50(%rbp),%rsi
mov    $0x10,%edx
call   1040 <write@plt>
cmp    $0x10,%eax
je     13ca <pgheader_write+0x24a>
mov    -0x24(%rbp),%edi
call   1050 <close@plt>
mov    -0x28(%rbp),%edi
call   1050 <close@plt>
movl   $0x1,-0x4(%rbp)
jmp    1478 <pgheader_write+0x2f8>
jmp    13cf <pgheader_write+0x24f>
mov    -0x24(%rbp),%edi
lea    -0x50(%rbp),%rsi
mov    $0x10,%edx
call   1060 <read@plt>
mov    %eax,-0x30(%rbp)
cmp    $0x10,%eax
jne    1425 <pgheader_write+0x2a5>
mov    -0x28(%rbp),%edi
lea    -0x50(%rbp),%rsi
mov    -0x30(%rbp),%edx
call   1040 <write@plt>
cmp    $0x10,%eax
je     1420 <pgheader_write+0x2a0>
mov    -0x24(%rbp),%edi
call   1050 <close@plt>
mov    -0x28(%rbp),%edi
call   1050 <close@plt>
movl   $0x1,-0x4(%rbp)
jmp    1478 <pgheader_write+0x2f8>
jmp    13cf <pgheader_write+0x24f>
mov    -0x24(%rbp),%edi
call   1050 <close@plt>
mov    -0x28(%rbp),%edi
call   1050 <close@plt>
xor    %eax,%eax
cmp    -0x30(%rbp),%eax
jge    1456 <pgheader_write+0x2d6>
cmpl   $0x10,-0x30(%rbp)
jge    1456 <pgheader_write+0x2d6>
movl   $0x2,-0x4(%rbp)
jmp    1478 <pgheader_write+0x2f8>
cmpl   $0xffffffff,-0x30(%rbp)
jne    146c <pgheader_write+0x2ec>
movl   $0x1,-0x4(%rbp)
jmp    1478 <pgheader_write+0x2f8>
jmp    1471 <pgheader_write+0x2f1>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pgheader_write>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x28,%rsp
mov    %rdx,%rbp
mov    %rsi,%rbx
mov    %rdi,%r15
mov    %rsi,%rdi
call   1090 <pgheader_detect@plt>
test   %eax,%eax
je     11aa <pgheader_write+0x2a>
add    $0x28,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1070 <strcmp@plt>
test   %eax,%eax
je     130a <pgheader_write+0x18a>
mov    0x2e14(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1080 <open@plt>
mov    %eax,%ebx
mov    $0x1,%eax
cmp    $0xffffffff,%ebx
je     119f <pgheader_write+0x1f>
mov    0x2dcd(%rip),%rax
mov    0x2e0e(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2dfb(%rip),%rax
or     (%rax),%esi
mov    0x2dc2(%rip),%rax
mov    0x2dcb(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    %rbp,%rdi
xor    %eax,%eax
call   1080 <open@plt>
cmp    $0xffffffff,%eax
je     1314 <pgheader_write+0x194>
mov    %eax,%r14d
lea    0x10(%rsp),%rbp
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %ebx,%edi
mov    %rbp,%rsi
mov    $0x10,%edx
call   1060 <read@plt>
cmp    $0x10,%eax
jl     1325 <pgheader_write+0x1a5>
movq   0x10(%rsp),%xmm0
movq   %xmm0,%rax
test   %rax,%rax
je     1230 <pgheader_write+0xb0>
lea    0x8(%rsp),%rdi
lea    0x4(%rsp),%rdx
mov    %r15,%rsi
call   10a0 <pgheader_create_raw@plt>
test   %eax,%eax
jne    119f <pgheader_write+0x1f>
cmpl   $0x0,0x4(%rsp)
je     12af <pgheader_write+0x12f>
xor    %ebp,%ebp
lea    0x3(%rsp),%r15
mov    0x8(%rsp),%rax
movzbl (%rax,%rbp,1),%eax
mov    %al,0x3(%rsp)
mov    %r14d,%edi
mov    %r15,%rsi
mov    $0x1,%edx
call   1040 <write@plt>
cmp    $0x1,%eax
jne    12fe <pgheader_write+0x17e>
add    $0x1,%rbp
mov    0x4(%rsp),%eax
cmp    %rax,%rbp
jb     1280 <pgheader_write+0x100>
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
lea    0x10(%rsp),%rsi
mov    %r14d,%edi
mov    $0x10,%edx
call   1040 <write@plt>
cmp    $0x10,%eax
jne    12fe <pgheader_write+0x17e>
lea    0x10(%rsp),%r15
mov    %ebx,%edi
mov    %r15,%rsi
mov    $0x10,%edx
call   1060 <read@plt>
cmp    $0x10,%eax
jne    133e <pgheader_write+0x1be>
mov    %r14d,%edi
mov    %r15,%rsi
mov    $0x10,%edx
call   1040 <write@plt>
cmp    $0x10,%eax
je     12d5 <pgheader_write+0x155>
mov    %ebx,%edi
call   1050 <close@plt>
mov    %r14d,%edi
jmp    1316 <pgheader_write+0x196>
mov    $0x4,%eax
jmp    119f <pgheader_write+0x1f>
mov    %ebx,%edi
call   1050 <close@plt>
mov    $0x1,%eax
jmp    119f <pgheader_write+0x1f>
mov    %ebx,%edi
call   1050 <close@plt>
mov    %r14d,%edi
call   1050 <close@plt>
mov    $0x2,%eax
jmp    119f <pgheader_write+0x1f>
mov    %eax,%ebp
mov    %ebx,%edi
call   1050 <close@plt>
mov    %r14d,%edi
call   1050 <close@plt>
lea    -0x1(%rbp),%ecx
mov    $0x2,%eax
cmp    $0xf,%ecx
jb     119f <pgheader_write+0x1f>
xor    %eax,%eax
cmp    $0xffffffff,%ebp
sete   %al
jmp    119f <pgheader_write+0x1f>

LLVM IR (-O0):
@O_RDONLY = global i32 0
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
define i32 @pgheader_write(i8* %0, i8* %1, i8* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i8
%13 = alloca [16 x i8]
%14 = alloca i8*
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
%18 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
%19 = load i8*, i8** %6
%20 = call i32 @pgheader_detect(i8* %19)
store i32 %20, i32* %11
%21 = icmp ne i32 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %3
%23 = load i32, i32* %11
store i32 %23, i32* %4
br label %164
24: ; preds = %3
%25 = load i8*, i8** %6
%26 = load i8*, i8** %7
%27 = call i32 @strcmp(i8* %25, i8* %26)
%28 = icmp ne i32 %27, 0
br i1 %28, label %30, label %29
29: ; preds = %24
store i32 4, i32* %4
br label %164
30: ; preds = %24
%31 = load i8*, i8** %6
%32 = load i32, i32* @O_RDONLY
%33 = or i32 %32, 0
%34 = call i32 (i8*, i32, ...) @open(i8* %31, i32 %33)
store i32 %34, i32* %8
%35 = load i32, i32* %8
%36 = icmp eq i32 %35, -1
br i1 %36, label %37, label %38
37: ; preds = %30
store i32 1, i32* %4
br label %164
38: ; preds = %30
%39 = load i8*, i8** %7
%40 = load i32, i32* @O_WRONLY
%41 = load i32, i32* @O_CREAT
%42 = or i32 %40, %41
%43 = load i32, i32* @O_TRUNC
%44 = or i32 %42, %43
%45 = or i32 %44, 0
%46 = load i32, i32* @S_IRUSR
%47 = load i32, i32* @S_IWUSR
%48 = or i32 %46, %47
%49 = call i32 (i8*, i32, ...) @open(i8* %39, i32 %45, i32 %48)
store i32 %49, i32* %9
%50 = load i32, i32* %9
%51 = icmp eq i32 %50, -1
br i1 %51, label %52, label %55
52: ; preds = %38
%53 = load i32, i32* %8
%54 = call i32 @close(i32 %53)
store i32 1, i32* %4
br label %164
55: ; preds = %38
br label %56
56: ; preds = %55, %87
%57 = load i32, i32* %8
%58 = getelementptr inbounds [16 x i8], [16 x i8]* %13, i64 0, i64 0
%59 = call i32 @read(i32 %57, i8* %58, i32 16)
store i32 %59, i32* %17
%60 = load i32, i32* %17
%61 = icmp slt i32 %60, 16
br i1 %61, label %62, label %67
62: ; preds = %56
%63 = load i32, i32* %8
%64 = call i32 @close(i32 %63)
%65 = load i32, i32* %9
%66 = call i32 @close(i32 %65)
store i32 2, i32* %4
br label %164
67: ; preds = %56
store i32 1, i32* %18
store i32 0, i32* %16
br label %68
68: ; preds = %80, %67
%69 = load i32, i32* %16
%70 = icmp slt i32 %69, 8
br i1 %70, label %71, label %83
71: ; preds = %68
%72 = load i32, i32* %16
%73 = sext i32 %72 to i64
%74 = getelementptr inbounds [16 x i8], [16 x i8]* %13, i64 0, i64 %73
%75 = load i8, i8* %74
%76 = sext i8 %75 to i32
%77 = icmp ne i32 %76, 0
br i1 %77, label %78, label %79
78: ; preds = %71
store i32 0, i32* %18
br label %79
79: ; preds = %78, %71
br label %80
80: ; preds = %79
%81 = load i32, i32* %16
%82 = add nsw i32 %81, 1
store i32 %82, i32* %16
br label %68
83: ; preds = %68
%84 = load i32, i32* %18
%85 = icmp ne i32 %84, 0
br i1 %85, label %87, label %86
86: ; preds = %83
br label %88
87: ; preds = %83
br label %56
88: ; preds = %86
%89 = load i8*, i8** %5
%90 = call i32 @pgheader_create_raw(i8** %14, i8* %89, i32* %15)
store i32 %90, i32* %11
%91 = icmp ne i32 %90, 0
br i1 %91, label %92, label %94
92: ; preds = %88
%93 = load i32, i32* %11
store i32 %93, i32* %4
br label %164
94: ; preds = %88
store i32 0, i32* %10
br label %95
95: ; preds = %114, %94
%96 = load i32, i32* %10
%97 = load i32, i32* %15
%98 = icmp ult i32 %96, %97
br i1 %98, label %99, label %117
99: ; preds = %95
%100 = load i8*, i8** %14
%101 = load i32, i32* %10
%102 = sext i32 %101 to i64
%103 = getelementptr inbounds i8, i8* %100, i64 %102
%104 = load i8, i8* %103
store i8 %104, i8* %12
%105 = load i32, i32* %9
%106 = call i32 @write(i32 %105, i8* %12, i32 1)
%107 = icmp ne i32 %106, 1
br i1 %107, label %108, label %113
108: ; preds = %99
%109 = load i32, i32* %8
%110 = call i32 @close(i32 %109)
%111 = load i32, i32* %9
%112 = call i32 @close(i32 %111)
store i32 1, i32* %4
br label %164
113: ; preds = %99
br label %114
114: ; preds = %113
%115 = load i32, i32* %10
%116 = add nsw i32 %115, 1
store i32 %116, i32* %10
br label %95
117: ; preds = %95
%118 = load i8*, i8** %14
%119 = call i32 @free(i8* %118)
%120 = load i32, i32* %9
%121 = getelementptr inbounds [16 x i8], [16 x i8]* %13, i64 0, i64 0
%122 = call i32 @write(i32 %120, i8* %121, i32 16)
%123 = icmp ne i32 %122, 16
br i1 %123, label %124, label %129
124: ; preds = %117
%125 = load i32, i32* %8
%126 = call i32 @close(i32 %125)
%127 = load i32, i32* %9
%128 = call i32 @close(i32 %127)
store i32 1, i32* %4
br label %164
129: ; preds = %117
br label %130
130: ; preds = %146, %129
%131 = load i32, i32* %8
%132 = getelementptr inbounds [16 x i8], [16 x i8]* %13, i64 0, i64 0
%133 = call i32 @read(i32 %131, i8* %132, i32 16)
store i32 %133, i32* %11
%134 = icmp eq i32 %133, 16
br i1 %134, label %135, label %147
135: ; preds = %130
%136 = load i32, i32* %9
%137 = getelementptr inbounds [16 x i8], [16 x i8]* %13, i64 0, i64 0
%138 = load i32, i32* %11
%139 = call i32 @write(i32 %136, i8* %137, i32 %138)
%140 = icmp ne i32 %139, 16
br i1 %140, label %141, label %146
141: ; preds = %135
%142 = load i32, i32* %8
%143 = call i32 @close(i32 %142)
%144 = load i32, i32* %9
%145 = call i32 @close(i32 %144)
store i32 1, i32* %4
br label %164
146: ; preds = %135
br label %130
147: ; preds = %130
%148 = load i32, i32* %8
%149 = call i32 @close(i32 %148)
%150 = load i32, i32* %9
%151 = call i32 @close(i32 %150)
%152 = load i32, i32* %11
%153 = icmp slt i32 0, %152
br i1 %153, label %154, label %158
154: ; preds = %147
%155 = load i32, i32* %11
%156 = icmp slt i32 %155, 16
br i1 %156, label %157, label %158
157: ; preds = %154
store i32 2, i32* %4
br label %164
158: ; preds = %154, %147
%159 = load i32, i32* %11
%160 = icmp eq i32 %159, -1
br i1 %160, label %161, label %162
161: ; preds = %158
store i32 1, i32* %4
br label %164
162: ; preds = %158
br label %163
163: ; preds = %162
store i32 0, i32* %4
br label %164
164: ; preds = %163, %161, %157, %141, %124, %108, %92, %62, %52, %37, %29, %22
%165 = load i32, i32* %4
ret i32 %165
}

LLVM IR (-O2):
@O_RDONLY = global i32 0
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
define i32 @pgheader_write(i8* %0, i8* %1, i8* nocapture %2) {
%4 = alloca i8
%5 = alloca [16 x i8]
%6 = alloca i8*
%7 = alloca i32
%8 = getelementptr inbounds [16 x i8], [16 x i8]* %5, i64 0, i64 0
%9 = bitcast i8** %6 to i8*
%10 = bitcast i32* %7 to i8*
%11 = tail call i32 @pgheader_detect(i8* %1)
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %92
13: ; preds = %3
%14 = tail call i32 @strcmp(i8* dereferenceable(1) %1, i8* dereferenceable(1) %2)
%15 = icmp eq i32 %14, 0
br i1 %15, label %92, label %16
16: ; preds = %13
%17 = load i32, i32* @O_RDONLY
%18 = tail call i32 (i8*, i32, ...) @open(i8* %1, i32 %17)
%19 = icmp eq i32 %18, -1
br i1 %19, label %92, label %20
20: ; preds = %16
%21 = load i32, i32* @O_WRONLY
%22 = load i32, i32* @O_CREAT
%23 = or i32 %22, %21
%24 = load i32, i32* @O_TRUNC
%25 = or i32 %23, %24
%26 = load i32, i32* @S_IRUSR
%27 = load i32, i32* @S_IWUSR
%28 = or i32 %27, %26
%29 = tail call i32 (i8*, i32, ...) @open(i8* %2, i32 %25, i32 %28)
%30 = icmp eq i32 %29, -1
br i1 %30, label %33, label %31
31: ; preds = %20
%32 = bitcast [16 x i8]* %5 to <8 x i8>*
br label %35
33: ; preds = %20
%34 = tail call i32 @close(i32 %18)
br label %92
35: ; preds = %31, %38
%36 = call i32 @read(i32 %18, i8* %8, i32 16)
%37 = icmp slt i32 %36, 16
br i1 %37, label %43, label %38
38: ; preds = %35
%39 = load <8 x i8>, <8 x i8>* %32
%40 = freeze <8 x i8> %39
%41 = bitcast <8 x i8> %40 to i64
%42 = icmp eq i64 %41, 0
br i1 %42, label %35, label %46
43: ; preds = %35
%44 = tail call i32 @close(i32 %18)
%45 = tail call i32 @close(i32 %29)
br label %92
46: ; preds = %38
%47 = call i32 @pgheader_create_raw(i8** %6, i8* %0, i32* %7)
%48 = icmp eq i32 %47, 0
br i1 %48, label %49, label %92
49: ; preds = %46
%50 = load i32, i32* %7
%51 = icmp eq i32 %50, 0
br i1 %51, label %67, label %56
52: ; preds = %56
%53 = load i32, i32* %7
%54 = zext i32 %53 to i64
%55 = icmp ult i64 %63, %54
br i1 %55, label %56, label %67
56: ; preds = %49, %52
%57 = phi i64 [ %63, %52 ], [ 0, %49 ]
%58 = load i8*, i8** %6
%59 = getelementptr inbounds i8, i8* %58, i64 %57
%60 = load i8, i8* %59
store i8 %60, i8* %4
%61 = call i32 @write(i32 %29, i8* %4, i32 1)
%62 = icmp eq i32 %61, 1
%63 = add nuw nsw i64 %57, 1
br i1 %62, label %52, label %64
64: ; preds = %56
%65 = call i32 @close(i32 %18)
%66 = call i32 @close(i32 %29)
br label %92
67: ; preds = %52, %49
%68 = load i8*, i8** %6
%69 = call i32 @free(i8* %68)
%70 = call i32 @write(i32 %29, i8* %8, i32 16)
%71 = icmp eq i32 %70, 16
br i1 %71, label %75, label %72
72: ; preds = %67
%73 = call i32 @close(i32 %18)
%74 = call i32 @close(i32 %29)
br label %92
75: ; preds = %67, %78
%76 = call i32 @read(i32 %18, i8* %8, i32 16)
%77 = icmp eq i32 %76, 16
br i1 %77, label %78, label %84
78: ; preds = %75
%79 = call i32 @write(i32 %29, i8* %8, i32 16)
%80 = icmp eq i32 %79, 16
br i1 %80, label %75, label %81
81: ; preds = %78
%82 = call i32 @close(i32 %18)
%83 = call i32 @close(i32 %29)
br label %92
84: ; preds = %75
%85 = call i32 @close(i32 %18)
%86 = call i32 @close(i32 %29)
%87 = add i32 %76, -1
%88 = icmp ult i32 %87, 15
br i1 %88, label %92, label %89
89: ; preds = %84
%90 = icmp eq i32 %76, -1
%91 = zext i1 %90 to i32
br label %92
92: ; preds = %43, %89, %84, %46, %16, %13, %3, %81, %72, %64, %33
%93 = phi i32 [ 1, %33 ], [ 1, %64 ], [ 1, %72 ], [ 1, %81 ], [ %11, %3 ], [ 4, %13 ], [ 1, %16 ], [ %47, %46 ], [ 2, %84 ], [ %91, %89 ], [ 2, %43 ]
ret i32 %93
}