#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*/ serv_addr;
typedef int /*<<< orphan*/ fastopen_enable;
typedef int /*<<< orphan*/ cli_addr;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ IPPROTO_TCP;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ TCP_FASTOPEN;
int accept(int, struct sockaddr *, unsigned int *);
int /*<<< orphan*/ bind(int, struct sockaddr *, int);
int /*<<< orphan*/ bzero(char *, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ listen(int, int);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ read(int, char *, int);
int /*<<< orphan*/ setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/,
                              int *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ write(int, char *, int);
int main(int argc, char *argv[]) {
  int portno = 50007;
  int sockfd = socket(AF_INET, SOCK_STREAM, 0);
  struct sockaddr_in serv_addr;
  bzero((char *)&serv_addr, sizeof(serv_addr));
  serv_addr.sin_family = AF_INET;
  serv_addr.sin_addr.s_addr = INADDR_ANY;
  serv_addr.sin_port = htons(portno);
  bind(sockfd, (struct sockaddr *)&serv_addr, sizeof(serv_addr));
  listen(sockfd, 1);
  int fastopen_enable = 1;
  setsockopt(sockfd, IPPROTO_TCP, TCP_FASTOPEN, &fastopen_enable,
             sizeof(fastopen_enable));
  struct sockaddr_in cli_addr;
  unsigned int clilen = sizeof(cli_addr);
  char buffer[256];
  while (1) {
    int newsockfd = accept(sockfd, (struct sockaddr *)&cli_addr, &clilen);
    write(newsockfd, "abcdefg", 7);
    bzero(buffer, 256);
    read(newsockfd, buffer, 255);
    printf("Received message: %s\n", buffer);
    close(newsockfd);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x150,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0xc357,-0x14(%rbp)
mov    0x2e11(%rip),%rax
mov    (%rax),%edi
mov    0x2de8(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10d0 <socket@plt>
mov    %eax,-0x18(%rbp)
lea    -0x28(%rbp),%rdi
mov    $0xc,%esi
call   10b0 <bzero@plt>
mov    0x2de7(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    0x2dd3(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    -0x14(%rbp),%edi
call   1050 <htons@plt>
mov    %eax,-0x28(%rbp)
mov    -0x18(%rbp),%edi
lea    -0x28(%rbp),%rsi
mov    $0xc,%edx
call   10a0 <bind@plt>
mov    -0x18(%rbp),%edi
mov    $0x1,%esi
call   1090 <listen@plt>
movl   $0x1,-0x2c(%rbp)
mov    -0x18(%rbp),%edi
mov    0x2d8c(%rip),%rax
mov    (%rax),%esi
mov    0x2d6b(%rip),%rax
mov    (%rax),%edx
lea    -0x2c(%rbp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
movl   $0xc,-0x3c(%rbp)
mov    -0x18(%rbp),%edi
lea    -0x38(%rbp),%rsi
lea    -0x3c(%rbp),%rdx
call   10c0 <accept@plt>
mov    %eax,-0x144(%rbp)
mov    -0x144(%rbp),%edi
lea    0xd70(%rip),%rsi
mov    $0x7,%edx
call   1040 <write@plt>
lea    -0x140(%rbp),%rdi
mov    $0x100,%esi
call   10b0 <bzero@plt>
mov    -0x144(%rbp),%edi
lea    -0x140(%rbp),%rsi
mov    $0xff,%edx
call   1080 <read@plt>
lea    -0x140(%rbp),%rsi
lea    0xd38(%rip),%rdi
call   1060 <printf@plt>
mov    -0x144(%rbp),%edi
call   1070 <close@plt>
jmp    126d <main+0xbd>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x138,%rsp
mov    0x2e20(%rip),%r14
mov    (%r14),%edi
mov    0x2df6(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10d0 <socket@plt>
mov    %eax,%ebp
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0xc,%esi
call   10b0 <bzero@plt>
mov    (%r14),%eax
mov    %eax,0x18(%rsp)
mov    0x2de3(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x14(%rsp)
mov    $0xc357,%edi
call   1050 <htons@plt>
mov    %eax,0x10(%rsp)
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0xc,%edx
call   10a0 <bind@plt>
mov    %ebp,%edi
mov    $0x1,%esi
call   1090 <listen@plt>
movl   $0x1,0xc(%rsp)
mov    0x2d9d(%rip),%rax
mov    (%rax),%esi
mov    0x2d7c(%rip),%rax
mov    (%rax),%edx
lea    0xc(%rsp),%rcx
mov    %ebp,%edi
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
movl   $0xc,0x8(%rsp)
lea    0x8(%rsp),%r15
lea    0xd94(%rip),%r12
lea    0x30(%rsp),%rbx
lea    0xd90(%rip),%r13
nopl   0x0(%rax,%rax,1)
mov    %ebp,%edi
lea    0x20(%rsp),%rsi
mov    %r15,%rdx
call   10c0 <accept@plt>
mov    %eax,%r14d
mov    %eax,%edi
mov    %r12,%rsi
mov    $0x7,%edx
call   1040 <write@plt>
mov    %rbx,%rdi
mov    $0x100,%esi
call   10b0 <bzero@plt>
mov    %r14d,%edi
mov    %rbx,%rsi
mov    $0xff,%edx
call   1080 <read@plt>
mov    %r13,%rdi
mov    %rbx,%rsi
call   1060 <printf@plt>
mov    %r14d,%edi
call   1070 <close@plt>
jmp    1280 <main+0xd0>

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
@IPPROTO_TCP = global i32 0
@TCP_FASTOPEN = global i32 0
@.str = [8 x i8] c"abcdefg\00"
@.str.1 = [22 x i8] c"Received message: %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca %struct.sockaddr_in
%9 = alloca i32
%10 = alloca %struct.sockaddr_in
%11 = alloca i32
%12 = alloca [256 x i8]
%13 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 50007, i32* %6
%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* %7
%17 = bitcast %struct.sockaddr_in* %8 to i8*
%18 = call i32 @bzero(i8* %17, i32 12)
%19 = load i32, i32* @AF_INET
%20 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 2
store i32 %19, i32* %20
%21 = load i32, i32* @INADDR_ANY
%22 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 1
%23 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %22, i32 0, i32 0
store i32 %21, i32* %23
%24 = load i32, i32* %6
%25 = call i32 @htons(i32 %24)
%26 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 0
store i32 %25, i32* %26
%27 = load i32, i32* %7
%28 = bitcast %struct.sockaddr_in* %8 to %struct.sockaddr*
%29 = call i32 @bind(i32 %27, %struct.sockaddr* %28, i32 12)
%30 = load i32, i32* %7
%31 = call i32 @listen(i32 %30, i32 1)
store i32 1, i32* %9
%32 = load i32, i32* %7
%33 = load i32, i32* @IPPROTO_TCP
%34 = load i32, i32* @TCP_FASTOPEN
%35 = call i32 @setsockopt(i32 %32, i32 %33, i32 %34, i32* %9, i32 4)
store i32 12, i32* %11
br label %36
36: ; preds = %2, %36
%37 = load i32, i32* %7
%38 = bitcast %struct.sockaddr_in* %10 to %struct.sockaddr*
%39 = call i32 @accept(i32 %37, %struct.sockaddr* %38, i32* %11)
store i32 %39, i32* %13
%40 = load i32, i32* %13
%41 = call i32 @write(i32 %40, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 7)
%42 = getelementptr inbounds [256 x i8], [256 x i8]* %12, i64 0, i64 0
%43 = call i32 @bzero(i8* %42, i32 256)
%44 = load i32, i32* %13
%45 = getelementptr inbounds [256 x i8], [256 x i8]* %12, i64 0, i64 0
%46 = call i32 @read(i32 %44, i8* %45, i32 255)
%47 = getelementptr inbounds [256 x i8], [256 x i8]* %12, i64 0, i64 0
%48 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i8* %47)
%49 = load i32, i32* %13
%50 = call i32 @close(i32 %49)
br label %36
}

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
@IPPROTO_TCP = global i32 0
@TCP_FASTOPEN = global i32 0
@.str = [8 x i8] c"abcdefg\00"
@.str.1 = [22 x i8] c"Received message: %s\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca i32
%5 = alloca %struct.sockaddr_in
%6 = alloca i32
%7 = alloca [256 x i8]
%8 = load i32, i32* @AF_INET
%9 = load i32, i32* @SOCK_STREAM
%10 = tail call i32 @socket(i32 %8, i32 %9, i32 0)
%11 = bitcast %struct.sockaddr_in* %3 to i8*
%12 = call i32 @bzero(i8* %11, i32 12)
%13 = load i32, i32* @AF_INET
%14 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %13, i32* %14
%15 = load i32, i32* @INADDR_ANY
%16 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1, i32 0
store i32 %15, i32* %16
%17 = tail call i32 @htons(i32 50007)
%18 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
store i32 %17, i32* %18
%19 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%20 = call i32 @bind(i32 %10, %struct.sockaddr* %19, i32 12)
%21 = call i32 @listen(i32 %10, i32 1)
%22 = bitcast i32* %4 to i8*
store i32 1, i32* %4
%23 = load i32, i32* @IPPROTO_TCP
%24 = load i32, i32* @TCP_FASTOPEN
%25 = call i32 @setsockopt(i32 %10, i32 %23, i32 %24, i32* %4, i32 4)
%26 = bitcast %struct.sockaddr_in* %5 to i8*
%27 = bitcast i32* %6 to i8*
store i32 12, i32* %6
%28 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%29 = bitcast %struct.sockaddr_in* %5 to %struct.sockaddr*
br label %30
30: ; preds = %30, %2
%31 = call i32 @accept(i32 %10, %struct.sockaddr* %29, i32* %6)
%32 = call i32 @write(i32 %31, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 7)
%33 = call i32 @bzero(i8* %28, i32 256)
%34 = call i32 @read(i32 %31, i8* %28, i32 255)
%35 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i8* %28)
%36 = call i32 @close(i32 %31)
br label %30
}