#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 */
struct sockaddr_in {
  int dummy;
};
typedef int /*<<< orphan*/ socklen_t;

/* Variables and functions */
scalar_t__ NAME_MAX;
scalar_t__ PATH_MAX;
int close_socket();
int parse_client_args(int, char **, int *, char *, char *, char *);
int send_file(int, char *, char *);
int setup_client_socket(int *, int, char *);
int start_client(int argc, char **argv) {
  int returnValue;
  int socket_id, data_socket_id;
  int client_port;
  struct sockaddr_in client_addr;
  socklen_t client_addr_len;
  char from_file_name[PATH_MAX + NAME_MAX + 1];
  char to_file_name[PATH_MAX + NAME_MAX + 1];
  char host[16];
  if (parse_client_args(argc, argv, &client_port, from_file_name, host,
                        to_file_name) == -1)
    return -1;
  if (setup_client_socket(&socket_id, client_port, host) == -1)
    return -1;
  if (send_file(socket_id, from_file_name, to_file_name) == -1) {
    close_socket();
    return -1;
  }
  if (close_socket() == -1)
    return -1;
  return 0;
}


x86 assembly (clang, -O0):
<start_client>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e97(%rip),%rdx
mov    (%rdx),%rcx
mov    0x2e6d(%rip),%rax
mov    (%rax),%rdi
lea    0x1(%rcx,%rdi,1),%rsi
mov    %rsp,%r8
mov    %r8,-0x38(%rbp)
lea    0x10(%rcx,%rdi,1),%rdi
and    $0xfffffffffffffff0,%rdi
mov    %rsp,%rcx
sub    %rdi,%rcx
mov    %rcx,-0x78(%rbp)
mov    %rcx,%rsp
mov    %rsi,-0x40(%rbp)
mov    (%rdx),%rdx
mov    (%rax),%rsi
lea    0x1(%rdx,%rsi,1),%rax
lea    0x10(%rdx,%rsi,1),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%r9
sub    %rdx,%r9
mov    %r9,-0x70(%rbp)
mov    %r9,%rsp
mov    %rax,-0x48(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    -0x60(%rbp),%r8
lea    -0x20(%rbp),%rdx
call   1030 <parse_client_args@plt>
cmp    $0xffffffff,%eax
jne    11e1 <start_client+0xa1>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x64(%rbp)
jmp    1271 <start_client+0x131>
mov    -0x20(%rbp),%esi
lea    -0x60(%rbp),%rdx
lea    -0x18(%rbp),%rdi
call   1050 <setup_client_socket@plt>
cmp    $0xffffffff,%eax
jne    120d <start_client+0xcd>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x64(%rbp)
jmp    1271 <start_client+0x131>
mov    -0x70(%rbp),%rdx
mov    -0x78(%rbp),%rsi
mov    -0x18(%rbp),%edi
call   1060 <send_file@plt>
cmp    $0xffffffff,%eax
jne    1240 <start_client+0x100>
mov    $0x0,%al
call   1040 <close_socket@plt>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x64(%rbp)
jmp    1271 <start_client+0x131>
mov    $0x0,%al
call   1040 <close_socket@plt>
cmp    $0xffffffff,%eax
jne    1263 <start_client+0x123>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x64(%rbp)
jmp    1271 <start_client+0x131>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x64(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<start_client>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x20,%rsp
mov    %rsp,%r12
mov    0x2e97(%rip),%rax
mov    (%rax),%rcx
mov    0x2e6d(%rip),%rdx
mov    (%rdx),%rbx
add    %rbx,%rcx
add    $0x10,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%r15
sub    %rcx,%r15
mov    %r15,%rsp
mov    (%rax),%rax
mov    (%rdx),%rcx
add    %rcx,%rax
add    $0x10,%rax
and    $0xfffffffffffffff0,%rax
mov    %rsp,%rbx
sub    %rax,%rbx
mov    %rbx,%rsp
lea    -0x24(%rbp),%rdx
lea    -0x40(%rbp),%r8
mov    %r15,%rcx
mov    %rbx,%r9
call   1030 <parse_client_args@plt>
mov    $0xffffffff,%r14d
cmp    $0xffffffff,%eax
je     11f0 <start_client+0xb0>
mov    -0x24(%rbp),%esi
lea    -0x28(%rbp),%rdi
lea    -0x40(%rbp),%rdx
call   1050 <setup_client_socket@plt>
cmp    $0xffffffff,%eax
je     11f0 <start_client+0xb0>
mov    -0x28(%rbp),%edi
mov    %r15,%rsi
mov    %rbx,%rdx
call   1060 <send_file@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1040 <close_socket@plt>
cmp    $0xffffffff,%ebx
je     11f0 <start_client+0xb0>
xor    %r14d,%r14d
cmp    $0xffffffff,%eax
sete   %r14b
neg    %r14d
mov    %r12,%rsp
mov    %r14d,%eax
lea    -0x20(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { i32 }
@PATH_MAX = global i64 0
@NAME_MAX = global i64 0
define i32 @start_client(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca %struct.sockaddr_in
%11 = alloca i32
%12 = alloca i8*
%13 = alloca i64
%14 = alloca i64
%15 = alloca [16 x i8]
%16 = alloca i32
store i32 %0, i32* %4
store i8** %1, i8*** %5
%17 = load i64, i64* @PATH_MAX
%18 = load i64, i64* @NAME_MAX
%19 = add nsw i64 %17, %18
%20 = add nsw i64 %19, 1
%21 = call i8* @llvm.stacksave()
store i8* %21, i8** %12
%22 = alloca i8, i64 %20
store i64 %20, i64* %13
%23 = load i64, i64* @PATH_MAX
%24 = load i64, i64* @NAME_MAX
%25 = add nsw i64 %23, %24
%26 = add nsw i64 %25, 1
%27 = alloca i8, i64 %26
store i64 %26, i64* %14
%28 = load i32, i32* %4
%29 = load i8**, i8*** %5
%30 = getelementptr inbounds [16 x i8], [16 x i8]* %15, i64 0, i64 0
%31 = call i32 @parse_client_args(i32 %28, i8** %29, i32* %9, i8* %22, i8* %30, i8* %27)
%32 = icmp eq i32 %31, -1
br i1 %32, label %33, label %34
33: ; preds = %2
store i32 -1, i32* %3
store i32 1, i32* %16
br label %51
34: ; preds = %2
%35 = load i32, i32* %9
%36 = getelementptr inbounds [16 x i8], [16 x i8]* %15, i64 0, i64 0
%37 = call i32 @setup_client_socket(i32* %7, i32 %35, i8* %36)
%38 = icmp eq i32 %37, -1
br i1 %38, label %39, label %40
39: ; preds = %34
store i32 -1, i32* %3
store i32 1, i32* %16
br label %51
40: ; preds = %34
%41 = load i32, i32* %7
%42 = call i32 @send_file(i32 %41, i8* %22, i8* %27)
%43 = icmp eq i32 %42, -1
br i1 %43, label %44, label %46
44: ; preds = %40
%45 = call i32 (...) @close_socket()
store i32 -1, i32* %3
store i32 1, i32* %16
br label %51
46: ; preds = %40
%47 = call i32 (...) @close_socket()
%48 = icmp eq i32 %47, -1
br i1 %48, label %49, label %50
49: ; preds = %46
store i32 -1, i32* %3
store i32 1, i32* %16
br label %51
50: ; preds = %46
store i32 0, i32* %3
store i32 1, i32* %16
br label %51
51: ; preds = %50, %49, %44, %39, %33
%52 = load i8*, i8** %12
%53 = load i32, i32* %3
ret i32 %53
}

LLVM IR (-O2):
@PATH_MAX = global i64 0
@NAME_MAX = global i64 0
define i32 @start_client(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca [16 x i8]
%6 = bitcast i32* %3 to i8*
%7 = bitcast i32* %4 to i8*
%8 = load i64, i64* @PATH_MAX
%9 = load i64, i64* @NAME_MAX
%10 = add i64 %8, 1
%11 = add i64 %10, %9
%12 = tail call i8* @llvm.stacksave()
%13 = alloca i8, i64 %11
%14 = load i64, i64* @PATH_MAX
%15 = load i64, i64* @NAME_MAX
%16 = add i64 %14, 1
%17 = add i64 %16, %15
%18 = alloca i8, i64 %17
%19 = getelementptr inbounds [16 x i8], [16 x i8]* %5, i64 0, i64 0
%20 = call i32 @parse_client_args(i32 %0, i8** %1, i32* %4, i8* %13, i8* %19, i8* %18)
%21 = icmp eq i32 %20, -1
br i1 %21, label %34, label %22
22: ; preds = %2
%23 = load i32, i32* %4
%24 = call i32 @setup_client_socket(i32* %3, i32 %23, i8* %19)
%25 = icmp eq i32 %24, -1
br i1 %25, label %34, label %26
26: ; preds = %22
%27 = load i32, i32* %3
%28 = call i32 @send_file(i32 %27, i8* %13, i8* %18)
%29 = icmp eq i32 %28, -1
%30 = call i32 (...) @close_socket()
br i1 %29, label %34, label %31
31: ; preds = %26
%32 = icmp eq i32 %30, -1
%33 = sext i1 %32 to i32
br label %34
34: ; preds = %26, %31, %22, %2
%35 = phi i32 [ -1, %2 ], [ -1, %22 ], [ %33, %31 ], [ -1, %26 ]
ret i32 %35
}