#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 uint8_t;
typedef int uint32_t;
typedef int /*<<< orphan*/ uint16_t;
typedef int ssize_t;
typedef int /*<<< orphan*/ nonce_buffer;

/* Variables and functions */
int /*<<< orphan*/ close(int);
scalar_t__ connect_client(char const *, int /*<<< orphan*/, int *);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int multi_receive_file_from_socket(int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ stdout;
int write(int, int *, int);
int multi_receive_file_from_server(const char *ip_str, uint16_t port,
                                   uint32_t nonce) {
  printf("\n");
  fflush(stdout);
  int client_socket = -1;
  if (connect_client(ip_str, port, &client_socket) != 0) {
    goto fail1;
  }
  uint8_t nonce_buffer[4];
  nonce_buffer[0] = nonce >> 24;
  nonce_buffer[1] = nonce >> 16;
  nonce_buffer[2] = nonce >> 8;
  nonce_buffer[3] = nonce;
  ssize_t wrote = write(client_socket, nonce_buffer, sizeof(nonce_buffer));
  if (wrote != sizeof(nonce_buffer)) {
    perror("write(nonce)");
    goto fail1;
  }
  int ret = multi_receive_file_from_socket(client_socket);
  if (ret != 0) {
    goto fail1;
  }
  close(client_socket);
  return 0;
fail1:
  if (client_socket >= 0) {
    close(client_socket);
  }
  return 1;
}


x86 assembly (clang, -O0):
<multi_receive_file_from_server>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
lea    0xe77(%rip),%rdi
call   1040 <printf@plt>
mov    0x2e4b(%rip),%rax
mov    (%rax),%edi
call   1070 <fflush@plt>
movl   $0xffffffff,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
lea    -0x1c(%rbp),%rdx
call   1060 <connect_client@plt>
cmp    $0x0,%rax
je     11c2 <multi_receive_file_from_server+0x52>
jmp    1244 <multi_receive_file_from_server+0xd4>
mov    -0x18(%rbp),%eax
sar    $0x18,%eax
mov    %eax,-0x30(%rbp)
mov    -0x18(%rbp),%eax
sar    $0x10,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x18(%rbp),%eax
sar    $0x8,%eax
mov    %eax,-0x28(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x1c(%rbp),%edi
lea    -0x30(%rbp),%rsi
mov    $0x10,%edx
call   1030 <write@plt>
mov    %eax,-0x34(%rbp)
movslq -0x34(%rbp),%rax
cmp    $0x10,%rax
je     1216 <multi_receive_file_from_server+0xa6>
lea    0xdf6(%rip),%rdi
call   1080 <perror@plt>
jmp    1244 <multi_receive_file_from_server+0xd4>
mov    -0x1c(%rbp),%edi
call   1090 <multi_receive_file_from_socket@plt>
mov    %eax,-0x38(%rbp)
cmpl   $0x0,-0x38(%rbp)
je     1230 <multi_receive_file_from_server+0xc0>
jmp    1244 <multi_receive_file_from_server+0xd4>
mov    -0x1c(%rbp),%edi
call   1050 <close@plt>
movl   $0x0,-0x4(%rbp)
jmp    125d <multi_receive_file_from_server+0xed>
cmpl   $0x0,-0x1c(%rbp)
jl     1256 <multi_receive_file_from_server+0xe6>
mov    -0x1c(%rbp),%edi
call   1050 <close@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<multi_receive_file_from_server>:
push   %rbp
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    %edx,%r14d
mov    %esi,%ebp
mov    %rdi,%rbx
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    0x2e4f(%rip),%rax
mov    (%rax),%edi
call   1070 <fflush@plt>
movl   $0xffffffff,0xc(%rsp)
ff
lea    0xc(%rsp),%rdx
mov    %rbx,%rdi
mov    %ebp,%esi
call   1060 <connect_client@plt>
test   %rax,%rax
jne    11fc <multi_receive_file_from_server+0x8c>
mov    %r14d,%eax
sar    $0x18,%eax
mov    %eax,0x10(%rsp)
mov    %r14d,%eax
sar    $0x10,%eax
mov    %eax,0x14(%rsp)
mov    %r14d,%eax
sar    $0x8,%eax
mov    %eax,0x18(%rsp)
mov    %r14d,0x1c(%rsp)
mov    0xc(%rsp),%edi
lea    0x10(%rsp),%rsi
mov    $0x10,%edx
call   1040 <write@plt>
cmp    $0x10,%eax
jne    1221 <multi_receive_file_from_server+0xb1>
mov    0xc(%rsp),%edi
call   1090 <multi_receive_file_from_socket@plt>
test   %eax,%eax
je     1219 <multi_receive_file_from_server+0xa9>
mov    0xc(%rsp),%edi
mov    $0x1,%ebx
test   %edi,%edi
js     120e <multi_receive_file_from_server+0x9e>
call   1050 <close@plt>
mov    %ebx,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
xor    %ebx,%ebx
mov    0xc(%rsp),%edi
jmp    1209 <multi_receive_file_from_server+0x99>
lea    0xdd8(%rip),%rdi
call   1080 <perror@plt>
jmp    11fc <multi_receive_file_from_server+0x8c>

LLVM IR (-O0):
@.str = [2 x i8] c"\0A\00"
@stdout = global i32 0
@.str.1 = [13 x i8] c"write(nonce)\00"
define i32 @multi_receive_file_from_server(i8* %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca [4 x i32]
%10 = alloca i32
%11 = alloca i32
store i8* %0, i8** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
%12 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%13 = load i32, i32* @stdout
%14 = call i32 @fflush(i32 %13)
store i32 -1, i32* %8
%15 = load i8*, i8** %5
%16 = load i32, i32* %6
%17 = call i64 @connect_client(i8* %15, i32 %16, i32* %8)
%18 = icmp ne i64 %17, 0
br i1 %18, label %19, label %20
19: ; preds = %3
br label %49
20: ; preds = %3
%21 = load i32, i32* %7
%22 = ashr i32 %21, 24
%23 = getelementptr inbounds [4 x i32], [4 x i32]* %9, i64 0, i64 0
store i32 %22, i32* %23
%24 = load i32, i32* %7
%25 = ashr i32 %24, 16
%26 = getelementptr inbounds [4 x i32], [4 x i32]* %9, i64 0, i64 1
store i32 %25, i32* %26
%27 = load i32, i32* %7
%28 = ashr i32 %27, 8
%29 = getelementptr inbounds [4 x i32], [4 x i32]* %9, i64 0, i64 2
store i32 %28, i32* %29
%30 = load i32, i32* %7
%31 = getelementptr inbounds [4 x i32], [4 x i32]* %9, i64 0, i64 3
store i32 %30, i32* %31
%32 = load i32, i32* %8
%33 = getelementptr inbounds [4 x i32], [4 x i32]* %9, i64 0, i64 0
%34 = call i32 @write(i32 %32, i32* %33, i32 16)
store i32 %34, i32* %10
%35 = load i32, i32* %10
%36 = sext i32 %35 to i64
%37 = icmp ne i64 %36, 16
br i1 %37, label %38, label %40
38: ; preds = %20
%39 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
br label %49
40: ; preds = %20
%41 = load i32, i32* %8
%42 = call i32 @multi_receive_file_from_socket(i32 %41)
store i32 %42, i32* %11
%43 = load i32, i32* %11
%44 = icmp ne i32 %43, 0
br i1 %44, label %45, label %46
45: ; preds = %40
br label %49
46: ; preds = %40
%47 = load i32, i32* %8
%48 = call i32 @close(i32 %47)
store i32 0, i32* %4
br label %56
49: ; preds = %45, %38, %19
%50 = load i32, i32* %8
%51 = icmp sge i32 %50, 0
br i1 %51, label %52, label %55
52: ; preds = %49
%53 = load i32, i32* %8
%54 = call i32 @close(i32 %53)
br label %55
55: ; preds = %52, %49
store i32 1, i32* %4
br label %56
56: ; preds = %55, %46
%57 = load i32, i32* %4
ret i32 %57
}

LLVM IR (-O2):
@stdout = global i32 0
@.str.1 = [13 x i8] c"write(nonce)\00"
define i32 @multi_receive_file_from_server(i8* %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca [4 x i32]
%6 = tail call i32 @putchar(i32 10)
%7 = load i32, i32* @stdout
%8 = tail call i32 @fflush(i32 %7)
%9 = bitcast i32* %4 to i8*
store i32 -1, i32* %4
%10 = call i64 @connect_client(i8* %0, i32 %1, i32* %4)
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %31
12: ; preds = %3
%13 = ashr i32 %2, 24
%14 = getelementptr inbounds [4 x i32], [4 x i32]* %5, i64 0, i64 0
store i32 %13, i32* %14
%15 = ashr i32 %2, 16
%16 = getelementptr inbounds [4 x i32], [4 x i32]* %5, i64 0, i64 1
store i32 %15, i32* %16
%17 = ashr i32 %2, 8
%18 = getelementptr inbounds [4 x i32], [4 x i32]* %5, i64 0, i64 2
store i32 %17, i32* %18
%19 = getelementptr inbounds [4 x i32], [4 x i32]* %5, i64 0, i64 3
store i32 %2, i32* %19
%20 = load i32, i32* %4
%21 = call i32 @write(i32 %20, i32* %14, i32 16)
%22 = icmp eq i32 %21, 16
br i1 %22, label %25, label %23
23: ; preds = %12
%24 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
br label %31
25: ; preds = %12
%26 = load i32, i32* %4
%27 = call i32 @multi_receive_file_from_socket(i32 %26)
%28 = icmp eq i32 %27, 0
br i1 %28, label %29, label %31
29: ; preds = %25
%30 = load i32, i32* %4
br label %34
31: ; preds = %25, %3, %23
%32 = load i32, i32* %4
%33 = icmp sgt i32 %32, -1
br i1 %33, label %34, label %38
34: ; preds = %31, %29
%35 = phi i32 [ %30, %29 ], [ %32, %31 ]
%36 = phi i32 [ 0, %29 ], [ 1, %31 ]
%37 = call i32 @close(i32 %35)
br label %38
38: ; preds = %34, %31
%39 = phi i32 [ 1, %31 ], [ %36, %34 ]
ret i32 %39
}