#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 /*<<< orphan*/ File_Close(int);
int File_Open(char const *);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
scalar_t__ read(int, ...);
int write(int, char *, int);
int File_UpgradeConstruct(const char *inFile, const char *outFile) {
  int in_fd, out_fd;
  int i, len;
  char buf[2048];
  if ((in_fd = File_Open(inFile)) < 0)
    return -1;
  if ((out_fd = File_Open(outFile)) < 0)
    return -1;
  while (read(in_fd, &i, 4) > 0) {
    if (read(in_fd, &len, 4) <= 0)
      break;
    memset(buf, 0, 2048);
    if (read(in_fd, buf, len) <= 0)
      break;
    if (write(out_fd, buf, len) != len)
      break;
  }
  File_Close(in_fd);
  File_Close(out_fd);
  return 0;
}


x86 assembly (clang, -O0):
<File_UpgradeConstruct>:
push   %rbp
mov    %rsp,%rbp
sub    $0x830,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <File_Open@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
jge    1184 <File_UpgradeConstruct+0x34>
movl   $0xffffffff,-0x4(%rbp)
jmp    125b <File_UpgradeConstruct+0x10b>
mov    -0x18(%rbp),%rdi
call   1060 <File_Open@plt>
mov    %eax,-0x20(%rbp)
cmp    $0x0,%eax
jge    11a5 <File_UpgradeConstruct+0x55>
movl   $0xffffffff,-0x4(%rbp)
jmp    125b <File_UpgradeConstruct+0x10b>
jmp    11aa <File_UpgradeConstruct+0x5a>
mov    -0x1c(%rbp),%edi
lea    -0x24(%rbp),%rsi
mov    $0x4,%edx
mov    $0x0,%al
call   1050 <read@plt>
cmp    $0x0,%rax
jle    1244 <File_UpgradeConstruct+0xf4>
mov    -0x1c(%rbp),%edi
lea    -0x28(%rbp),%rsi
mov    $0x4,%edx
mov    $0x0,%al
call   1050 <read@plt>
cmp    $0x0,%rax
jg     11e9 <File_UpgradeConstruct+0x99>
jmp    1244 <File_UpgradeConstruct+0xf4>
lea    -0x830(%rbp),%rdi
xor    %esi,%esi
mov    $0x800,%edx
call   1040 <memset@plt>
mov    -0x1c(%rbp),%edi
lea    -0x830(%rbp),%rsi
mov    -0x28(%rbp),%edx
mov    $0x0,%al
call   1050 <read@plt>
cmp    $0x0,%rax
jg     121f <File_UpgradeConstruct+0xcf>
jmp    1244 <File_UpgradeConstruct+0xf4>
mov    -0x20(%rbp),%edi
lea    -0x830(%rbp),%rsi
mov    -0x28(%rbp),%edx
call   1030 <write@plt>
cmp    -0x28(%rbp),%eax
je     123f <File_UpgradeConstruct+0xef>
jmp    1244 <File_UpgradeConstruct+0xf4>
jmp    11aa <File_UpgradeConstruct+0x5a>
mov    -0x1c(%rbp),%edi
call   1070 <File_Close@plt>
mov    -0x20(%rbp),%edi
call   1070 <File_Close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x830,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<File_UpgradeConstruct>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x810,%rsp
mov    %rsi,%r14
call   1060 <File_Open@plt>
mov    $0xffffffff,%ebp
test   %eax,%eax
js     1216 <File_UpgradeConstruct+0xc6>
mov    %eax,%ebx
mov    %r14,%rdi
call   1060 <File_Open@plt>
test   %eax,%eax
js     1216 <File_UpgradeConstruct+0xc6>
mov    %eax,%r12d
lea    0xc(%rsp),%r14
lea    0x8(%rsp),%r15
lea    0x10(%rsp),%rbp
nopl   0x0(%rax,%rax,1)
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x4,%edx
xor    %eax,%eax
call   1050 <read@plt>
test   %rax,%rax
jle    1205 <File_UpgradeConstruct+0xb5>
mov    %ebx,%edi
mov    %r15,%rsi
mov    $0x4,%edx
xor    %eax,%eax
call   1050 <read@plt>
test   %rax,%rax
jle    1205 <File_UpgradeConstruct+0xb5>
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0x800,%edx
call   1040 <memset@plt>
mov    0x8(%rsp),%edx
mov    %ebx,%edi
mov    %rbp,%rsi
xor    %eax,%eax
call   1050 <read@plt>
test   %rax,%rax
jle    1205 <File_UpgradeConstruct+0xb5>
mov    0x8(%rsp),%edx
mov    %r12d,%edi
mov    %rbp,%rsi
call   1030 <write@plt>
cmp    0x8(%rsp),%eax
je     11a0 <File_UpgradeConstruct+0x50>
mov    %ebx,%edi
call   1070 <File_Close@plt>
mov    %r12d,%edi
call   1070 <File_Close@plt>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x810,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @File_UpgradeConstruct(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 [2048 x i8]
store i8* %0, i8** %4
store i8* %1, i8** %5
%11 = load i8*, i8** %4
%12 = call i32 @File_Open(i8* %11)
store i32 %12, i32* %6
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %15
14: ; preds = %2
store i32 -1, i32* %3
br label %53
15: ; preds = %2
%16 = load i8*, i8** %5
%17 = call i32 @File_Open(i8* %16)
store i32 %17, i32* %7
%18 = icmp slt i32 %17, 0
br i1 %18, label %19, label %20
19: ; preds = %15
store i32 -1, i32* %3
br label %53
20: ; preds = %15
br label %21
21: ; preds = %47, %20
%22 = load i32, i32* %6
%23 = call i64 (i32, ...) @read(i32 %22, i32* %8, i32 4)
%24 = icmp sgt i64 %23, 0
br i1 %24, label %25, label %48
25: ; preds = %21
%26 = load i32, i32* %6
%27 = call i64 (i32, ...) @read(i32 %26, i32* %9, i32 4)
%28 = icmp sle i64 %27, 0
br i1 %28, label %29, label %30
29: ; preds = %25
br label %48
30: ; preds = %25
%31 = getelementptr inbounds [2048 x i8], [2048 x i8]* %10, i64 0, i64 0
%32 = call i32 @memset(i8* %31, i32 0, i32 2048)
%33 = load i32, i32* %6
%34 = getelementptr inbounds [2048 x i8], [2048 x i8]* %10, i64 0, i64 0
%35 = load i32, i32* %9
%36 = call i64 (i32, ...) @read(i32 %33, i8* %34, i32 %35)
%37 = icmp sle i64 %36, 0
br i1 %37, label %38, label %39
38: ; preds = %30
br label %48
39: ; preds = %30
%40 = load i32, i32* %7
%41 = getelementptr inbounds [2048 x i8], [2048 x i8]* %10, i64 0, i64 0
%42 = load i32, i32* %9
%43 = call i32 @write(i32 %40, i8* %41, i32 %42)
%44 = load i32, i32* %9
%45 = icmp ne i32 %43, %44
br i1 %45, label %46, label %47
46: ; preds = %39
br label %48
47: ; preds = %39
br label %21
48: ; preds = %46, %38, %29, %21
%49 = load i32, i32* %6
%50 = call i32 @File_Close(i32 %49)
%51 = load i32, i32* %7
%52 = call i32 @File_Close(i32 %51)
store i32 0, i32* %3
br label %53
53: ; preds = %48, %19, %14
%54 = load i32, i32* %3
ret i32 %54
}

LLVM IR (-O2):
define i32 @File_UpgradeConstruct(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca [2048 x i8]
%6 = bitcast i32* %3 to i8*
%7 = bitcast i32* %4 to i8*
%8 = getelementptr inbounds [2048 x i8], [2048 x i8]* %5, i64 0, i64 0
%9 = tail call i32 @File_Open(i8* %0)
%10 = icmp slt i32 %9, 0
br i1 %10, label %33, label %11
11: ; preds = %2
%12 = tail call i32 @File_Open(i8* %1)
%13 = icmp slt i32 %12, 0
br i1 %13, label %33, label %14
14: ; preds = %11, %25
%15 = call i64 (i32, ...) @read(i32 %9, i32* %3, i32 4)
%16 = icmp sgt i64 %15, 0
br i1 %16, label %17, label %30
17: ; preds = %14
%18 = call i64 (i32, ...) @read(i32 %9, i32* %4, i32 4)
%19 = icmp slt i64 %18, 1
br i1 %19, label %30, label %20
20: ; preds = %17
%21 = call i32 @memset(i8* %8, i32 0, i32 2048)
%22 = load i32, i32* %4
%23 = call i64 (i32, ...) @read(i32 %9, i8* %8, i32 %22)
%24 = icmp slt i64 %23, 1
br i1 %24, label %30, label %25
25: ; preds = %20
%26 = load i32, i32* %4
%27 = call i32 @write(i32 %12, i8* %8, i32 %26)
%28 = load i32, i32* %4
%29 = icmp eq i32 %27, %28
br i1 %29, label %14, label %30
30: ; preds = %25, %20, %17, %14
%31 = call i32 @File_Close(i32 %9)
%32 = call i32 @File_Close(i32 %12)
br label %33
33: ; preds = %11, %2, %30
%34 = phi i32 [ 0, %30 ], [ -1, %2 ], [ -1, %11 ]
ret i32 %34
}