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

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ SOCK_STREAM;
scalar_t__ bind(int, struct sockaddr *, int);
int /*<<< orphan*/ close(int);
int errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int, char *);
int /*<<< orphan*/ handle_clients(int);
int /*<<< orphan*/ htons(int);
scalar_t__ listen(int, int);
int /*<<< orphan*/ memset(struct sockaddr_in *, int /*<<< orphan*/, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
char *strerror(int);
int main() {
  int sockfd = -1;
  struct sockaddr_in serv_addr;
  memset(&serv_addr, 0, sizeof(struct sockaddr_in));
  sockfd = socket(AF_INET, SOCK_STREAM, 0);
  if (-1 == sockfd) {
    fprintf(stderr, "Error: socket()!\n\tErrNo: %d\n\tErrMsg: %s", errno,
            strerror(errno));
    exit(errno);
  }
  serv_addr.sin_family = AF_INET;
  serv_addr.sin_port = htons(6060);
  serv_addr.sin_addr.s_addr = INADDR_ANY;
  if (0 != bind(sockfd, (struct sockaddr *)&serv_addr, sizeof(serv_addr))) {
    fprintf(stderr, "Error: bind()!\n\tErrNo: %d\n\tErrMsg: %s", errno,
            strerror(errno));
    exit(errno);
  }
  if (0 != listen(sockfd, 5)) {
    fprintf(stderr, "Error: listen()!\n\tErrNo: %d\n\tErrMsg: %s", errno,
            strerror(errno));
    exit(errno);
  }
  handle_clients(sockfd);
  close(sockfd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0xffffffff,-0x8(%rbp)
lea    -0x18(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1040 <memset@plt>
mov    0x2e1b(%rip),%rax
mov    (%rax),%edi
mov    0x2df2(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10c0 <socket@plt>
mov    %eax,-0x8(%rbp)
mov    $0xffffffff,%eax
cmp    -0x8(%rbp),%eax
jne    1239 <main+0x99>
mov    0x2dd9(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    0x2dbd(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    0x2db1(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
mov    -0x20(%rbp),%edi
mov    -0x1c(%rbp),%edx
mov    %rax,%rcx
lea    0xdda(%rip),%rsi
call   1060 <fprintf@plt>
mov    0x2d8e(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
mov    0x2da8(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
mov    $0x17ac,%edi
call   1030 <htons@plt>
mov    %eax,-0x14(%rbp)
mov    0x2d87(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    $0xc,%edx
call   1090 <bind@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
je     12c6 <main+0x126>
mov    0x2d4c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    0x2d30(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    0x2d24(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
mov    -0x28(%rbp),%edi
mov    -0x24(%rbp),%edx
mov    %rax,%rcx
lea    0xd75(%rip),%rsi
call   1060 <fprintf@plt>
mov    0x2d01(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
mov    -0x8(%rbp),%edi
mov    $0x5,%esi
call   1080 <listen@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
je     132a <main+0x18a>
mov    0x2ce8(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
mov    0x2ccc(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    0x2cc0(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
mov    -0x30(%rbp),%edi
mov    -0x2c(%rbp),%edx
mov    %rax,%rcx
lea    0xd37(%rip),%rsi
call   1060 <fprintf@plt>
mov    0x2c9d(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
mov    -0x8(%rbp),%edi
call   1070 <handle_clients@plt>
mov    -0x8(%rbp),%edi
call   1050 <close@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsp,%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1040 <memset@plt>
mov    0x2e2a(%rip),%rbp
mov    0x0(%rbp),%edi
mov    0x2e00(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10c0 <socket@plt>
cmp    $0xffffffff,%eax
je     1237 <main+0x97>
mov    %eax,%ebx
mov    0x0(%rbp),%eax
mov    %eax,0x8(%rsp)
mov    $0x17ac,%edi
call   1030 <htons@plt>
mov    %eax,0x4(%rsp)
mov    0x2dec(%rip),%rax
mov    (%rax),%eax
mov    %eax,(%rsp)
mov    %rsp,%rsi
mov    %ebx,%edi
mov    $0xc,%edx
call   1090 <bind@plt>
test   %rax,%rax
jne    125a <main+0xba>
mov    %ebx,%edi
mov    $0x5,%esi
call   1080 <listen@plt>
test   %rax,%rax
jne    127d <main+0xdd>
mov    %ebx,%edi
call   1070 <handle_clients@plt>
mov    %ebx,%edi
call   1050 <close@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    0x2d92(%rip),%rax
mov    (%rax),%ebx
mov    0x2d79(%rip),%r14
mov    (%r14),%ebp
mov    %ebp,%edi
call   10b0 <strerror@plt>
lea    0xda8(%rip),%rsi
jmp    129e <main+0xfe>
mov    0x2d6f(%rip),%rax
mov    (%rax),%ebx
mov    0x2d56(%rip),%r14
mov    (%r14),%ebp
mov    %ebp,%edi
call   10b0 <strerror@plt>
lea    0xdad(%rip),%rsi
jmp    129e <main+0xfe>
mov    0x2d4c(%rip),%rax
mov    (%rax),%ebx
mov    0x2d33(%rip),%r14
mov    (%r14),%ebp
mov    %ebp,%edi
call   10b0 <strerror@plt>
lea    0xdb0(%rip),%rsi
mov    %ebx,%edi
mov    %ebp,%edx
mov    %rax,%rcx
call   1060 <fprintf@plt>
mov    (%r14),%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 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@stderr = global i32 0
@.str = [40 x i8] c"Error: socket()!\0A\09ErrNo: %d\0A\09ErrMsg: %s\00"
@errno = global i32 0
@INADDR_ANY = global i32 0
@.str.1 = [38 x i8] c"Error: bind()!\0A\09ErrNo: %d\0A\09ErrMsg: %s\00"
@.str.2 = [40 x i8] c"Error: listen()!\0A\09ErrNo: %d\0A\09ErrMsg: %s\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca %struct.sockaddr_in
store i32 0, i32* %1
store i32 -1, i32* %2
%4 = call i32 @memset(%struct.sockaddr_in* %3, i32 0, i32 12)
%5 = load i32, i32* @AF_INET
%6 = load i32, i32* @SOCK_STREAM
%7 = call i32 @socket(i32 %5, i32 %6, i32 0)
store i32 %7, i32* %2
%8 = load i32, i32* %2
%9 = icmp eq i32 -1, %8
br i1 %9, label %10, label %18
10: ; preds = %0
%11 = load i32, i32* @stderr
%12 = load i32, i32* @errno
%13 = load i32, i32* @errno
%14 = call i8* @strerror(i32 %13)
%15 = call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0), i32 %12, i8* %14)
%16 = load i32, i32* @errno
%17 = call i32 @exit(i32 %16)
unreachable
18: ; preds = %0
%19 = load i32, i32* @AF_INET
%20 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 2
store i32 %19, i32* %20
%21 = call i32 @htons(i32 6060)
%22 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 1
store i32 %21, i32* %22
%23 = load i32, i32* @INADDR_ANY
%24 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 0
%25 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %24, i32 0, i32 0
store i32 %23, i32* %25
%26 = load i32, i32* %2
%27 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%28 = call i64 @bind(i32 %26, %struct.sockaddr* %27, i32 12)
%29 = icmp ne i64 0, %28
br i1 %29, label %30, label %38
30: ; preds = %18
%31 = load i32, i32* @stderr
%32 = load i32, i32* @errno
%33 = load i32, i32* @errno
%34 = call i8* @strerror(i32 %33)
%35 = call i32 @fprintf(i32 %31, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i32 %32, i8* %34)
%36 = load i32, i32* @errno
%37 = call i32 @exit(i32 %36)
unreachable
38: ; preds = %18
%39 = load i32, i32* %2
%40 = call i64 @listen(i32 %39, i32 5)
%41 = icmp ne i64 0, %40
br i1 %41, label %42, label %50
42: ; preds = %38
%43 = load i32, i32* @stderr
%44 = load i32, i32* @errno
%45 = load i32, i32* @errno
%46 = call i8* @strerror(i32 %45)
%47 = call i32 @fprintf(i32 %43, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0), i32 %44, i8* %46)
%48 = load i32, i32* @errno
%49 = call i32 @exit(i32 %48)
unreachable
50: ; preds = %38
%51 = load i32, i32* %2
%52 = call i32 @handle_clients(i32 %51)
%53 = load i32, i32* %2
%54 = call i32 @close(i32 %53)
ret i32 0
}

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
@SOCK_STREAM = global i32 0
@stderr = global i32 0
@.str = [40 x i8] c"Error: socket()!\0A\09ErrNo: %d\0A\09ErrMsg: %s\00"
@errno = global i32 0
@INADDR_ANY = global i32 0
@.str.1 = [38 x i8] c"Error: bind()!\0A\09ErrNo: %d\0A\09ErrMsg: %s\00"
@.str.2 = [40 x i8] c"Error: listen()!\0A\09ErrNo: %d\0A\09ErrMsg: %s\00"
define i32 @main() {
%1 = alloca %struct.sockaddr_in
%2 = bitcast %struct.sockaddr_in* %1 to i8*
%3 = call i32 @memset(%struct.sockaddr_in* %1, i32 0, i32 12)
%4 = load i32, i32* @AF_INET
%5 = load i32, i32* @SOCK_STREAM
%6 = call i32 @socket(i32 %4, i32 %5, i32 0)
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %15
8: ; preds = %0
%9 = load i32, i32* @stderr
%10 = load i32, i32* @errno
%11 = call i8* @strerror(i32 %10)
%12 = call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0), i32 %10, i8* %11)
%13 = load i32, i32* @errno
%14 = call i32 @exit(i32 %13)
unreachable
15: ; preds = %0
%16 = load i32, i32* @AF_INET
%17 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 2
store i32 %16, i32* %17
%18 = call i32 @htons(i32 6060)
%19 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 1
store i32 %18, i32* %19
%20 = load i32, i32* @INADDR_ANY
%21 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 0, i32 0
store i32 %20, i32* %21
%22 = bitcast %struct.sockaddr_in* %1 to %struct.sockaddr*
%23 = call i64 @bind(i32 %6, %struct.sockaddr* %22, i32 12)
%24 = icmp eq i64 %23, 0
br i1 %24, label %32, label %25
25: ; preds = %15
%26 = load i32, i32* @stderr
%27 = load i32, i32* @errno
%28 = call i8* @strerror(i32 %27)
%29 = call i32 @fprintf(i32 %26, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i32 %27, i8* %28)
%30 = load i32, i32* @errno
%31 = call i32 @exit(i32 %30)
unreachable
32: ; preds = %15
%33 = call i64 @listen(i32 %6, i32 5)
%34 = icmp eq i64 %33, 0
br i1 %34, label %42, label %35
35: ; preds = %32
%36 = load i32, i32* @stderr
%37 = load i32, i32* @errno
%38 = call i8* @strerror(i32 %37)
%39 = call i32 @fprintf(i32 %36, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0), i32 %37, i8* %38)
%40 = load i32, i32* @errno
%41 = call i32 @exit(i32 %40)
unreachable
42: ; preds = %32
%43 = call i32 @handle_clients(i32 %6)
%44 = call i32 @close(i32 %6)
ret i32 0
}