#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*/ die(char *, int /*<<< orphan*/);
int /*<<< orphan*/ ftpexpect(int, char *);
int /*<<< orphan*/ ftpparse(int, char *, char *, char *);
int net_connect_tcp(char *, char *, int /*<<< orphan*/);
int ftp_open(char *host, char *user, char *pass) {
  int in = net_connect_tcp(host, "ftp", 0);
  if (in < 0)
    die("Connect", 0);
  ftpexpect(in, "220 ");
  ftpparse(in, "USER %s\r\n", user, user);
  ftpexpect(in, "331 ");
  ftpparse(in, "PASS %s\r\n", pass, "<omitted>");
  ftpexpect(in, "230 ");
  return in;
}


x86 assembly (clang, -O0):
<ftp_open>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xea1(%rip),%rsi
xor    %edx,%edx
call   1040 <net_connect_tcp@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    1181 <ftp_open+0x41>
lea    0xe8a(%rip),%rdi
xor    %esi,%esi
call   1060 <die@plt>
mov    -0x1c(%rbp),%edi
lea    0xe81(%rip),%rsi
call   1030 <ftpexpect@plt>
mov    -0x1c(%rbp),%edi
mov    -0x10(%rbp),%rdx
mov    -0x10(%rbp),%rcx
lea    0xe6f(%rip),%rsi
call   1050 <ftpparse@plt>
mov    -0x1c(%rbp),%edi
lea    0xe6a(%rip),%rsi
call   1030 <ftpexpect@plt>
mov    -0x1c(%rbp),%edi
mov    -0x18(%rbp),%rdx
lea    0xe5c(%rip),%rsi
lea    0xe5f(%rip),%rcx
call   1050 <ftpparse@plt>
mov    -0x1c(%rbp),%edi
lea    0xe5a(%rip),%rsi
call   1030 <ftpexpect@plt>
mov    -0x1c(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ftp_open>:
push   %rbp
push   %r14
push   %rbx
mov    %rdx,%r14
mov    %rsi,%rbx
lea    0xeaf(%rip),%rsi
xor    %edx,%edx
call   1040 <net_connect_tcp@plt>
mov    %eax,%ebp
test   %eax,%eax
jns    116c <ftp_open+0x2c>
lea    0xe9f(%rip),%rdi
xor    %esi,%esi
call   1060 <die@plt>
lea    0xe99(%rip),%rsi
mov    %ebp,%edi
call   1030 <ftpexpect@plt>
lea    0xe90(%rip),%rsi
mov    %ebp,%edi
mov    %rbx,%rdx
mov    %rbx,%rcx
call   1050 <ftpparse@plt>
lea    0xe86(%rip),%rsi
mov    %ebp,%edi
call   1030 <ftpexpect@plt>
lea    0xe7d(%rip),%rsi
lea    0xe80(%rip),%rcx
mov    %ebp,%edi
mov    %r14,%rdx
call   1050 <ftpparse@plt>
lea    0xe79(%rip),%rsi
mov    %ebp,%edi
call   1030 <ftpexpect@plt>
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"ftp\00"
@.str.1 = [8 x i8] c"Connect\00"
@.str.2 = [5 x i8] c"220 \00"
@.str.3 = [10 x i8] c"USER %s\0D\0A\00"
@.str.4 = [5 x i8] c"331 \00"
@.str.5 = [10 x i8] c"PASS %s\0D\0A\00"
@.str.6 = [10 x i8] c"<omitted>\00"
@.str.7 = [5 x i8] c"230 \00"
define i32 @ftp_open(i8* %0, i8* %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i8* %2, i8** %6
%8 = load i8*, i8** %4
%9 = call i32 @net_connect_tcp(i8* %8, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 0)
store i32 %9, i32* %7
%10 = load i32, i32* %7
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %3
%13 = call i32 @die(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 0)
br label %14
14: ; preds = %12, %3
%15 = load i32, i32* %7
%16 = call i32 @ftpexpect(i32 %15, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%17 = load i32, i32* %7
%18 = load i8*, i8** %5
%19 = load i8*, i8** %5
%20 = call i32 @ftpparse(i32 %17, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i8* %18, i8* %19)
%21 = load i32, i32* %7
%22 = call i32 @ftpexpect(i32 %21, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%23 = load i32, i32* %7
%24 = load i8*, i8** %6
%25 = call i32 @ftpparse(i32 %23, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0), i8* %24, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0))
%26 = load i32, i32* %7
%27 = call i32 @ftpexpect(i32 %26, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0))
%28 = load i32, i32* %7
ret i32 %28
}

LLVM IR (-O2):
@.str = [4 x i8] c"ftp\00"
@.str.1 = [8 x i8] c"Connect\00"
@.str.2 = [5 x i8] c"220 \00"
@.str.3 = [10 x i8] c"USER %s\0D\0A\00"
@.str.4 = [5 x i8] c"331 \00"
@.str.5 = [10 x i8] c"PASS %s\0D\0A\00"
@.str.6 = [10 x i8] c"<omitted>\00"
@.str.7 = [5 x i8] c"230 \00"
define i32 @ftp_open(i8* %0, i8* %1, i8* %2) {
%4 = tail call i32 @net_connect_tcp(i8* %0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 0)
%5 = icmp slt i32 %4, 0
br i1 %5, label %6, label %8
6: ; preds = %3
%7 = tail call i32 @die(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 0)
br label %8
8: ; preds = %6, %3
%9 = tail call i32 @ftpexpect(i32 %4, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%10 = tail call i32 @ftpparse(i32 %4, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i8* %1, i8* %1)
%11 = tail call i32 @ftpexpect(i32 %4, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%12 = tail call i32 @ftpparse(i32 %4, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0), i8* %2, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0))
%13 = tail call i32 @ftpexpect(i32 %4, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0))
ret i32 %4
}