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

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ INADDR_ANY;
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*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fork();
int /*<<< orphan*/ go(int);
int /*<<< orphan*/ htonl(int /*<<< orphan*/);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ listen(int, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int main(int argc, char **argv) {
  int listenfd, connfd;
  pid_t childpid;
  socklen_t clilen;
  struct sockaddr_in cliaddr, servaddr;
  listenfd = socket(AF_INET, SOCK_STREAM, 0);
  bzero(&servaddr, sizeof(servaddr));
  servaddr.sin_family = AF_INET;
  servaddr.sin_addr.s_addr = htonl(INADDR_ANY);
  servaddr.sin_port = htons(2020);
  bind(listenfd, (struct sockaddr *)&servaddr, sizeof(servaddr));
  listen(listenfd, 1024);
  for (;;) {
    clilen = sizeof(cliaddr);
    connfd = accept(listenfd, (struct sockaddr *)&cliaddr, &clilen);
    if ((childpid = fork()) == 0) {
      close(listenfd);
      go(connfd);
      exit(0);
    }
    close(connfd);
  }
}


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    0x2e1b(%rip),%rax
mov    (%rax),%edi
mov    0x2dfa(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10d0 <socket@plt>
mov    %eax,-0x14(%rbp)
lea    -0x40(%rbp),%rdi
mov    $0xc,%esi
call   1090 <bzero@plt>
mov    0x2df1(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x38(%rbp)
mov    0x2ddd(%rip),%rax
mov    (%rax),%edi
call   1050 <htonl@plt>
mov    %eax,-0x3c(%rbp)
mov    $0x7e4,%edi
call   1040 <htons@plt>
mov    %eax,-0x40(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x40(%rbp),%rsi
mov    $0xc,%edx
call   1080 <bind@plt>
mov    -0x14(%rbp),%edi
mov    $0x400,%esi
call   1070 <listen@plt>
movl   $0xc,-0x20(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x30(%rbp),%rsi
lea    -0x20(%rbp),%rdx
call   10a0 <accept@plt>
mov    %eax,-0x18(%rbp)
mov    $0x0,%al
call   10c0 <fork@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
jne    127c <main+0xcc>
mov    -0x14(%rbp),%edi
call   1060 <close@plt>
mov    -0x18(%rbp),%edi
call   1030 <go@plt>
xor    %edi,%edi
call   10b0 <exit@plt>
mov    -0x18(%rbp),%edi
call   1060 <close@plt>
jmp    1238 <main+0x88>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x28,%rsp
mov    0x2e27(%rip),%rbp
mov    0x0(%rbp),%edi
mov    0x2e05(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10d0 <socket@plt>
mov    %eax,%r14d
lea    0x8(%rsp),%rbx
mov    %rbx,%rdi
mov    $0xc,%esi
call   1090 <bzero@plt>
mov    0x0(%rbp),%eax
mov    %eax,0x10(%rsp)
mov    0x2de9(%rip),%rax
mov    (%rax),%edi
call   1050 <htonl@plt>
mov    %eax,0xc(%rsp)
mov    $0x7e4,%edi
call   1040 <htons@plt>
mov    %eax,0x8(%rsp)
mov    %r14d,%edi
mov    %rbx,%rsi
mov    $0xc,%edx
call   1080 <bind@plt>
mov    %r14d,%edi
mov    $0x400,%esi
call   1070 <listen@plt>
movl   $0xc,0x4(%rsp)
lea    0x18(%rsp),%rsi
lea    0x4(%rsp),%rdx
mov    %r14d,%edi
call   10a0 <accept@plt>
mov    %eax,%ebp
xor    %eax,%eax
call   10c0 <fork@plt>
test   %eax,%eax
je     128a <main+0xda>
lea    0x18(%rsp),%r15
lea    0x4(%rsp),%rbx
xchg   %ax,%ax
mov    %ebp,%edi
call   1060 <close@plt>
movl   $0xc,0x4(%rsp)
mov    %r14d,%edi
mov    %r15,%rsi
mov    %rbx,%rdx
call   10a0 <accept@plt>
mov    %eax,%ebp
xor    %eax,%eax
call   10c0 <fork@plt>
test   %eax,%eax
jne    1260 <main+0xb0>
mov    %r14d,%edi
call   1060 <close@plt>
mov    %ebp,%edi
call   1030 <go@plt>
xor    %edi,%edi
call   10b0 <exit@plt>

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
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca %struct.sockaddr_in
%11 = alloca %struct.sockaddr_in
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = load i32, i32* @AF_INET
%13 = load i32, i32* @SOCK_STREAM
%14 = call i32 @socket(i32 %12, i32 %13, i32 0)
store i32 %14, i32* %6
%15 = call i32 @bzero(%struct.sockaddr_in* %11, i32 12)
%16 = load i32, i32* @AF_INET
%17 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %11, i32 0, i32 2
store i32 %16, i32* %17
%18 = load i32, i32* @INADDR_ANY
%19 = call i32 @htonl(i32 %18)
%20 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %11, i32 0, i32 1
%21 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %20, i32 0, i32 0
store i32 %19, i32* %21
%22 = call i32 @htons(i32 2020)
%23 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %11, i32 0, i32 0
store i32 %22, i32* %23
%24 = load i32, i32* %6
%25 = bitcast %struct.sockaddr_in* %11 to %struct.sockaddr*
%26 = call i32 @bind(i32 %24, %struct.sockaddr* %25, i32 12)
%27 = load i32, i32* %6
%28 = call i32 @listen(i32 %27, i32 1024)
br label %29
29: ; preds = %41, %2
store i32 12, i32* %9
%30 = load i32, i32* %6
%31 = bitcast %struct.sockaddr_in* %10 to %struct.sockaddr*
%32 = call i32 @accept(i32 %30, %struct.sockaddr* %31, i32* %9)
store i32 %32, i32* %7
%33 = call i32 (...) @fork()
store i32 %33, i32* %8
%34 = icmp eq i32 %33, 0
br i1 %34, label %35, label %41
35: ; preds = %29
%36 = load i32, i32* %6
%37 = call i32 @close(i32 %36)
%38 = load i32, i32* %7
%39 = call i32 @go(i32 %38)
%40 = call i32 @exit(i32 0)
unreachable
41: ; preds = %29
%42 = load i32, i32* %7
%43 = call i32 @close(i32 %42)
br label %29
}

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
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = alloca %struct.sockaddr_in
%5 = alloca %struct.sockaddr_in
%6 = bitcast i32* %3 to i8*
%7 = bitcast %struct.sockaddr_in* %4 to i8*
%8 = bitcast %struct.sockaddr_in* %5 to i8*
%9 = load i32, i32* @AF_INET
%10 = load i32, i32* @SOCK_STREAM
%11 = tail call i32 @socket(i32 %9, i32 %10, i32 0)
%12 = call i32 @bzero(%struct.sockaddr_in* %5, i32 12)
%13 = load i32, i32* @AF_INET
%14 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 2
store i32 %13, i32* %14
%15 = load i32, i32* @INADDR_ANY
%16 = tail call i32 @htonl(i32 %15)
%17 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 1, i32 0
store i32 %16, i32* %17
%18 = tail call i32 @htons(i32 2020)
%19 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 0
store i32 %18, i32* %19
%20 = bitcast %struct.sockaddr_in* %5 to %struct.sockaddr*
%21 = call i32 @bind(i32 %11, %struct.sockaddr* %20, i32 12)
%22 = call i32 @listen(i32 %11, i32 1024)
%23 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
store i32 12, i32* %3
%24 = call i32 @accept(i32 %11, %struct.sockaddr* %23, i32* %3)
%25 = call i32 (...) @fork()
%26 = icmp eq i32 %25, 0
br i1 %26, label %27, label %32
27: ; preds = %32, %2
%28 = phi i32 [ %24, %2 ], [ %35, %32 ]
%29 = call i32 @close(i32 %11)
%30 = call i32 @go(i32 %28)
%31 = call i32 @exit(i32 0)
unreachable
32: ; preds = %2, %32
%33 = phi i32 [ %35, %32 ], [ %24, %2 ]
%34 = call i32 @close(i32 %33)
store i32 12, i32* %3
%35 = call i32 @accept(i32 %11, %struct.sockaddr* %23, i32* %3)
%36 = call i32 (...) @fork()
%37 = icmp eq i32 %36, 0
br i1 %37, label %27, label %32
}