#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 ssize_t;
typedef int /*<<< orphan*/ header_size_buf;

/* Variables and functions */
long INT_MAX;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int raw_receive_file(char *, long, int);
int read_all(int, char *, long);
int /*<<< orphan*/ stderr;
char *strchr(char *, char);
scalar_t__ strcmp(char *, char *);
long strtol(char *, char **, int);
int multi_receive_file_from_socket(int sock) {
  for (;;) {
    ssize_t got;
    char *endptr;
    char header_size_buf[5];
    got = read_all(sock, header_size_buf, sizeof(header_size_buf));
    if (got < 0) {
      return -1;
    }
    if (got < sizeof(header_size_buf)) {
      fprintf(stderr, "Did not receive full-length header size.\n");
      return -1;
    }
    if (header_size_buf[4] != ' ') {
      fprintf(stderr, "Header size not followed by space.\n");
      return -1;
    }
    header_size_buf[4] = '\0';
    long header_size = strtol(header_size_buf, &endptr, 16);
    if (*header_size_buf == '\0' || *endptr != '\0' || header_size <= 0 ||
        header_size > (4096)) {
      fprintf(stderr, "Invalid header size: %s\n", header_size_buf);
      return -1;
    }
    char header_buf[(4096)];
    got = read_all(sock, header_buf, header_size);
    if (got < 0) {
      return -1;
    }
    if (got < header_size) {
      fprintf(stderr, "Did not receive full-length header.\n");
      return -1;
    }
    char *space = strchr(header_buf, ' ');
    if (space == NULL) {
      fprintf(stderr, "No space in header.\n");
      return -1;
    }
    *space = '\0';
    long file_size = strtol(header_buf, &endptr, 10);
    if (*header_buf == '\0' || *endptr != '\0' || file_size < 0 ||
        file_size > INT_MAX) {
      fprintf(stderr, "Invalid file size: %s\n", header_buf);
      return -1;
    }
    char *file_name = space + 1;
    char *newline = strchr(file_name, '\n');
    if (newline == NULL) {
      fprintf(stderr, "No newline in header.\n");
      return -1;
    }
    *newline = '\0';
    if (file_size == 0 && strcmp(file_name, "--continue") == 0) {
      continue;
    }
    if (file_size == 0 && strcmp(file_name, "--complete") == 0) {
      break;
    }
    int ret = raw_receive_file(file_name, file_size, sock);
    if (ret != 0) {
      return -1;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<multi_receive_file_from_socket>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1060,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x1d(%rbp),%rsi
mov    $0x5,%edx
call   1080 <read_all@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    1198 <multi_receive_file_from_socket+0x38>
movl   $0xffffffff,-0x4(%rbp)
jmp    14b1 <multi_receive_file_from_socket+0x351>
movslq -0xc(%rbp),%rax
cmp    $0x5,%rax
jae    11c9 <multi_receive_file_from_socket+0x69>
mov    0x2e2b(%rip),%rax
mov    (%rax),%edi
lea    0xe4a(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    14b1 <multi_receive_file_from_socket+0x351>
movsbl -0x19(%rbp),%eax
cmp    $0x20,%eax
je     11f9 <multi_receive_file_from_socket+0x99>
mov    0x2dfb(%rip),%rax
mov    (%rax),%edi
lea    0xe44(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    14b1 <multi_receive_file_from_socket+0x351>
movb   $0x0,-0x19(%rbp)
lea    -0x1d(%rbp),%rdi
lea    -0x18(%rbp),%rsi
mov    $0x10,%edx
call   1070 <strtol@plt>
mov    %rax,-0x28(%rbp)
movsbl -0x1d(%rbp),%eax
cmp    $0x0,%eax
je     1249 <multi_receive_file_from_socket+0xe9>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    1249 <multi_receive_file_from_socket+0xe9>
cmpq   $0x0,-0x28(%rbp)
jle    1249 <multi_receive_file_from_socket+0xe9>
cmpq   $0x1000,-0x28(%rbp)
jle    1270 <multi_receive_file_from_socket+0x110>
mov    0x2d88(%rip),%rax
mov    (%rax),%edi
lea    -0x1d(%rbp),%rdx
lea    0xdf1(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    14b1 <multi_receive_file_from_socket+0x351>
mov    -0x8(%rbp),%edi
lea    -0x1030(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   1080 <read_all@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    129c <multi_receive_file_from_socket+0x13c>
movl   $0xffffffff,-0x4(%rbp)
jmp    14b1 <multi_receive_file_from_socket+0x351>
movslq -0xc(%rbp),%rax
cmp    -0x28(%rbp),%rax
jge    12cd <multi_receive_file_from_socket+0x16d>
mov    0x2d27(%rip),%rax
mov    (%rax),%edi
lea    0xdad(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    14b1 <multi_receive_file_from_socket+0x351>
lea    -0x1030(%rbp),%rdi
mov    $0x20,%esi
call   1030 <strchr@plt>
mov    %rax,-0x1038(%rbp)
cmpq   $0x0,-0x1038(%rbp)
jne    1316 <multi_receive_file_from_socket+0x1b6>
mov    0x2cde(%rip),%rax
mov    (%rax),%edi
lea    0xd89(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    14b1 <multi_receive_file_from_socket+0x351>
mov    -0x1038(%rbp),%rax
movb   $0x0,(%rax)
lea    -0x1030(%rbp),%rdi
lea    -0x18(%rbp),%rsi
mov    $0xa,%edx
call   1070 <strtol@plt>
mov    %rax,-0x1040(%rbp)
movsbl -0x1030(%rbp),%eax
cmp    $0x0,%eax
je     1381 <multi_receive_file_from_socket+0x221>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    1381 <multi_receive_file_from_socket+0x221>
cmpq   $0x0,-0x1040(%rbp)
jl     1381 <multi_receive_file_from_socket+0x221>
mov    -0x1040(%rbp),%rax
mov    0x2c70(%rip),%rcx
cmp    (%rcx),%rax
jle    13ab <multi_receive_file_from_socket+0x24b>
mov    0x2c50(%rip),%rax
mov    (%rax),%edi
lea    -0x1030(%rbp),%rdx
lea    0xd09(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    14b1 <multi_receive_file_from_socket+0x351>
mov    -0x1038(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x1048(%rbp)
mov    -0x1048(%rbp),%rdi
mov    $0xa,%esi
call   1030 <strchr@plt>
mov    %rax,-0x1050(%rbp)
cmpq   $0x0,-0x1050(%rbp)
jne    1406 <multi_receive_file_from_socket+0x2a6>
mov    0x2bee(%rip),%rax
mov    (%rax),%edi
lea    0xcc5(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    14b1 <multi_receive_file_from_socket+0x351>
mov    -0x1050(%rbp),%rax
movb   $0x0,(%rax)
cmpq   $0x0,-0x1040(%rbp)
jne    1440 <multi_receive_file_from_socket+0x2e0>
mov    -0x1048(%rbp),%rdi
lea    0xca3(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    1440 <multi_receive_file_from_socket+0x2e0>
jmp    116e <multi_receive_file_from_socket+0xe>
cmpq   $0x0,-0x1040(%rbp)
jne    1470 <multi_receive_file_from_socket+0x310>
mov    -0x1048(%rbp),%rdi
lea    0xc7e(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    1470 <multi_receive_file_from_socket+0x310>
jmp    14aa <multi_receive_file_from_socket+0x34a>
mov    -0x1048(%rbp),%rdi
mov    -0x1040(%rbp),%rsi
mov    -0x8(%rbp),%edx
call   1060 <raw_receive_file@plt>
mov    %eax,-0x1054(%rbp)
cmpl   $0x0,-0x1054(%rbp)
je     14a5 <multi_receive_file_from_socket+0x345>
movl   $0xffffffff,-0x4(%rbp)
jmp    14b1 <multi_receive_file_from_socket+0x351>
jmp    116e <multi_receive_file_from_socket+0xe>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1060,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<multi_receive_file_from_socket>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1018,%rsp
mov    %edi,%ebx
lea    0x3(%rsp),%rsi
mov    $0x5,%edx
call   1080 <read_all@plt>
test   %eax,%eax
js     1388 <multi_receive_file_from_socket+0x228>
lea    0x3(%rsp),%r14
lea    0x8(%rsp),%r15
lea    0x10(%rsp),%r12
cmp    $0x4,%eax
jbe    1329 <multi_receive_file_from_socket+0x1c9>
cmpb   $0x20,0x7(%rsp)
jne    133b <multi_receive_file_from_socket+0x1db>
movb   $0x0,0x7(%rsp)
mov    %r14,%rdi
mov    %r15,%rsi
mov    $0x10,%edx
call   1070 <strtol@plt>
cmpb   $0x0,0x3(%rsp)
je     12f4 <multi_receive_file_from_socket+0x194>
mov    %rax,%rbp
mov    0x8(%rsp),%rax
cmpb   $0x0,(%rax)
jne    12f4 <multi_receive_file_from_socket+0x194>
test   %rbp,%rbp
jle    12f4 <multi_receive_file_from_socket+0x194>
cmp    $0x1001,%rbp
jge    12f4 <multi_receive_file_from_socket+0x194>
mov    %ebx,%edi
mov    %r12,%rsi
mov    %rbp,%rdx
call   1080 <read_all@plt>
test   %eax,%eax
js     1388 <multi_receive_file_from_socket+0x228>
mov    %eax,%eax
cmp    %rax,%rbp
ja     134d <multi_receive_file_from_socket+0x1ed>
mov    %r12,%rdi
mov    $0x20,%esi
call   1030 <strchr@plt>
test   %rax,%rax
je     135f <multi_receive_file_from_socket+0x1ff>
mov    %rax,%rbp
movb   $0x0,(%rax)
mov    %r12,%rdi
mov    %r15,%rsi
mov    $0xa,%edx
call   1070 <strtol@plt>
cmpb   $0x0,0x10(%rsp)
je     130b <multi_receive_file_from_socket+0x1ab>
mov    %rax,%r13
mov    0x8(%rsp),%rax
cmpb   $0x0,(%rax)
jne    130b <multi_receive_file_from_socket+0x1ab>
test   %r13,%r13
js     130b <multi_receive_file_from_socket+0x1ab>
mov    0x2d7c(%rip),%rax
cmp    (%rax),%r13
jg     130b <multi_receive_file_from_socket+0x1ab>
add    $0x1,%rbp
mov    %rbp,%rdi
mov    $0xa,%esi
call   1030 <strchr@plt>
test   %rax,%rax
je     1371 <multi_receive_file_from_socket+0x211>
movb   $0x0,(%rax)
test   %r13,%r13
jne    12c3 <multi_receive_file_from_socket+0x163>
mov    %rbp,%rdi
lea    0xe2e(%rip),%rsi
call   1040 <strcmp@plt>
test   %rax,%rax
je     12d8 <multi_receive_file_from_socket+0x178>
mov    %rbp,%rdi
lea    0xe25(%rip),%rsi
call   1040 <strcmp@plt>
test   %rax,%rax
je     139f <multi_receive_file_from_socket+0x23f>
mov    %rbp,%rdi
mov    %r13,%rsi
mov    %ebx,%edx
call   1060 <raw_receive_file@plt>
test   %eax,%eax
jne    1388 <multi_receive_file_from_socket+0x228>
mov    $0x5,%edx
mov    %ebx,%edi
mov    %r14,%rsi
call   1080 <read_all@plt>
test   %eax,%eax
jns    1199 <multi_receive_file_from_socket+0x39>
jmp    1388 <multi_receive_file_from_socket+0x228>
mov    0x2cdd(%rip),%rax
mov    (%rax),%edi
lea    0xd4a(%rip),%rsi
lea    0x3(%rsp),%rdx
jmp    1320 <multi_receive_file_from_socket+0x1c0>
mov    0x2cc6(%rip),%rax
mov    (%rax),%edi
lea    0xd86(%rip),%rsi
lea    0x10(%rsp),%rdx
xor    %eax,%eax
call   1050 <fprintf@plt>
jmp    1388 <multi_receive_file_from_socket+0x228>
mov    0x2ca8(%rip),%rax
mov    (%rax),%edi
lea    0xcc7(%rip),%rsi
jmp    1381 <multi_receive_file_from_socket+0x221>
mov    0x2c96(%rip),%rax
mov    (%rax),%edi
lea    0xcdf(%rip),%rsi
jmp    1381 <multi_receive_file_from_socket+0x221>
mov    0x2c84(%rip),%rax
mov    (%rax),%edi
lea    0xd0a(%rip),%rsi
jmp    1381 <multi_receive_file_from_socket+0x221>
mov    0x2c72(%rip),%rax
mov    (%rax),%edi
lea    0xd1d(%rip),%rsi
jmp    1381 <multi_receive_file_from_socket+0x221>
mov    0x2c60(%rip),%rax
mov    (%rax),%edi
lea    0xd37(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0xffffffff,%eax
add    $0x1018,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %eax,%eax
jmp    138d <multi_receive_file_from_socket+0x22d>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [42 x i8] c"Did not receive full-length header size.\0A\00"
@.str.1 = [36 x i8] c"Header size not followed by space.\0A\00"
@.str.2 = [25 x i8] c"Invalid header size: %s\0A\00"
@.str.3 = [37 x i8] c"Did not receive full-length header.\0A\00"
@.str.4 = [21 x i8] c"No space in header.\0A\00"
@INT_MAX = global i64 0
@.str.5 = [23 x i8] c"Invalid file size: %s\0A\00"
@.str.6 = [23 x i8] c"No newline in header.\0A\00"
@.str.7 = [11 x i8] c"--continue\00"
@.str.8 = [11 x i8] c"--complete\00"
define i32 @multi_receive_file_from_socket(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
%6 = alloca [5 x i8]
%7 = alloca i64
%8 = alloca [4096 x i8]
%9 = alloca i8*
%10 = alloca i64
%11 = alloca i8*
%12 = alloca i8*
%13 = alloca i32
store i32 %0, i32* %3
br label %14
14: ; preds = %142, %125, %1
%15 = load i32, i32* %3
%16 = getelementptr inbounds [5 x i8], [5 x i8]* %6, i64 0, i64 0
%17 = call i32 @read_all(i32 %15, i8* %16, i64 5)
store i32 %17, i32* %4
%18 = load i32, i32* %4
%19 = icmp slt i32 %18, 0
br i1 %19, label %20, label %21
20: ; preds = %14
store i32 -1, i32* %2
br label %144
21: ; preds = %14
%22 = load i32, i32* %4
%23 = sext i32 %22 to i64
%24 = icmp ult i64 %23, 5
br i1 %24, label %25, label %28
25: ; preds = %21
%26 = load i32, i32* @stderr
%27 = call i32 (i32, i8*, ...) @fprintf(i32 %26, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %2
br label %144
28: ; preds = %21
%29 = getelementptr inbounds [5 x i8], [5 x i8]* %6, i64 0, i64 4
%30 = load i8, i8* %29
%31 = sext i8 %30 to i32
%32 = icmp ne i32 %31, 32
br i1 %32, label %33, label %36
33: ; preds = %28
%34 = load i32, i32* @stderr
%35 = call i32 (i32, i8*, ...) @fprintf(i32 %34, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %2
br label %144
36: ; preds = %28
%37 = getelementptr inbounds [5 x i8], [5 x i8]* %6, i64 0, i64 4
store i8 0, i8* %37
%38 = getelementptr inbounds [5 x i8], [5 x i8]* %6, i64 0, i64 0
%39 = call i64 @strtol(i8* %38, i8** %5, i32 16)
store i64 %39, i64* %7
%40 = getelementptr inbounds [5 x i8], [5 x i8]* %6, i64 0, i64 0
%41 = load i8, i8* %40
%42 = sext i8 %41 to i32
%43 = icmp eq i32 %42, 0
br i1 %43, label %55, label %44
44: ; preds = %36
%45 = load i8*, i8** %5
%46 = load i8, i8* %45
%47 = sext i8 %46 to i32
%48 = icmp ne i32 %47, 0
br i1 %48, label %55, label %49
49: ; preds = %44
%50 = load i64, i64* %7
%51 = icmp sle i64 %50, 0
br i1 %51, label %55, label %52
52: ; preds = %49
%53 = load i64, i64* %7
%54 = icmp sgt i64 %53, 4096
br i1 %54, label %55, label %59
55: ; preds = %52, %49, %44, %36
%56 = load i32, i32* @stderr
%57 = getelementptr inbounds [5 x i8], [5 x i8]* %6, i64 0, i64 0
%58 = call i32 (i32, i8*, ...) @fprintf(i32 %56, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i8* %57)
store i32 -1, i32* %2
br label %144
59: ; preds = %52
%60 = load i32, i32* %3
%61 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 0
%62 = load i64, i64* %7
%63 = call i32 @read_all(i32 %60, i8* %61, i64 %62)
store i32 %63, i32* %4
%64 = load i32, i32* %4
%65 = icmp slt i32 %64, 0
br i1 %65, label %66, label %67
66: ; preds = %59
store i32 -1, i32* %2
br label %144
67: ; preds = %59
%68 = load i32, i32* %4
%69 = sext i32 %68 to i64
%70 = load i64, i64* %7
%71 = icmp slt i64 %69, %70
br i1 %71, label %72, label %75
72: ; preds = %67
%73 = load i32, i32* @stderr
%74 = call i32 (i32, i8*, ...) @fprintf(i32 %73, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.3, i64 0, i64 0))
store i32 -1, i32* %2
br label %144
75: ; preds = %67
%76 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 0
%77 = call i8* @strchr(i8* %76, i8 signext 32)
store i8* %77, i8** %9
%78 = load i8*, i8** %9
%79 = icmp eq i8* %78, null
br i1 %79, label %80, label %83
80: ; preds = %75
%81 = load i32, i32* @stderr
%82 = call i32 (i32, i8*, ...) @fprintf(i32 %81, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0))
store i32 -1, i32* %2
br label %144
83: ; preds = %75
%84 = load i8*, i8** %9
store i8 0, i8* %84
%85 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 0
%86 = call i64 @strtol(i8* %85, i8** %5, i32 10)
store i64 %86, i64* %10
%87 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 0
%88 = load i8, i8* %87
%89 = sext i8 %88 to i32
%90 = icmp eq i32 %89, 0
br i1 %90, label %103, label %91
91: ; preds = %83
%92 = load i8*, i8** %5
%93 = load i8, i8* %92
%94 = sext i8 %93 to i32
%95 = icmp ne i32 %94, 0
br i1 %95, label %103, label %96
96: ; preds = %91
%97 = load i64, i64* %10
%98 = icmp slt i64 %97, 0
br i1 %98, label %103, label %99
99: ; preds = %96
%100 = load i64, i64* %10
%101 = load i64, i64* @INT_MAX
%102 = icmp sgt i64 %100, %101
br i1 %102, label %103, label %107
103: ; preds = %99, %96, %91, %83
%104 = load i32, i32* @stderr
%105 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 0
%106 = call i32 (i32, i8*, ...) @fprintf(i32 %104, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0), i8* %105)
store i32 -1, i32* %2
br label %144
107: ; preds = %99
%108 = load i8*, i8** %9
%109 = getelementptr inbounds i8, i8* %108, i64 1
store i8* %109, i8** %11
%110 = load i8*, i8** %11
%111 = call i8* @strchr(i8* %110, i8 signext 10)
store i8* %111, i8** %12
%112 = load i8*, i8** %12
%113 = icmp eq i8* %112, null
br i1 %113, label %114, label %117
114: ; preds = %107
%115 = load i32, i32* @stderr
%116 = call i32 (i32, i8*, ...) @fprintf(i32 %115, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.6, i64 0, i64 0))
store i32 -1, i32* %2
br label %144
117: ; preds = %107
%118 = load i8*, i8** %12
store i8 0, i8* %118
%119 = load i64, i64* %10
%120 = icmp eq i64 %119, 0
br i1 %120, label %121, label %126
121: ; preds = %117
%122 = load i8*, i8** %11
%123 = call i64 @strcmp(i8* %122, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.7, i64 0, i64 0))
%124 = icmp eq i64 %123, 0
br i1 %124, label %125, label %126
125: ; preds = %121
br label %14
126: ; preds = %121, %117
%127 = load i64, i64* %10
%128 = icmp eq i64 %127, 0
br i1 %128, label %129, label %134
129: ; preds = %126
%130 = load i8*, i8** %11
%131 = call i64 @strcmp(i8* %130, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.8, i64 0, i64 0))
%132 = icmp eq i64 %131, 0
br i1 %132, label %133, label %134
133: ; preds = %129
br label %143
134: ; preds = %129, %126
%135 = load i8*, i8** %11
%136 = load i64, i64* %10
%137 = load i32, i32* %3
%138 = call i32 @raw_receive_file(i8* %135, i64 %136, i32 %137)
store i32 %138, i32* %13
%139 = load i32, i32* %13
%140 = icmp ne i32 %139, 0
br i1 %140, label %141, label %142
141: ; preds = %134
store i32 -1, i32* %2
br label %144
142: ; preds = %134
br label %14
143: ; preds = %133
store i32 0, i32* %2
br label %144
144: ; preds = %143, %141, %114, %103, %80, %72, %66, %55, %33, %25, %20
%145 = load i32, i32* %2
ret i32 %145
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [42 x i8] c"Did not receive full-length header size.\0A\00"
@.str.1 = [36 x i8] c"Header size not followed by space.\0A\00"
@.str.2 = [25 x i8] c"Invalid header size: %s\0A\00"
@.str.3 = [37 x i8] c"Did not receive full-length header.\0A\00"
@.str.4 = [21 x i8] c"No space in header.\0A\00"
@INT_MAX = global i64 0
@.str.5 = [23 x i8] c"Invalid file size: %s\0A\00"
@.str.6 = [23 x i8] c"No newline in header.\0A\00"
@.str.7 = [11 x i8] c"--continue\00"
@.str.8 = [11 x i8] c"--complete\00"
define i32 @multi_receive_file_from_socket(i32 %0) {
%2 = alloca i8*
%3 = alloca [5 x i8]
%4 = alloca [4096 x i8]
%5 = bitcast i8** %2 to i8*
%6 = getelementptr inbounds [5 x i8], [5 x i8]* %3, i64 0, i64 0
%7 = call i32 @read_all(i32 %0, i8* %6, i64 5)
%8 = icmp slt i32 %7, 0
br i1 %8, label %88, label %9
9: ; preds = %1
%10 = getelementptr inbounds [5 x i8], [5 x i8]* %3, i64 0, i64 4
%11 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 0
br label %12
12: ; preds = %9, %90
%13 = phi i32 [ %7, %9 ], [ %91, %90 ]
%14 = icmp ult i32 %13, 5
br i1 %14, label %15, label %18
15: ; preds = %12
%16 = load i32, i32* @stderr
%17 = call i32 (i32, i8*, ...) @fprintf(i32 %16, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0))
br label %88
18: ; preds = %12
%19 = load i8, i8* %10
%20 = icmp eq i8 %19, 32
br i1 %20, label %24, label %21
21: ; preds = %18
%22 = load i32, i32* @stderr
%23 = call i32 (i32, i8*, ...) @fprintf(i32 %22, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0))
br label %88
24: ; preds = %18
store i8 0, i8* %10
%25 = call i64 @strtol(i8* %6, i8** %2, i32 16)
%26 = load i8, i8* %6
%27 = icmp eq i8 %26, 0
br i1 %27, label %36, label %28
28: ; preds = %24
%29 = load i8*, i8** %2
%30 = load i8, i8* %29
%31 = icmp ne i8 %30, 0
%32 = icmp slt i64 %25, 1
%33 = select i1 %31, i1 true, i1 %32
%34 = icmp sgt i64 %25, 4096
%35 = select i1 %33, i1 true, i1 %34
br i1 %35, label %36, label %39
36: ; preds = %28, %24
%37 = load i32, i32* @stderr
%38 = call i32 (i32, i8*, ...) @fprintf(i32 %37, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i8* %6)
br label %88
39: ; preds = %28
%40 = call i32 @read_all(i32 %0, i8* %11, i64 %25)
%41 = icmp slt i32 %40, 0
br i1 %41, label %89, label %42
42: ; preds = %39
%43 = zext i32 %40 to i64
%44 = icmp ugt i64 %25, %43
br i1 %44, label %45, label %48
45: ; preds = %42
%46 = load i32, i32* @stderr
%47 = call i32 (i32, i8*, ...) @fprintf(i32 %46, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.3, i64 0, i64 0))
br label %89
48: ; preds = %42
%49 = call i8* @strchr(i8* %11, i8 signext 32)
%50 = icmp eq i8* %49, null
br i1 %50, label %51, label %54
51: ; preds = %48
%52 = load i32, i32* @stderr
%53 = call i32 (i32, i8*, ...) @fprintf(i32 %52, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0))
br label %89
54: ; preds = %48
store i8 0, i8* %49
%55 = call i64 @strtol(i8* %11, i8** %2, i32 10)
%56 = load i8, i8* %11
%57 = icmp eq i8 %56, 0
br i1 %57, label %67, label %58
58: ; preds = %54
%59 = load i8*, i8** %2
%60 = load i8, i8* %59
%61 = icmp ne i8 %60, 0
%62 = icmp slt i64 %55, 0
%63 = select i1 %61, i1 true, i1 %62
%64 = load i64, i64* @INT_MAX
%65 = icmp sgt i64 %55, %64
%66 = select i1 %63, i1 true, i1 %65
br i1 %66, label %67, label %70
67: ; preds = %58, %54
%68 = load i32, i32* @stderr
%69 = call i32 (i32, i8*, ...) @fprintf(i32 %68, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0), i8* %11)
br label %89
70: ; preds = %58
%71 = getelementptr inbounds i8, i8* %49, i64 1
%72 = call i8* @strchr(i8* %71, i8 signext 10)
%73 = icmp eq i8* %72, null
br i1 %73, label %74, label %77
74: ; preds = %70
%75 = load i32, i32* @stderr
%76 = call i32 (i32, i8*, ...) @fprintf(i32 %75, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.6, i64 0, i64 0))
br label %89
77: ; preds = %70
store i8 0, i8* %72
%78 = icmp eq i64 %55, 0
br i1 %78, label %79, label %85
79: ; preds = %77
%80 = call i64 @strcmp(i8* %71, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.7, i64 0, i64 0))
%81 = icmp eq i64 %80, 0
br i1 %81, label %90, label %82
82: ; preds = %79
%83 = call i64 @strcmp(i8* %71, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.8, i64 0, i64 0))
%84 = icmp eq i64 %83, 0
br i1 %84, label %93, label %85
85: ; preds = %77, %82
%86 = call i32 @raw_receive_file(i8* %71, i64 %55, i32 %0)
%87 = icmp eq i32 %86, 0
br i1 %87, label %90, label %89
88: ; preds = %90, %1, %15, %21, %36
br label %94
89: ; preds = %39, %85, %45, %51, %67, %74
br label %94
90: ; preds = %85, %79
%91 = call i32 @read_all(i32 %0, i8* %6, i64 5)
%92 = icmp slt i32 %91, 0
br i1 %92, label %88, label %12
93: ; preds = %82
br label %94
94: ; preds = %89, %88, %93
%95 = phi i32 [ 0, %93 ], [ -1, %88 ], [ -1, %89 ]
ret i32 %95
}