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

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int Accept(int, struct sockaddr *, int *);
int /*<<< orphan*/ Bind(int, struct sockaddr *, int);
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ Listen(int, int);
int /*<<< orphan*/ SOCK_STREAM;
int Socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ handle_request(int);
int /*<<< orphan*/ htonl(int /*<<< orphan*/);
short htons(int);
int /*<<< orphan*/ memset(struct sockaddr_in *, int /*<<< orphan*/, int);
int main(int argc, char **argv) {
  int sockfd, clientfd;
  short port;
  struct sockaddr_in serv_addr, client_addr;
  socklen_t serv_len, client_len;
  port = htons(8080);
  sockfd = Socket(AF_INET, SOCK_STREAM, 0);
  memset(&serv_addr, 0, sizeof(serv_addr));
  serv_addr.sin_family = AF_INET;
  serv_addr.sin_port = port;
  serv_addr.sin_addr.s_addr = htonl(INADDR_ANY);
  Bind(sockfd, (struct sockaddr *)&serv_addr, sizeof(serv_addr));
  Listen(sockfd, 6);
  while (1) {
    client_len = sizeof(client_addr);
    clientfd = Accept(sockfd, (struct sockaddr *)&client_addr, &client_len);
    handle_request(clientfd);
    close(clientfd);
  }
  close(sockfd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x1f90,%edi
call   1040 <htons@plt>
mov    %ax,-0x1a(%rbp)
mov    0x2e2d(%rip),%rax
mov    (%rax),%edi
mov    0x2e0c(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10b0 <Socket@plt>
mov    %eax,-0x14(%rbp)
lea    -0x28(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1060 <memset@plt>
mov    0x2e01(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    -0x1a(%rbp),%ax
mov    %ax,-0x28(%rbp)
mov    0x2de5(%rip),%rax
mov    (%rax),%edi
call   1050 <htonl@plt>
mov    %eax,-0x24(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x28(%rbp),%rsi
mov    $0xc,%edx
call   10a0 <Bind@plt>
mov    -0x14(%rbp),%edi
mov    $0x6,%esi
call   1090 <Listen@plt>
movl   $0xc,-0x40(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x38(%rbp),%rsi
lea    -0x40(%rbp),%rdx
call   1030 <Accept@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%edi
call   1080 <handle_request@plt>
mov    -0x18(%rbp),%edi
call   1070 <close@plt>
jmp    1223 <main+0x93>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x28,%rsp
mov    $0x1f90,%edi
call   1040 <htons@plt>
mov    %eax,%ebp
mov    0x2e3b(%rip),%r15
mov    (%r15),%edi
mov    0x2e19(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10b0 <Socket@plt>
mov    %eax,%ebx
lea    0x8(%rsp),%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1060 <memset@plt>
mov    (%r15),%eax
mov    %eax,0x10(%rsp)
mov    %bp,0x8(%rsp)
mov    0x2df7(%rip),%rax
mov    (%rax),%edi
call   1050 <htonl@plt>
mov    %eax,0xc(%rsp)
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0xc,%edx
call   10a0 <Bind@plt>
mov    %ebx,%edi
mov    $0x6,%esi
call   1090 <Listen@plt>
lea    0x18(%rsp),%r14
lea    0x4(%rsp),%r15
nopl   0x0(%rax)
movl   $0xc,0x4(%rsp)
mov    %ebx,%edi
mov    %r14,%rsi
mov    %r15,%rdx
call   1030 <Accept@plt>
mov    %eax,%ebp
mov    %eax,%edi
call   1080 <handle_request@plt>
mov    %ebp,%edi
call   1070 <close@plt>
jmp    1220 <main+0x90>

LLVM IR (-O0):
%struct.sockaddr_in = type { i16, %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
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i16
%9 = alloca %struct.sockaddr_in
%10 = alloca %struct.sockaddr_in
%11 = alloca i32
%12 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%13 = call signext i16 @htons(i32 8080)
store i16 %13, i16* %8
%14 = load i32, i32* @AF_INET
%15 = load i32, i32* @SOCK_STREAM
%16 = call i32 @Socket(i32 %14, i32 %15, i32 0)
store i32 %16, i32* %6
%17 = call i32 @memset(%struct.sockaddr_in* %9, i32 0, i32 12)
%18 = load i32, i32* @AF_INET
%19 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 2
store i32 %18, i32* %19
%20 = load i16, i16* %8
%21 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 0
store i16 %20, i16* %21
%22 = load i32, i32* @INADDR_ANY
%23 = call i32 @htonl(i32 %22)
%24 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 1
%25 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %24, i32 0, i32 0
store i32 %23, i32* %25
%26 = load i32, i32* %6
%27 = bitcast %struct.sockaddr_in* %9 to %struct.sockaddr*
%28 = call i32 @Bind(i32 %26, %struct.sockaddr* %27, i32 12)
%29 = load i32, i32* %6
%30 = call i32 @Listen(i32 %29, i32 6)
br label %31
31: ; preds = %2, %31
store i32 12, i32* %12
%32 = load i32, i32* %6
%33 = bitcast %struct.sockaddr_in* %10 to %struct.sockaddr*
%34 = call i32 @Accept(i32 %32, %struct.sockaddr* %33, i32* %12)
store i32 %34, i32* %7
%35 = load i32, i32* %7
%36 = call i32 @handle_request(i32 %35)
%37 = load i32, i32* %7
%38 = call i32 @close(i32 %37)
br label %31
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i16, %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
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca %struct.sockaddr_in
%5 = alloca i32
%6 = bitcast %struct.sockaddr_in* %3 to i8*
%7 = bitcast %struct.sockaddr_in* %4 to i8*
%8 = bitcast i32* %5 to i8*
%9 = tail call signext i16 @htons(i32 8080)
%10 = load i32, i32* @AF_INET
%11 = load i32, i32* @SOCK_STREAM
%12 = tail call i32 @Socket(i32 %10, i32 %11, i32 0)
%13 = call i32 @memset(%struct.sockaddr_in* %3, i32 0, i32 12)
%14 = load i32, i32* @AF_INET
%15 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %14, i32* %15
%16 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
store i16 %9, i16* %16
%17 = load i32, i32* @INADDR_ANY
%18 = call i32 @htonl(i32 %17)
%19 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1, i32 0
store i32 %18, i32* %19
%20 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%21 = call i32 @Bind(i32 %12, %struct.sockaddr* %20, i32 12)
%22 = call i32 @Listen(i32 %12, i32 6)
%23 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
br label %24
24: ; preds = %24, %2
store i32 12, i32* %5
%25 = call i32 @Accept(i32 %12, %struct.sockaddr* %23, i32* %5)
%26 = call i32 @handle_request(i32 %25)
%27 = call i32 @close(i32 %25)
br label %24
}