#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*/ socklen_t;
typedef int /*<<< orphan*/ address;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ SOCK_STREAM;
int accept(int, struct sockaddr *, int /*<<< orphan*/ *);
int /*<<< orphan*/ bind(int, struct sockaddr *, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ listen(int, int);
char *malloc(int);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ recv(int, char *, int, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ write(int, char *, int);
int main() {
  int create_socket, new_socket;
  socklen_t addrlen;
  int bufsize = 1024;
  char *buffer = malloc(bufsize);
  struct sockaddr_in address;
  create_socket = socket(AF_INET, SOCK_STREAM, 0);
  address.sin_family = AF_INET;
  address.sin_addr.s_addr = INADDR_ANY;
  address.sin_port = htons(15000);
  bind(create_socket, (struct sockaddr *)&address, sizeof(address));
  while (1) {
    listen(create_socket, 10);
    new_socket = accept(create_socket, (struct sockaddr *)&address, &addrlen);
    recv(new_socket, buffer, bufsize, 0);
    printf("%s\n", buffer);
    write(new_socket, "hello world\n", 12);
    close(new_socket);
  }
  close(create_socket);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x400,-0x14(%rbp)
mov    -0x14(%rbp),%edi
call   1080 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    0x2e1f(%rip),%rax
mov    (%rax),%edi
mov    0x2dfe(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10c0 <socket@plt>
mov    %eax,-0x8(%rbp)
mov    0x2e03(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    0x2def(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    $0x3a98,%edi
call   1050 <htons@plt>
mov    %eax,-0x30(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x30(%rbp),%rsi
mov    $0xc,%edx
call   10a0 <bind@plt>
mov    -0x8(%rbp),%edi
mov    $0xa,%esi
call   1090 <listen@plt>
mov    -0x8(%rbp),%edi
lea    -0x30(%rbp),%rsi
lea    -0x10(%rbp),%rdx
call   10b0 <accept@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%edi
mov    -0x20(%rbp),%rsi
mov    -0x14(%rbp),%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    -0x20(%rbp),%rsi
lea    0xdb0(%rip),%rdi
call   1060 <printf@plt>
mov    -0xc(%rbp),%edi
lea    0xda5(%rip),%rsi
mov    $0xc,%edx
call   1040 <write@plt>
mov    -0xc(%rbp),%edi
call   1070 <close@plt>
jmp    1214 <main+0x74>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    $0x400,%edi
call   1080 <malloc@plt>
mov    %rax,%rbx
mov    0x2e26(%rip),%r14
mov    (%r14),%edi
mov    0x2e04(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10c0 <socket@plt>
mov    %eax,%ebp
mov    (%r14),%eax
mov    %eax,0x10(%rsp)
mov    0x2dfb(%rip),%rax
mov    (%rax),%eax
mov    %eax,0xc(%rsp)
mov    $0x3a98,%edi
call   1050 <htons@plt>
mov    %eax,0x8(%rsp)
lea    0x8(%rsp),%rsi
mov    %ebp,%edi
mov    $0xc,%edx
call   10a0 <bind@plt>
lea    0x14(%rsp),%r15
lea    0xdea(%rip),%r12
lea    0xde7(%rip),%r13
nopl   (%rax)
mov    %ebp,%edi
mov    $0xa,%esi
call   1090 <listen@plt>
mov    %ebp,%edi
lea    0x8(%rsp),%rsi
mov    %r15,%rdx
call   10b0 <accept@plt>
mov    %eax,%r14d
mov    %eax,%edi
mov    %rbx,%rsi
mov    $0x400,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %r12,%rdi
mov    %rbx,%rsi
call   1060 <printf@plt>
mov    %r14d,%edi
mov    %r13,%rsi
mov    $0xc,%edx
call   1040 <write@plt>
mov    %r14d,%edi
call   1070 <close@plt>
jmp    1220 <main+0x80>

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
@INADDR_ANY = global i32 0
@.str = [4 x i8] c"%s\0A\00"
@.str.1 = [13 x i8] c"hello world\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca %struct.sockaddr_in
store i32 0, i32* %1
store i32 1024, i32* %5
%8 = load i32, i32* %5
%9 = call i8* @malloc(i32 %8)
store i8* %9, i8** %6
%10 = load i32, i32* @AF_INET
%11 = load i32, i32* @SOCK_STREAM
%12 = call i32 @socket(i32 %10, i32 %11, i32 0)
store i32 %12, i32* %2
%13 = load i32, i32* @AF_INET
%14 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 2
store i32 %13, i32* %14
%15 = load i32, i32* @INADDR_ANY
%16 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, 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 15000)
%19 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 0
store i32 %18, i32* %19
%20 = load i32, i32* %2
%21 = bitcast %struct.sockaddr_in* %7 to %struct.sockaddr*
%22 = call i32 @bind(i32 %20, %struct.sockaddr* %21, i32 12)
br label %23
23: ; preds = %0, %23
%24 = load i32, i32* %2
%25 = call i32 @listen(i32 %24, i32 10)
%26 = load i32, i32* %2
%27 = bitcast %struct.sockaddr_in* %7 to %struct.sockaddr*
%28 = call i32 @accept(i32 %26, %struct.sockaddr* %27, i32* %4)
store i32 %28, i32* %3
%29 = load i32, i32* %3
%30 = load i8*, i8** %6
%31 = load i32, i32* %5
%32 = call i32 @recv(i32 %29, i8* %30, i32 %31, i32 0)
%33 = load i8*, i8** %6
%34 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %33)
%35 = load i32, i32* %3
%36 = call i32 @write(i32 %35, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32 12)
%37 = load i32, i32* %3
%38 = call i32 @close(i32 %37)
br label %23
}

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
@INADDR_ANY = global i32 0
@.str = [4 x i8] c"%s\0A\00"
@.str.1 = [13 x i8] c"hello world\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.sockaddr_in
%3 = bitcast i32* %1 to i8*
%4 = tail call dereferenceable_or_null(1024) i8* @malloc(i32 1024)
%5 = bitcast %struct.sockaddr_in* %2 to i8*
%6 = load i32, i32* @AF_INET
%7 = load i32, i32* @SOCK_STREAM
%8 = tail call i32 @socket(i32 %6, i32 %7, i32 0)
%9 = load i32, i32* @AF_INET
%10 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 2
store i32 %9, i32* %10
%11 = load i32, i32* @INADDR_ANY
%12 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 1, i32 0
store i32 %11, i32* %12
%13 = tail call i32 @htons(i32 15000)
%14 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 0
store i32 %13, i32* %14
%15 = bitcast %struct.sockaddr_in* %2 to %struct.sockaddr*
%16 = call i32 @bind(i32 %8, %struct.sockaddr* %15, i32 12)
br label %17
17: ; preds = %17, %0
%18 = call i32 @listen(i32 %8, i32 10)
%19 = call i32 @accept(i32 %8, %struct.sockaddr* %15, i32* %1)
%20 = call i32 @recv(i32 %19, i8* %4, i32 1024, i32 0)
%21 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %4)
%22 = call i32 @write(i32 %19, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32 12)
%23 = call i32 @close(i32 %19)
br label %17
}