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

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ EXIT_SUCCESS;
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ IPPROTO_TCP;
int /*<<< orphan*/ LOG_ERR;
int /*<<< orphan*/ SOCK_STREAM;
int accept(int, int /*<<< orphan*/ *, int /*<<< orphan*/ *);
scalar_t__ accept_client(int);
scalar_t__ bind(int, struct sockaddr const *, int);
scalar_t__ daemonize();
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ htons(int);
scalar_t__ listen(int, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
int /*<<< orphan*/ syslog(int /*<<< orphan*/, char *, int /*<<< orphan*/);
int main(void) {
  if (daemonize() < 0) {
    exit(EXIT_FAILURE);
  }
  int sockfd;
  if ((sockfd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0) {
    syslog(LOG_ERR, "socket(2) error when creating main server socket: %s\n",
           strerror(errno));
    exit(EXIT_FAILURE);
  }
  struct sockaddr_in sockaddr;
  sockaddr.sin_family = AF_INET;
  sockaddr.sin_port = htons(3000);
  sockaddr.sin_addr.s_addr = INADDR_ANY;
  if (bind(sockfd, (const struct sockaddr *)&sockaddr, sizeof(sockaddr)) < 0) {
    syslog(LOG_ERR, "bind(2) error on main socket: %s\n", strerror(errno));
    exit(EXIT_FAILURE);
  }
  if (listen(sockfd, 10) < 0) {
    syslog(LOG_ERR, "listen(2) error on main socket: %s\n", strerror(errno));
    exit(EXIT_FAILURE);
  }
  int clientfd;
  while ((clientfd = accept(sockfd, NULL, NULL)) >= 0) {
    if (accept_client(clientfd) < 0) {
      syslog(LOG_ERR, "Error accepting client: %s\n", strerror(errno));
    }
  }
  if (clientfd < 0) {
    syslog(LOG_ERR, "accept(2) error: %s\n", strerror(errno));
    exit(EXIT_FAILURE);
  }
  exit(EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1040 <daemonize@plt>
cmp    $0x0,%rax
jge    11ce <main+0x2e>
mov    0x2df1(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
mov    0x2e13(%rip),%rax
mov    (%rax),%edi
mov    0x2dea(%rip),%rax
mov    (%rax),%esi
mov    0x2df1(%rip),%rax
mov    (%rax),%edx
call   10c0 <socket@plt>
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
jge    1233 <main+0x93>
mov    0x2d9f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    0x2db3(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
mov    -0x20(%rbp),%edi
mov    %eax,%edx
lea    0xde0(%rip),%rsi
call   1060 <syslog@plt>
mov    0x2d8c(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
mov    0x2dae(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
mov    $0xbb8,%edi
call   1050 <htons@plt>
mov    %eax,-0x14(%rbp)
mov    0x2d8d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    $0xc,%edx
call   1080 <bind@plt>
cmp    $0x0,%rax
jge    12ac <main+0x10c>
mov    0x2d26(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    0x2d3a(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
mov    -0x24(%rbp),%edi
mov    %eax,%edx
lea    0xd9d(%rip),%rsi
call   1060 <syslog@plt>
mov    0x2d13(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
mov    -0x8(%rbp),%edi
mov    $0xa,%esi
call   1070 <listen@plt>
cmp    $0x0,%rax
jge    12fc <main+0x15c>
mov    0x2cd6(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    0x2cea(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
mov    -0x28(%rbp),%edi
mov    %eax,%edx
lea    0xd6f(%rip),%rsi
call   1060 <syslog@plt>
mov    0x2cc3(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
jmp    1301 <main+0x161>
mov    -0x8(%rbp),%edi
xor    %eax,%eax
mov    %eax,%edx
mov    %rdx,%rsi
call   1090 <accept@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
jl     135e <main+0x1be>
mov    -0x1c(%rbp),%edi
call   1030 <accept_client@plt>
cmp    $0x0,%rax
jge    1359 <main+0x1b9>
mov    0x2c6b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    0x2c7f(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
mov    -0x2c(%rbp),%edi
mov    %eax,%edx
lea    0xd28(%rip),%rsi
call   1060 <syslog@plt>
jmp    1301 <main+0x161>
cmpl   $0x0,-0x1c(%rbp)
jge    13a1 <main+0x201>
mov    0x2c31(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
mov    0x2c45(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
mov    -0x30(%rbp),%edi
mov    %eax,%edx
lea    0xd0a(%rip),%rsi
call   1060 <syslog@plt>
mov    0x2c1e(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
mov    0x2c08(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
xor    %eax,%eax
call   1040 <daemonize@plt>
test   %rax,%rax
js     131c <main+0x17c>
mov    0x2e25(%rip),%rbp
mov    0x0(%rbp),%edi
mov    0x2dfb(%rip),%rax
mov    (%rax),%esi
mov    0x2e02(%rip),%rax
mov    (%rax),%edx
call   10c0 <socket@plt>
test   %eax,%eax
jns    1204 <main+0x64>
mov    0x2dc0(%rip),%rax
mov    (%rax),%ebx
mov    0x2dcf(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
lea    0xe01(%rip),%rsi
jmp    1313 <main+0x173>
mov    %eax,%ebx
mov    0x0(%rbp),%eax
mov    %eax,0x8(%rsp)
mov    $0xbb8,%edi
call   1050 <htons@plt>
mov    %eax,0x4(%rsp)
mov    0x2dbe(%rip),%rax
mov    (%rax),%eax
mov    %eax,(%rsp)
mov    %rsp,%rsi
mov    %ebx,%edi
mov    $0xc,%edx
call   1080 <bind@plt>
test   %rax,%rax
jns    125e <main+0xbe>
mov    0x2d66(%rip),%rax
mov    (%rax),%ebx
mov    0x2d75(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
lea    0xddd(%rip),%rsi
jmp    1313 <main+0x173>
mov    %ebx,%edi
mov    $0xa,%esi
call   1070 <listen@plt>
test   %rax,%rax
jns    1292 <main+0xf2>
mov    0x2d32(%rip),%rax
mov    (%rax),%ebx
mov    0x2d41(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
lea    0xdcb(%rip),%rsi
jmp    1313 <main+0x173>
mov    %ebx,%edi
xor    %esi,%esi
xor    %edx,%edx
call   1090 <accept@plt>
test   %eax,%eax
js     12f5 <main+0x155>
mov    0x2d00(%rip),%r15
mov    0x2d11(%rip),%r12
lea    0xdc6(%rip),%r14
jmp    12cf <main+0x12f>
nopl   0x0(%rax,%rax,1)
mov    %ebx,%edi
xor    %esi,%esi
xor    %edx,%edx
call   1090 <accept@plt>
test   %eax,%eax
js     12f5 <main+0x155>
mov    %eax,%edi
call   1030 <accept_client@plt>
test   %rax,%rax
jns    12c0 <main+0x120>
mov    (%r15),%ebp
mov    (%r12),%edi
call   10b0 <strerror@plt>
mov    %ebp,%edi
mov    %r14,%rsi
mov    %eax,%edx
call   1060 <syslog@plt>
jmp    12c0 <main+0x120>
mov    0x2cac(%rip),%rax
mov    (%rax),%ebx
mov    0x2cbb(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
lea    0xd85(%rip),%rsi
mov    %ebx,%edi
mov    %eax,%edx
call   1060 <syslog@plt>
mov    0x2c95(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@EXIT_FAILURE = global i32 0
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@IPPROTO_TCP = global i32 0
@LOG_ERR = global i32 0
@.str = [54 x i8] c"socket(2) error when creating main server socket: %s\0A\00"
@errno = global i32 0
@INADDR_ANY = global i32 0
@.str.1 = [34 x i8] c"bind(2) error on main socket: %s\0A\00"
@.str.2 = [36 x i8] c"listen(2) error on main socket: %s\0A\00"
@.str.3 = [28 x i8] c"Error accepting client: %s\0A\00"
@.str.4 = [21 x i8] c"accept(2) error: %s\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca %struct.sockaddr_in
%4 = alloca i32
store i32 0, i32* %1
%5 = call i64 (...) @daemonize()
%6 = icmp slt i64 %5, 0
br i1 %6, label %7, label %10
7: ; preds = %0
%8 = load i32, i32* @EXIT_FAILURE
%9 = call i32 @exit(i32 %8)
unreachable
10: ; preds = %0
%11 = load i32, i32* @AF_INET
%12 = load i32, i32* @SOCK_STREAM
%13 = load i32, i32* @IPPROTO_TCP
%14 = call i32 @socket(i32 %11, i32 %12, i32 %13)
store i32 %14, i32* %2
%15 = icmp slt i32 %14, 0
br i1 %15, label %16, label %23
16: ; preds = %10
%17 = load i32, i32* @LOG_ERR
%18 = load i32, i32* @errno
%19 = call i32 @strerror(i32 %18)
%20 = call i32 @syslog(i32 %17, i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str, i64 0, i64 0), i32 %19)
%21 = load i32, i32* @EXIT_FAILURE
%22 = call i32 @exit(i32 %21)
unreachable
23: ; preds = %10
%24 = load i32, i32* @AF_INET
%25 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 2
store i32 %24, i32* %25
%26 = call i32 @htons(i32 3000)
%27 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 1
store i32 %26, i32* %27
%28 = load i32, i32* @INADDR_ANY
%29 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 0
%30 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %29, i32 0, i32 0
store i32 %28, i32* %30
%31 = load i32, i32* %2
%32 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%33 = call i64 @bind(i32 %31, %struct.sockaddr* %32, i32 12)
%34 = icmp slt i64 %33, 0
br i1 %34, label %35, label %42
35: ; preds = %23
%36 = load i32, i32* @LOG_ERR
%37 = load i32, i32* @errno
%38 = call i32 @strerror(i32 %37)
%39 = call i32 @syslog(i32 %36, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i32 %38)
%40 = load i32, i32* @EXIT_FAILURE
%41 = call i32 @exit(i32 %40)
unreachable
42: ; preds = %23
%43 = load i32, i32* %2
%44 = call i64 @listen(i32 %43, i32 10)
%45 = icmp slt i64 %44, 0
br i1 %45, label %46, label %53
46: ; preds = %42
%47 = load i32, i32* @LOG_ERR
%48 = load i32, i32* @errno
%49 = call i32 @strerror(i32 %48)
%50 = call i32 @syslog(i32 %47, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0), i32 %49)
%51 = load i32, i32* @EXIT_FAILURE
%52 = call i32 @exit(i32 %51)
unreachable
53: ; preds = %42
br label %54
54: ; preds = %67, %53
%55 = load i32, i32* %2
%56 = call i32 @accept(i32 %55, i32* null, i32* null)
store i32 %56, i32* %4
%57 = icmp sge i32 %56, 0
br i1 %57, label %58, label %68
58: ; preds = %54
%59 = load i32, i32* %4
%60 = call i64 @accept_client(i32 %59)
%61 = icmp slt i64 %60, 0
br i1 %61, label %62, label %67
62: ; preds = %58
%63 = load i32, i32* @LOG_ERR
%64 = load i32, i32* @errno
%65 = call i32 @strerror(i32 %64)
%66 = call i32 @syslog(i32 %63, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0), i32 %65)
br label %67
67: ; preds = %62, %58
br label %54
68: ; preds = %54
%69 = load i32, i32* %4
%70 = icmp slt i32 %69, 0
br i1 %70, label %71, label %78
71: ; preds = %68
%72 = load i32, i32* @LOG_ERR
%73 = load i32, i32* @errno
%74 = call i32 @strerror(i32 %73)
%75 = call i32 @syslog(i32 %72, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0), i32 %74)
%76 = load i32, i32* @EXIT_FAILURE
%77 = call i32 @exit(i32 %76)
unreachable
78: ; preds = %68
%79 = load i32, i32* @EXIT_SUCCESS
%80 = call i32 @exit(i32 %79)
unreachable
}

LLVM IR (-O2):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@EXIT_FAILURE = global i32 0
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@IPPROTO_TCP = global i32 0
@LOG_ERR = global i32 0
@.str = [54 x i8] c"socket(2) error when creating main server socket: %s\0A\00"
@errno = global i32 0
@INADDR_ANY = global i32 0
@.str.1 = [34 x i8] c"bind(2) error on main socket: %s\0A\00"
@.str.2 = [36 x i8] c"listen(2) error on main socket: %s\0A\00"
@.str.3 = [28 x i8] c"Error accepting client: %s\0A\00"
@.str.4 = [21 x i8] c"accept(2) error: %s\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca %struct.sockaddr_in
%2 = tail call i64 (...) @daemonize()
%3 = icmp slt i64 %2, 0
br i1 %3, label %4, label %7
4: ; preds = %0
%5 = load i32, i32* @EXIT_FAILURE
%6 = tail call i32 @exit(i32 %5)
unreachable
7: ; preds = %0
%8 = load i32, i32* @AF_INET
%9 = load i32, i32* @SOCK_STREAM
%10 = load i32, i32* @IPPROTO_TCP
%11 = tail call i32 @socket(i32 %8, i32 %9, i32 %10)
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %20
13: ; preds = %7
%14 = load i32, i32* @LOG_ERR
%15 = load i32, i32* @errno
%16 = tail call i32 @strerror(i32 %15)
%17 = tail call i32 @syslog(i32 %14, i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str, i64 0, i64 0), i32 %16)
%18 = load i32, i32* @EXIT_FAILURE
%19 = tail call i32 @exit(i32 %18)
unreachable
20: ; preds = %7
%21 = bitcast %struct.sockaddr_in* %1 to i8*
%22 = load i32, i32* @AF_INET
%23 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 2
store i32 %22, i32* %23
%24 = tail call i32 @htons(i32 3000)
%25 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 1
store i32 %24, i32* %25
%26 = load i32, i32* @INADDR_ANY
%27 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 0, i32 0
store i32 %26, i32* %27
%28 = bitcast %struct.sockaddr_in* %1 to %struct.sockaddr*
%29 = call i64 @bind(i32 %11, %struct.sockaddr* %28, i32 12)
%30 = icmp slt i64 %29, 0
br i1 %30, label %31, label %38
31: ; preds = %20
%32 = load i32, i32* @LOG_ERR
%33 = load i32, i32* @errno
%34 = call i32 @strerror(i32 %33)
%35 = call i32 @syslog(i32 %32, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i32 %34)
%36 = load i32, i32* @EXIT_FAILURE
%37 = call i32 @exit(i32 %36)
unreachable
38: ; preds = %20
%39 = call i64 @listen(i32 %11, i32 10)
%40 = icmp slt i64 %39, 0
br i1 %40, label %44, label %41
41: ; preds = %38
%42 = call i32 @accept(i32 %11, i32* null, i32* null)
%43 = icmp sgt i32 %42, -1
br i1 %43, label %51, label %63
44: ; preds = %38
%45 = load i32, i32* @LOG_ERR
%46 = load i32, i32* @errno
%47 = call i32 @strerror(i32 %46)
%48 = call i32 @syslog(i32 %45, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0), i32 %47)
%49 = load i32, i32* @EXIT_FAILURE
%50 = call i32 @exit(i32 %49)
unreachable
51: ; preds = %41, %60
%52 = phi i32 [ %61, %60 ], [ %42, %41 ]
%53 = call i64 @accept_client(i32 %52)
%54 = icmp slt i64 %53, 0
br i1 %54, label %55, label %60
55: ; preds = %51
%56 = load i32, i32* @LOG_ERR
%57 = load i32, i32* @errno
%58 = call i32 @strerror(i32 %57)
%59 = call i32 @syslog(i32 %56, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0), i32 %58)
br label %60
60: ; preds = %55, %51
%61 = call i32 @accept(i32 %11, i32* null, i32* null)
%62 = icmp sgt i32 %61, -1
br i1 %62, label %51, label %63
63: ; preds = %60, %41
%64 = load i32, i32* @LOG_ERR
%65 = load i32, i32* @errno
%66 = call i32 @strerror(i32 %65)
%67 = call i32 @syslog(i32 %64, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0), i32 %66)
%68 = load i32, i32* @EXIT_FAILURE
%69 = call i32 @exit(i32 %68)
unreachable
}