#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;
};
struct linger {
  int /*<<< orphan*/ member_1;
  int /*<<< orphan*/ member_0;
};

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ Log(char *);
int /*<<< orphan*/ PF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_LINGER;
scalar_t__ bind(int, struct sockaddr *, int);
int /*<<< orphan*/ htonl(int /*<<< orphan*/);
int /*<<< orphan*/ htons(int);
scalar_t__ listen(int, int);
scalar_t__ setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/, void const *,
                      int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int start_server() {
  Log("Starting server...");
  int sfd = socket(AF_INET, SOCK_STREAM, 0);
  if (sfd < 0)
    return -1;
  Log("- Socket creation");
  struct sockaddr_in sin;
  sin.sin_family = PF_INET;
  sin.sin_port = htons(42380);
  sin.sin_addr.s_addr = htonl(INADDR_ANY);
  if (bind(sfd, (struct sockaddr *)&sin, sizeof(struct sockaddr_in)) < 0)
    return -1;
  Log("- Socket binding");
  if (listen(sfd, 5) < 0)
    return -1;
  Log("- Socket in listening mode");
  struct linger l = {0, 0};
  if (setsockopt(sfd, SOL_SOCKET, SO_LINGER, (const void *)&l,
                 sizeof(struct linger)) < 0)
    return -1;
  Log("Server started.");
  return sfd;
}


x86 assembly (clang, -O0):
<start_server>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    0xe71(%rip),%rdi
call   1080 <Log@plt>
mov    0x2e45(%rip),%rax
mov    (%rax),%edi
mov    0x2e1c(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10a0 <socket@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    11c6 <start_server+0x46>
movl   $0xffffffff,-0x4(%rbp)
jmp    12ba <start_server+0x13a>
lea    0xe46(%rip),%rdi
call   1080 <Log@plt>
mov    0x2ddf(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
mov    $0xa58c,%edi
call   1040 <htons@plt>
mov    %eax,-0x14(%rbp)
mov    0x2dde(%rip),%rax
mov    (%rax),%edi
call   1050 <htonl@plt>
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    $0xc,%edx
call   1090 <bind@plt>
cmp    $0x0,%rax
jge    1223 <start_server+0xa3>
movl   $0xffffffff,-0x4(%rbp)
jmp    12ba <start_server+0x13a>
lea    0xdfb(%rip),%rdi
call   1080 <Log@plt>
mov    -0x8(%rbp),%edi
mov    $0x5,%esi
call   1070 <listen@plt>
cmp    $0x0,%rax
jge    1252 <start_server+0xd2>
movl   $0xffffffff,-0x4(%rbp)
jmp    12ba <start_server+0x13a>
lea    0xddd(%rip),%rdi
call   1080 <Log@plt>
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1060 <memset@plt>
mov    -0x8(%rbp),%edi
mov    0x2d70(%rip),%rax
mov    (%rax),%esi
mov    0x2d57(%rip),%rax
mov    (%rax),%edx
lea    -0x20(%rbp),%rcx
mov    $0x8,%r8d
call   1030 <setsockopt@plt>
cmp    $0x0,%rax
jge    12a8 <start_server+0x128>
movl   $0xffffffff,-0x4(%rbp)
jmp    12ba <start_server+0x13a>
lea    0xda2(%rip),%rdi
call   1080 <Log@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<start_server>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
lea    0xe83(%rip),%rdi
call   1070 <Log@plt>
mov    0x2e57(%rip),%rax
mov    (%rax),%edi
mov    0x2e2e(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1090 <socket@plt>
test   %eax,%eax
js     125f <start_server+0xef>
mov    %eax,%ebx
lea    0xe67(%rip),%rdi
call   1070 <Log@plt>
mov    0x2e00(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x8(%rsp)
mov    $0xa58c,%edi
call   1040 <htons@plt>
mov    %eax,0x4(%rsp)
mov    0x2dfd(%rip),%rax
mov    (%rax),%edi
call   1050 <htonl@plt>
mov    %eax,(%rsp)
mov    %rsp,%rsi
mov    %ebx,%edi
mov    $0xc,%edx
call   1080 <bind@plt>
mov    $0xffffffff,%ebp
test   %rax,%rax
js     126d <start_server+0xfd>
lea    0xe28(%rip),%rdi
call   1070 <Log@plt>
mov    %ebx,%edi
mov    $0x5,%esi
call   1060 <listen@plt>
test   %rax,%rax
js     126d <start_server+0xfd>
lea    0xe1c(%rip),%rdi
call   1070 <Log@plt>
movq   $0x0,0x10(%rsp)
mov    0x2db9(%rip),%rax
mov    (%rax),%esi
mov    0x2da0(%rip),%rax
mov    (%rax),%edx
lea    0x10(%rsp),%rcx
mov    %ebx,%edi
mov    $0x8,%r8d
call   1030 <setsockopt@plt>
test   %rax,%rax
js     1266 <start_server+0xf6>
lea    0xdf9(%rip),%rdi
call   1070 <Log@plt>
jmp    126b <start_server+0xfb>
mov    $0xffffffff,%ebp
jmp    126d <start_server+0xfd>
mov    $0xffffffff,%ebx
mov    %ebx,%ebp
mov    %ebp,%eax
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.linger = type { i32, i32 }
%struct.sockaddr = type { i32 }
@.str = [19 x i8] c"Starting server...\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [18 x i8] c"- Socket creation\00"
@PF_INET = global i32 0
@INADDR_ANY = global i32 0
@.str.2 = [17 x i8] c"- Socket binding\00"
@.str.3 = [27 x i8] c"- Socket in listening mode\00"
@SOL_SOCKET = global i32 0
@SO_LINGER = global i32 0
@.str.4 = [16 x i8] c"Server started.\00"
define i32 @start_server() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca %struct.sockaddr_in
%4 = alloca %struct.linger
%5 = call i32 @Log(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
%6 = load i32, i32* @AF_INET
%7 = load i32, i32* @SOCK_STREAM
%8 = call i32 @socket(i32 %6, i32 %7, i32 0)
store i32 %8, i32* %2
%9 = load i32, i32* %2
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %12
11: ; preds = %0
store i32 -1, i32* %1
br label %46
12: ; preds = %0
%13 = call i32 @Log(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
%14 = load i32, i32* @PF_INET
%15 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 2
store i32 %14, i32* %15
%16 = call i32 @htons(i32 42380)
%17 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 1
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, i32 0, i32 0
%21 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %20, i32 0, i32 0
store i32 %19, i32* %21
%22 = load i32, i32* %2
%23 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%24 = call i64 @bind(i32 %22, %struct.sockaddr* %23, i32 12)
%25 = icmp slt i64 %24, 0
br i1 %25, label %26, label %27
26: ; preds = %12
store i32 -1, i32* %1
br label %46
27: ; preds = %12
%28 = call i32 @Log(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
%29 = load i32, i32* %2
%30 = call i64 @listen(i32 %29, i32 5)
%31 = icmp slt i64 %30, 0
br i1 %31, label %32, label %33
32: ; preds = %27
store i32 -1, i32* %1
br label %46
33: ; preds = %27
%34 = call i32 @Log(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0))
%35 = bitcast %struct.linger* %4 to i8*
%36 = load i32, i32* %2
%37 = load i32, i32* @SOL_SOCKET
%38 = load i32, i32* @SO_LINGER
%39 = bitcast %struct.linger* %4 to i8*
%40 = call i64 @setsockopt(i32 %36, i32 %37, i32 %38, i8* %39, i32 8)
%41 = icmp slt i64 %40, 0
br i1 %41, label %42, label %43
42: ; preds = %33
store i32 -1, i32* %1
br label %46
43: ; preds = %33
%44 = call i32 @Log(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0))
%45 = load i32, i32* %2
store i32 %45, i32* %1
br label %46
46: ; preds = %43, %42, %32, %26, %11
%47 = load i32, i32* %1
ret i32 %47
}

LLVM IR (-O2):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [19 x i8] c"Starting server...\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [18 x i8] c"- Socket creation\00"
@PF_INET = global i32 0
@INADDR_ANY = global i32 0
@.str.2 = [17 x i8] c"- Socket binding\00"
@.str.3 = [27 x i8] c"- Socket in listening mode\00"
@SOL_SOCKET = global i32 0
@SO_LINGER = global i32 0
@.str.4 = [16 x i8] c"Server started.\00"
define i32 @start_server() {
%1 = alloca %struct.sockaddr_in
%2 = alloca i64
%3 = tail call i32 @Log(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
%4 = load i32, i32* @AF_INET
%5 = load i32, i32* @SOCK_STREAM
%6 = tail call i32 @socket(i32 %4, i32 %5, i32 0)
%7 = icmp slt i32 %6, 0
br i1 %7, label %38, label %8
8: ; preds = %0
%9 = tail call i32 @Log(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
%10 = bitcast %struct.sockaddr_in* %1 to i8*
%11 = load i32, i32* @PF_INET
%12 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 2
store i32 %11, i32* %12
%13 = tail call i32 @htons(i32 42380)
%14 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 1
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* %1, i64 0, i32 0, i32 0
store i32 %16, i32* %17
%18 = bitcast %struct.sockaddr_in* %1 to %struct.sockaddr*
%19 = call i64 @bind(i32 %6, %struct.sockaddr* %18, i32 12)
%20 = icmp slt i64 %19, 0
br i1 %20, label %36, label %21
21: ; preds = %8
%22 = call i32 @Log(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
%23 = call i64 @listen(i32 %6, i32 5)
%24 = icmp slt i64 %23, 0
br i1 %24, label %36, label %25
25: ; preds = %21
%26 = call i32 @Log(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0))
%27 = bitcast i64* %2 to i8*
store i64 0, i64* %2
%28 = load i32, i32* @SOL_SOCKET
%29 = load i32, i32* @SO_LINGER
%30 = call i64 @setsockopt(i32 %6, i32 %28, i32 %29, i8* %27, i32 8)
%31 = icmp slt i64 %30, 0
br i1 %31, label %34, label %32
32: ; preds = %25
%33 = call i32 @Log(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0))
br label %34
34: ; preds = %25, %32
%35 = phi i32 [ %6, %32 ], [ -1, %25 ]
br label %36
36: ; preds = %21, %8, %34
%37 = phi i32 [ %35, %34 ], [ -1, %8 ], [ -1, %21 ]
br label %38
38: ; preds = %0, %36
%39 = phi i32 [ %37, %36 ], [ -1, %0 ]
ret i32 %39
}