#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 _parse_tcp_arg(char *, char *, char **, char **);
scalar_t__ _set_socket_timeout(int);
int _tcp_connect(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ stderr;
int _open_tcp_connection(char *name, char *port_arg) {
  char *host;
  char *port;
  int ret = _parse_tcp_arg(name, port_arg, &host, &port);
  if (ret) {
    fprintf(stderr, "Error while parsing tcp arguments\n");
    return -1;
  }
  int sfd = _tcp_connect(host, port);
  if (_set_socket_timeout(sfd)) {
    fprintf(stderr, "Error while setting socket options\n");
    return -1;
  }
  return sfd;
}


x86 assembly (clang, -O0):
<_open_tcp_connection>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
lea    -0x20(%rbp),%rdx
lea    -0x28(%rbp),%rcx
call   1060 <_parse_tcp_arg@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
je     1193 <_open_tcp_connection+0x53>
mov    0x2e67(%rip),%rax
mov    (%rax),%edi
lea    0xe7e(%rip),%rsi
call   1030 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11dc <_open_tcp_connection+0x9c>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1050 <_tcp_connect@plt>
mov    %eax,-0x30(%rbp)
mov    -0x30(%rbp),%edi
call   1040 <_set_socket_timeout@plt>
cmp    $0x0,%rax
je     11d6 <_open_tcp_connection+0x96>
mov    0x2e24(%rip),%rax
mov    (%rax),%edi
lea    0xe5e(%rip),%rsi
call   1030 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11dc <_open_tcp_connection+0x9c>
mov    -0x30(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_open_tcp_connection>:
push   %rbx
sub    $0x10,%rsp
lea    0x8(%rsp),%rdx
mov    %rsp,%rcx
call   1060 <_parse_tcp_arg@plt>
test   %eax,%eax
je     115f <_open_tcp_connection+0x1f>
lea    0xea3(%rip),%rsi
jmp    1182 <_open_tcp_connection+0x42>
mov    0x8(%rsp),%rdi
mov    (%rsp),%rsi
call   1050 <_tcp_connect@plt>
mov    %eax,%ebx
mov    %eax,%edi
call   1040 <_set_socket_timeout@plt>
test   %rax,%rax
je     1195 <_open_tcp_connection+0x55>
lea    0xea1(%rip),%rsi
mov    0x2e57(%rip),%rax
mov    (%rax),%edi
call   1030 <fprintf@plt>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [35 x i8] c"Error while parsing tcp arguments\0A\00"
@.str.1 = [36 x i8] c"Error while setting socket options\0A\00"
define i32 @_open_tcp_connection(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
%10 = load i8*, i8** %4
%11 = load i8*, i8** %5
%12 = call i32 @_parse_tcp_arg(i8* %10, i8* %11, i8** %6, i8** %7)
store i32 %12, i32* %8
%13 = load i32, i32* %8
%14 = icmp ne i32 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %2
%16 = load i32, i32* @stderr
%17 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %30
18: ; preds = %2
%19 = load i8*, i8** %6
%20 = load i8*, i8** %7
%21 = call i32 @_tcp_connect(i8* %19, i8* %20)
store i32 %21, i32* %9
%22 = load i32, i32* %9
%23 = call i64 @_set_socket_timeout(i32 %22)
%24 = icmp ne i64 %23, 0
br i1 %24, label %25, label %28
25: ; preds = %18
%26 = load i32, i32* @stderr
%27 = call i32 @fprintf(i32 %26, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %3
br label %30
28: ; preds = %18
%29 = load i32, i32* %9
store i32 %29, i32* %3
br label %30
30: ; preds = %28, %25, %15
%31 = load i32, i32* %3
ret i32 %31
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [35 x i8] c"Error while parsing tcp arguments\0A\00"
@.str.1 = [36 x i8] c"Error while setting socket options\0A\00"
define i32 @_open_tcp_connection(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = bitcast i8** %3 to i8*
%6 = bitcast i8** %4 to i8*
%7 = call i32 @_parse_tcp_arg(i8* %0, i8* %1, i8** %3, i8** %4)
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %15
9: ; preds = %2
%10 = load i8*, i8** %3
%11 = load i8*, i8** %4
%12 = call i32 @_tcp_connect(i8* %10, i8* %11)
%13 = call i64 @_set_socket_timeout(i32 %12)
%14 = icmp eq i64 %13, 0
br i1 %14, label %19, label %15
15: ; preds = %9, %2
%16 = 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), %9 ]
%17 = load i32, i32* @stderr
%18 = call i32 @fprintf(i32 %17, i8* %16)
br label %19
19: ; preds = %15, %9
%20 = phi i32 [ %12, %9 ], [ -1, %15 ]
ret i32 %20
}