#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*/ server_addr;
typedef int /*<<< orphan*/ client_addr;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ INADDR_ANY;
int INET_ADDRSTRLEN;
int /*<<< orphan*/ SOCK_STREAM;
int accept(int, struct sockaddr *, int *);
int /*<<< orphan*/ bind(int, struct sockaddr *, int);
int /*<<< orphan*/ bzero(struct sockaddr_in *, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ htonl(int /*<<< orphan*/);
int /*<<< orphan*/ htons(int);
char *inet_ntop(int /*<<< orphan*/, TYPE_1__ *, char *, int);
int /*<<< orphan*/ listen(int, int);
int ntohs(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int read(int, char *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ write(int, char *, int);
int main(void) {
  struct sockaddr_in server_addr, client_addr;
  socklen_t clientadrr_len;
  int listen_fd, conn_fd;
  char buf[1024];
  char str[INET_ADDRSTRLEN];
  int i, n;
  listen_fd = socket(AF_INET, SOCK_STREAM, 0);
  bzero(&server_addr, sizeof(server_addr));
  server_addr.sin_family = AF_INET;
  server_addr.sin_addr.s_addr = htonl(INADDR_ANY);
  server_addr.sin_port = htons(8087);
  bind(listen_fd, (struct sockaddr *)&server_addr, sizeof(server_addr));
  listen(listen_fd, 20);
  printf("accepting connection...\n");
  while (1) {
    clientadrr_len = sizeof(client_addr);
    conn_fd =
        accept(listen_fd, (struct sockaddr *)&client_addr, &clientadrr_len);
    n = read(conn_fd, buf, 1024);
    buf[n] = '\0';
    char *a = inet_ntop(AF_INET, &client_addr.sin_addr, str, sizeof(str));
    printf("recieved from = %s PORT =%d DATA= %s\n", a,
           ntohs(server_addr.sin_port), buf);
    write(conn_fd, buf, n);
    close(conn_fd);
  }
  printf("Hello world\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x470,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2ddf(%rip),%rax
mov    (%rax),%eax
mov    %rax,-0x460(%rbp)
mov    %rsp,%rcx
mov    %rcx,-0x438(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x458(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x440(%rbp)
mov    0x2dc3(%rip),%rax
mov    (%rax),%edi
mov    0x2da2(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10f0 <socket@plt>
mov    %eax,-0x28(%rbp)
lea    -0x10(%rbp),%rdi
mov    $0xc,%esi
call   10d0 <bzero@plt>
mov    0x2d99(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x8(%rbp)
mov    0x2d85(%rip),%rax
mov    (%rax),%edi
call   1070 <htonl@plt>
mov    %eax,-0xc(%rbp)
mov    $0x1f97,%edi
call   1050 <htons@plt>
mov    %eax,-0x10(%rbp)
mov    -0x28(%rbp),%edi
lea    -0x10(%rbp),%rsi
mov    $0xc,%edx
call   10c0 <bind@plt>
mov    -0x28(%rbp),%edi
mov    $0x14,%esi
call   10a0 <listen@plt>
lea    0xd69(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    12a3 <main+0xd3>
movl   $0xc,-0x24(%rbp)
mov    -0x28(%rbp),%edi
lea    -0x20(%rbp),%rsi
lea    -0x24(%rbp),%rdx
call   10e0 <accept@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%edi
lea    -0x430(%rbp),%rsi
mov    $0x400,%edx
call   1090 <read@plt>
mov    -0x458(%rbp),%rdx
mov    %eax,%ecx
mov    -0x460(%rbp),%rax
mov    %ecx,-0x448(%rbp)
movslq -0x448(%rbp),%rcx
movb   $0x0,-0x430(%rbp,%rcx,1)
mov    0x2ceb(%rip),%rcx
mov    (%rcx),%edi
lea    -0x20(%rbp),%rsi
add    $0x4,%rsi
mov    %eax,%ecx
call   1030 <inet_ntop@plt>
mov    %rax,-0x450(%rbp)
mov    -0x450(%rbp),%rax
mov    %rax,-0x468(%rbp)
mov    -0x10(%rbp),%edi
call   10b0 <ntohs@plt>
mov    -0x468(%rbp),%rsi
mov    %eax,%edx
lea    -0x430(%rbp),%rcx
lea    0xcd7(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x2c(%rbp),%edi
lea    -0x430(%rbp),%rsi
mov    -0x448(%rbp),%edx
call   1040 <write@plt>
mov    -0x2c(%rbp),%edi
call   1080 <close@plt>
jmp    129e <main+0xce>

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x438,%rsp
mov    0x2dcd(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rax,-0x48(%rbp)
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rcx
mov    %rcx,-0x40(%rbp)
mov    %rcx,%rsp
mov    0x2dcb(%rip),%r15
mov    (%r15),%edi
mov    0x2da9(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1100 <socket@plt>
mov    %eax,%ebx
lea    -0x38(%rbp),%r14
mov    %r14,%rdi
mov    $0xc,%esi
call   10e0 <bzero@plt>
mov    (%r15),%eax
mov    %eax,-0x30(%rbp)
mov    0x2d90(%rip),%rax
mov    (%rax),%edi
call   1080 <htonl@plt>
mov    %eax,-0x34(%rbp)
mov    $0x1f97,%edi
call   1060 <htons@plt>
mov    %eax,-0x38(%rbp)
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0xc,%edx
call   10d0 <bind@plt>
mov    %ebx,%edi
mov    $0x14,%esi
call   10b0 <listen@plt>
lea    0xd9d(%rip),%rdi
call   1040 <puts@plt>
lea    -0x460(%rbp),%r13
cs nopw 0x0(%rax,%rax,1)
nop
movl   $0xc,-0x2c(%rbp)
mov    %ebx,%edi
lea    -0x58(%rbp),%rsi
lea    -0x2c(%rbp),%rdx
call   10f0 <accept@plt>
mov    %eax,%r12d
mov    %eax,%edi
mov    %r13,%rsi
mov    $0x400,%edx
call   10a0 <read@plt>
movslq %eax,%r14
movb   $0x0,-0x460(%rbp,%r14,1)
mov    0x2d0d(%rip),%rax
mov    (%rax),%edi
lea    -0x54(%rbp),%rsi
mov    -0x40(%rbp),%rdx
mov    -0x48(%rbp),%rcx
call   1030 <inet_ntop@plt>
mov    %rax,%r15
mov    -0x38(%rbp),%edi
call   10c0 <ntohs@plt>
lea    0xd00(%rip),%rdi
mov    %r15,%rsi
mov    %eax,%edx
mov    %r13,%rcx
xor    %eax,%eax
call   1070 <printf@plt>
mov    %r12d,%edi
mov    %r13,%rsi
mov    %r14d,%edx
call   1050 <write@plt>
mov    %r12d,%edi
call   1090 <close@plt>
jmp    12a0 <main+0xc0>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@INET_ADDRSTRLEN = global i32 0
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@INADDR_ANY = global i32 0
@.str = [25 x i8] c"accepting connection...\0A\00"
@.str.1 = [38 x i8] c"recieved from = %s PORT =%d DATA= %s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.sockaddr_in
%3 = alloca %struct.sockaddr_in
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca [1024 x i8]
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i32
%11 = alloca i32
%12 = alloca i8*
store i32 0, i32* %1
%13 = load i32, i32* @INET_ADDRSTRLEN
%14 = zext i32 %13 to i64
%15 = call i8* @llvm.stacksave()
store i8* %15, i8** %8
%16 = alloca i8, i64 %14
store i64 %14, i64* %9
%17 = load i32, i32* @AF_INET
%18 = load i32, i32* @SOCK_STREAM
%19 = call i32 @socket(i32 %17, i32 %18, i32 0)
store i32 %19, i32* %5
%20 = call i32 @bzero(%struct.sockaddr_in* %2, i32 12)
%21 = load i32, i32* @AF_INET
%22 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i32 0, i32 2
store i32 %21, i32* %22
%23 = load i32, i32* @INADDR_ANY
%24 = call i32 @htonl(i32 %23)
%25 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i32 0, i32 1
%26 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %25, i32 0, i32 0
store i32 %24, i32* %26
%27 = call i32 @htons(i32 8087)
%28 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i32 0, i32 0
store i32 %27, i32* %28
%29 = load i32, i32* %5
%30 = bitcast %struct.sockaddr_in* %2 to %struct.sockaddr*
%31 = call i32 @bind(i32 %29, %struct.sockaddr* %30, i32 12)
%32 = load i32, i32* %5
%33 = call i32 @listen(i32 %32, i32 20)
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
br label %35
35: ; preds = %36, %0
br label %36
36: ; preds = %35
store i32 12, i32* %4
%37 = load i32, i32* %5
%38 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%39 = call i32 @accept(i32 %37, %struct.sockaddr* %38, i32* %4)
store i32 %39, i32* %6
%40 = load i32, i32* %6
%41 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%42 = call i32 @read(i32 %40, i8* %41, i32 1024)
store i32 %42, i32* %11
%43 = load i32, i32* %11
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 %44
store i8 0, i8* %45
%46 = load i32, i32* @AF_INET
%47 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 1
%48 = trunc i64 %14 to i32
%49 = call i8* @inet_ntop(i32 %46, %struct.TYPE_2__* %47, i8* %16, i32 %48)
store i8* %49, i8** %12
%50 = load i8*, i8** %12
%51 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i32 0, i32 0
%52 = load i32, i32* %51
%53 = call i32 @ntohs(i32 %52)
%54 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%55 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i8* %50, i32 %53, i8* %54)
%56 = load i32, i32* %6
%57 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%58 = load i32, i32* %11
%59 = call i32 @write(i32 %56, i8* %57, i32 %58)
%60 = load i32, i32* %6
%61 = call i32 @close(i32 %60)
br label %35
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@INET_ADDRSTRLEN = global i32 0
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@INADDR_ANY = global i32 0
@.str.1 = [38 x i8] c"recieved from = %s PORT =%d DATA= %s\0A\00"
@str = [24 x i8] c"accepting connection...\00"
define i32 @main() {
%1 = alloca %struct.sockaddr_in
%2 = alloca %struct.sockaddr_in
%3 = alloca i32
%4 = alloca [1024 x i8]
%5 = bitcast %struct.sockaddr_in* %1 to i8*
%6 = bitcast %struct.sockaddr_in* %2 to i8*
%7 = bitcast i32* %3 to i8*
%8 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%9 = load i32, i32* @INET_ADDRSTRLEN
%10 = zext i32 %9 to i64
%11 = alloca i8, i64 %10
%12 = load i32, i32* @AF_INET
%13 = load i32, i32* @SOCK_STREAM
%14 = tail call i32 @socket(i32 %12, i32 %13, i32 0)
%15 = call i32 @bzero(%struct.sockaddr_in* %1, i32 12)
%16 = load i32, i32* @AF_INET
%17 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 2
store i32 %16, i32* %17
%18 = load i32, i32* @INADDR_ANY
%19 = tail call i32 @htonl(i32 %18)
%20 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 1, i32 0
store i32 %19, i32* %20
%21 = tail call i32 @htons(i32 8087)
%22 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 0
store i32 %21, i32* %22
%23 = bitcast %struct.sockaddr_in* %1 to %struct.sockaddr*
%24 = call i32 @bind(i32 %14, %struct.sockaddr* %23, i32 12)
%25 = call i32 @listen(i32 %14, i32 20)
%26 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str, i64 0, i64 0))
%27 = bitcast %struct.sockaddr_in* %2 to %struct.sockaddr*
%28 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 1
br label %29
29: ; preds = %29, %0
store i32 12, i32* %3
%30 = call i32 @accept(i32 %14, %struct.sockaddr* %27, i32* %3)
%31 = call i32 @read(i32 %30, i8* %8, i32 1024)
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 %32
store i8 0, i8* %33
%34 = load i32, i32* @AF_INET
%35 = call i8* @inet_ntop(i32 %34, %struct.TYPE_2__* %28, i8* %11, i32 %9)
%36 = load i32, i32* %22
%37 = call i32 @ntohs(i32 %36)
%38 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i8* %35, i32 %37, i8* %8)
%39 = call i32 @write(i32 %30, i8* %8, i32 %31)
%40 = call i32 @close(i32 %30)
br label %29
}