#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 /*<<< orphan*/ s;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_STREAM;
scalar_t__ connect(int, struct sockaddr *, int);
int /*<<< orphan*/ die(char *, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ setup_other_sockaddr(struct sockaddr_in *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
int open_otherhost(void) {
  int sock = socket(AF_INET, SOCK_STREAM, 0);
  struct sockaddr_in s;
  if (sock < 0) {
    die("Could not create outbound socket (errno %d: %s).\n", errno,
        strerror(errno));
  }
  setup_other_sockaddr(&s);
  if (connect(sock, (struct sockaddr *)&s, sizeof(s)) < 0) {
    die("Could not connect outbound socket (errno %d: %s).\n", errno,
        strerror(errno));
  }
  return sock;
}


x86 assembly (clang, -O0):
<open_otherhost>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0x2e89(%rip),%rax
mov    (%rax),%edi
mov    0x2e70(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1070 <socket@plt>
mov    %eax,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
jge    11a9 <open_otherhost+0x59>
mov    0x2e4b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xc(%rbp)
mov    0x2e3f(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    -0xc(%rbp),%esi
mov    %eax,%edx
lea    0xe5c(%rip),%rdi
call   1030 <die@plt>
lea    -0x8(%rbp),%rdi
call   1050 <setup_other_sockaddr@plt>
mov    -0x4(%rbp),%edi
lea    -0x8(%rbp),%rsi
mov    $0x4,%edx
call   1040 <connect@plt>
cmp    $0x0,%rax
jge    11f8 <open_otherhost+0xa8>
mov    0x2dfc(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
mov    0x2df0(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    -0x10(%rbp),%esi
mov    %eax,%edx
lea    0xe3f(%rip),%rdi
call   1030 <die@plt>
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<open_otherhost>:
push   %rbp
push   %rbx
push   %rax
mov    0x2e8e(%rip),%rax
mov    (%rax),%edi
mov    0x2e75(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1070 <socket@plt>
mov    %eax,%ebx
test   %eax,%eax
jns    1192 <open_otherhost+0x42>
mov    0x2e57(%rip),%rax
mov    (%rax),%ebp
mov    %ebp,%edi
call   1060 <strerror@plt>
lea    0xe77(%rip),%rdi
mov    %ebp,%esi
mov    %eax,%edx
call   1030 <die@plt>
mov    %rsp,%rbp
mov    %rbp,%rdi
call   1050 <setup_other_sockaddr@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
mov    $0x4,%edx
call   1040 <connect@plt>
test   %rax,%rax
jns    11d1 <open_otherhost+0x81>
mov    0x2e18(%rip),%rax
mov    (%rax),%ebp
mov    %ebp,%edi
call   1060 <strerror@plt>
lea    0xe6a(%rip),%rdi
mov    %ebp,%esi
mov    %eax,%edx
call   1030 <die@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [50 x i8] c"Could not create outbound socket (errno %d: %s).\0A\00"
@errno = global i32 0
@.str.1 = [51 x i8] c"Could not connect outbound socket (errno %d: %s).\0A\00"
define i32 @open_otherhost() {
%1 = alloca i32
%2 = alloca %struct.sockaddr_in
%3 = load i32, i32* @AF_INET
%4 = load i32, i32* @SOCK_STREAM
%5 = call i32 @socket(i32 %3, i32 %4, i32 0)
store i32 %5, i32* %1
%6 = load i32, i32* %1
%7 = icmp slt i32 %6, 0
br i1 %7, label %8, label %13
8: ; preds = %0
%9 = load i32, i32* @errno
%10 = load i32, i32* @errno
%11 = call i32 @strerror(i32 %10)
%12 = call i32 @die(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str, i64 0, i64 0), i32 %9, i32 %11)
br label %13
13: ; preds = %8, %0
%14 = call i32 @setup_other_sockaddr(%struct.sockaddr_in* %2)
%15 = load i32, i32* %1
%16 = bitcast %struct.sockaddr_in* %2 to %struct.sockaddr*
%17 = call i64 @connect(i32 %15, %struct.sockaddr* %16, i32 4)
%18 = icmp slt i64 %17, 0
br i1 %18, label %19, label %24
19: ; preds = %13
%20 = load i32, i32* @errno
%21 = load i32, i32* @errno
%22 = call i32 @strerror(i32 %21)
%23 = call i32 @die(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.1, i64 0, i64 0), i32 %20, i32 %22)
br label %24
24: ; preds = %19, %13
%25 = load i32, i32* %1
ret i32 %25
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [50 x i8] c"Could not create outbound socket (errno %d: %s).\0A\00"
@errno = global i32 0
@.str.1 = [51 x i8] c"Could not connect outbound socket (errno %d: %s).\0A\00"
define i32 @open_otherhost() {
%1 = alloca %struct.sockaddr_in
%2 = load i32, i32* @AF_INET
%3 = load i32, i32* @SOCK_STREAM
%4 = tail call i32 @socket(i32 %2, i32 %3, i32 0)
%5 = bitcast %struct.sockaddr_in* %1 to i8*
%6 = icmp slt i32 %4, 0
br i1 %6, label %7, label %11
7: ; preds = %0
%8 = load i32, i32* @errno
%9 = tail call i32 @strerror(i32 %8)
%10 = tail call i32 @die(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str, i64 0, i64 0), i32 %8, i32 %9)
br label %11
11: ; preds = %7, %0
%12 = call i32 @setup_other_sockaddr(%struct.sockaddr_in* %1)
%13 = bitcast %struct.sockaddr_in* %1 to %struct.sockaddr*
%14 = call i64 @connect(i32 %4, %struct.sockaddr* %13, i32 4)
%15 = icmp slt i64 %14, 0
br i1 %15, label %16, label %20
16: ; preds = %11
%17 = load i32, i32* @errno
%18 = call i32 @strerror(i32 %17)
%19 = call i32 @die(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.1, i64 0, i64 0), i32 %17, i32 %18)
br label %20
20: ; preds = %16, %11
ret i32 %4
}