#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*/ uint8_t;
typedef char *uint32_t;
typedef int /*<<< orphan*/ tempfile;
typedef scalar_t__ ssize_t;

/* Variables and functions */
int PATH_MAX;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int mkstemp(char *);
int /*<<< orphan*/ perror(char *);
scalar_t__ read(int, int /*<<< orphan*/ *, int const);
int rename(char *, char const *);
int snprintf(char *, int, char *, char *, char const *, char *, char const *);
int /*<<< orphan*/ stderr;
char *strrchr(char const *, char);
scalar_t__ write(int, int /*<<< orphan*/ *, scalar_t__);
int raw_receive_file(const char *path, int expected_size, int sock) {
  int ret;
  const char *slash = strrchr(path, '/');
  if (slash == NULL) {
    fprintf(stderr, "Could not find slash in file name.\n");
    return -1;
  }
  char tempfile[PATH_MAX];
  ret = snprintf(tempfile, sizeof(tempfile), "%.*s%s%s-XXXXXX",
                 (uint32_t)(slash - path + 1), path, ("exopackage_temp-"),
                 slash + 1);
  if (ret <= 0 || ret >= sizeof(tempfile)) {
    fprintf(stderr, "temp file name snprintf failed: %d\n", ret);
    return -1;
  }
  int temp_fd = -1;
  ret = mkstemp(tempfile);
  if (ret < 0) {
    perror("mkstemp");
    return ret;
  }
  temp_fd = ret;
  ssize_t total_size = 0;
  for (;;) {
    const int buffer_size = 128 * 1024;
    uint8_t buffer[buffer_size];
    ssize_t got = read(sock, buffer, buffer_size);
    if (got < 0) {
      perror("read(file)");
      goto error;
    }
    if (got == 0) {
      break;
    }
    ssize_t wrote = write(temp_fd, buffer, got);
    if (wrote != got) {
      perror("write");
      goto error;
    }
    total_size += wrote;
  }
  close(temp_fd);
  temp_fd = -1;
  if (total_size != expected_size) {
    fprintf(stderr, "Received only %d of %d bytes.", (int)total_size,
            (int)expected_size);
    goto error;
  }
  ret = rename(tempfile, path);
  if (ret != 0) {
    perror("rename");
    goto error;
  }
  return 0;
error:
  if (temp_fd >= 0) {
    close(temp_fd);
  }
  return -1;
}


x86 assembly (clang, -O0):
<raw_receive_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x2f,%esi
call   1050 <strrchr@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11e5 <raw_receive_file+0x55>
mov    0x2e0f(%rip),%rax
mov    (%rax),%edi
lea    0xe2e(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1490 <raw_receive_file+0x300>
mov    0x2e04(%rip),%rax
mov    (%rax),%eax
mov    %rax,-0x78(%rbp)
mov    %rsp,%rcx
mov    %rcx,-0x30(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x70(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x38(%rbp)
mov    %eax,%esi
mov    -0x28(%rbp),%rcx
mov    -0x10(%rbp),%rax
sub    %rax,%rcx
add    $0x1,%rcx
mov    -0x10(%rbp),%r8
mov    -0x28(%rbp),%rax
add    $0x1,%rax
lea    0xdeb(%rip),%rdx
lea    0xdf4(%rip),%r9
sub    $0x10,%rsp
mov    %rax,(%rsp)
call   1040 <snprintf@plt>
add    $0x10,%rsp
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jle    126f <raw_receive_file+0xdf>
mov    -0x78(%rbp),%rcx
movslq -0x1c(%rbp),%rax
cmp    %rcx,%rax
jb     129c <raw_receive_file+0x10c>
mov    0x2d62(%rip),%rax
mov    (%rax),%edi
mov    -0x1c(%rbp),%edx
lea    0xdc3(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x3c(%rbp)
jmp    1489 <raw_receive_file+0x2f9>
mov    -0x70(%rbp),%rdi
movl   $0xffffffff,-0x40(%rbp)
call   1090 <mkstemp@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    12d7 <raw_receive_file+0x147>
lea    0xda9(%rip),%rdi
call   10a0 <perror@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x3c(%rbp)
jmp    1489 <raw_receive_file+0x2f9>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x40(%rbp)
movq   $0x0,-0x48(%rbp)
movl   $0x20000,-0x4c(%rbp)
mov    %rsp,%rax
mov    %rax,-0x58(%rbp)
mov    %rsp,%rsi
add    $0xfffffffffff80000,%rsi
mov    %rsi,-0x80(%rbp)
mov    %rsi,%rsp
mov    -0x18(%rbp),%edi
mov    $0x20000,%edx
call   1070 <read@plt>
mov    %rax,-0x60(%rbp)
cmpq   $0x0,-0x60(%rbp)
jge    1338 <raw_receive_file+0x1a8>
lea    0xd4a(%rip),%rdi
call   10a0 <perror@plt>
movl   $0x4,-0x3c(%rbp)
jmp    139c <raw_receive_file+0x20c>
cmpq   $0x0,-0x60(%rbp)
jne    134f <raw_receive_file+0x1bf>
movl   $0x2,-0x3c(%rbp)
jmp    139c <raw_receive_file+0x20c>
mov    -0x80(%rbp),%rsi
mov    -0x40(%rbp),%edi
mov    -0x60(%rbp),%rdx
call   1030 <write@plt>
mov    %rax,-0x68(%rbp)
mov    -0x68(%rbp),%rax
cmp    -0x60(%rbp),%rax
je     1389 <raw_receive_file+0x1f9>
lea    0xd04(%rip),%rdi
call   10a0 <perror@plt>
movl   $0x4,-0x3c(%rbp)
jmp    139c <raw_receive_file+0x20c>
mov    -0x68(%rbp),%rax
add    -0x48(%rbp),%rax
mov    %rax,-0x48(%rbp)
movl   $0x0,-0x3c(%rbp)
mov    -0x58(%rbp),%rax
mov    %rax,%rsp
mov    -0x3c(%rbp),%eax
mov    %eax,-0x84(%rbp)
test   %eax,%eax
je     13e1 <raw_receive_file+0x251>
jmp    13b9 <raw_receive_file+0x229>
mov    -0x84(%rbp),%eax
sub    $0x2,%eax
je     13e6 <raw_receive_file+0x256>
jmp    13cd <raw_receive_file+0x23d>
mov    -0x84(%rbp),%eax
sub    $0x4,%eax
je     1469 <raw_receive_file+0x2d9>
jmp    1489 <raw_receive_file+0x2f9>
jmp    12e5 <raw_receive_file+0x155>
mov    -0x40(%rbp),%edi
call   1060 <close@plt>
movl   $0xffffffff,-0x40(%rbp)
mov    -0x48(%rbp),%rax
movslq -0x14(%rbp),%rcx
cmp    %rcx,%rax
je     142b <raw_receive_file+0x29b>
mov    0x2bcb(%rip),%rax
mov    (%rax),%edi
mov    -0x48(%rbp),%rax
mov    %eax,%edx
mov    -0x14(%rbp),%ecx
lea    0xc63(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
jmp    1469 <raw_receive_file+0x2d9>
mov    -0x70(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   10b0 <rename@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     1456 <raw_receive_file+0x2c6>
lea    0xc54(%rip),%rdi
call   10a0 <perror@plt>
jmp    1469 <raw_receive_file+0x2d9>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x3c(%rbp)
jmp    1489 <raw_receive_file+0x2f9>
cmpl   $0x0,-0x40(%rbp)
jl     147b <raw_receive_file+0x2eb>
mov    -0x40(%rbp),%edi
call   1060 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x3c(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<raw_receive_file>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %edx,-0x2c(%rbp)
mov    %esi,%r15d
mov    %rdi,%r12
mov    $0x2f,%esi
call   1050 <strrchr@plt>
test   %rax,%rax
je     12cd <raw_receive_file+0x13d>
mov    %rsp,%r14
mov    0x2e29(%rip),%rcx
mov    (%rcx),%ebx
mov    %rsp,%r13
lea    0xf(%rbx),%rcx
and    $0xfffffffffffffff0,%rcx
sub    %rcx,%r13
mov    %r13,%rsp
mov    %rax,%rcx
sub    %r12,%rcx
add    $0x1,%rcx
add    $0x1,%rax
sub    $0x8,%rsp
lea    0xe31(%rip),%rdx
lea    0xe3a(%rip),%r9
mov    %r13,%rdi
mov    %ebx,%esi
mov    %r12,%r8
push   %rax
call   1040 <snprintf@plt>
add    $0x10,%rsp
test   %eax,%eax
jle    12ee <raw_receive_file+0x15e>
movslq %eax,%rcx
cmp    %rbx,%rcx
jae    12ee <raw_receive_file+0x15e>
mov    %r13,%rdi
call   1090 <mkstemp@plt>
mov    %eax,%ebx
test   %eax,%eax
js     137f <raw_receive_file+0x1ef>
mov    %r13,-0x48(%rbp)
mov    %r12,-0x50(%rbp)
mov    %r15d,-0x3c(%rbp)
mov    %rsp,%r12
mov    %rsp,%r15
add    $0xfffffffffff80000,%r15
mov    %r15,%rsp
mov    -0x2c(%rbp),%edi
mov    %r15,%rsi
mov    $0x20000,%edx
call   1070 <read@plt>
test   %rax,%rax
js     12c1 <raw_receive_file+0x131>
mov    %rax,%r13
mov    %r14,-0x38(%rbp)
xor    %r14d,%r14d
nopl   (%rax)
test   %r13,%r13
je     130e <raw_receive_file+0x17e>
mov    %ebx,%edi
mov    %r15,%rsi
mov    %r13,%rdx
call   1030 <write@plt>
cmp    %r13,%rax
jne    138d <raw_receive_file+0x1fd>
add    %r13,%r14
mov    %r12,%rsp
mov    %rsp,%r12
mov    %rsp,%r15
add    $0xfffffffffff80000,%r15
mov    %r15,%rsp
mov    -0x2c(%rbp),%edi
mov    %r15,%rsi
mov    $0x20000,%edx
call   1070 <read@plt>
mov    %rax,%r13
test   %rax,%rax
jns    1270 <raw_receive_file+0xe0>
mov    -0x38(%rbp),%r14
lea    0xda9(%rip),%rdi
jmp    1398 <raw_receive_file+0x208>
mov    0x2d04(%rip),%rax
mov    (%rax),%edi
lea    0xd23(%rip),%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    $0xffffffff,%ebx
jmp    136e <raw_receive_file+0x1de>
mov    0x2ce3(%rip),%rcx
mov    (%rcx),%edi
lea    0xd47(%rip),%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    $0xffffffff,%ebx
jmp    136b <raw_receive_file+0x1db>
mov    %r12,%rsp
mov    %ebx,%edi
call   1060 <close@plt>
mov    -0x3c(%rbp),%ecx
movslq %ecx,%rax
cmp    %rax,%r14
jne    1348 <raw_receive_file+0x1b8>
mov    -0x48(%rbp),%rdi
mov    -0x50(%rbp),%rsi
call   10b0 <rename@plt>
xor    %ebx,%ebx
test   %eax,%eax
mov    -0x38(%rbp),%r14
je     136b <raw_receive_file+0x1db>
lea    0xd5f(%rip),%rdi
call   10a0 <perror@plt>
jmp    1307 <raw_receive_file+0x177>
mov    0x2c89(%rip),%rax
mov    (%rax),%edi
lea    0xd2a(%rip),%rsi
mov    %r14d,%edx
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    $0xffffffff,%ebx
mov    -0x38(%rbp),%r14
mov    %r14,%rsp
mov    %ebx,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xce3(%rip),%rdi
call   10a0 <perror@plt>
jmp    136b <raw_receive_file+0x1db>
lea    0xce8(%rip),%rdi
mov    -0x38(%rbp),%r14
call   10a0 <perror@plt>
mov    %r12,%rsp
test   %ebx,%ebx
js     1307 <raw_receive_file+0x177>
mov    %ebx,%edi
call   1060 <close@plt>
jmp    1307 <raw_receive_file+0x177>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [36 x i8] c"Could not find slash in file name.\0A\00"
@PATH_MAX = global i32 0
@.str.1 = [16 x i8] c"%.*s%s%s-XXXXXX\00"
@.str.2 = [17 x i8] c"exopackage_temp-\00"
@.str.3 = [36 x i8] c"temp file name snprintf failed: %d\0A\00"
@.str.4 = [8 x i8] c"mkstemp\00"
@.str.5 = [11 x i8] c"read(file)\00"
@.str.6 = [6 x i8] c"write\00"
@.str.7 = [30 x i8] c"Received only %d of %d bytes.\00"
@.str.8 = [7 x i8] c"rename\00"
define i32 @raw_receive_file(i8* %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i64
%12 = alloca i32
%13 = alloca i32
%14 = alloca i64
%15 = alloca i32
%16 = alloca i8*
%17 = alloca i64
%18 = alloca i64
store i8* %0, i8** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
%19 = load i8*, i8** %5
%20 = call i8* @strrchr(i8* %19, i8 signext 47)
store i8* %20, i8** %9
%21 = load i8*, i8** %9
%22 = icmp eq i8* %21, null
br i1 %22, label %23, label %26
23: ; preds = %3
%24 = load i32, i32* @stderr
%25 = call i32 (i32, i8*, ...) @fprintf(i32 %24, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %4
br label %122
26: ; preds = %3
%27 = load i32, i32* @PATH_MAX
%28 = zext i32 %27 to i64
%29 = call i8* @llvm.stacksave()
store i8* %29, i8** %10
%30 = alloca i8, i64 %28
store i64 %28, i64* %11
%31 = trunc i64 %28 to i32
%32 = load i8*, i8** %9
%33 = load i8*, i8** %5
%34 = ptrtoint i8* %32 to i64
%35 = ptrtoint i8* %33 to i64
%36 = sub i64 %34, %35
%37 = add nsw i64 %36, 1
%38 = inttoptr i64 %37 to i8*
%39 = load i8*, i8** %5
%40 = load i8*, i8** %9
%41 = getelementptr inbounds i8, i8* %40, i64 1
%42 = call i32 @snprintf(i8* %30, i32 %31, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* %38, i8* %39, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8* %41)
store i32 %42, i32* %8
%43 = load i32, i32* %8
%44 = icmp sle i32 %43, 0
br i1 %44, label %49, label %45
45: ; preds = %26
%46 = load i32, i32* %8
%47 = sext i32 %46 to i64
%48 = icmp uge i64 %47, %28
br i1 %48, label %49, label %53
49: ; preds = %45, %26
%50 = load i32, i32* @stderr
%51 = load i32, i32* %8
%52 = call i32 (i32, i8*, ...) @fprintf(i32 %50, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0), i32 %51)
store i32 -1, i32* %4
store i32 1, i32* %12
br label %120
53: ; preds = %45
store i32 -1, i32* %13
%54 = call i32 @mkstemp(i8* %30)
store i32 %54, i32* %8
%55 = load i32, i32* %8
%56 = icmp slt i32 %55, 0
br i1 %56, label %57, label %60
57: ; preds = %53
%58 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
%59 = load i32, i32* %8
store i32 %59, i32* %4
store i32 1, i32* %12
br label %120
60: ; preds = %53
%61 = load i32, i32* %8
store i32 %61, i32* %13
store i64 0, i64* %14
br label %62
62: ; preds = %91, %60
store i32 131072, i32* %15
%63 = call i8* @llvm.stacksave()
store i8* %63, i8** %16
%64 = alloca i32, i64 131072
%65 = load i32, i32* %7
%66 = call i64 @read(i32 %65, i32* %64, i32 131072)
store i64 %66, i64* %17
%67 = load i64, i64* %17
%68 = icmp slt i64 %67, 0
br i1 %68, label %69, label %71
69: ; preds = %62
%70 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0))
store i32 4, i32* %12
br label %88
71: ; preds = %62
%72 = load i64, i64* %17
%73 = icmp eq i64 %72, 0
br i1 %73, label %74, label %75
74: ; preds = %71
store i32 2, i32* %12
br label %88
75: ; preds = %71
%76 = load i32, i32* %13
%77 = load i64, i64* %17
%78 = call i64 @write(i32 %76, i32* %64, i64 %77)
store i64 %78, i64* %18
%79 = load i64, i64* %18
%80 = load i64, i64* %17
%81 = icmp ne i64 %79, %80
br i1 %81, label %82, label %84
82: ; preds = %75
%83 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0))
store i32 4, i32* %12
br label %88
84: ; preds = %75
%85 = load i64, i64* %18
%86 = load i64, i64* %14
%87 = add nsw i64 %86, %85
store i64 %87, i64* %14
store i32 0, i32* %12
br label %88
88: ; preds = %82, %69, %84, %74
%89 = load i8*, i8** %16
%90 = load i32, i32* %12
switch i32 %90, label %120 [
i32 0, label %91
i32 2, label %92
i32 4, label %113
]
91: ; preds = %88
br label %62
92: ; preds = %88
%93 = load i32, i32* %13
%94 = call i32 @close(i32 %93)
store i32 -1, i32* %13
%95 = load i64, i64* %14
%96 = load i32, i32* %6
%97 = sext i32 %96 to i64
%98 = icmp ne i64 %95, %97
br i1 %98, label %99, label %105
99: ; preds = %92
%100 = load i32, i32* @stderr
%101 = load i64, i64* %14
%102 = trunc i64 %101 to i32
%103 = load i32, i32* %6
%104 = call i32 (i32, i8*, ...) @fprintf(i32 %100, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.7, i64 0, i64 0), i32 %102, i32 %103)
br label %113
105: ; preds = %92
%106 = load i8*, i8** %5
%107 = call i32 @rename(i8* %30, i8* %106)
store i32 %107, i32* %8
%108 = load i32, i32* %8
%109 = icmp ne i32 %108, 0
br i1 %109, label %110, label %112
110: ; preds = %105
%111 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.8, i64 0, i64 0))
br label %113
112: ; preds = %105
store i32 0, i32* %4
store i32 1, i32* %12
br label %120
113: ; preds = %88, %110, %99
%114 = load i32, i32* %13
%115 = icmp sge i32 %114, 0
br i1 %115, label %116, label %119
116: ; preds = %113
%117 = load i32, i32* %13
%118 = call i32 @close(i32 %117)
br label %119
119: ; preds = %116, %113
store i32 -1, i32* %4
store i32 1, i32* %12
br label %120
120: ; preds = %119, %112, %88, %57, %49
%121 = load i8*, i8** %10
br label %122
122: ; preds = %120, %23
%123 = load i32, i32* %4
ret i32 %123
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [36 x i8] c"Could not find slash in file name.\0A\00"
@PATH_MAX = global i32 0
@.str.1 = [16 x i8] c"%.*s%s%s-XXXXXX\00"
@.str.2 = [17 x i8] c"exopackage_temp-\00"
@.str.3 = [36 x i8] c"temp file name snprintf failed: %d\0A\00"
@.str.4 = [8 x i8] c"mkstemp\00"
@.str.5 = [11 x i8] c"read(file)\00"
@.str.6 = [6 x i8] c"write\00"
@.str.7 = [30 x i8] c"Received only %d of %d bytes.\00"
@.str.8 = [7 x i8] c"rename\00"
define i32 @raw_receive_file(i8* %0, i32 %1, i32 %2) {
%4 = tail call i8* @strrchr(i8* dereferenceable(1) %0, i8 signext 47)
%5 = icmp eq i8* %4, null
br i1 %5, label %6, label %9
6: ; preds = %3
%7 = load i32, i32* @stderr
%8 = tail call i32 (i32, i8*, ...) @fprintf(i32 %7, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
br label %77
9: ; preds = %3
%10 = load i32, i32* @PATH_MAX
%11 = zext i32 %10 to i64
%12 = tail call i8* @llvm.stacksave()
%13 = alloca i8, i64 %11
%14 = ptrtoint i8* %4 to i64
%15 = ptrtoint i8* %0 to i64
%16 = sub i64 1, %15
%17 = add i64 %16, %14
%18 = inttoptr i64 %17 to i8*
%19 = getelementptr inbounds i8, i8* %4, i64 1
%20 = call i32 @snprintf(i8* %13, i32 %10, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* %18, i8* %0, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8* %19)
%21 = icmp slt i32 %20, 1
%22 = sext i32 %20 to i64
%23 = icmp uge i64 %22, %11
%24 = or i1 %21, %23
br i1 %24, label %25, label %28
25: ; preds = %9
%26 = load i32, i32* @stderr
%27 = call i32 (i32, i8*, ...) @fprintf(i32 %26, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0), i32 %20)
br label %75
28: ; preds = %9
%29 = call i32 @mkstemp(i8* %13)
%30 = icmp slt i32 %29, 0
br i1 %30, label %37, label %31
31: ; preds = %28
%32 = call i8* @llvm.stacksave()
%33 = alloca [131072 x i32]
%34 = getelementptr inbounds [131072 x i32], [131072 x i32]* %33, i64 0, i64 0
%35 = call i64 @read(i32 %2, i32* %34, i32 131072)
%36 = icmp slt i64 %35, 0
br i1 %36, label %68, label %39
37: ; preds = %28
%38 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
br label %75
39: ; preds = %31, %48
%40 = phi i64 [ %53, %48 ], [ %35, %31 ]
%41 = phi i32* [ %52, %48 ], [ %34, %31 ]
%42 = phi i8* [ %50, %48 ], [ %32, %31 ]
%43 = phi i64 [ %49, %48 ], [ 0, %31 ]
%44 = icmp eq i64 %40, 0
br i1 %44, label %55, label %45
45: ; preds = %39
%46 = call i64 @write(i32 %29, i32* %41, i64 %40)
%47 = icmp eq i64 %46, %40
br i1 %47, label %48, label %68
48: ; preds = %45
%49 = add nsw i64 %40, %43
%50 = call i8* @llvm.stacksave()
%51 = alloca [131072 x i32]
%52 = getelementptr inbounds [131072 x i32], [131072 x i32]* %51, i64 0, i64 0
%53 = call i64 @read(i32 %2, i32* %52, i32 131072)
%54 = icmp slt i64 %53, 0
br i1 %54, label %68, label %39
55: ; preds = %39
%56 = call i32 @close(i32 %29)
%57 = sext i32 %1 to i64
%58 = icmp eq i64 %43, %57
br i1 %58, label %63, label %59
59: ; preds = %55
%60 = load i32, i32* @stderr
%61 = trunc i64 %43 to i32
%62 = call i32 (i32, i8*, ...) @fprintf(i32 %60, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.7, i64 0, i64 0), i32 %61, i32 %1)
br label %75
63: ; preds = %55
%64 = call i32 @rename(i8* %13, i8* %0)
%65 = icmp eq i32 %64, 0
br i1 %65, label %75, label %66
66: ; preds = %63
%67 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.8, i64 0, i64 0))
br label %75
68: ; preds = %45, %48, %31
%69 = phi i8* [ getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0), %31 ], [ getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0), %48 ], [ getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0), %45 ]
%70 = phi i8* [ %32, %31 ], [ %50, %48 ], [ %42, %45 ]
%71 = call i32 @perror(i8* %69)
%72 = icmp sgt i32 %29, -1
br i1 %72, label %73, label %75
73: ; preds = %68
%74 = call i32 @close(i32 %29)
br label %75
75: ; preds = %66, %59, %37, %68, %73, %63, %25
%76 = phi i32 [ -1, %25 ], [ %29, %37 ], [ 0, %63 ], [ -1, %73 ], [ -1, %68 ], [ -1, %59 ], [ -1, %66 ]
br label %77
77: ; preds = %75, %6
%78 = phi i32 [ -1, %6 ], [ %76, %75 ]
ret i32 %78
}