#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_port;
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ str;
typedef int socklen_t;
typedef int /*<<< orphan*/ serv_addr;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ IPPROTO_TCP;
int /*<<< orphan*/ SOCK_STREAM;
int accept(int, struct sockaddr *, int *);
int /*<<< orphan*/ bind(int, struct sockaddr *, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ inet_addr(char *);
int /*<<< orphan*/ listen(int, int);
int /*<<< orphan*/ memset(struct sockaddr_in *, int /*<<< orphan*/, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ write(int, char *, int);
int main(void) {
  int serv_sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
  struct sockaddr_in serv_addr;
  memset(&serv_addr, 0, sizeof(serv_addr));
  serv_addr.sin_family = AF_INET;
  serv_addr.sin_addr.s_addr = inet_addr("127.0.0.1");
  serv_addr.sin_port = htons(1234);
  bind(serv_sock, (struct sockaddr *)&serv_addr, sizeof(serv_addr));
  listen(serv_sock, 20);
  struct sockaddr_in clnt_addr;
  socklen_t clnt_addr_size = sizeof(struct sockaddr_in);
  int clnt_sock =
      accept(serv_sock, (struct sockaddr *)&clnt_addr, &clnt_addr_size);
  char str[] = "Hello World!\n";
  write(clnt_sock, str, sizeof(str));
  close(clnt_sock);
  close(serv_sock);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e42(%rip),%rax
mov    (%rax),%edi
mov    0x2e21(%rip),%rax
mov    (%rax),%esi
mov    0x2e28(%rip),%rax
mov    (%rax),%edx
call   10b0 <socket@plt>
mov    %eax,-0x8(%rbp)
lea    -0x18(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1050 <memset@plt>
mov    0x2e0f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
lea    0xe1b(%rip),%rdi
call   1070 <inet_addr@plt>
mov    %eax,-0x14(%rbp)
mov    $0x4d2,%edi
call   1040 <htons@plt>
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    $0xc,%edx
call   1090 <bind@plt>
mov    -0x8(%rbp),%edi
mov    $0x14,%esi
call   1080 <listen@plt>
movl   $0xc,-0x2c(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x28(%rbp),%rsi
lea    -0x2c(%rbp),%rdx
call   10a0 <accept@plt>
mov    %eax,-0x30(%rbp)
mov    0xdd1(%rip),%rax
mov    %rax,-0x3e(%rbp)
mov    0xdcf(%rip),%eax
mov    %eax,-0x36(%rbp)
mov    0xdc9(%rip),%ax
mov    %ax,-0x32(%rbp)
mov    -0x30(%rbp),%edi
lea    -0x3e(%rbp),%rsi
mov    $0xe,%edx
call   1030 <write@plt>
mov    -0x30(%rbp),%edi
call   1060 <close@plt>
mov    -0x8(%rbp),%edi
call   1060 <close@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x40,%rsp
mov    0x2e49(%rip),%rbp
mov    0x0(%rbp),%edi
mov    0x2e27(%rip),%rax
mov    (%rax),%esi
mov    0x2e2e(%rip),%rax
mov    (%rax),%edx
call   10b0 <socket@plt>
mov    %eax,%ebx
lea    0x10(%rsp),%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1050 <memset@plt>
mov    0x0(%rbp),%eax
mov    %eax,0x18(%rsp)
lea    0xe23(%rip),%rdi
call   1070 <inet_addr@plt>
mov    %eax,0x14(%rsp)
mov    $0x4d2,%edi
call   1040 <htons@plt>
mov    %eax,0x10(%rsp)
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0xc,%edx
call   1090 <bind@plt>
mov    %ebx,%edi
mov    $0x14,%esi
call   1080 <listen@plt>
movl   $0xc,0xc(%rsp)
lea    0x30(%rsp),%rsi
lea    0xc(%rsp),%rdx
mov    %ebx,%edi
call   10a0 <accept@plt>
mov    %eax,%ebp
movabs $0xa21646c726f57,%rax
mov    %rax,0x26(%rsp)
movabs $0x6f57206f6c6c6548,%rax
20 57 6f
mov    %rax,0x20(%rsp)
lea    0x20(%rsp),%rsi
mov    %ebp,%edi
mov    $0xe,%edx
call   1030 <write@plt>
mov    %ebp,%edi
call   1060 <close@plt>
mov    %ebx,%edi
call   1060 <close@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@IPPROTO_TCP = global i32 0
@.str = [10 x i8] c"127.0.0.1\00"
@__const.main.str = [14 x i8] c"Hello World!\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca %struct.sockaddr_in
%4 = alloca %struct.sockaddr_in
%5 = alloca i32
%6 = alloca i32
%7 = alloca [14 x i8]
store i32 0, i32* %1
%8 = load i32, i32* @AF_INET
%9 = load i32, i32* @SOCK_STREAM
%10 = load i32, i32* @IPPROTO_TCP
%11 = call i32 @socket(i32 %8, i32 %9, i32 %10)
store i32 %11, i32* %2
%12 = call i32 @memset(%struct.sockaddr_in* %3, i32 0, i32 12)
%13 = load i32, i32* @AF_INET
%14 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, 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* %3, i32 0, i32 1
%17 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %16, i32 0, i32 0
store i32 %15, i32* %17
%18 = call i32 @htons(i32 1234)
%19 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 0
store i32 %18, i32* %19
%20 = load i32, i32* %2
%21 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%22 = call i32 @bind(i32 %20, %struct.sockaddr* %21, i32 12)
%23 = load i32, i32* %2
%24 = call i32 @listen(i32 %23, i32 20)
store i32 12, i32* %5
%25 = load i32, i32* %2
%26 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%27 = call i32 @accept(i32 %25, %struct.sockaddr* %26, i32* %5)
store i32 %27, i32* %6
%28 = bitcast [14 x i8]* %7 to i8*
%29 = load i32, i32* %6
%30 = getelementptr inbounds [14 x i8], [14 x i8]* %7, i64 0, i64 0
%31 = call i32 @write(i32 %29, i8* %30, i32 14)
%32 = load i32, i32* %6
%33 = call i32 @close(i32 %32)
%34 = load i32, i32* %2
%35 = call i32 @close(i32 %34)
ret i32 0
}

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