#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 */
typedef struct TYPE_2__ TYPE_1__;

/* Type definitions */
struct TYPE_2__ {
  int /*<<< orphan*/ s_addr;
};
struct sockaddr_in {
  int /*<<< orphan*/ sin_zero;
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
typedef int socklen_t;
typedef int /*<<< orphan*/ serverAddr;
typedef int /*<<< orphan*/ clientAddr;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int accept(int, struct sockaddr *, int *);
int /*<<< orphan*/ bind(int, struct sockaddr *, int);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ inet_addr(char *);
scalar_t__ listen(int, int);
int /*<<< orphan*/ memset(int /*<<< orphan*/, char, int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ send(int, char *, int, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strcpy(char *, char *);
int main() {
  int welcomeSocket, newSocket;
  char buffer[1024];
  struct sockaddr_in serverAddr, clientAddr;
  socklen_t addr_size;
  welcomeSocket = socket(AF_INET, SOCK_STREAM, 0);
  serverAddr.sin_family = AF_INET;
  serverAddr.sin_port = htons(5555);
  serverAddr.sin_addr.s_addr = inet_addr("127.0.0.1");
  memset(serverAddr.sin_zero, '\0', sizeof serverAddr.sin_zero);
  bind(welcomeSocket, (struct sockaddr *)&serverAddr, sizeof(serverAddr));
  if (listen(welcomeSocket, 5) == 0)
    printf("Listening\n");
  else
    printf("Error\n");
  addr_size = sizeof(clientAddr);
  newSocket = accept(welcomeSocket, (struct sockaddr *)&clientAddr, &addr_size);
  strcpy(buffer, "Hello World\n");
  send(newSocket, buffer, 13, 0);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x440,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e2f(%rip),%rax
mov    (%rax),%edi
mov    0x2e16(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10c0 <socket@plt>
mov    %eax,-0x8(%rbp)
mov    0x2e13(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x414(%rbp)
mov    $0x15b3,%edi
call   1040 <htons@plt>
mov    %eax,-0x418(%rbp)
lea    0xe0c(%rip),%rdi
call   1080 <inet_addr@plt>
mov    %eax,-0x41c(%rbp)
mov    -0x420(%rbp),%edi
xor    %esi,%esi
mov    $0x4,%edx
call   1070 <memset@plt>
mov    -0x8(%rbp),%edi
lea    -0x420(%rbp),%rsi
mov    $0x10,%edx
call   10a0 <bind@plt>
mov    -0x8(%rbp),%edi
mov    $0x5,%esi
call   1090 <listen@plt>
cmp    $0x0,%rax
jne    124d <main+0xad>
lea    0xdc7(%rip),%rdi
call   1060 <printf@plt>
jmp    1259 <main+0xb9>
lea    0xdc1(%rip),%rdi
call   1060 <printf@plt>
movl   $0x10,-0x434(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x430(%rbp),%rsi
lea    -0x434(%rbp),%rdx
call   10b0 <accept@plt>
mov    %eax,-0xc(%rbp)
lea    -0x410(%rbp),%rdi
lea    0xd92(%rip),%rsi
call   1030 <strcpy@plt>
mov    -0xc(%rbp),%edi
lea    -0x410(%rbp),%rsi
mov    $0xd,%edx
xor    %ecx,%ecx
call   1050 <send@plt>
xor    %eax,%eax
add    $0x440,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x438,%rsp
mov    0x2e37(%rip),%r14
mov    (%r14),%edi
mov    0x2e1d(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10c0 <socket@plt>
mov    %eax,%ebx
mov    (%r14),%eax
mov    %eax,0x1c(%rsp)
mov    $0x15b3,%edi
call   1050 <htons@plt>
mov    %eax,0x18(%rsp)
lea    0xe1e(%rip),%rdi
call   1080 <inet_addr@plt>
mov    %eax,0x14(%rsp)
xor    %esi,%esi
mov    $0x4,%edx
call   1070 <memset@plt>
lea    0x10(%rsp),%rsi
mov    %ebx,%edi
mov    $0x10,%edx
call   10a0 <bind@plt>
mov    %ebx,%edi
mov    $0x5,%esi
call   1090 <listen@plt>
test   %rax,%rax
lea    0xdff(%rip),%rax
lea    0xdf2(%rip),%rdi
cmove  %rax,%rdi
call   1040 <puts@plt>
movl   $0x10,0xc(%rsp)
lea    0x20(%rsp),%rsi
lea    0xc(%rsp),%rdx
mov    %ebx,%edi
call   10b0 <accept@plt>
mov    %eax,%ebx
lea    0xdba(%rip),%rsi
lea    0x30(%rsp),%r14
mov    %r14,%rdi
call   1030 <strcpy@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0xd,%edx
xor    %ecx,%ecx
call   1060 <send@plt>
xor    %eax,%eax
add    $0x438,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [10 x i8] c"127.0.0.1\00"
@.str.1 = [11 x i8] c"Listening\0A\00"
@.str.2 = [7 x i8] c"Error\0A\00"
@.str.3 = [13 x i8] c"Hello World\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca [1024 x i8]
%5 = alloca %struct.sockaddr_in
%6 = alloca %struct.sockaddr_in
%7 = alloca i32
store i32 0, i32* %1
%8 = load i32, i32* @AF_INET
%9 = load i32, i32* @SOCK_STREAM
%10 = call i32 @socket(i32 %8, i32 %9, i32 0)
store i32 %10, i32* %2
%11 = load i32, i32* @AF_INET
%12 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i32 0, i32 3
store i32 %11, i32* %12
%13 = call i32 @htons(i32 5555)
%14 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i32 0, i32 2
store i32 %13, i32* %14
%15 = call i32 @inet_addr(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%16 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i32 0, i32 1
%17 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %16, i32 0, i32 0
store i32 %15, i32* %17
%18 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i32 0, i32 0
%19 = load i32, i32* %18
%20 = call i32 @memset(i32 %19, i8 signext 0, i32 4)
%21 = load i32, i32* %2
%22 = bitcast %struct.sockaddr_in* %5 to %struct.sockaddr*
%23 = call i32 @bind(i32 %21, %struct.sockaddr* %22, i32 16)
%24 = load i32, i32* %2
%25 = call i64 @listen(i32 %24, i32 5)
%26 = icmp eq i64 %25, 0
br i1 %26, label %27, label %29
27: ; preds = %0
%28 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
br label %31
29: ; preds = %0
%30 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
br label %31
31: ; preds = %29, %27
store i32 16, i32* %7
%32 = load i32, i32* %2
%33 = bitcast %struct.sockaddr_in* %6 to %struct.sockaddr*
%34 = call i32 @accept(i32 %32, %struct.sockaddr* %33, i32* %7)
store i32 %34, i32* %3
%35 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%36 = call i32 @strcpy(i8* %35, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
%37 = load i32, i32* %3
%38 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%39 = call i32 @send(i32 %37, i8* %38, i32 13, i32 0)
ret i32 0
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [10 x i8] c"127.0.0.1\00"
@.str.3 = [13 x i8] c"Hello World\0A\00"
@str = [6 x i8] c"Error\00"
@str.4 = [10 x i8] c"Listening\00"
define i32 @main() {
%1 = alloca [1024 x i8]
%2 = alloca %struct.sockaddr_in
%3 = alloca %struct.sockaddr_in
%4 = alloca i32
%5 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 0
%6 = bitcast %struct.sockaddr_in* %2 to i8*
%7 = bitcast %struct.sockaddr_in* %3 to i8*
%8 = bitcast i32* %4 to i8*
%9 = load i32, i32* @AF_INET
%10 = load i32, i32* @SOCK_STREAM
%11 = tail call i32 @socket(i32 %9, i32 %10, i32 0)
%12 = load i32, i32* @AF_INET
%13 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 3
store i32 %12, i32* %13
%14 = tail call i32 @htons(i32 5555)
%15 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 2
store i32 %14, i32* %15
%16 = tail call i32 @inet_addr(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%17 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 1, i32 0
store i32 %16, i32* %17
%18 = tail call i32 @memset(i32 undef, i8 signext 0, i32 4)
%19 = bitcast %struct.sockaddr_in* %2 to %struct.sockaddr*
%20 = call i32 @bind(i32 %11, %struct.sockaddr* %19, i32 16)
%21 = call i64 @listen(i32 %11, i32 5)
%22 = icmp eq i64 %21, 0
%23 = select i1 %22, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @str.4, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @str, i64 0, i64 0)
%24 = call i32 @puts(i8* dereferenceable(1) %23)
store i32 16, i32* %4
%25 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%26 = call i32 @accept(i32 %11, %struct.sockaddr* %25, i32* %4)
%27 = call i32 @strcpy(i8* %5, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
%28 = call i32 @send(i32 %26, i8* %5, i32 13, i32 0)
ret i32 0
}