#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 ftpsub_buf {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ CmdCLOSE(struct ftpsub_buf *, int *);
int /*<<< orphan*/ CmdQUIT(struct ftpsub_buf *, int);
int OkResultCheck(struct ftpsub_buf *, int, char *);
int OpenConnect(struct ftpsub_buf *, char const *, int);
int RecvMessage_(struct ftpsub_buf *, int);
int CmdOPEN(struct ftpsub_buf *fbf, const char *rhost, int iport) {
  int sockfd;
  if ((sockfd = OpenConnect(fbf, rhost, iport)) == -1) {
    return (-1);
  };
  if (RecvMessage_(fbf, sockfd) == -1) {
    CmdQUIT(fbf, sockfd);
    CmdCLOSE(fbf, &sockfd);
    return (-1);
  }
  if (OkResultCheck(fbf, 1, "220") == -1) {
    CmdQUIT(fbf, sockfd);
    CmdCLOSE(fbf, &sockfd);
    return (-1);
  }
  return (sockfd);
}


x86 assembly (clang, -O0):
<CmdOPEN>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1040 <OpenConnect@plt>
mov    %eax,-0x20(%rbp)
cmp    $0xffffffff,%eax
jne    118b <CmdOPEN+0x3b>
movl   $0xffffffff,-0x4(%rbp)
jmp    120e <CmdOPEN+0xbe>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%esi
call   1030 <RecvMessage_@plt>
cmp    $0xffffffff,%eax
jne    11c5 <CmdOPEN+0x75>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%esi
call   1050 <CmdQUIT@plt>
mov    -0x10(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1060 <CmdCLOSE@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    120e <CmdOPEN+0xbe>
mov    -0x10(%rbp),%rdi
mov    $0x1,%esi
lea    0xe2b(%rip),%rdx
call   1070 <OkResultCheck@plt>
cmp    $0xffffffff,%eax
jne    1208 <CmdOPEN+0xb8>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%esi
call   1050 <CmdQUIT@plt>
mov    -0x10(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1060 <CmdCLOSE@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    120e <CmdOPEN+0xbe>
mov    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<CmdOPEN>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
call   1040 <OpenConnect@plt>
mov    %eax,0xc(%rsp)
mov    $0xffffffff,%r14d
cmp    $0xffffffff,%eax
je     11b5 <CmdOPEN+0x65>
mov    %eax,%ebp
mov    %rbx,%rdi
mov    %eax,%esi
call   1030 <RecvMessage_@plt>
cmp    $0xffffffff,%eax
je     119e <CmdOPEN+0x4e>
lea    0xe79(%rip),%rdx
mov    %rbx,%rdi
mov    $0x1,%esi
call   1070 <OkResultCheck@plt>
cmp    $0xffffffff,%eax
je     119e <CmdOPEN+0x4e>
mov    %ebp,%r14d
jmp    11b5 <CmdOPEN+0x65>
mov    %rbx,%rdi
mov    %ebp,%esi
call   1050 <CmdQUIT@plt>
lea    0xc(%rsp),%rsi
mov    %rbx,%rdi
call   1060 <CmdCLOSE@plt>
mov    %r14d,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.ftpsub_buf = type { i32 }
@.str = [4 x i8] c"220\00"
define i32 @CmdOPEN(%struct.ftpsub_buf* %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca %struct.ftpsub_buf*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
store %struct.ftpsub_buf* %0, %struct.ftpsub_buf** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
%9 = load %struct.ftpsub_buf*, %struct.ftpsub_buf** %5
%10 = load i8*, i8** %6
%11 = load i32, i32* %7
%12 = call i32 @OpenConnect(%struct.ftpsub_buf* %9, i8* %10, i32 %11)
store i32 %12, i32* %8
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %15
14: ; preds = %3
store i32 -1, i32* %4
br label %38
15: ; preds = %3
%16 = load %struct.ftpsub_buf*, %struct.ftpsub_buf** %5
%17 = load i32, i32* %8
%18 = call i32 @RecvMessage_(%struct.ftpsub_buf* %16, i32 %17)
%19 = icmp eq i32 %18, -1
br i1 %19, label %20, label %26
20: ; preds = %15
%21 = load %struct.ftpsub_buf*, %struct.ftpsub_buf** %5
%22 = load i32, i32* %8
%23 = call i32 @CmdQUIT(%struct.ftpsub_buf* %21, i32 %22)
%24 = load %struct.ftpsub_buf*, %struct.ftpsub_buf** %5
%25 = call i32 @CmdCLOSE(%struct.ftpsub_buf* %24, i32* %8)
store i32 -1, i32* %4
br label %38
26: ; preds = %15
%27 = load %struct.ftpsub_buf*, %struct.ftpsub_buf** %5
%28 = call i32 @OkResultCheck(%struct.ftpsub_buf* %27, i32 1, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%29 = icmp eq i32 %28, -1
br i1 %29, label %30, label %36
30: ; preds = %26
%31 = load %struct.ftpsub_buf*, %struct.ftpsub_buf** %5
%32 = load i32, i32* %8
%33 = call i32 @CmdQUIT(%struct.ftpsub_buf* %31, i32 %32)
%34 = load %struct.ftpsub_buf*, %struct.ftpsub_buf** %5
%35 = call i32 @CmdCLOSE(%struct.ftpsub_buf* %34, i32* %8)
store i32 -1, i32* %4
br label %38
36: ; preds = %26
%37 = load i32, i32* %8
store i32 %37, i32* %4
br label %38
38: ; preds = %36, %30, %20, %14
%39 = load i32, i32* %4
ret i32 %39
}

LLVM IR (-O2):
%struct.ftpsub_buf = type { i32 }
@.str = [4 x i8] c"220\00"
define i32 @CmdOPEN(%struct.ftpsub_buf* %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = bitcast i32* %4 to i8*
%6 = tail call i32 @OpenConnect(%struct.ftpsub_buf* %0, i8* %1, i32 %2)
store i32 %6, i32* %4
%7 = icmp eq i32 %6, -1
br i1 %7, label %17, label %8
8: ; preds = %3
%9 = tail call i32 @RecvMessage_(%struct.ftpsub_buf* %0, i32 %6)
%10 = icmp eq i32 %9, -1
br i1 %10, label %14, label %11
11: ; preds = %8
%12 = tail call i32 @OkResultCheck(%struct.ftpsub_buf* %0, i32 1, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %17
14: ; preds = %11, %8
%15 = tail call i32 @CmdQUIT(%struct.ftpsub_buf* %0, i32 %6)
%16 = call i32 @CmdCLOSE(%struct.ftpsub_buf* %0, i32* %4)
br label %17
17: ; preds = %14, %11, %3
%18 = phi i32 [ -1, %3 ], [ %6, %11 ], [ -1, %14 ]
ret i32 %18
}