#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 /*<<< orphan*/ O_RDONLY;
int O_TRUNC;
int O_WRONLY;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ lseek(int, unsigned int, int /*<<< orphan*/);
char *malloc(int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
unsigned int ntohl(unsigned int);
int open(char *, int, ...);
int read(int, ...);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ write(int, char *, unsigned int);
int expand(char *from, char *to) {
  int fdi;
  int fdo;
  unsigned int pos, prepos;
  unsigned int len, prelen, n;
  unsigned int count;
  char *buf;
  count = 0;
  if ((fdi = open(from, O_RDONLY)) < 0) {
    fprintf(stderr, "Can't open compressed file %s\n", from);
    return 0;
  }
  if ((fdo = open(to, O_WRONLY | O_CREAT | O_TRUNC, 0666)) < 0) {
    fprintf(stderr, "Can't open expanded file %s\n", to);
    close(fdi);
    return 0;
  }
  if (!(buf = malloc(2048))) {
    fprintf(stderr, "can't allocate memory\n");
    close(fdi);
    close(fdo);
    return 0;
  }
  read(fdi, (char *)&len, 4);
  fprintf(stderr, "TOTAL LEN=%x", len);
  len = ntohl(len);
  fprintf(stderr, "[%x]\n", len);
  memset(buf, 0, 2048);
  while (len > 0) {
    n = (len > 2048) ? 2048 : len;
    write(fdo, buf, n);
    len -= n;
  }
  lseek(fdo, 0, SEEK_SET);
  while (read(fdi, &pos, 4) == 4) {
    if (read(fdi, &len, 4) != 4)
      break;
    prepos = pos;
    prelen = len;
    pos = ntohl(pos);
    len = ntohl(len);
    fprintf(stderr, "POS=%x[%x]:LEN=%x[%x]", prepos, pos, prelen, len);
    lseek(fdo, pos, SEEK_SET);
    fprintf(stderr, "    -->    DATA=%x\n", buf[0]);
    fflush(stderr);
    read(fdi, buf, len);
    write(fdo, buf, len);
  }
  close(fdi);
  close(fdo);
  free(buf);
}


x86 assembly (clang, -O0):
<expand>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x0,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e06(%rip),%rax
mov    (%rax),%esi
mov    $0x0,%al
call   10c0 <open@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
jge    120e <expand+0x5e>
mov    0x2dda(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe05(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1485 <expand+0x2d5>
mov    -0x18(%rbp),%rdi
mov    0x2d97(%rip),%rax
mov    (%rax),%esi
mov    0x2dd6(%rip),%rax
or     (%rax),%esi
mov    0x2dc5(%rip),%rax
or     (%rax),%esi
mov    $0x1b6,%edx
mov    $0x0,%al
call   10c0 <open@plt>
mov    %eax,-0x20(%rbp)
cmp    $0x0,%eax
jge    1274 <expand+0xc4>
mov    0x2d7c(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
lea    0xdc6(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    -0x1c(%rbp),%edi
call   1070 <close@plt>
movl   $0x0,-0x4(%rbp)
jmp    1485 <expand+0x2d5>
mov    $0x800,%edi
call   10a0 <malloc@plt>
mov    %rax,-0x40(%rbp)
cmp    $0x0,%rax
jne    12bf <expand+0x10f>
mov    0x2d35(%rip),%rax
mov    (%rax),%edi
lea    0xda0(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    -0x1c(%rbp),%edi
call   1070 <close@plt>
mov    -0x20(%rbp),%edi
call   1070 <close@plt>
movl   $0x0,-0x4(%rbp)
jmp    1485 <expand+0x2d5>
mov    -0x1c(%rbp),%edi
lea    -0x2c(%rbp),%rsi
mov    $0x4,%edx
mov    $0x0,%al
call   1080 <read@plt>
mov    0x2cef(%rip),%rax
mov    (%rax),%edi
mov    -0x2c(%rbp),%edx
lea    0xd6e(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    -0x2c(%rbp),%edi
call   10d0 <ntohl@plt>
mov    %eax,-0x2c(%rbp)
mov    0x2cca(%rip),%rax
mov    (%rax),%edi
mov    -0x2c(%rbp),%edx
lea    0xd56(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    -0x40(%rbp),%rdi
xor    %esi,%esi
mov    $0x800,%edx
call   1060 <memset@plt>
cmpl   $0x0,-0x2c(%rbp)
jbe    1370 <expand+0x1c0>
cmpl   $0x800,-0x2c(%rbp)
jbe    1345 <expand+0x195>
mov    $0x800,%eax
mov    %eax,-0x44(%rbp)
jmp    134b <expand+0x19b>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x44(%rbp)
mov    -0x44(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x20(%rbp),%edi
mov    -0x40(%rbp),%rsi
mov    -0x34(%rbp),%edx
call   1040 <write@plt>
mov    -0x34(%rbp),%ecx
mov    -0x2c(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x2c(%rbp)
jmp    1321 <expand+0x171>
mov    -0x20(%rbp),%edi
mov    0x2c46(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1050 <lseek@plt>
mov    -0x1c(%rbp),%edi
lea    -0x24(%rbp),%rsi
mov    $0x4,%edx
mov    $0x0,%al
call   1080 <read@plt>
cmp    $0x4,%eax
jne    146c <expand+0x2bc>
mov    -0x1c(%rbp),%edi
lea    -0x2c(%rbp),%rsi
mov    $0x4,%edx
mov    $0x0,%al
call   1080 <read@plt>
cmp    $0x4,%eax
je     13c0 <expand+0x210>
jmp    146c <expand+0x2bc>
mov    -0x24(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x2c(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x24(%rbp),%edi
call   10d0 <ntohl@plt>
mov    %eax,-0x24(%rbp)
mov    -0x2c(%rbp),%edi
call   10d0 <ntohl@plt>
mov    %eax,-0x2c(%rbp)
mov    0x2bdf(%rip),%rax
mov    (%rax),%edi
mov    -0x28(%rbp),%edx
mov    -0x24(%rbp),%ecx
mov    -0x30(%rbp),%r8d
mov    -0x2c(%rbp),%r9d
lea    0xc66(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    -0x20(%rbp),%edi
mov    -0x24(%rbp),%esi
mov    0x2bac(%rip),%rax
mov    (%rax),%edx
call   1050 <lseek@plt>
mov    0x2ba6(%rip),%rax
mov    (%rax),%edi
mov    -0x40(%rbp),%rax
movsbl (%rax),%edx
lea    0xc4a(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    0x2b88(%rip),%rax
mov    (%rax),%edi
call   10b0 <fflush@plt>
mov    -0x1c(%rbp),%edi
mov    -0x40(%rbp),%rsi
mov    -0x2c(%rbp),%edx
mov    $0x0,%al
call   1080 <read@plt>
mov    -0x20(%rbp),%edi
mov    -0x40(%rbp),%rsi
mov    -0x2c(%rbp),%edx
call   1040 <write@plt>
jmp    1383 <expand+0x1d3>
mov    -0x1c(%rbp),%edi
call   1070 <close@plt>
mov    -0x20(%rbp),%edi
call   1070 <close@plt>
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<expand>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r14
mov    %rdi,%rbp
mov    0x2e0d(%rip),%rax
mov    (%rax),%esi
xor    %eax,%eax
call   10c0 <open@plt>
test   %eax,%eax
js     13ef <expand+0x23f>
mov    %eax,%ebx
mov    0x2dcb(%rip),%rax
mov    0x2e0c(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2df9(%rip),%rax
or     (%rax),%esi
mov    %r14,%rdi
mov    $0x1b6,%edx
xor    %eax,%eax
call   10c0 <open@plt>
test   %eax,%eax
js     140b <expand+0x25b>
mov    %eax,%r12d
mov    $0x800,%edi
call   10a0 <malloc@plt>
test   %rax,%rax
je     1429 <expand+0x279>
mov    %rax,%r14
lea    0xc(%rsp),%rsi
mov    %ebx,%edi
mov    $0x4,%edx
xor    %eax,%eax
call   1080 <read@plt>
mov    0x2d85(%rip),%rbp
mov    0x0(%rbp),%edi
mov    0xc(%rsp),%edx
lea    0xe02(%rip),%rsi
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    0xc(%rsp),%edi
call   10d0 <ntohl@plt>
mov    %eax,0xc(%rsp)
mov    0x0(%rbp),%edi
lea    0xdf1(%rip),%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    $0x800,%r15d
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x800,%edx
call   1060 <memset@plt>
mov    0xc(%rsp),%ebp
test   %ebp,%ebp
je     12c5 <expand+0x115>
cs nopw 0x0(%rax,%rax,1)
nop
cmp    $0x800,%ebp
cmovae %r15d,%ebp
mov    %r12d,%edi
mov    %r14,%rsi
mov    %ebp,%edx
call   1040 <write@plt>
mov    0xc(%rsp),%eax
sub    %ebp,%eax
mov    %eax,0xc(%rsp)
mov    %eax,%ebp
jne    12a0 <expand+0xf0>
mov    0x2cf4(%rip),%rax
mov    (%rax),%edx
mov    %r12d,%edi
xor    %esi,%esi
call   1050 <lseek@plt>
lea    0x10(%rsp),%rsi
mov    %ebx,%edi
mov    $0x4,%edx
xor    %eax,%eax
call   1080 <read@plt>
cmp    $0x4,%eax
jne    13d6 <expand+0x226>
mov    %ebx,0x14(%rsp)
nopl   0x0(%rax,%rax,1)
mov    %ebx,%edi
lea    0xc(%rsp),%rsi
mov    $0x4,%edx
xor    %eax,%eax
call   1080 <read@plt>
cmp    $0x4,%eax
jne    13d6 <expand+0x226>
mov    0x10(%rsp),%ebp
mov    %r12d,%r13d
mov    0xc(%rsp),%r12d
mov    %ebp,%edi
call   10d0 <ntohl@plt>
mov    %eax,%r15d
mov    %eax,0x10(%rsp)
mov    %r12d,%edi
call   10d0 <ntohl@plt>
mov    %eax,0xc(%rsp)
mov    0x2c7f(%rip),%rbx
mov    (%rbx),%edi
lea    0xd14(%rip),%rsi
mov    %ebp,%edx
mov    %r15d,%ecx
mov    %r12d,%r8d
mov    %r13d,%r12d
mov    %eax,%r9d
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    0x10(%rsp),%esi
mov    0x2c4e(%rip),%rax
mov    (%rax),%edx
mov    %r13d,%edi
call   1050 <lseek@plt>
mov    (%rbx),%edi
movsbl (%r14),%edx
lea    0xcf3(%rip),%rsi
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    (%rbx),%edi
mov    0x14(%rsp),%ebx
call   10b0 <fflush@plt>
mov    0xc(%rsp),%edx
mov    %ebx,%edi
mov    %r14,%rsi
xor    %eax,%eax
call   1080 <read@plt>
mov    0xc(%rsp),%edx
mov    %r13d,%edi
mov    %r14,%rsi
call   1040 <write@plt>
mov    %ebx,%edi
lea    0x10(%rsp),%rsi
mov    $0x4,%edx
xor    %eax,%eax
call   1080 <read@plt>
cmp    $0x4,%eax
je     1300 <expand+0x150>
mov    %ebx,%edi
call   1070 <close@plt>
mov    %r12d,%edi
call   1070 <close@plt>
mov    %r14,%rdi
call   1030 <free@plt>
jmp    144f <expand+0x29f>
mov    0x2bd2(%rip),%rax
mov    (%rax),%edi
lea    0xc01(%rip),%rsi
mov    %rbp,%rdx
xor    %eax,%eax
call   1090 <fprintf@plt>
jmp    144f <expand+0x29f>
mov    0x2bb6(%rip),%rax
mov    (%rax),%edi
lea    0xc04(%rip),%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    %ebx,%edi
jmp    144a <expand+0x29a>
mov    0x2b98(%rip),%rax
mov    (%rax),%edi
lea    0xc03(%rip),%rsi
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    %ebx,%edi
call   1070 <close@plt>
mov    %r12d,%edi
call   1070 <close@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@O_RDONLY = global i32 0
@stderr = global i32 0
@.str = [31 x i8] c"Can't open compressed file %s\0A\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@.str.1 = [29 x i8] c"Can't open expanded file %s\0A\00"
@.str.2 = [23 x i8] c"can't allocate memory\0A\00"
@.str.3 = [13 x i8] c"TOTAL LEN=%x\00"
@.str.4 = [6 x i8] c"[%x]\0A\00"
@SEEK_SET = global i32 0
@.str.5 = [22 x i8] c"POS=%x[%x]:LEN=%x[%x]\00"
@.str.6 = [20 x i8] c" --> DATA=%x\0A\00"
define i32 @expand(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 0, i32* %13
%15 = load i8*, i8** %4
%16 = load i32, i32* @O_RDONLY
%17 = call i32 (i8*, i32, ...) @open(i8* %15, i32 %16)
store i32 %17, i32* %6
%18 = icmp slt i32 %17, 0
br i1 %18, label %19, label %23
19: ; preds = %2
%20 = load i32, i32* @stderr
%21 = load i8*, i8** %4
%22 = call i32 (i32, i8*, ...) @fprintf(i32 %20, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i8* %21)
store i32 0, i32* %3
br label %133
23: ; preds = %2
%24 = load i8*, i8** %5
%25 = load i32, i32* @O_WRONLY
%26 = load i32, i32* @O_CREAT
%27 = or i32 %25, %26
%28 = load i32, i32* @O_TRUNC
%29 = or i32 %27, %28
%30 = call i32 (i8*, i32, ...) @open(i8* %24, i32 %29, i32 438)
store i32 %30, i32* %7
%31 = icmp slt i32 %30, 0
br i1 %31, label %32, label %38
32: ; preds = %23
%33 = load i32, i32* @stderr
%34 = load i8*, i8** %5
%35 = call i32 (i32, i8*, ...) @fprintf(i32 %33, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i8* %34)
%36 = load i32, i32* %6
%37 = call i32 @close(i32 %36)
store i32 0, i32* %3
br label %133
38: ; preds = %23
%39 = call i8* @malloc(i32 2048)
store i8* %39, i8** %14
%40 = icmp ne i8* %39, null
br i1 %40, label %48, label %41
41: ; preds = %38
%42 = load i32, i32* @stderr
%43 = call i32 (i32, i8*, ...) @fprintf(i32 %42, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
%44 = load i32, i32* %6
%45 = call i32 @close(i32 %44)
%46 = load i32, i32* %7
%47 = call i32 @close(i32 %46)
store i32 0, i32* %3
br label %133
48: ; preds = %38
%49 = load i32, i32* %6
%50 = bitcast i32* %10 to i8*
%51 = call i32 (i32, ...) @read(i32 %49, i8* %50, i32 4)
%52 = load i32, i32* @stderr
%53 = load i32, i32* %10
%54 = call i32 (i32, i8*, ...) @fprintf(i32 %52, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i32 %53)
%55 = load i32, i32* %10
%56 = call i32 @ntohl(i32 %55)
store i32 %56, i32* %10
%57 = load i32, i32* @stderr
%58 = load i32, i32* %10
%59 = call i32 (i32, i8*, ...) @fprintf(i32 %57, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i32 %58)
%60 = load i8*, i8** %14
%61 = call i32 @memset(i8* %60, i32 0, i32 2048)
br label %62
62: ; preds = %71, %48
%63 = load i32, i32* %10
%64 = icmp ugt i32 %63, 0
br i1 %64, label %65, label %80
65: ; preds = %62
%66 = load i32, i32* %10
%67 = icmp ugt i32 %66, 2048
br i1 %67, label %68, label %69
68: ; preds = %65
br label %71
69: ; preds = %65
%70 = load i32, i32* %10
br label %71
71: ; preds = %69, %68
%72 = phi i32 [ 2048, %68 ], [ %70, %69 ]
store i32 %72, i32* %12
%73 = load i32, i32* %7
%74 = load i8*, i8** %14
%75 = load i32, i32* %12
%76 = call i32 @write(i32 %73, i8* %74, i32 %75)
%77 = load i32, i32* %12
%78 = load i32, i32* %10
%79 = sub i32 %78, %77
store i32 %79, i32* %10
br label %62
80: ; preds = %62
%81 = load i32, i32* %7
%82 = load i32, i32* @SEEK_SET
%83 = call i32 @lseek(i32 %81, i32 0, i32 %82)
br label %84
84: ; preds = %93, %80
%85 = load i32, i32* %6
%86 = call i32 (i32, ...) @read(i32 %85, i32* %8, i32 4)
%87 = icmp eq i32 %86, 4
br i1 %87, label %88, label %126
88: ; preds = %84
%89 = load i32, i32* %6
%90 = call i32 (i32, ...) @read(i32 %89, i32* %10, i32 4)
%91 = icmp ne i32 %90, 4
br i1 %91, label %92, label %93
92: ; preds = %88
br label %126
93: ; preds = %88
%94 = load i32, i32* %8
store i32 %94, i32* %9
%95 = load i32, i32* %10
store i32 %95, i32* %11
%96 = load i32, i32* %8
%97 = call i32 @ntohl(i32 %96)
store i32 %97, i32* %8
%98 = load i32, i32* %10
%99 = call i32 @ntohl(i32 %98)
store i32 %99, i32* %10
%100 = load i32, i32* @stderr
%101 = load i32, i32* %9
%102 = load i32, i32* %8
%103 = load i32, i32* %11
%104 = load i32, i32* %10
%105 = call i32 (i32, i8*, ...) @fprintf(i32 %100, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0), i32 %101, i32 %102, i32 %103, i32 %104)
%106 = load i32, i32* %7
%107 = load i32, i32* %8
%108 = load i32, i32* @SEEK_SET
%109 = call i32 @lseek(i32 %106, i32 %107, i32 %108)
%110 = load i32, i32* @stderr
%111 = load i8*, i8** %14
%112 = getelementptr inbounds i8, i8* %111, i64 0
%113 = load i8, i8* %112
%114 = sext i8 %113 to i32
%115 = call i32 (i32, i8*, ...) @fprintf(i32 %110, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.6, i64 0, i64 0), i32 %114)
%116 = load i32, i32* @stderr
%117 = call i32 @fflush(i32 %116)
%118 = load i32, i32* %6
%119 = load i8*, i8** %14
%120 = load i32, i32* %10
%121 = call i32 (i32, ...) @read(i32 %118, i8* %119, i32 %120)
%122 = load i32, i32* %7
%123 = load i8*, i8** %14
%124 = load i32, i32* %10
%125 = call i32 @write(i32 %122, i8* %123, i32 %124)
br label %84
126: ; preds = %92, %84
%127 = load i32, i32* %6
%128 = call i32 @close(i32 %127)
%129 = load i32, i32* %7
%130 = call i32 @close(i32 %129)
%131 = load i8*, i8** %14
%132 = call i32 @free(i8* %131)
br label %133
133: ; preds = %126, %41, %32, %19
%134 = load i32, i32* %3
ret i32 %134
}

LLVM IR (-O2):
@O_RDONLY = global i32 0
@stderr = global i32 0
@.str = [31 x i8] c"Can't open compressed file %s\0A\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@.str.1 = [29 x i8] c"Can't open expanded file %s\0A\00"
@.str.2 = [23 x i8] c"can't allocate memory\0A\00"
@.str.3 = [13 x i8] c"TOTAL LEN=%x\00"
@.str.4 = [6 x i8] c"[%x]\0A\00"
@SEEK_SET = global i32 0
@.str.5 = [22 x i8] c"POS=%x[%x]:LEN=%x[%x]\00"
@.str.6 = [20 x i8] c" --> DATA=%x\0A\00"
define i32 @expand(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = bitcast i32* %3 to i8*
%6 = bitcast i32* %4 to i8*
%7 = load i32, i32* @O_RDONLY
%8 = tail call i32 (i8*, i32, ...) @open(i8* %0, i32 %7)
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %13
10: ; preds = %2
%11 = load i32, i32* @stderr
%12 = tail call i32 (i32, i8*, ...) @fprintf(i32 %11, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %87
13: ; preds = %2
%14 = load i32, i32* @O_WRONLY
%15 = load i32, i32* @O_CREAT
%16 = or i32 %15, %14
%17 = load i32, i32* @O_TRUNC
%18 = or i32 %16, %17
%19 = tail call i32 (i8*, i32, ...) @open(i8* %1, i32 %18, i32 438)
%20 = icmp slt i32 %19, 0
br i1 %20, label %21, label %25
21: ; preds = %13
%22 = load i32, i32* @stderr
%23 = tail call i32 (i32, i8*, ...) @fprintf(i32 %22, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i8* %1)
%24 = tail call i32 @close(i32 %8)
br label %87
25: ; preds = %13
%26 = tail call dereferenceable_or_null(2048) i8* @malloc(i32 2048)
%27 = icmp eq i8* %26, null
br i1 %27, label %28, label %33
28: ; preds = %25
%29 = load i32, i32* @stderr
%30 = tail call i32 (i32, i8*, ...) @fprintf(i32 %29, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
%31 = tail call i32 @close(i32 %8)
%32 = tail call i32 @close(i32 %19)
br label %87
33: ; preds = %25
%34 = call i32 (i32, ...) @read(i32 %8, i32* %4, i32 4)
%35 = load i32, i32* @stderr
%36 = load i32, i32* %4
%37 = call i32 (i32, i8*, ...) @fprintf(i32 %35, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i32 %36)
%38 = load i32, i32* %4
%39 = call i32 @ntohl(i32 %38)
store i32 %39, i32* %4
%40 = load i32, i32* @stderr
%41 = call i32 (i32, i8*, ...) @fprintf(i32 %40, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i32 %39)
%42 = call i32 @memset(i8* %26, i32 0, i32 2048)
%43 = load i32, i32* %4
%44 = icmp eq i32 %43, 0
br i1 %44, label %53, label %45
45: ; preds = %33, %45
%46 = phi i32 [ %51, %45 ], [ %43, %33 ]
%47 = icmp ult i32 %46, 2048
%48 = select i1 %47, i32 %46, i32 2048
%49 = call i32 @write(i32 %19, i8* %26, i32 %48)
%50 = load i32, i32* %4
%51 = sub i32 %50, %48
store i32 %51, i32* %4
%52 = icmp eq i32 %51, 0
br i1 %52, label %53, label %45
53: ; preds = %45, %33
%54 = load i32, i32* @SEEK_SET
%55 = call i32 @lseek(i32 %19, i32 0, i32 %54)
%56 = call i32 (i32, ...) @read(i32 %8, i32* %3, i32 4)
%57 = icmp eq i32 %56, 4
br i1 %57, label %58, label %83
58: ; preds = %53, %61
%59 = call i32 (i32, ...) @read(i32 %8, i32* %4, i32 4)
%60 = icmp eq i32 %59, 4
br i1 %60, label %61, label %83
61: ; preds = %58
%62 = load i32, i32* %3
%63 = load i32, i32* %4
%64 = call i32 @ntohl(i32 %62)
store i32 %64, i32* %3
%65 = call i32 @ntohl(i32 %63)
store i32 %65, i32* %4
%66 = load i32, i32* @stderr
%67 = call i32 (i32, i8*, ...) @fprintf(i32 %66, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0), i32 %62, i32 %64, i32 %63, i32 %65)
%68 = load i32, i32* %3
%69 = load i32, i32* @SEEK_SET
%70 = call i32 @lseek(i32 %19, i32 %68, i32 %69)
%71 = load i32, i32* @stderr
%72 = load i8, i8* %26
%73 = sext i8 %72 to i32
%74 = call i32 (i32, i8*, ...) @fprintf(i32 %71, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.6, i64 0, i64 0), i32 %73)
%75 = load i32, i32* @stderr
%76 = call i32 @fflush(i32 %75)
%77 = load i32, i32* %4
%78 = call i32 (i32, ...) @read(i32 %8, i8* %26, i32 %77)
%79 = load i32, i32* %4
%80 = call i32 @write(i32 %19, i8* %26, i32 %79)
%81 = call i32 (i32, ...) @read(i32 %8, i32* %3, i32 4)
%82 = icmp eq i32 %81, 4
br i1 %82, label %58, label %83
83: ; preds = %61, %58, %53
%84 = call i32 @close(i32 %8)
%85 = call i32 @close(i32 %19)
%86 = call i32 @free(i8* %26)
br label %87
87: ; preds = %83, %28, %21, %10
ret i32 0
}