#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*/ errno;
int /*<<< orphan*/ printf(char *, char *);
scalar_t__ socket_connect(int, char *, char *);
int socket_create();
char *strerror(int /*<<< orphan*/);
int connect_to_server(char *dest, char *port) {
  int sockfd;
  if ((sockfd = socket_create()) < 0) {
    printf("Error creating Client-Socket: %s", strerror(errno));
    return -1;
  }
  if (socket_connect(sockfd, dest, port) < 0) {
    printf("Error Connecting to Server-Socket: %s\n", strerror(errno));
    return -1;
  }
  return sockfd;
}


x86 assembly (clang, -O0):
<connect_to_server>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    $0x0,%al
call   1050 <socket_create@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
jge    118c <connect_to_server+0x4c>
mov    0x2e76(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    %rax,%rsi
lea    0xe85(%rip),%rdi
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11d5 <connect_to_server+0x95>
mov    -0x1c(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1040 <socket_connect@plt>
cmp    $0x0,%rax
jge    11cf <connect_to_server+0x8f>
mov    0x2e33(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    %rax,%rsi
lea    0xe63(%rip),%rdi
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11d5 <connect_to_server+0x95>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<connect_to_server>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
xor    %eax,%eax
call   1050 <socket_create@plt>
test   %eax,%eax
js     1173 <connect_to_server+0x33>
mov    %eax,%ebx
mov    %eax,%edi
mov    %r15,%rsi
mov    %r14,%rdx
call   1040 <socket_connect@plt>
test   %rax,%rax
jns    1198 <connect_to_server+0x58>
lea    0xeb0(%rip),%rbx
jmp    117a <connect_to_server+0x3a>
lea    0xe86(%rip),%rbx
mov    0x2e5f(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    %rbx,%rdi
mov    %rax,%rsi
call   1030 <printf@plt>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [33 x i8] c"Error creating Client-Socket: %s\00"
@errno = global i32 0
@.str.1 = [39 x i8] c"Error Connecting to Server-Socket: %s\0A\00"
define i32 @connect_to_server(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
%7 = call i32 (...) @socket_create()
store i32 %7, i32* %6
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %13
9: ; preds = %2
%10 = load i32, i32* @errno
%11 = call i8* @strerror(i32 %10)
%12 = call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i8* %11)
store i32 -1, i32* %3
br label %25
13: ; preds = %2
%14 = load i32, i32* %6
%15 = load i8*, i8** %4
%16 = load i8*, i8** %5
%17 = call i64 @socket_connect(i32 %14, i8* %15, i8* %16)
%18 = icmp slt i64 %17, 0
br i1 %18, label %19, label %23
19: ; preds = %13
%20 = load i32, i32* @errno
%21 = call i8* @strerror(i32 %20)
%22 = call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0), i8* %21)
store i32 -1, i32* %3
br label %25
23: ; preds = %13
%24 = load i32, i32* %6
store i32 %24, i32* %3
br label %25
25: ; preds = %23, %19, %9
%26 = load i32, i32* %3
ret i32 %26
}

LLVM IR (-O2):
@.str = [33 x i8] c"Error creating Client-Socket: %s\00"
@errno = global i32 0
@.str.1 = [39 x i8] c"Error Connecting to Server-Socket: %s\0A\00"
define i32 @connect_to_server(i8* %0, i8* %1) {
%3 = tail call i32 (...) @socket_create()
%4 = icmp slt i32 %3, 0
br i1 %4, label %8, label %5
5: ; preds = %2
%6 = tail call i64 @socket_connect(i32 %3, i8* %0, i8* %1)
%7 = icmp slt i64 %6, 0
br i1 %7, label %8, label %13
8: ; preds = %5, %2
%9 = phi i8* [ getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), %2 ], [ getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0), %5 ]
%10 = load i32, i32* @errno
%11 = tail call i8* @strerror(i32 %10)
%12 = tail call i32 @printf(i8* %9, i8* %11)
br label %13
13: ; preds = %8, %5
%14 = phi i32 [ %3, %5 ], [ -1, %8 ]
ret i32 %14
}