#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 */
typedef int uint16_t;
struct sockaddr_in {
  int dummy;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ servername;

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ EXIT_SUCCESS;
int /*<<< orphan*/ PF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ close(int);
scalar_t__ connect(int, struct sockaddr *, int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ write_to_server(int);
int main(void) {
  extern void init_sockaddr(struct sockaddr_in * name, const char *hostname,
                            uint16_t port);
  int sock;
  struct sockaddr_in servername;
  sock = socket(PF_INET, SOCK_STREAM, 0);
  if (sock < 0) {
    perror("socket (client)");
    exit(EXIT_FAILURE);
  }
  init_sockaddr(&servername, "www.gnu.org", 5555);
  if (0 > connect(sock, (struct sockaddr *)&servername, sizeof(servername))) {
    perror("connect (client)");
    exit(EXIT_FAILURE);
  }
  write_to_server(sock);
  close(sock);
  exit(EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e52(%rip),%rax
mov    (%rax),%edi
mov    0x2e51(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1090 <socket@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    11bf <main+0x4f>
lea    0xe54(%rip),%rdi
call   1060 <perror@plt>
mov    0x2e18(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
lea    -0x10(%rbp),%rdi
lea    0xe46(%rip),%rsi
mov    $0x15b3,%edx
call   1050 <init_sockaddr@plt>
mov    -0x8(%rbp),%edi
lea    -0x10(%rbp),%rsi
mov    $0x4,%edx
call   1080 <connect@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jle    120d <main+0x9d>
lea    0xe22(%rip),%rdi
call   1060 <perror@plt>
mov    0x2dca(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    -0x8(%rbp),%edi
call   1040 <write_to_server@plt>
mov    -0x8(%rbp),%edi
call   1030 <close@plt>
mov    0x2da4(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    0x2e5d(%rip),%rax
mov    (%rax),%edi
mov    0x2e5c(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1090 <socket@plt>
test   %eax,%eax
jns    119a <main+0x2a>
lea    0xe68(%rip),%rdi
jmp    11ce <main+0x5e>
mov    %eax,%ebx
lea    0xe6d(%rip),%rsi
mov    %rsp,%r14
mov    %r14,%rdi
mov    $0x15b3,%edx
call   1050 <init_sockaddr@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x4,%edx
call   1080 <connect@plt>
test   %rax,%rax
jns    11e1 <main+0x71>
lea    0xe4e(%rip),%rdi
call   1060 <perror@plt>
mov    0x2df6(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    %ebx,%edi
call   1040 <write_to_server@plt>
mov    %ebx,%edi
call   1030 <close@plt>
mov    0x2dd2(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32 }
%struct.sockaddr = type { i32 }
@PF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [16 x i8] c"socket (client)\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [12 x i8] c"www.gnu.org\00"
@.str.2 = [17 x i8] c"connect (client)\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca %struct.sockaddr_in
store i32 0, i32* %1
%4 = load i32, i32* @PF_INET
%5 = load i32, i32* @SOCK_STREAM
%6 = call i32 @socket(i32 %4, i32 %5, i32 0)
store i32 %6, i32* %2
%7 = load i32, i32* %2
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %13
9: ; preds = %0
%10 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%11 = load i32, i32* @EXIT_FAILURE
%12 = call i32 @exit(i32 %11)
unreachable
13: ; preds = %0
%14 = load i32, i32* %2
%15 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%16 = call i64 @connect(i32 %14, %struct.sockaddr* %15, i32 4)
%17 = icmp sgt i64 0, %16
br i1 %17, label %18, label %22
18: ; preds = %13
%19 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
%20 = load i32, i32* @EXIT_FAILURE
%21 = call i32 @exit(i32 %20)
unreachable
22: ; preds = %13
%23 = load i32, i32* %2
%24 = call i32 @write_to_server(i32 %23)
%25 = load i32, i32* %2
%26 = call i32 @close(i32 %25)
%27 = load i32, i32* @EXIT_SUCCESS
%28 = call i32 @exit(i32 %27)
unreachable
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32 }
%struct.sockaddr = type { i32 }
@PF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [16 x i8] c"socket (client)\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [12 x i8] c"www.gnu.org\00"
@.str.2 = [17 x i8] c"connect (client)\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca %struct.sockaddr_in
%2 = bitcast %struct.sockaddr_in* %1 to i8*
%3 = load i32, i32* @PF_INET
%4 = load i32, i32* @SOCK_STREAM
%5 = tail call i32 @socket(i32 %3, i32 %4, i32 0)
%6 = icmp slt i32 %5, 0
br i1 %6, label %7, label %11
7: ; preds = %0
%8 = tail call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%9 = load i32, i32* @EXIT_FAILURE
%10 = tail call i32 @exit(i32 %9)
unreachable
11: ; preds = %0
%12 = bitcast %struct.sockaddr_in* %1 to %struct.sockaddr*
%13 = call i64 @connect(i32 %5, %struct.sockaddr* %12, i32 4)
%14 = icmp slt i64 %13, 0
br i1 %14, label %15, label %19
15: ; preds = %11
%16 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
%17 = load i32, i32* @EXIT_FAILURE
%18 = call i32 @exit(i32 %17)
unreachable
19: ; preds = %11
%20 = call i32 @write_to_server(i32 %5)
%21 = call i32 @close(i32 %5)
%22 = load i32, i32* @EXIT_SUCCESS
%23 = call i32 @exit(i32 %22)
unreachable
}