#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 sin_port;
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_family;
};

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ INADDR_LOOPBACK;
int /*<<< orphan*/ SOCK_STREAM;
int accept(int, struct sockaddr_in *, int *);
int /*<<< orphan*/ bind(int, struct sockaddr_in *, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ htonl(int /*<<< orphan*/);
int /*<<< orphan*/ listen(int, int);
int /*<<< orphan*/ recv(int, char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ send(int, char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ shutdown(int, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int main() {
  int sock = socket(AF_INET, SOCK_STREAM, 0);
  struct sockaddr_in addr1;
  addr1.sin_family = AF_INET;
  addr1.sin_port = 44004;
  addr1.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
  bind(sock, &addr1, sizeof(struct sockaddr_in));
  struct sockaddr_in addr2;
  listen(sock, 1);
  int sockcl;
  int bu;
  sockcl = accept(sock, &addr2, &bu);
  char buf[12];
  recv(sockcl, buf, 12, NULL);
  send(sockcl, buf, 12, NULL);
  shutdown(sock, 2);
  close(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
xor    %edx,%edx
call   10b0 <socket@plt>
mov    %eax,-0x8(%rbp)
mov    0x2e26(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
movl   $0xabe4,-0x18(%rbp)
mov    0x2e0b(%rip),%rax
mov    (%rax),%edi
call   1060 <htonl@plt>
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    $0xc,%edx
call   1090 <bind@plt>
mov    -0x8(%rbp),%edi
mov    $0x1,%esi
call   1080 <listen@plt>
mov    -0x8(%rbp),%edi
lea    -0x28(%rbp),%rsi
lea    -0x30(%rbp),%rdx
call   10a0 <accept@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%edi
lea    -0x3c(%rbp),%rsi
mov    $0xc,%edx
xor    %eax,%eax
mov    %eax,%ecx
call   1030 <recv@plt>
mov    -0x2c(%rbp),%edi
lea    -0x3c(%rbp),%rsi
mov    $0xc,%edx
xor    %eax,%eax
mov    %eax,%ecx
call   1050 <send@plt>
mov    -0x8(%rbp),%edi
mov    $0x2,%esi
call   1040 <shutdown@plt>
mov    -0x8(%rbp),%edi
call   1070 <close@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x30,%rsp
mov    0x2e49(%rip),%rbp
mov    0x0(%rbp),%edi
mov    0x2e27(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10b0 <socket@plt>
mov    %eax,%ebx
mov    0x0(%rbp),%eax
mov    %eax,0x10(%rsp)
movl   $0xabe4,0x8(%rsp)
mov    0x2e16(%rip),%rax
mov    (%rax),%edi
call   1060 <htonl@plt>
mov    %eax,0xc(%rsp)
lea    0x8(%rsp),%rsi
mov    %ebx,%edi
mov    $0xc,%edx
call   1090 <bind@plt>
mov    %ebx,%edi
mov    $0x1,%esi
call   1080 <listen@plt>
lea    0x18(%rsp),%rsi
lea    0x14(%rsp),%rdx
mov    %ebx,%edi
call   10a0 <accept@plt>
mov    %eax,%ebp
lea    0x24(%rsp),%r14
mov    %eax,%edi
mov    %r14,%rsi
mov    $0xc,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %ebp,%edi
mov    %r14,%rsi
mov    $0xc,%edx
xor    %ecx,%ecx
call   1050 <send@plt>
mov    %ebx,%edi
mov    $0x2,%esi
call   1040 <shutdown@plt>
mov    %ebx,%edi
call   1070 <close@plt>
xor    %eax,%eax
add    $0x30,%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 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@INADDR_LOOPBACK = global i32 0
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 [12 x i8]
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* %3, i32 0, i32 2
store i32 %11, i32* %12
%13 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 0
store i32 44004, i32* %13
%14 = load i32, i32* @INADDR_LOOPBACK
%15 = call i32 @htonl(i32 %14)
%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 = load i32, i32* %2
%19 = call i32 @bind(i32 %18, %struct.sockaddr_in* %3, i32 12)
%20 = load i32, i32* %2
%21 = call i32 @listen(i32 %20, i32 1)
%22 = load i32, i32* %2
%23 = call i32 @accept(i32 %22, %struct.sockaddr_in* %4, i32* %6)
store i32 %23, i32* %5
%24 = load i32, i32* %5
%25 = getelementptr inbounds [12 x i8], [12 x i8]* %7, i64 0, i64 0
%26 = call i32 @recv(i32 %24, i8* %25, i32 12, i32* null)
%27 = load i32, i32* %5
%28 = getelementptr inbounds [12 x i8], [12 x i8]* %7, i64 0, i64 0
%29 = call i32 @send(i32 %27, i8* %28, i32 12, i32* null)
%30 = load i32, i32* %2
%31 = call i32 @shutdown(i32 %30, i32 2)
%32 = load i32, i32* %2
%33 = call i32 @close(i32 %32)
ret i32 0
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@INADDR_LOOPBACK = global i32 0
define i32 @main() {
%1 = alloca %struct.sockaddr_in
%2 = alloca %struct.sockaddr_in
%3 = alloca i32
%4 = alloca [12 x i8]
%5 = load i32, i32* @AF_INET
%6 = load i32, i32* @SOCK_STREAM
%7 = tail call i32 @socket(i32 %5, i32 %6, i32 0)
%8 = bitcast %struct.sockaddr_in* %1 to i8*
%9 = load i32, i32* @AF_INET
%10 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 2
store i32 %9, i32* %10
%11 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 0
store i32 44004, i32* %11
%12 = load i32, i32* @INADDR_LOOPBACK
%13 = tail call i32 @htonl(i32 %12)
%14 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 1, i32 0
store i32 %13, i32* %14
%15 = call i32 @bind(i32 %7, %struct.sockaddr_in* %1, i32 12)
%16 = bitcast %struct.sockaddr_in* %2 to i8*
%17 = call i32 @listen(i32 %7, i32 1)
%18 = bitcast i32* %3 to i8*
%19 = call i32 @accept(i32 %7, %struct.sockaddr_in* %2, i32* %3)
%20 = getelementptr inbounds [12 x i8], [12 x i8]* %4, i64 0, i64 0
%21 = call i32 @recv(i32 %19, i8* %20, i32 12, i32* null)
%22 = call i32 @send(i32 %19, i8* %20, i32 12, i32* null)
%23 = call i32 @shutdown(i32 %7, i32 2)
%24 = call i32 @close(i32 %7)
ret i32 0
}