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

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ PF_INET;
int /*<<< orphan*/ SOCK_STREAM;
scalar_t__ bind(int, struct sockaddr *, int);
int /*<<< orphan*/ check_err(int *, int, char *);
int /*<<< orphan*/ htonl(int /*<<< orphan*/);
int /*<<< orphan*/ htons(unsigned short);
scalar_t__ listen(int, int);
int /*<<< orphan*/ memset(struct sockaddr_in *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int start(int *port, int *listen_queue) {
  int server_port;
  struct sockaddr_in server_addr;
  if (!port || *port <= 0 || !listen_queue || *listen_queue <= 0) {
    perror("port or listen_queue are not found");
    return -1;
  }
  server_port = socket(PF_INET, SOCK_STREAM, 0);
  check_err(&server_port, -1, "Create socket failed.");
  memset(&server_addr, 0, sizeof(struct sockaddr_in));
  server_addr.sin_family = AF_INET;
  server_addr.sin_port = htons((unsigned short)*port);
  server_addr.sin_addr.s_addr = htonl(INADDR_ANY);
  if (bind(server_port, (struct sockaddr *)&server_addr, sizeof(server_addr)) <
      0) {
    perror("bind failed.");
    return -1;
  }
  if (listen(server_port, *listen_queue) < 0) {
    perror("listen port failed.");
    return -1;
  }
  return server_port;
}


x86 assembly (clang, -O0):
<start>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11c0 <start+0x40>
mov    -0x10(%rbp),%rax
cmpl   $0x0,(%rax)
jle    11c0 <start+0x40>
cmpq   $0x0,-0x18(%rbp)
je     11c0 <start+0x40>
mov    -0x18(%rbp),%rax
cmpl   $0x0,(%rax)
jg     11d8 <start+0x58>
lea    0xe39(%rip),%rdi
call   1090 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12b0 <start+0x130>
mov    0x2de9(%rip),%rax
mov    (%rax),%edi
mov    0x2de8(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10a0 <socket@plt>
mov    %eax,-0x1c(%rbp)
lea    -0x1c(%rbp),%rdi
mov    $0xffffffff,%esi
lea    0xe1f(%rip),%rdx
call   1070 <check_err@plt>
lea    -0x28(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1050 <memset@plt>
mov    0x2dc8(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
movzwl %ax,%edi
call   1030 <htons@plt>
mov    %eax,-0x24(%rbp)
mov    0x2da3(%rip),%rax
mov    (%rax),%edi
call   1040 <htonl@plt>
mov    %eax,-0x28(%rbp)
mov    -0x1c(%rbp),%edi
lea    -0x28(%rbp),%rsi
mov    $0xc,%edx
call   1080 <bind@plt>
cmp    $0x0,%rax
jge    127a <start+0xfa>
lea    0xdd0(%rip),%rdi
call   1090 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12b0 <start+0x130>
mov    -0x1c(%rbp),%edi
mov    -0x18(%rbp),%rax
mov    (%rax),%esi
call   1060 <listen@plt>
cmp    $0x0,%rax
jge    12aa <start+0x12a>
lea    0xdad(%rip),%rdi
call   1090 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12b0 <start+0x130>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<start>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
test   %rdi,%rdi
je     125a <start+0xda>
mov    %rsi,%rbx
test   %rsi,%rsi
je     125a <start+0xda>
mov    %rdi,%rbp
cmpl   $0x0,(%rdi)
jle    125a <start+0xda>
cmpl   $0x0,(%rbx)
jle    125a <start+0xda>
mov    0x2e0d(%rip),%rax
mov    (%rax),%edi
mov    0x2e0c(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10a0 <socket@plt>
mov    %eax,0x4(%rsp)
lea    0xe4b(%rip),%rdx
lea    0x4(%rsp),%rdi
mov    $0xffffffff,%r14d
mov    $0xffffffff,%esi
call   1070 <check_err@plt>
lea    0x8(%rsp),%r15
mov    %r15,%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1050 <memset@plt>
mov    0x2de0(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x10(%rsp)
movzwl 0x0(%rbp),%edi
call   1030 <htons@plt>
mov    %eax,0xc(%rsp)
mov    0x2dbe(%rip),%rax
mov    (%rax),%edi
call   1040 <htonl@plt>
mov    %eax,0x8(%rsp)
mov    0x4(%rsp),%edi
mov    %r15,%rsi
mov    $0xc,%edx
call   1080 <bind@plt>
test   %rax,%rax
js     1263 <start+0xe3>
mov    0x4(%rsp),%edi
mov    (%rbx),%esi
call   1060 <listen@plt>
test   %rax,%rax
js     1271 <start+0xf1>
mov    0x4(%rsp),%r14d
jmp    1283 <start+0x103>
lea    0xd9f(%rip),%rdi
jmp    1278 <start+0xf8>
lea    0xdcf(%rip),%rdi
call   1090 <perror@plt>
jmp    1283 <start+0x103>
lea    0xdce(%rip),%rdi
call   1090 <perror@plt>
mov    $0xffffffff,%r14d
mov    %r14d,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [35 x i8] c"port or listen_queue are not found\00"
@PF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [22 x i8] c"Create socket failed.\00"
@AF_INET = global i32 0
@INADDR_ANY = global i32 0
@.str.2 = [13 x i8] c"bind failed.\00"
@.str.3 = [20 x i8] c"listen port failed.\00"
define i32 @start(i32* %0, i32* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca i32
%7 = alloca %struct.sockaddr_in
store i32* %0, i32** %4
store i32* %1, i32** %5
%8 = load i32*, i32** %4
%9 = icmp ne i32* %8, null
br i1 %9, label %10, label %21
10: ; preds = %2
%11 = load i32*, i32** %4
%12 = load i32, i32* %11
%13 = icmp sle i32 %12, 0
br i1 %13, label %21, label %14
14: ; preds = %10
%15 = load i32*, i32** %5
%16 = icmp ne i32* %15, null
br i1 %16, label %17, label %21
17: ; preds = %14
%18 = load i32*, i32** %5
%19 = load i32, i32* %18
%20 = icmp sle i32 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %17, %14, %10, %2
%22 = call i32 @perror(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %56
23: ; preds = %17
%24 = load i32, i32* @PF_INET
%25 = load i32, i32* @SOCK_STREAM
%26 = call i32 @socket(i32 %24, i32 %25, i32 0)
store i32 %26, i32* %6
%27 = call i32 @check_err(i32* %6, i32 -1, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
%28 = call i32 @memset(%struct.sockaddr_in* %7, i32 0, i32 12)
%29 = load i32, i32* @AF_INET
%30 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 2
store i32 %29, i32* %30
%31 = load i32*, i32** %4
%32 = load i32, i32* %31
%33 = trunc i32 %32 to i16
%34 = call i32 @htons(i16 zeroext %33)
%35 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 1
store i32 %34, i32* %35
%36 = load i32, i32* @INADDR_ANY
%37 = call i32 @htonl(i32 %36)
%38 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 0
%39 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %38, i32 0, i32 0
store i32 %37, i32* %39
%40 = load i32, i32* %6
%41 = bitcast %struct.sockaddr_in* %7 to %struct.sockaddr*
%42 = call i64 @bind(i32 %40, %struct.sockaddr* %41, i32 12)
%43 = icmp slt i64 %42, 0
br i1 %43, label %44, label %46
44: ; preds = %23
%45 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %3
br label %56
46: ; preds = %23
%47 = load i32, i32* %6
%48 = load i32*, i32** %5
%49 = load i32, i32* %48
%50 = call i64 @listen(i32 %47, i32 %49)
%51 = icmp slt i64 %50, 0
br i1 %51, label %52, label %54
52: ; preds = %46
%53 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
store i32 -1, i32* %3
br label %56
54: ; preds = %46
%55 = load i32, i32* %6
store i32 %55, i32* %3
br label %56
56: ; preds = %54, %52, %44, %21
%57 = load i32, i32* %3
ret i32 %57
}

LLVM IR (-O2):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [35 x i8] c"port or listen_queue are not found\00"
@PF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [22 x i8] c"Create socket failed.\00"
@AF_INET = global i32 0
@INADDR_ANY = global i32 0
@.str.2 = [13 x i8] c"bind failed.\00"
@.str.3 = [20 x i8] c"listen port failed.\00"
define i32 @start(i32* %0, i32* %1) {
%3 = alloca i32
%4 = alloca %struct.sockaddr_in
%5 = bitcast i32* %3 to i8*
%6 = bitcast %struct.sockaddr_in* %4 to i8*
%7 = icmp eq i32* %0, null
br i1 %7, label %16, label %8
8: ; preds = %2
%9 = load i32, i32* %0
%10 = icmp sgt i32 %9, 0
%11 = icmp ne i32* %1, null
%12 = and i1 %11, %10
br i1 %12, label %13, label %16
13: ; preds = %8
%14 = load i32, i32* %1
%15 = icmp slt i32 %14, 1
br i1 %15, label %16, label %18
16: ; preds = %13, %8, %2
%17 = tail call i32 @perror(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0))
br label %48
18: ; preds = %13
%19 = load i32, i32* @PF_INET
%20 = load i32, i32* @SOCK_STREAM
%21 = tail call i32 @socket(i32 %19, i32 %20, i32 0)
store i32 %21, i32* %3
%22 = call i32 @check_err(i32* %3, i32 -1, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
%23 = call i32 @memset(%struct.sockaddr_in* %4, i32 0, i32 12)
%24 = load i32, i32* @AF_INET
%25 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 2
store i32 %24, i32* %25
%26 = load i32, i32* %0
%27 = trunc i32 %26 to i16
%28 = call i32 @htons(i16 zeroext %27)
%29 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 1
store i32 %28, i32* %29
%30 = load i32, i32* @INADDR_ANY
%31 = call i32 @htonl(i32 %30)
%32 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 0, i32 0
store i32 %31, i32* %32
%33 = load i32, i32* %3
%34 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%35 = call i64 @bind(i32 %33, %struct.sockaddr* %34, i32 12)
%36 = icmp slt i64 %35, 0
br i1 %36, label %37, label %39
37: ; preds = %18
%38 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
br label %48
39: ; preds = %18
%40 = load i32, i32* %3
%41 = load i32, i32* %1
%42 = call i64 @listen(i32 %40, i32 %41)
%43 = icmp slt i64 %42, 0
br i1 %43, label %44, label %46
44: ; preds = %39
%45 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
br label %48
46: ; preds = %39
%47 = load i32, i32* %3
br label %48
48: ; preds = %46, %44, %37, %16
%49 = phi i32 [ -1, %16 ], [ -1, %37 ], [ -1, %44 ], [ %47, %46 ]
ret i32 %49
}