#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 /*<<< orphan*/ ftp_reset(int);
int ftp_retr(int, char *, int);
int /*<<< orphan*/ ftp_type(int);
int /*<<< orphan*/ login(int);
int /*<<< orphan*/ printf(char *);
int ftp_get(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_reset(sockfd);
  ftp_type(sockfd);
  pasv_sockfd = ftp_pasv(sockfd);
  if (pasv_sockfd < 0) {
    printf("###%s(),ftp_pasv failed!\n");
  }
  ret = ftp_retr(sockfd, filename, pasv_sockfd);
  ftp_close_datasockfd(sockfd, pasv_sockfd);
  ftp_quit(sockfd);
out:
  close(sockfd);
}


x86 assembly (clang, -O0):
<ftp_get>:
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    0xe38(%rip),%rdi
mov    $0x15,%esi
call   10b0 <connect_to_ftpserver@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    11eb <ftp_get+0x4b>
movl   $0xffffffff,-0x4(%rbp)
jmp    1251 <ftp_get+0xb1>
mov    -0x14(%rbp),%edi
call   1090 <login@plt>
mov    -0x14(%rbp),%edi
call   1050 <ftp_reset@plt>
mov    -0x14(%rbp),%edi
call   1040 <ftp_type@plt>
mov    -0x14(%rbp),%edi
call   10a0 <ftp_pasv@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    1224 <ftp_get+0x84>
lea    0xdef(%rip),%rdi
call   1060 <printf@plt>
mov    -0x14(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%edx
call   1030 <ftp_retr@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x14(%rbp),%edi
mov    -0x18(%rbp),%esi
call   10c0 <ftp_close_datasockfd@plt>
mov    -0x14(%rbp),%edi
call   1070 <ftp_quit@plt>
mov    -0x14(%rbp),%edi
call   1080 <close@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ftp_get>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%r14
lea    0xe52(%rip),%rdi
mov    $0x15,%esi
call   10b0 <connect_to_ftpserver@plt>
test   %eax,%eax
js     120f <ftp_get+0x6f>
mov    %eax,%ebx
mov    %eax,%edi
call   1090 <login@plt>
mov    %ebx,%edi
call   1050 <ftp_reset@plt>
mov    %ebx,%edi
call   1040 <ftp_type@plt>
mov    %ebx,%edi
call   10a0 <ftp_pasv@plt>
mov    %eax,%ebp
test   %eax,%eax
jns    11ec <ftp_get+0x4c>
lea    0xe27(%rip),%rdi
call   1060 <printf@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    %ebp,%edx
call   1030 <ftp_retr@plt>
mov    %ebx,%edi
mov    %ebp,%esi
call   10c0 <ftp_close_datasockfd@plt>
mov    %ebx,%edi
call   1070 <ftp_quit@plt>
mov    %ebx,%edi
call   1080 <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_get(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 %37
11: ; preds = %1
%12 = load i32, i32* %4
%13 = call i32 @login(i32 %12)
%14 = load i32, i32* %4
%15 = call i32 @ftp_reset(i32 %14)
%16 = load i32, i32* %4
%17 = call i32 @ftp_type(i32 %16)
%18 = load i32, i32* %4
%19 = call i32 @ftp_pasv(i32 %18)
store i32 %19, i32* %5
%20 = load i32, i32* %5
%21 = icmp slt i32 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %11
%23 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
br label %24
24: ; preds = %22, %11
%25 = load i32, i32* %4
%26 = load i8*, i8** %3
%27 = load i32, i32* %5
%28 = call i32 @ftp_retr(i32 %25, i8* %26, i32 %27)
store i32 %28, i32* %6
%29 = load i32, i32* %4
%30 = load i32, i32* %5
%31 = call i32 @ftp_close_datasockfd(i32 %29, i32 %30)
%32 = load i32, i32* %4
%33 = call i32 @ftp_quit(i32 %32)
br label %34
34: ; preds = %24
%35 = load i32, i32* %4
%36 = call i32 @close(i32 %35)
br label %37
37: ; preds = %34, %10
%38 = load i32, i32* %2
ret i32 %38
}

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_get(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 %17, label %4
4: ; preds = %1
%5 = tail call i32 @login(i32 %2)
%6 = tail call i32 @ftp_reset(i32 %2)
%7 = tail call i32 @ftp_type(i32 %2)
%8 = tail call i32 @ftp_pasv(i32 %2)
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %4
%11 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
br label %12
12: ; preds = %10, %4
%13 = tail call i32 @ftp_retr(i32 %2, i8* %0, i32 %8)
%14 = tail call i32 @ftp_close_datasockfd(i32 %2, i32 %8)
%15 = tail call i32 @ftp_quit(i32 %2)
%16 = tail call i32 @close(i32 %2)
br label %17
17: ; preds = %1, %12
ret i32 -1
}