#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 /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_addr;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ saddr;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_STREAM;
scalar_t__ connect(int, struct sockaddr *, int);
int /*<<< orphan*/ error(char *);
char *inet_ntoa(int /*<<< orphan*/);
int ntohs(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int create_network_link(struct sockaddr_in saddr) {
  int s;
  printf("Connecting to server %s on port %d\n", inet_ntoa(saddr.sin_addr),
         ntohs(saddr.sin_port));
  s = socket(AF_INET, SOCK_STREAM, 0);
  if (s == -1)
    error("Could not open socket");
  if (connect(s, (struct sockaddr *)&saddr, sizeof(saddr)))
    error("Could not connect");
  return (s);
}


x86 assembly (clang, -O0):
<create_network_link>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x4(%rbp),%edi
call   1030 <inet_ntoa@plt>
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%edi
call   1050 <ntohs@plt>
mov    -0x18(%rbp),%rsi
mov    %eax,%edx
lea    0xe73(%rip),%rdi
call   1040 <printf@plt>
mov    0x2e4f(%rip),%rax
mov    (%rax),%edi
mov    0x2e36(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1080 <socket@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0xffffffff,-0xc(%rbp)
jne    11c4 <create_network_link+0x64>
lea    0xe65(%rip),%rdi
call   1060 <error@plt>
mov    -0xc(%rbp),%edi
lea    -0x8(%rbp),%rsi
mov    $0x8,%edx
call   1070 <connect@plt>
cmp    $0x0,%rax
je     11eb <create_network_link+0x8b>
lea    0xe54(%rip),%rdi
call   1060 <error@plt>
mov    -0xc(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<create_network_link>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    %rdi,(%rsp)
shr    $0x20,%rdi
call   1030 <inet_ntoa@plt>
mov    %rax,%r14
mov    %ebx,%edi
call   1050 <ntohs@plt>
lea    0xe7b(%rip),%rdi
mov    %r14,%rsi
mov    %eax,%edx
call   1040 <printf@plt>
mov    0x2e52(%rip),%rax
mov    (%rax),%edi
mov    0x2e39(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1080 <socket@plt>
mov    %eax,%ebx
cmp    $0xffffffff,%eax
jne    11bb <create_network_link+0x5b>
lea    0xe6e(%rip),%rdi
call   1060 <error@plt>
mov    %rsp,%rsi
mov    %ebx,%edi
mov    $0x8,%edx
call   1070 <connect@plt>
test   %rax,%rax
je     11db <create_network_link+0x7b>
lea    0xe64(%rip),%rdi
call   1060 <error@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, i32 }
%struct.sockaddr = type { i32 }
@.str = [36 x i8] c"Connecting to server %s on port %d\0A\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [22 x i8] c"Could not open socket\00"
@.str.2 = [18 x i8] c"Could not connect\00"
define i32 @create_network_link(i64 %0) {
%2 = alloca %struct.sockaddr_in
%3 = alloca i32
%4 = bitcast %struct.sockaddr_in* %2 to i64*
store i64 %0, i64* %4
%5 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i32 0, i32 1
%6 = load i32, i32* %5
%7 = call i8* @inet_ntoa(i32 %6)
%8 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i32 0, i32 0
%9 = load i32, i32* %8
%10 = call i32 @ntohs(i32 %9)
%11 = call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i8* %7, i32 %10)
%12 = load i32, i32* @AF_INET
%13 = load i32, i32* @SOCK_STREAM
%14 = call i32 @socket(i32 %12, i32 %13, i32 0)
store i32 %14, i32* %3
%15 = load i32, i32* %3
%16 = icmp eq i32 %15, -1
br i1 %16, label %17, label %19
17: ; preds = %1
%18 = call i32 @error(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
br label %19
19: ; preds = %17, %1
%20 = load i32, i32* %3
%21 = bitcast %struct.sockaddr_in* %2 to %struct.sockaddr*
%22 = call i64 @connect(i32 %20, %struct.sockaddr* %21, i32 8)
%23 = icmp ne i64 %22, 0
br i1 %23, label %24, label %26
24: ; preds = %19
%25 = call i32 @error(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
br label %26
26: ; preds = %24, %19
%27 = load i32, i32* %3
ret i32 %27
}

LLVM IR (-O2):
%struct.sockaddr = type { i32 }
@.str = [36 x i8] c"Connecting to server %s on port %d\0A\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [22 x i8] c"Could not open socket\00"
@.str.2 = [18 x i8] c"Could not connect\00"
define i32 @create_network_link(i64 %0) {
%2 = alloca i64
store i64 %0, i64* %2
%3 = lshr i64 %0, 32
%4 = trunc i64 %3 to i32
%5 = tail call i8* @inet_ntoa(i32 %4)
%6 = trunc i64 %0 to i32
%7 = tail call i32 @ntohs(i32 %6)
%8 = tail call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i8* %5, i32 %7)
%9 = load i32, i32* @AF_INET
%10 = load i32, i32* @SOCK_STREAM
%11 = tail call i32 @socket(i32 %9, i32 %10, i32 0)
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %15
13: ; preds = %1
%14 = tail call i32 @error(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
br label %15
15: ; preds = %13, %1
%16 = bitcast i64* %2 to %struct.sockaddr*
%17 = call i64 @connect(i32 %11, %struct.sockaddr* %16, i32 8)
%18 = icmp eq i64 %17, 0
br i1 %18, label %21, label %19
19: ; preds = %15
%20 = call i32 @error(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
br label %21
21: ; preds = %19, %15
ret i32 %11
}