#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 atoi(char *);
int /*<<< orphan*/ close(int);
char *ftpexpect(int, char *);
int /*<<< orphan*/ ftpparse(int, char *, char *, char *);
int /*<<< orphan*/ ftpsend(int, char *);
int net_connect_tcp(char *, char *, int /*<<< orphan*/);
int /*<<< orphan*/ send(int, char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ sprintf(char *, char *, int);
char *strchr(char *, char);
void ftp_send(int in, char *file, char *msg, int msglen) {
  ftpsend(in, "PASV\r\n");
  char *ip = ftpexpect(in, "227 ");
  ip = strchr(ip, '(') + 1;
  char *r2 = strchr(ip, ',');
  char p, port[6];
  for (p = 0; p < 3; ++p) {
    *r2 = '.';
    r2 = strchr(r2, ',');
  }
  *(r2++) = '\0';
  sprintf(port, "%d\0", atoi(r2) * 256 + atoi(strchr(r2, ',') + 1));
  int out = net_connect_tcp(ip, port, 0);
  ftpparse(in, "STOR %s\r\n", file, file);
  ftpexpect(in, "150 ");
  send(out, msg, msglen, 0);
  close(out);
  ftpexpect(in, "226 ");
}


x86 assembly (clang, -O0):
<ftp_send>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    -0x4(%rbp),%edi
lea    0xe50(%rip),%rsi
call   1070 <ftpsend@plt>
mov    -0x4(%rbp),%edi
lea    0xe48(%rip),%rsi
call   1030 <ftpexpect@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    $0x28,%esi
call   1050 <strchr@plt>
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    $0x2c,%esi
call   1050 <strchr@plt>
mov    %rax,-0x30(%rbp)
movb   $0x0,-0x31(%rbp)
movsbl -0x31(%rbp),%eax
cmp    $0x3,%eax
jge    1227 <ftp_send+0x97>
mov    -0x30(%rbp),%rax
movb   $0x2e,(%rax)
mov    -0x30(%rbp),%rdi
mov    $0x2c,%esi
call   1050 <strchr@plt>
mov    %rax,-0x30(%rbp)
mov    -0x31(%rbp),%al
add    $0x1,%al
mov    %al,-0x31(%rbp)
jmp    11f4 <ftp_send+0x64>
mov    -0x30(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x30(%rbp)
movb   $0x0,(%rax)
lea    -0x37(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x30(%rbp),%rdi
call   10a0 <atoi@plt>
shl    $0x8,%eax
mov    %eax,-0x4c(%rbp)
mov    -0x30(%rbp),%rdi
mov    $0x2c,%esi
call   1050 <strchr@plt>
mov    %rax,%rdi
add    $0x1,%rdi
call   10a0 <atoi@plt>
mov    -0x4c(%rbp),%edx
mov    -0x48(%rbp),%rdi
add    %eax,%edx
lea    0xda6(%rip),%rsi
call   10b0 <sprintf@plt>
mov    -0x28(%rbp),%rdi
lea    -0x37(%rbp),%rsi
xor    %edx,%edx
call   1080 <net_connect_tcp@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rdx
mov    -0x10(%rbp),%rcx
lea    0xd69(%rip),%rsi
call   1090 <ftpparse@plt>
mov    -0x4(%rbp),%edi
lea    0xd64(%rip),%rsi
call   1030 <ftpexpect@plt>
mov    -0x3c(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
xor    %ecx,%ecx
call   1040 <send@plt>
mov    -0x3c(%rbp),%edi
call   1060 <close@plt>
mov    -0x4(%rbp),%edi
lea    0xd41(%rip),%rsi
call   1030 <ftpexpect@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ftp_send>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %ecx,0xc(%rsp)
mov    %rdx,%r15
mov    %rsi,%r12
mov    %edi,%ebx
lea    0xe4f(%rip),%rsi
call   1070 <ftpsend@plt>
lea    0xe4a(%rip),%rsi
mov    %ebx,%edi
call   1030 <ftpexpect@plt>
mov    %rax,%rdi
mov    $0x28,%esi
call   1050 <strchr@plt>
lea    0x1(%rax),%r13
mov    %r13,%rdi
mov    $0x2c,%esi
call   1050 <strchr@plt>
movb   $0x2e,(%rax)
mov    %rax,%rdi
mov    $0x2c,%esi
call   1050 <strchr@plt>
movb   $0x2e,(%rax)
mov    %rax,%rdi
mov    $0x2c,%esi
call   1050 <strchr@plt>
movb   $0x2e,(%rax)
mov    %rax,%rdi
mov    $0x2c,%esi
call   1050 <strchr@plt>
movb   $0x0,(%rax)
lea    0x1(%rax),%rbp
mov    %rbp,%rdi
call   10a0 <atoi@plt>
mov    %eax,%r14d
shl    $0x8,%r14d
mov    %rbp,%rdi
mov    $0x2c,%esi
call   1050 <strchr@plt>
lea    0x1(%rax),%rdi
call   10a0 <atoi@plt>
add    %eax,%r14d
lea    0xdd8(%rip),%rsi
lea    0x12(%rsp),%rbp
mov    %rbp,%rdi
mov    %r14d,%edx
call   10b0 <sprintf@plt>
mov    %r13,%rdi
mov    %rbp,%rsi
xor    %edx,%edx
call   1080 <net_connect_tcp@plt>
mov    %eax,%ebp
lea    0xd9e(%rip),%rsi
mov    %ebx,%edi
mov    %r12,%rdx
mov    %r12,%rcx
call   1090 <ftpparse@plt>
lea    0xd94(%rip),%rsi
mov    %ebx,%edi
call   1030 <ftpexpect@plt>
mov    %ebp,%edi
mov    %r15,%rsi
mov    0xc(%rsp),%edx
xor    %ecx,%ecx
call   1040 <send@plt>
mov    %ebp,%edi
call   1060 <close@plt>
lea    0xd74(%rip),%rsi
mov    %ebx,%edi
call   1030 <ftpexpect@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [7 x i8] c"PASV\0D\0A\00"
@.str.1 = [5 x i8] c"227 \00"
@.str.2 = [4 x i8] c"%d\00\00"
@.str.3 = [10 x i8] c"STOR %s\0D\0A\00"
@.str.4 = [5 x i8] c"150 \00"
@.str.5 = [5 x i8] c"226 \00"
define void @ftp_send(i32 %0, i8* %1, i8* %2, i32 %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i8
%12 = alloca [6 x i8]
%13 = alloca i32
store i32 %0, i32* %5
store i8* %1, i8** %6
store i8* %2, i8** %7
store i32 %3, i32* %8
%14 = load i32, i32* %5
%15 = call i32 @ftpsend(i32 %14, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%16 = load i32, i32* %5
%17 = call i8* @ftpexpect(i32 %16, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
store i8* %17, i8** %9
%18 = load i8*, i8** %9
%19 = call i8* @strchr(i8* %18, i8 signext 40)
%20 = getelementptr inbounds i8, i8* %19, i64 1
store i8* %20, i8** %9
%21 = load i8*, i8** %9
%22 = call i8* @strchr(i8* %21, i8 signext 44)
store i8* %22, i8** %10
store i8 0, i8* %11
br label %23
23: ; preds = %31, %4
%24 = load i8, i8* %11
%25 = sext i8 %24 to i32
%26 = icmp slt i32 %25, 3
br i1 %26, label %27, label %34
27: ; preds = %23
%28 = load i8*, i8** %10
store i8 46, i8* %28
%29 = load i8*, i8** %10
%30 = call i8* @strchr(i8* %29, i8 signext 44)
store i8* %30, i8** %10
br label %31
31: ; preds = %27
%32 = load i8, i8* %11
%33 = add i8 %32, 1
store i8 %33, i8* %11
br label %23
34: ; preds = %23
%35 = load i8*, i8** %10
%36 = getelementptr inbounds i8, i8* %35, i32 1
store i8* %36, i8** %10
store i8 0, i8* %35
%37 = getelementptr inbounds [6 x i8], [6 x i8]* %12, i64 0, i64 0
%38 = load i8*, i8** %10
%39 = call i32 @atoi(i8* %38)
%40 = mul nsw i32 %39, 256
%41 = load i8*, i8** %10
%42 = call i8* @strchr(i8* %41, i8 signext 44)
%43 = getelementptr inbounds i8, i8* %42, i64 1
%44 = call i32 @atoi(i8* %43)
%45 = add nsw i32 %40, %44
%46 = call i32 @sprintf(i8* %37, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %45)
%47 = load i8*, i8** %9
%48 = getelementptr inbounds [6 x i8], [6 x i8]* %12, i64 0, i64 0
%49 = call i32 @net_connect_tcp(i8* %47, i8* %48, i32 0)
store i32 %49, i32* %13
%50 = load i32, i32* %5
%51 = load i8*, i8** %6
%52 = load i8*, i8** %6
%53 = call i32 @ftpparse(i32 %50, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i8* %51, i8* %52)
%54 = load i32, i32* %5
%55 = call i8* @ftpexpect(i32 %54, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%56 = load i32, i32* %13
%57 = load i8*, i8** %7
%58 = load i32, i32* %8
%59 = call i32 @send(i32 %56, i8* %57, i32 %58, i32 0)
%60 = load i32, i32* %13
%61 = call i32 @close(i32 %60)
%62 = load i32, i32* %5
%63 = call i8* @ftpexpect(i32 %62, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [7 x i8] c"PASV\0D\0A\00"
@.str.1 = [5 x i8] c"227 \00"
@.str.2 = [4 x i8] c"%d\00\00"
@.str.3 = [10 x i8] c"STOR %s\0D\0A\00"
@.str.4 = [5 x i8] c"150 \00"
@.str.5 = [5 x i8] c"226 \00"
define void @ftp_send(i32 %0, i8* %1, i8* %2, i32 %3) {
%5 = alloca [6 x i8]
%6 = tail call i32 @ftpsend(i32 %0, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%7 = tail call i8* @ftpexpect(i32 %0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%8 = tail call i8* @strchr(i8* dereferenceable(1) %7, i8 signext 40)
%9 = getelementptr inbounds i8, i8* %8, i64 1
%10 = tail call i8* @strchr(i8* %9, i8 signext 44)
%11 = getelementptr inbounds [6 x i8], [6 x i8]* %5, i64 0, i64 0
store i8 46, i8* %10
%12 = tail call i8* @strchr(i8* %10, i8 signext 44)
store i8 46, i8* %12
%13 = tail call i8* @strchr(i8* %12, i8 signext 44)
store i8 46, i8* %13
%14 = tail call i8* @strchr(i8* %13, i8 signext 44)
%15 = getelementptr inbounds i8, i8* %14, i64 1
store i8 0, i8* %14
%16 = tail call i32 @atoi(i8* %15)
%17 = shl nsw i32 %16, 8
%18 = tail call i8* @strchr(i8* %15, i8 signext 44)
%19 = getelementptr inbounds i8, i8* %18, i64 1
%20 = tail call i32 @atoi(i8* %19)
%21 = add nsw i32 %20, %17
%22 = call i32 @sprintf(i8* %11, i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %21)
%23 = call i32 @net_connect_tcp(i8* %9, i8* %11, i32 0)
%24 = call i32 @ftpparse(i32 %0, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i8* %1, i8* %1)
%25 = call i8* @ftpexpect(i32 %0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%26 = call i32 @send(i32 %23, i8* %2, i32 %3, i32 0)
%27 = call i32 @close(i32 %23)
%28 = call i8* @ftpexpect(i32 %0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
ret void
}