#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 sockaddr_in {
  int dummy;
};
struct sockaddr {
  int dummy;
};
typedef int socklen_t;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int connect(int, struct sockaddr *, int);
int /*<<< orphan*/ perror(char *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int build_connect_ftpd(int type, struct sockaddr *addr) {
  int transform_fd;
  socklen_t sin_size = sizeof(struct sockaddr_in);
  if ((transform_fd = socket(AF_INET, SOCK_STREAM, 0)) == -1) {
    perror("Failed to create transform socket\n");
    return -1;
  }
  if (connect(transform_fd, addr, sin_size) == -1) {
    perror("Failed to connect transfrom socket\n");
    return -1;
  }
  return transform_fd;
}


x86 assembly (clang, -O0):
<build_connect_ftpd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x4,-0x18(%rbp)
mov    0x2e9b(%rip),%rax
mov    (%rax),%edi
mov    0x2e82(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1050 <socket@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
jne    1183 <build_connect_ftpd+0x53>
lea    0xe8e(%rip),%rdi
call   1030 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b9 <build_connect_ftpd+0x89>
mov    -0x14(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%edx
call   1040 <connect@plt>
cmp    $0xffffffff,%eax
jne    11b3 <build_connect_ftpd+0x83>
lea    0xe81(%rip),%rdi
call   1030 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b9 <build_connect_ftpd+0x89>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<build_connect_ftpd>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    0x2eab(%rip),%rax
mov    (%rax),%edi
mov    0x2e92(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1050 <socket@plt>
cmp    $0xffffffff,%eax
je     1173 <build_connect_ftpd+0x43>
mov    %eax,%ebp
mov    %eax,%edi
mov    %rbx,%rsi
mov    $0x4,%edx
call   1040 <connect@plt>
cmp    $0xffffffff,%eax
je     117c <build_connect_ftpd+0x4c>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xe86(%rip),%rdi
jmp    1183 <build_connect_ftpd+0x53>
lea    0xea0(%rip),%rdi
call   1030 <perror@plt>
mov    $0xffffffff,%ebp
jmp    116a <build_connect_ftpd+0x3a>

LLVM IR (-O0):
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [35 x i8] c"Failed to create transform socket\0A\00"
@.str.1 = [36 x i8] c"Failed to connect transfrom socket\0A\00"
define i32 @build_connect_ftpd(i32 %0, %struct.sockaddr* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca %struct.sockaddr*
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %4
store %struct.sockaddr* %1, %struct.sockaddr** %5
store i32 4, i32* %7
%8 = load i32, i32* @AF_INET
%9 = load i32, i32* @SOCK_STREAM
%10 = call i32 @socket(i32 %8, i32 %9, i32 0)
store i32 %10, i32* %6
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %14
12: ; preds = %2
%13 = call i32 @perror(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %24
14: ; preds = %2
%15 = load i32, i32* %6
%16 = load %struct.sockaddr*, %struct.sockaddr** %5
%17 = load i32, i32* %7
%18 = call i32 @connect(i32 %15, %struct.sockaddr* %16, i32 %17)
%19 = icmp eq i32 %18, -1
br i1 %19, label %20, label %22
20: ; preds = %14
%21 = call i32 @perror(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %3
br label %24
22: ; preds = %14
%23 = load i32, i32* %6
store i32 %23, i32* %3
br label %24
24: ; preds = %22, %20, %12
%25 = load i32, i32* %3
ret i32 %25
}

LLVM IR (-O2):
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [35 x i8] c"Failed to create transform socket\0A\00"
@.str.1 = [36 x i8] c"Failed to connect transfrom socket\0A\00"
define i32 @build_connect_ftpd(i32 %0, %struct.sockaddr* %1) {
%3 = load i32, i32* @AF_INET
%4 = load i32, i32* @SOCK_STREAM
%5 = tail call i32 @socket(i32 %3, i32 %4, i32 0)
%6 = icmp eq i32 %5, -1
br i1 %6, label %10, label %7
7: ; preds = %2
%8 = tail call i32 @connect(i32 %5, %struct.sockaddr* %1, i32 4)
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %13
10: ; preds = %7, %2
%11 = phi i8* [ getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), %2 ], [ getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0), %7 ]
%12 = tail call i32 @perror(i8* %11)
br label %13
13: ; preds = %10, %7
%14 = phi i32 [ %5, %7 ], [ -1, %10 ]
ret i32 %14
}