#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*/ server_addr;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ IPPROTO_TCP;
int /*<<< orphan*/ PF_INET;
int /*<<< orphan*/ SOCK_STREAM;
scalar_t__ bind(int, struct sockaddr *, int);
int /*<<< orphan*/ die(char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, ...);
int /*<<< orphan*/ getdate(char *);
int /*<<< orphan*/ htonl(int /*<<< orphan*/);
int /*<<< orphan*/ htons(unsigned int);
scalar_t__ listen(int, unsigned int);
int /*<<< orphan*/ memset(struct sockaddr_in *, int /*<<< orphan*/, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ tm_thread(int, unsigned int);
void init_server_listen(unsigned int port, unsigned int max_client) {
  int serversock;
  struct sockaddr_in server_addr;
  char currtime[32];
  if ((serversock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0) {
    die("Failed to create socket");
  }
  memset(&server_addr, 0, sizeof(server_addr));
  server_addr.sin_family = AF_INET;
  server_addr.sin_addr.s_addr = htonl(INADDR_ANY);
  server_addr.sin_port = htons(port);
  if (bind(serversock, (struct sockaddr *)&server_addr, sizeof(server_addr)) <
      0) {
    die("Failed to bind the server socket");
  }
  if (listen(serversock, max_client) < 0) {
    die("Failed to listen on server socket");
  }
  getdate(currtime);
  fprintf(stdout, "[%s] Start server listening at port %d ...\n", currtime,
          port);
  fprintf(stdout, "[%s] Waiting client connection ...\n", currtime);
  tm_thread(serversock, max_client);
}


x86 assembly (clang, -O0):
<init_server_listen>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    0x2e0b(%rip),%rax
mov    (%rax),%edi
mov    0x2e0a(%rip),%rax
mov    (%rax),%esi
mov    0x2e11(%rip),%rax
mov    (%rax),%edx
call   10c0 <socket@plt>
mov    %eax,-0xc(%rbp)
cmp    $0x0,%eax
jge    11e6 <init_server_listen+0x46>
lea    0xe1f(%rip),%rdi
call   10a0 <die@plt>
lea    -0x18(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1050 <memset@plt>
mov    0x2deb(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
mov    0x2dd7(%rip),%rax
mov    (%rax),%edi
call   1040 <htonl@plt>
mov    %eax,-0x14(%rbp)
mov    -0x4(%rbp),%edi
call   1030 <htons@plt>
mov    %eax,-0x18(%rbp)
mov    -0xc(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    $0xc,%edx
call   1090 <bind@plt>
cmp    $0x0,%rax
jge    1245 <init_server_listen+0xa5>
lea    0xdd8(%rip),%rdi
call   10a0 <die@plt>
mov    -0xc(%rbp),%edi
mov    -0x8(%rbp),%esi
call   1080 <listen@plt>
cmp    $0x0,%rax
jge    1266 <init_server_listen+0xc6>
lea    0xdd8(%rip),%rdi
call   10a0 <die@plt>
lea    -0x40(%rbp),%rdi
call   1070 <getdate@plt>
mov    0x2d42(%rip),%rax
mov    (%rax),%edi
lea    -0x40(%rbp),%rdx
mov    -0x4(%rbp),%ecx
lea    0xdd5(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2d24(%rip),%rax
mov    (%rax),%edi
lea    -0x40(%rbp),%rdx
lea    0xde6(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0xc(%rbp),%edi
mov    -0x8(%rbp),%esi
call   10b0 <tm_thread@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<init_server_listen>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x30,%rsp
mov    %esi,%r14d
mov    %edi,%r15d
mov    0x2e07(%rip),%rax
mov    (%rax),%edi
mov    0x2e06(%rip),%rax
mov    (%rax),%esi
mov    0x2e0d(%rip),%rax
mov    (%rax),%edx
call   10c0 <socket@plt>
mov    %eax,%ebp
test   %eax,%eax
jns    11e4 <init_server_listen+0x44>
lea    0xe21(%rip),%rdi
call   10a0 <die@plt>
mov    %rsp,%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1050 <memset@plt>
mov    0x2deb(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x8(%rsp)
mov    0x2dd6(%rip),%rax
mov    (%rax),%edi
call   1040 <htonl@plt>
mov    %eax,0x4(%rsp)
mov    %r15d,%edi
call   1030 <htons@plt>
mov    %eax,(%rsp)
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0xc,%edx
call   1090 <bind@plt>
test   %rax,%rax
jns    1240 <init_server_listen+0xa0>
lea    0xddd(%rip),%rdi
call   10a0 <die@plt>
mov    %ebp,%edi
mov    %r14d,%esi
call   1080 <listen@plt>
test   %rax,%rax
jns    125b <init_server_listen+0xbb>
lea    0xde3(%rip),%rdi
call   10a0 <die@plt>
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
call   1070 <getdate@plt>
mov    0x2d49(%rip),%r12
mov    (%r12),%edi
lea    0xde1(%rip),%rsi
mov    %rbx,%rdx
mov    %r15d,%ecx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    (%r12),%edi
lea    0xdf5(%rip),%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    %ebp,%edi
mov    %r14d,%esi
call   10b0 <tm_thread@plt>
add    $0x30,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@PF_INET = global i32 0
@SOCK_STREAM = global i32 0
@IPPROTO_TCP = global i32 0
@.str = [24 x i8] c"Failed to create socket\00"
@AF_INET = global i32 0
@INADDR_ANY = global i32 0
@.str.1 = [33 x i8] c"Failed to bind the server socket\00"
@.str.2 = [34 x i8] c"Failed to listen on server socket\00"
@stdout = global i32 0
@.str.3 = [44 x i8] c"[%s] Start server listening at port %d ...\0A\00"
@.str.4 = [36 x i8] c"[%s] Waiting client connection ...\0A\00"
define void @init_server_listen(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca %struct.sockaddr_in
%7 = alloca [32 x i8]
store i32 %0, i32* %3
store i32 %1, i32* %4
%8 = load i32, i32* @PF_INET
%9 = load i32, i32* @SOCK_STREAM
%10 = load i32, i32* @IPPROTO_TCP
%11 = call i32 @socket(i32 %8, i32 %9, i32 %10)
store i32 %11, i32* %5
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %2
%14 = call i32 @die(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
br label %15
15: ; preds = %13, %2
%16 = call i32 @memset(%struct.sockaddr_in* %6, i32 0, i32 12)
%17 = load i32, i32* @AF_INET
%18 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 2
store i32 %17, i32* %18
%19 = load i32, i32* @INADDR_ANY
%20 = call i32 @htonl(i32 %19)
%21 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 1
%22 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %21, i32 0, i32 0
store i32 %20, i32* %22
%23 = load i32, i32* %3
%24 = call i32 @htons(i32 %23)
%25 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 0
store i32 %24, i32* %25
%26 = load i32, i32* %5
%27 = bitcast %struct.sockaddr_in* %6 to %struct.sockaddr*
%28 = call i64 @bind(i32 %26, %struct.sockaddr* %27, i32 12)
%29 = icmp slt i64 %28, 0
br i1 %29, label %30, label %32
30: ; preds = %15
%31 = call i32 @die(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0))
br label %32
32: ; preds = %30, %15
%33 = load i32, i32* %5
%34 = load i32, i32* %4
%35 = call i64 @listen(i32 %33, i32 %34)
%36 = icmp slt i64 %35, 0
br i1 %36, label %37, label %39
37: ; preds = %32
%38 = call i32 @die(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0))
br label %39
39: ; preds = %37, %32
%40 = getelementptr inbounds [32 x i8], [32 x i8]* %7, i64 0, i64 0
%41 = call i32 @getdate(i8* %40)
%42 = load i32, i32* @stdout
%43 = getelementptr inbounds [32 x i8], [32 x i8]* %7, i64 0, i64 0
%44 = load i32, i32* %3
%45 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %42, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.3, i64 0, i64 0), i8* %43, i32 %44)
%46 = load i32, i32* @stdout
%47 = getelementptr inbounds [32 x i8], [32 x i8]* %7, i64 0, i64 0
%48 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %46, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.4, i64 0, i64 0), i8* %47)
%49 = load i32, i32* %5
%50 = load i32, i32* %4
%51 = call i32 @tm_thread(i32 %49, i32 %50)
ret void
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@PF_INET = global i32 0
@SOCK_STREAM = global i32 0
@IPPROTO_TCP = global i32 0
@.str = [24 x i8] c"Failed to create socket\00"
@AF_INET = global i32 0
@INADDR_ANY = global i32 0
@.str.1 = [33 x i8] c"Failed to bind the server socket\00"
@.str.2 = [34 x i8] c"Failed to listen on server socket\00"
@stdout = global i32 0
@.str.3 = [44 x i8] c"[%s] Start server listening at port %d ...\0A\00"
@.str.4 = [36 x i8] c"[%s] Waiting client connection ...\0A\00"
define void @init_server_listen(i32 %0, i32 %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca [32 x i8]
%5 = bitcast %struct.sockaddr_in* %3 to i8*
%6 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 0
%7 = load i32, i32* @PF_INET
%8 = load i32, i32* @SOCK_STREAM
%9 = load i32, i32* @IPPROTO_TCP
%10 = tail call i32 @socket(i32 %7, i32 %8, i32 %9)
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %2
%13 = tail call i32 @die(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
br label %14
14: ; preds = %12, %2
%15 = call i32 @memset(%struct.sockaddr_in* %3, i32 0, i32 12)
%16 = load i32, i32* @AF_INET
%17 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 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* %3, i64 0, i32 1, i32 0
store i32 %19, i32* %20
%21 = call i32 @htons(i32 %0)
%22 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
store i32 %21, i32* %22
%23 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%24 = call i64 @bind(i32 %10, %struct.sockaddr* %23, i32 12)
%25 = icmp slt i64 %24, 0
br i1 %25, label %26, label %28
26: ; preds = %14
%27 = call i32 @die(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0))
br label %28
28: ; preds = %26, %14
%29 = call i64 @listen(i32 %10, i32 %1)
%30 = icmp slt i64 %29, 0
br i1 %30, label %31, label %33
31: ; preds = %28
%32 = call i32 @die(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0))
br label %33
33: ; preds = %31, %28
%34 = call i32 @getdate(i8* %6)
%35 = load i32, i32* @stdout
%36 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %35, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.3, i64 0, i64 0), i8* %6, i32 %0)
%37 = load i32, i32* @stdout
%38 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %37, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.4, i64 0, i64 0), i8* %6)
%39 = call i32 @tm_thread(i32 %10, i32 %1)
ret void
}