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

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ LOG_CRIT;
int /*<<< orphan*/ SOCK_STREAM;
scalar_t__ bind(int, struct sockaddr *, int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ get_cur_time(char *);
int /*<<< orphan*/ htonl(int /*<<< orphan*/);
int /*<<< orphan*/ htons(int);
scalar_t__ listen(int, int);
int /*<<< orphan*/ log_printf(int /*<<< orphan*/, char *, int /*<<< orphan*/,
                              int /*<<< orphan*/);
int /*<<< orphan*/ memset(void *, int /*<<< orphan*/, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
int new_server(int port, int max_user) {
  struct sockaddr_in host_addr;
  int listen_sock = 0;
  char cur_time[1024];
  memset((void *)&host_addr, 0, sizeof(struct sockaddr_in));
  host_addr.sin_family = AF_INET;
  host_addr.sin_port = htons(5555);
  host_addr.sin_addr.s_addr = htonl(INADDR_ANY);
  listen_sock = socket(AF_INET, SOCK_STREAM, 0);
  if (listen_sock < 0) {
    log_printf(LOG_CRIT, "[%s]create socked failed, %s\n",
               get_cur_time(cur_time), strerror(errno));
    return -1;
  }
  if (bind(listen_sock, (struct sockaddr *)&host_addr, sizeof(host_addr)) < 0) {
    log_printf(LOG_CRIT, "[%s]bind socket failed, %s\n", get_cur_time(cur_time),
               strerror(errno));
    return -1;
  }
  if (listen(listen_sock, max_user) < 0) {
    log_printf(LOG_CRIT, "[%s]listen socket failed, %s\n",
               get_cur_time(cur_time), strerror(errno));
    return -1;
  }
  return listen_sock;
}


x86 assembly (clang, -O0):
<new_server>:
push   %rbp
mov    %rsp,%rbp
sub    $0x440,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x1c(%rbp)
lea    -0x18(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1050 <memset@plt>
mov    0x2e29(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
mov    $0x15b3,%edi
call   1030 <htons@plt>
mov    %eax,-0x14(%rbp)
mov    0x2e00(%rip),%rax
mov    (%rax),%edi
call   1040 <htonl@plt>
mov    %eax,-0x18(%rbp)
mov    0x2dff(%rip),%rax
mov    (%rax),%edi
mov    0x2dd6(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10b0 <socket@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    125d <new_server+0xcd>
mov    0x2dd1(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x428(%rbp)
lea    -0x420(%rbp),%rdi
call   1070 <get_cur_time@plt>
mov    %eax,-0x424(%rbp)
mov    0x2d90(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
mov    -0x428(%rbp),%edi
mov    -0x424(%rbp),%edx
mov    %eax,%ecx
lea    0xdb4(%rip),%rsi
call   1060 <log_printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    133d <new_server+0x1ad>
mov    -0x1c(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    $0xc,%edx
call   1090 <bind@plt>
cmp    $0x0,%rax
jge    12cd <new_server+0x13d>
mov    0x2d61(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x430(%rbp)
lea    -0x420(%rbp),%rdi
call   1070 <get_cur_time@plt>
mov    %eax,-0x42c(%rbp)
mov    0x2d20(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
mov    -0x430(%rbp),%edi
mov    -0x42c(%rbp),%edx
mov    %eax,%ecx
lea    0xd62(%rip),%rsi
call   1060 <log_printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    133d <new_server+0x1ad>
mov    -0x1c(%rbp),%edi
mov    -0xc(%rbp),%esi
call   1080 <listen@plt>
cmp    $0x0,%rax
jge    1337 <new_server+0x1a7>
mov    0x2cf7(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x438(%rbp)
lea    -0x420(%rbp),%rdi
call   1070 <get_cur_time@plt>
mov    %eax,-0x434(%rbp)
mov    0x2cb6(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
mov    -0x438(%rbp),%edi
mov    -0x434(%rbp),%edx
mov    %eax,%ecx
lea    0xd14(%rip),%rsi
call   1060 <log_printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    133d <new_server+0x1ad>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x440,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<new_server>:
push   %rbp
push   %r14
push   %rbx
sub    $0x410,%rsp
mov    %esi,%ebx
mov    %rsp,%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1050 <memset@plt>
mov    0x2e35(%rip),%rbp
mov    0x0(%rbp),%eax
mov    %eax,0x8(%rsp)
mov    $0x15b3,%edi
call   1030 <htons@plt>
mov    %eax,0x4(%rsp)
mov    0x2e09(%rip),%rax
mov    (%rax),%edi
call   1040 <htonl@plt>
mov    %eax,(%rsp)
mov    0x0(%rbp),%edi
mov    0x2de5(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10b0 <socket@plt>
test   %eax,%eax
js     121d <new_server+0x8d>
mov    %eax,%ebp
mov    %rsp,%rsi
mov    %eax,%edi
mov    $0xc,%edx
call   1090 <bind@plt>
test   %rax,%rax
js     1226 <new_server+0x96>
mov    %ebp,%edi
mov    %ebx,%esi
call   1080 <listen@plt>
test   %rax,%rax
jns    1263 <new_server+0xd3>
lea    0xe1f(%rip),%r14
jmp    122d <new_server+0x9d>
lea    0xddc(%rip),%r14
jmp    122d <new_server+0x9d>
lea    0xdf1(%rip),%r14
mov    0x2dac(%rip),%rax
mov    (%rax),%ebp
lea    0x10(%rsp),%rdi
call   1070 <get_cur_time@plt>
mov    %eax,%ebx
mov    0x2d77(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
mov    %ebp,%edi
mov    %r14,%rsi
mov    %ebx,%edx
mov    %eax,%ecx
call   1060 <log_printf@plt>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
add    $0x410,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@INADDR_ANY = global i32 0
@SOCK_STREAM = global i32 0
@LOG_CRIT = global i32 0
@.str = [30 x i8] c"[%s]create socked failed, %s\0A\00"
@errno = global i32 0
@.str.1 = [28 x i8] c"[%s]bind socket failed, %s\0A\00"
@.str.2 = [30 x i8] c"[%s]listen socket failed, %s\0A\00"
define i32 @new_server(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca %struct.sockaddr_in
%7 = alloca i32
%8 = alloca [1024 x i8]
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32 0, i32* %7
%9 = bitcast %struct.sockaddr_in* %6 to i8*
%10 = call i32 @memset(i8* %9, i32 0, i32 12)
%11 = load i32, i32* @AF_INET
%12 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 2
store i32 %11, i32* %12
%13 = call i32 @htons(i32 5555)
%14 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 1
store i32 %13, i32* %14
%15 = load i32, i32* @INADDR_ANY
%16 = call i32 @htonl(i32 %15)
%17 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 0
%18 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %17, i32 0, i32 0
store i32 %16, i32* %18
%19 = load i32, i32* @AF_INET
%20 = load i32, i32* @SOCK_STREAM
%21 = call i32 @socket(i32 %19, i32 %20, i32 0)
store i32 %21, i32* %7
%22 = load i32, i32* %7
%23 = icmp slt i32 %22, 0
br i1 %23, label %24, label %31
24: ; preds = %2
%25 = load i32, i32* @LOG_CRIT
%26 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%27 = call i32 @get_cur_time(i8* %26)
%28 = load i32, i32* @errno
%29 = call i32 @strerror(i32 %28)
%30 = call i32 @log_printf(i32 %25, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i32 %27, i32 %29)
store i32 -1, i32* %3
br label %57
31: ; preds = %2
%32 = load i32, i32* %7
%33 = bitcast %struct.sockaddr_in* %6 to %struct.sockaddr*
%34 = call i64 @bind(i32 %32, %struct.sockaddr* %33, i32 12)
%35 = icmp slt i64 %34, 0
br i1 %35, label %36, label %43
36: ; preds = %31
%37 = load i32, i32* @LOG_CRIT
%38 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%39 = call i32 @get_cur_time(i8* %38)
%40 = load i32, i32* @errno
%41 = call i32 @strerror(i32 %40)
%42 = call i32 @log_printf(i32 %37, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i32 %39, i32 %41)
store i32 -1, i32* %3
br label %57
43: ; preds = %31
%44 = load i32, i32* %7
%45 = load i32, i32* %5
%46 = call i64 @listen(i32 %44, i32 %45)
%47 = icmp slt i64 %46, 0
br i1 %47, label %48, label %55
48: ; preds = %43
%49 = load i32, i32* @LOG_CRIT
%50 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%51 = call i32 @get_cur_time(i8* %50)
%52 = load i32, i32* @errno
%53 = call i32 @strerror(i32 %52)
%54 = call i32 @log_printf(i32 %49, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i32 %51, i32 %53)
store i32 -1, i32* %3
br label %57
55: ; preds = %43
%56 = load i32, i32* %7
store i32 %56, i32* %3
br label %57
57: ; preds = %55, %48, %36, %24
%58 = load i32, i32* %3
ret i32 %58
}

LLVM IR (-O2):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@INADDR_ANY = global i32 0
@SOCK_STREAM = global i32 0
@LOG_CRIT = global i32 0
@.str = [30 x i8] c"[%s]create socked failed, %s\0A\00"
@errno = global i32 0
@.str.1 = [28 x i8] c"[%s]bind socket failed, %s\0A\00"
@.str.2 = [30 x i8] c"[%s]listen socket failed, %s\0A\00"
define i32 @new_server(i32 %0, i32 %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca [1024 x i8]
%5 = bitcast %struct.sockaddr_in* %3 to i8*
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%7 = call i32 @memset(i8* %5, i32 0, i32 12)
%8 = load i32, i32* @AF_INET
%9 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %8, i32* %9
%10 = call i32 @htons(i32 5555)
%11 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1
store i32 %10, i32* %11
%12 = load i32, i32* @INADDR_ANY
%13 = call i32 @htonl(i32 %12)
%14 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0, i32 0
store i32 %13, i32* %14
%15 = load i32, i32* @AF_INET
%16 = load i32, i32* @SOCK_STREAM
%17 = call i32 @socket(i32 %15, i32 %16, i32 0)
%18 = icmp slt i32 %17, 0
br i1 %18, label %26, label %19
19: ; preds = %2
%20 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%21 = call i64 @bind(i32 %17, %struct.sockaddr* %20, i32 12)
%22 = icmp slt i64 %21, 0
br i1 %22, label %26, label %23
23: ; preds = %19
%24 = call i64 @listen(i32 %17, i32 %1)
%25 = icmp slt i64 %24, 0
br i1 %25, label %26, label %33
26: ; preds = %23, %19, %2
%27 = phi i8* [ getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), %2 ], [ getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), %19 ], [ getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), %23 ]
%28 = load i32, i32* @LOG_CRIT
%29 = call i32 @get_cur_time(i8* %6)
%30 = load i32, i32* @errno
%31 = call i32 @strerror(i32 %30)
%32 = call i32 @log_printf(i32 %28, i8* %27, i32 %29, i32 %31)
br label %33
33: ; preds = %26, %23
%34 = phi i32 [ %17, %23 ], [ -1, %26 ]
ret i32 %34
}