#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 */

/* Variables and functions */
int /*<<< orphan*/ close(int);
int connect_to_ftpserver(char *, int);
int /*<<< orphan*/ ftp_close_datasockfd(int, int);
int ftp_pasv(int);
int /*<<< orphan*/ ftp_quit(int);
int ftp_stor(int, char *, int);
int /*<<< orphan*/ ftp_type(int);
int /*<<< orphan*/ login(int);
int /*<<< orphan*/ printf(char *);
int ftp_put(char *filename) {
  int sockfd = -1;
  int pasv_sockfd = -1;
  int ret = -1;
  sockfd = connect_to_ftpserver("192.168.5.110", 21);
  if (sockfd < 0) {
    return -1;
  }
  login(sockfd);
  ftp_type(sockfd);
  pasv_sockfd = ftp_pasv(sockfd);
  if (pasv_sockfd < 0) {
    printf("###%s(),ftp_pasv failed!\n");
  }
  ret = ftp_stor(sockfd, filename, pasv_sockfd);
  ftp_close_datasockfd(sockfd, pasv_sockfd);
  ftp_quit(sockfd);
  close(sockfd);
}


x86 assembly (clang, -O0):
<ftp_put>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0xffffffff,-0x14(%rbp)
movl   $0xffffffff,-0x18(%rbp)
movl   $0xffffffff,-0x1c(%rbp)
lea    0xe48(%rip),%rdi
mov    $0x15,%esi
call   10a0 <connect_to_ftpserver@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    11db <ftp_put+0x4b>
movl   $0xffffffff,-0x4(%rbp)
jmp    1239 <ftp_put+0xa9>
mov    -0x14(%rbp),%edi
call   1080 <login@plt>
mov    -0x14(%rbp),%edi
call   1030 <ftp_type@plt>
mov    -0x14(%rbp),%edi
call   1090 <ftp_pasv@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    120c <ftp_put+0x7c>
lea    0xe07(%rip),%rdi
call   1050 <printf@plt>
mov    -0x14(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%edx
call   1040 <ftp_stor@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x14(%rbp),%edi
mov    -0x18(%rbp),%esi
call   10b0 <ftp_close_datasockfd@plt>
mov    -0x14(%rbp),%edi
call   1060 <ftp_quit@plt>
mov    -0x14(%rbp),%edi
call   1070 <close@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ftp_put>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%r14
lea    0xe62(%rip),%rdi
mov    $0x15,%esi
call   10a0 <connect_to_ftpserver@plt>
test   %eax,%eax
js     11f8 <ftp_put+0x68>
mov    %eax,%ebx
mov    %eax,%edi
call   1080 <login@plt>
mov    %ebx,%edi
call   1030 <ftp_type@plt>
mov    %ebx,%edi
call   1090 <ftp_pasv@plt>
mov    %eax,%ebp
test   %eax,%eax
jns    11d5 <ftp_put+0x45>
lea    0xe3e(%rip),%rdi
call   1050 <printf@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    %ebp,%edx
call   1040 <ftp_stor@plt>
mov    %ebx,%edi
mov    %ebp,%esi
call   10b0 <ftp_close_datasockfd@plt>
mov    %ebx,%edi
call   1060 <ftp_quit@plt>
mov    %ebx,%edi
call   1070 <close@plt>
mov    $0xffffffff,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [14 x i8] c"192.168.5.110\00"
@.str.1 = [26 x i8] c"###%s(),ftp_pasv failed!\0A\00"
define i32 @ftp_put(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %3
store i32 -1, i32* %4
store i32 -1, i32* %5
store i32 -1, i32* %6
%7 = call i32 @connect_to_ftpserver(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 21)
store i32 %7, i32* %4
%8 = load i32, i32* %4
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %11
10: ; preds = %1
store i32 -1, i32* %2
br label %34
11: ; preds = %1
%12 = load i32, i32* %4
%13 = call i32 @login(i32 %12)
%14 = load i32, i32* %4
%15 = call i32 @ftp_type(i32 %14)
%16 = load i32, i32* %4
%17 = call i32 @ftp_pasv(i32 %16)
store i32 %17, i32* %5
%18 = load i32, i32* %5
%19 = icmp slt i32 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %11
%21 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
br label %22
22: ; preds = %20, %11
%23 = load i32, i32* %4
%24 = load i8*, i8** %3
%25 = load i32, i32* %5
%26 = call i32 @ftp_stor(i32 %23, i8* %24, i32 %25)
store i32 %26, i32* %6
%27 = load i32, i32* %4
%28 = load i32, i32* %5
%29 = call i32 @ftp_close_datasockfd(i32 %27, i32 %28)
%30 = load i32, i32* %4
%31 = call i32 @ftp_quit(i32 %30)
%32 = load i32, i32* %4
%33 = call i32 @close(i32 %32)
br label %34
34: ; preds = %22, %10
%35 = load i32, i32* %2
ret i32 %35
}

LLVM IR (-O2):
@.str = [14 x i8] c"192.168.5.110\00"
@.str.1 = [26 x i8] c"###%s(),ftp_pasv failed!\0A\00"
define i32 @ftp_put(i8* %0) {
%2 = tail call i32 @connect_to_ftpserver(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 21)
%3 = icmp slt i32 %2, 0
br i1 %3, label %16, label %4
4: ; preds = %1
%5 = tail call i32 @login(i32 %2)
%6 = tail call i32 @ftp_type(i32 %2)
%7 = tail call i32 @ftp_pasv(i32 %2)
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %4
%10 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
br label %11
11: ; preds = %9, %4
%12 = tail call i32 @ftp_stor(i32 %2, i8* %0, i32 %7)
%13 = tail call i32 @ftp_close_datasockfd(i32 %2, i32 %7)
%14 = tail call i32 @ftp_quit(i32 %2)
%15 = tail call i32 @close(i32 %2)
br label %16
16: ; preds = %1, %11
ret i32 -1
}