#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 int 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 *);
int read(int, int /*<<< orphan*/ *, int);
int rename(char *, char const *);
int snprintf(char *, int, char *, char *, char const *, char *, char const *);
int /*<<< orphan*/ stderr;
char *strrchr(char const *, char);
int write(int, int /*<<< orphan*/ *, int);
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];
    int remaining = expected_size - total_size;
    if (remaining == 0) {
      break;
    }
    int want = buffer_size;
    if (want > remaining) {
      want = remaining;
    }
    ssize_t got = read(sock, buffer, want);
    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    $0x80,%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    14ad <raw_receive_file+0x31d>
mov    0x2e04(%rip),%rax
mov    (%rax),%eax
mov    %rax,-0x70(%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,-0x68(%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    -0x70(%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    14a6 <raw_receive_file+0x316>
mov    -0x68(%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    14a6 <raw_receive_file+0x316>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x40(%rbp)
movl   $0x0,-0x44(%rbp)
movl   $0x20000,-0x48(%rbp)
mov    %rsp,%rax
mov    %rax,-0x50(%rbp)
mov    %rsp,%rax
add    $0xfffffffffff80000,%rax
mov    %rax,-0x78(%rbp)
mov    %rax,%rsp
mov    -0x14(%rbp),%eax
sub    -0x44(%rbp),%eax
mov    %eax,-0x54(%rbp)
cmpl   $0x0,-0x54(%rbp)
jne    1321 <raw_receive_file+0x191>
movl   $0x2,-0x3c(%rbp)
jmp    13ca <raw_receive_file+0x23a>
movl   $0x20000,-0x58(%rbp)
mov    -0x58(%rbp),%eax
cmp    -0x54(%rbp),%eax
jle    133a <raw_receive_file+0x1aa>
mov    -0x54(%rbp),%eax
mov    %eax,-0x58(%rbp)
mov    -0x78(%rbp),%rsi
mov    -0x18(%rbp),%edi
mov    -0x58(%rbp),%edx
call   1070 <read@plt>
mov    %eax,-0x5c(%rbp)
cmpl   $0x0,-0x5c(%rbp)
jge    136e <raw_receive_file+0x1de>
lea    0xd14(%rip),%rdi
call   10a0 <perror@plt>
movl   $0x4,-0x3c(%rbp)
jmp    13ca <raw_receive_file+0x23a>
cmpl   $0x0,-0x5c(%rbp)
jne    1384 <raw_receive_file+0x1f4>
movl   $0x2,-0x3c(%rbp)
jmp    13ca <raw_receive_file+0x23a>
mov    -0x78(%rbp),%rsi
mov    -0x40(%rbp),%edi
mov    -0x5c(%rbp),%edx
call   1030 <write@plt>
mov    %eax,-0x60(%rbp)
mov    -0x60(%rbp),%eax
cmp    -0x5c(%rbp),%eax
je     13ba <raw_receive_file+0x22a>
lea    0xcd3(%rip),%rdi
call   10a0 <perror@plt>
movl   $0x4,-0x3c(%rbp)
jmp    13ca <raw_receive_file+0x23a>
mov    -0x60(%rbp),%eax
add    -0x44(%rbp),%eax
mov    %eax,-0x44(%rbp)
movl   $0x0,-0x3c(%rbp)
mov    -0x50(%rbp),%rax
mov    %rax,%rsp
mov    -0x3c(%rbp),%eax
mov    %eax,-0x7c(%rbp)
test   %eax,%eax
je     1406 <raw_receive_file+0x276>
jmp    13e4 <raw_receive_file+0x254>
mov    -0x7c(%rbp),%eax
sub    $0x2,%eax
je     140b <raw_receive_file+0x27b>
jmp    13f5 <raw_receive_file+0x265>
mov    -0x7c(%rbp),%eax
sub    $0x4,%eax
je     1486 <raw_receive_file+0x2f6>
jmp    14a6 <raw_receive_file+0x316>
jmp    12e4 <raw_receive_file+0x154>
mov    -0x40(%rbp),%edi
call   1060 <close@plt>
movl   $0xffffffff,-0x40(%rbp)
mov    -0x44(%rbp),%eax
cmp    -0x14(%rbp),%eax
je     1448 <raw_receive_file+0x2b8>
mov    0x2bab(%rip),%rax
mov    (%rax),%edi
mov    -0x44(%rbp),%edx
mov    -0x14(%rbp),%ecx
lea    0xc46(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
jmp    1486 <raw_receive_file+0x2f6>
mov    -0x68(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   10b0 <rename@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     1473 <raw_receive_file+0x2e3>
lea    0xc37(%rip),%rdi
call   10a0 <perror@plt>
jmp    1486 <raw_receive_file+0x2f6>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x3c(%rbp)
jmp    14a6 <raw_receive_file+0x316>
cmpl   $0x0,-0x40(%rbp)
jl     1498 <raw_receive_file+0x308>
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,-0x3c(%rbp)
mov    %esi,%ebx
mov    %rdi,%r12
mov    $0x2f,%esi
call   1050 <strrchr@plt>
test   %rax,%rax
je     12ef <raw_receive_file+0x15f>
mov    %rsp,%r14
mov    0x2e2a(%rip),%rcx
mov    (%rcx),%r15d
mov    %rsp,%r13
lea    0xf(%r15),%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    %r15d,%esi
mov    %r12,%r8
push   %rax
call   1040 <snprintf@plt>
add    $0x10,%rsp
test   %eax,%eax
jle    130e <raw_receive_file+0x17e>
movslq %eax,%rcx
cmp    %r15,%rcx
jae    130e <raw_receive_file+0x17e>
mov    %r13,%rdi
call   1090 <mkstemp@plt>
mov    %eax,%r15d
test   %eax,%eax
js     136a <raw_receive_file+0x1da>
mov    %r13,-0x48(%rbp)
mov    %r15d,-0x2c(%rbp)
mov    %r12,-0x50(%rbp)
mov    %r14,-0x38(%rbp)
mov    %rsp,%r15
mov    %rsp,%r13
add    $0xfffffffffff80000,%r13
mov    %r13,%rsp
xor    %r14d,%r14d
test   %ebx,%ebx
je     12b9 <raw_receive_file+0x129>
mov    %ebx,%edx
nopl   (%rax)
cmp    $0x20000,%edx
mov    $0x20000,%eax
cmovge %eax,%edx
mov    -0x3c(%rbp),%edi
mov    %r13,%rsi
call   1070 <read@plt>
test   %eax,%eax
js     1378 <raw_receive_file+0x1e8>
je     12b9 <raw_receive_file+0x129>
mov    %eax,%r12d
mov    -0x2c(%rbp),%edi
mov    %r13,%rsi
mov    %eax,%edx
call   1030 <write@plt>
cmp    %r12d,%eax
jne    1388 <raw_receive_file+0x1f8>
add    %r12d,%r14d
mov    %r15,%rsp
mov    %rsp,%r15
mov    %rsp,%r13
add    $0xfffffffffff80000,%r13
mov    %r13,%rsp
mov    %ebx,%edx
sub    %r14d,%edx
jne    1260 <raw_receive_file+0xd0>
mov    %r15,%rsp
mov    -0x2c(%rbp),%edi
call   1060 <close@plt>
cmp    %ebx,%r14d
jne    132f <raw_receive_file+0x19f>
mov    -0x48(%rbp),%rdi
mov    -0x50(%rbp),%rsi
call   10b0 <rename@plt>
xor    %r15d,%r15d
test   %eax,%eax
mov    -0x38(%rbp),%r14
je     1355 <raw_receive_file+0x1c5>
lea    0xdb8(%rip),%rdi
call   10a0 <perror@plt>
jmp    1327 <raw_receive_file+0x197>
mov    0x2ce2(%rip),%rax
mov    (%rax),%edi
lea    0xd01(%rip),%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    $0xffffffff,%r15d
jmp    1358 <raw_receive_file+0x1c8>
mov    0x2cc3(%rip),%rcx
mov    (%rcx),%edi
lea    0xd27(%rip),%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    $0xffffffff,%r15d
jmp    1355 <raw_receive_file+0x1c5>
mov    0x2ca2(%rip),%rax
mov    (%rax),%edi
lea    0xd43(%rip),%rsi
mov    %r14d,%edx
mov    %ebx,%ecx
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    $0xffffffff,%r15d
mov    -0x38(%rbp),%r14
mov    %r14,%rsp
mov    %r15d,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xcf8(%rip),%rdi
call   10a0 <perror@plt>
jmp    1355 <raw_receive_file+0x1c5>
mov    -0x38(%rbp),%r14
mov    -0x2c(%rbp),%ebx
lea    0xceb(%rip),%rdi
jmp    1396 <raw_receive_file+0x206>
lea    0xced(%rip),%rdi
mov    -0x38(%rbp),%r14
mov    -0x2c(%rbp),%ebx
call   10a0 <perror@plt>
mov    %r15,%rsp
test   %ebx,%ebx
js     1327 <raw_receive_file+0x197>
mov    %ebx,%edi
call   1060 <close@plt>
jmp    1327 <raw_receive_file+0x197>

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 i32
%15 = alloca i32
%16 = alloca i8*
%17 = alloca i32
%18 = alloca i32
%19 = alloca i32
%20 = alloca i32
store i8* %0, i8** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
%21 = load i8*, i8** %5
%22 = call i8* @strrchr(i8* %21, i8 signext 47)
store i8* %22, i8** %9
%23 = load i8*, i8** %9
%24 = icmp eq i8* %23, null
br i1 %24, label %25, label %28
25: ; preds = %3
%26 = load i32, i32* @stderr
%27 = call i32 (i32, i8*, ...) @fprintf(i32 %26, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %4
br label %136
28: ; preds = %3
%29 = load i32, i32* @PATH_MAX
%30 = zext i32 %29 to i64
%31 = call i8* @llvm.stacksave()
store i8* %31, i8** %10
%32 = alloca i8, i64 %30
store i64 %30, i64* %11
%33 = trunc i64 %30 to i32
%34 = load i8*, i8** %9
%35 = load i8*, i8** %5
%36 = ptrtoint i8* %34 to i64
%37 = ptrtoint i8* %35 to i64
%38 = sub i64 %36, %37
%39 = add nsw i64 %38, 1
%40 = inttoptr i64 %39 to i8*
%41 = load i8*, i8** %5
%42 = load i8*, i8** %9
%43 = getelementptr inbounds i8, i8* %42, i64 1
%44 = call i32 @snprintf(i8* %32, i32 %33, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* %40, i8* %41, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8* %43)
store i32 %44, i32* %8
%45 = load i32, i32* %8
%46 = icmp sle i32 %45, 0
br i1 %46, label %51, label %47
47: ; preds = %28
%48 = load i32, i32* %8
%49 = sext i32 %48 to i64
%50 = icmp uge i64 %49, %30
br i1 %50, label %51, label %55
51: ; preds = %47, %28
%52 = load i32, i32* @stderr
%53 = load i32, i32* %8
%54 = call i32 (i32, i8*, ...) @fprintf(i32 %52, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0), i32 %53)
store i32 -1, i32* %4
store i32 1, i32* %12
br label %134
55: ; preds = %47
store i32 -1, i32* %13
%56 = call i32 @mkstemp(i8* %32)
store i32 %56, i32* %8
%57 = load i32, i32* %8
%58 = icmp slt i32 %57, 0
br i1 %58, label %59, label %62
59: ; preds = %55
%60 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
%61 = load i32, i32* %8
store i32 %61, i32* %4
store i32 1, i32* %12
br label %134
62: ; preds = %55
%63 = load i32, i32* %8
store i32 %63, i32* %13
store i32 0, i32* %14
br label %64
64: ; preds = %107, %62
store i32 131072, i32* %15
%65 = call i8* @llvm.stacksave()
store i8* %65, i8** %16
%66 = alloca i32, i64 131072
%67 = load i32, i32* %6
%68 = load i32, i32* %14
%69 = sub nsw i32 %67, %68
store i32 %69, i32* %17
%70 = load i32, i32* %17
%71 = icmp eq i32 %70, 0
br i1 %71, label %72, label %73
72: ; preds = %64
store i32 2, i32* %12
br label %104
73: ; preds = %64
store i32 131072, i32* %18
%74 = load i32, i32* %18
%75 = load i32, i32* %17
%76 = icmp sgt i32 %74, %75
br i1 %76, label %77, label %79
77: ; preds = %73
%78 = load i32, i32* %17
store i32 %78, i32* %18
br label %79
79: ; preds = %77, %73
%80 = load i32, i32* %7
%81 = load i32, i32* %18
%82 = call i32 @read(i32 %80, i32* %66, i32 %81)
store i32 %82, i32* %19
%83 = load i32, i32* %19
%84 = icmp slt i32 %83, 0
br i1 %84, label %85, label %87
85: ; preds = %79
%86 = 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 %104
87: ; preds = %79
%88 = load i32, i32* %19
%89 = icmp eq i32 %88, 0
br i1 %89, label %90, label %91
90: ; preds = %87
store i32 2, i32* %12
br label %104
91: ; preds = %87
%92 = load i32, i32* %13
%93 = load i32, i32* %19
%94 = call i32 @write(i32 %92, i32* %66, i32 %93)
store i32 %94, i32* %20
%95 = load i32, i32* %20
%96 = load i32, i32* %19
%97 = icmp ne i32 %95, %96
br i1 %97, label %98, label %100
98: ; preds = %91
%99 = 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 %104
100: ; preds = %91
%101 = load i32, i32* %20
%102 = load i32, i32* %14
%103 = add nsw i32 %102, %101
store i32 %103, i32* %14
store i32 0, i32* %12
br label %104
104: ; preds = %98, %85, %100, %90, %72
%105 = load i8*, i8** %16
%106 = load i32, i32* %12
switch i32 %106, label %134 [
i32 0, label %107
i32 2, label %108
i32 4, label %127
]
107: ; preds = %104
br label %64
108: ; preds = %104
%109 = load i32, i32* %13
%110 = call i32 @close(i32 %109)
store i32 -1, i32* %13
%111 = load i32, i32* %14
%112 = load i32, i32* %6
%113 = icmp ne i32 %111, %112
br i1 %113, label %114, label %119
114: ; preds = %108
%115 = load i32, i32* @stderr
%116 = load i32, i32* %14
%117 = load i32, i32* %6
%118 = call i32 (i32, i8*, ...) @fprintf(i32 %115, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.7, i64 0, i64 0), i32 %116, i32 %117)
br label %127
119: ; preds = %108
%120 = load i8*, i8** %5
%121 = call i32 @rename(i8* %32, i8* %120)
store i32 %121, i32* %8
%122 = load i32, i32* %8
%123 = icmp ne i32 %122, 0
br i1 %123, label %124, label %126
124: ; preds = %119
%125 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.8, i64 0, i64 0))
br label %127
126: ; preds = %119
store i32 0, i32* %4
store i32 1, i32* %12
br label %134
127: ; preds = %104, %124, %114
%128 = load i32, i32* %13
%129 = icmp sge i32 %128, 0
br i1 %129, label %130, label %133
130: ; preds = %127
%131 = load i32, i32* %13
%132 = call i32 @close(i32 %131)
br label %133
133: ; preds = %130, %127
store i32 -1, i32* %4
store i32 1, i32* %12
br label %134
134: ; preds = %133, %126, %104, %59, %51
%135 = load i8*, i8** %10
br label %136
136: ; preds = %134, %25
%137 = load i32, i32* %4
ret i32 %137
}

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 %81
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 %79
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 = icmp eq i32 %1, 0
br i1 %34, label %60, label %35
35: ; preds = %31
%36 = getelementptr inbounds [131072 x i32], [131072 x i32]* %33, i64 0, i64 0
br 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 %79
39: ; preds = %35, %53
%40 = phi i32 [ %58, %53 ], [ %1, %35 ]
%41 = phi i32* [ %57, %53 ], [ %36, %35 ]
%42 = phi i8* [ %55, %53 ], [ %32, %35 ]
%43 = phi i32 [ %54, %53 ], [ 0, %35 ]
%44 = icmp slt i32 %40, 131072
%45 = select i1 %44, i32 %40, i32 131072
%46 = call i32 @read(i32 %2, i32* %41, i32 %45)
%47 = icmp slt i32 %46, 0
br i1 %47, label %73, label %48
48: ; preds = %39
%49 = icmp eq i32 %46, 0
br i1 %49, label %60, label %50
50: ; preds = %48
%51 = call i32 @write(i32 %29, i32* %41, i32 %46)
%52 = icmp eq i32 %51, %46
br i1 %52, label %53, label %73
53: ; preds = %50
%54 = add nsw i32 %46, %43
%55 = call i8* @llvm.stacksave()
%56 = alloca [131072 x i32]
%57 = getelementptr inbounds [131072 x i32], [131072 x i32]* %56, i64 0, i64 0
%58 = sub nsw i32 %1, %54
%59 = icmp eq i32 %58, 0
br i1 %59, label %60, label %39
60: ; preds = %48, %53, %31
%61 = phi i32 [ 0, %31 ], [ %54, %53 ], [ %43, %48 ]
%62 = phi i8* [ %32, %31 ], [ %55, %53 ], [ %42, %48 ]
%63 = call i32 @close(i32 %29)
%64 = icmp eq i32 %61, %1
br i1 %64, label %68, label %65
65: ; preds = %60
%66 = load i32, i32* @stderr
%67 = call i32 (i32, i8*, ...) @fprintf(i32 %66, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.7, i64 0, i64 0), i32 %61, i32 %1)
br label %79
68: ; preds = %60
%69 = call i32 @rename(i8* %13, i8* %0)
%70 = icmp eq i32 %69, 0
br i1 %70, label %79, label %71
71: ; preds = %68
%72 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.8, i64 0, i64 0))
br label %79
73: ; preds = %50, %39
%74 = phi i8* [ getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0), %39 ], [ getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0), %50 ]
%75 = call i32 @perror(i8* %74)
%76 = icmp sgt i32 %29, -1
br i1 %76, label %77, label %79
77: ; preds = %73
%78 = call i32 @close(i32 %29)
br label %79
79: ; preds = %71, %65, %37, %73, %77, %68, %25
%80 = phi i32 [ -1, %25 ], [ %29, %37 ], [ 0, %68 ], [ -1, %77 ], [ -1, %73 ], [ -1, %65 ], [ -1, %71 ]
br label %81
81: ; preds = %79, %6
%82 = phi i32 [ -1, %6 ], [ %80, %79 ]
ret i32 %82
}