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

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ SOCK_STREAM;
scalar_t__ bind(int, struct sockaddr *, int);
int /*<<< orphan*/ htonl(int /*<<< orphan*/);
int /*<<< orphan*/ htons(int);
scalar_t__ listen(int, int);
int /*<<< orphan*/ main_loop(int);
int /*<<< orphan*/ printf(char *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int main(int argc, char **argv) {
  int server_socket;
  static struct sockaddr_in server_address;
  if ((server_socket = socket(AF_INET, SOCK_STREAM, 0)) < 0)
    printf("Error when socket()");
  server_address.sin_family = AF_INET;
  server_address.sin_addr.s_addr = htonl(INADDR_ANY);
  server_address.sin_port = htons(6000);
  if (bind(server_socket, (struct sockaddr *)&server_address,
           sizeof(server_address)) < 0)
    printf("Error when bind()");
  if (listen(server_socket, 64) < 0)
    printf("Error when listen()");
  printf("TeaPot Start...");
  main_loop(server_socket);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e5b(%rip),%rax
mov    (%rax),%edi
mov    0x2e3a(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1090 <socket@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    11b7 <main+0x47>
lea    0xe4e(%rip),%rdi
call   1040 <printf@plt>
mov    0x2e2a(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x2e9e(%rip)
mov    0x2e13(%rip),%rax
mov    (%rax),%edi
call   1050 <htonl@plt>
mov    %eax,0x2e86(%rip)
mov    $0x1770,%edi
call   1030 <htons@plt>
mov    %eax,0x2e72(%rip)
mov    -0x14(%rbp),%edi
lea    0x2e68(%rip),%rsi
mov    $0xc,%edx
call   1070 <bind@plt>
cmp    $0x0,%rax
jge    1214 <main+0xa4>
lea    0xe05(%rip),%rdi
call   1040 <printf@plt>
mov    -0x14(%rbp),%edi
mov    $0x40,%esi
call   1060 <listen@plt>
cmp    $0x0,%rax
jge    1237 <main+0xc7>
lea    0xdf4(%rip),%rdi
call   1040 <printf@plt>
lea    0xdfc(%rip),%rdi
call   1040 <printf@plt>
mov    -0x14(%rbp),%edi
call   1080 <main_loop@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    0x2e6d(%rip),%r14
mov    (%r14),%edi
mov    0x2e4b(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1090 <socket@plt>
mov    %eax,%ebx
test   %eax,%eax
jns    11a0 <main+0x30>
lea    0xe65(%rip),%rdi
call   1040 <printf@plt>
mov    (%r14),%eax
mov    %eax,0x2ebb(%rip)
lea    0x2eac(%rip),%r14
mov    0x2e29(%rip),%rax
mov    (%rax),%edi
call   1050 <htonl@plt>
mov    %eax,0x2e9c(%rip)
mov    $0x1770,%edi
call   1030 <htons@plt>
mov    %eax,0x2e88(%rip)
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0xc,%edx
call   1070 <bind@plt>
test   %rax,%rax
jns    11f4 <main+0x84>
lea    0xe25(%rip),%rdi
call   1040 <printf@plt>
mov    %ebx,%edi
mov    $0x40,%esi
call   1060 <listen@plt>
test   %rax,%rax
jns    1211 <main+0xa1>
lea    0xe1a(%rip),%rdi
call   1040 <printf@plt>
lea    0xe22(%rip),%rdi
call   1040 <printf@plt>
mov    %ebx,%edi
call   1080 <main_loop@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@main.server_address = internal global %struct.sockaddr_in zeroinitializer
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [20 x i8] c"Error when socket()\00"
@INADDR_ANY = global i32 0
@.str.1 = [18 x i8] c"Error when bind()\00"
@.str.2 = [20 x i8] c"Error when listen()\00"
@.str.3 = [16 x i8] c"TeaPot Start...\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = load i32, i32* @AF_INET
%8 = load i32, i32* @SOCK_STREAM
%9 = call i32 @socket(i32 %7, i32 %8, i32 0)
store i32 %9, i32* %6
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %2
%12 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
br label %13
13: ; preds = %11, %2
%14 = load i32, i32* @AF_INET
store i32 %14, i32* getelementptr inbounds (%struct.sockaddr_in, %struct.sockaddr_in* @main.server_address, i32 0, i32 2)
%15 = load i32, i32* @INADDR_ANY
%16 = call i32 @htonl(i32 %15)
store i32 %16, i32* getelementptr inbounds (%struct.sockaddr_in, %struct.sockaddr_in* @main.server_address, i32 0, i32 1, i32 0)
%17 = call i32 @htons(i32 6000)
store i32 %17, i32* getelementptr inbounds (%struct.sockaddr_in, %struct.sockaddr_in* @main.server_address, i32 0, i32 0)
%18 = load i32, i32* %6
%19 = call i64 @bind(i32 %18, %struct.sockaddr* bitcast (%struct.sockaddr_in* @main.server_address to %struct.sockaddr*), i32 12)
%20 = icmp slt i64 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %13
%22 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
br label %23
23: ; preds = %21, %13
%24 = load i32, i32* %6
%25 = call i64 @listen(i32 %24, i32 64)
%26 = icmp slt i64 %25, 0
br i1 %26, label %27, label %29
27: ; preds = %23
%28 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
br label %29
29: ; preds = %27, %23
%30 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0))
%31 = load i32, i32* %6
%32 = call i32 @main_loop(i32 %31)
%33 = load i32, i32* %3
ret i32 %33
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@main.server_address = internal global %struct.sockaddr_in zeroinitializer
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [20 x i8] c"Error when socket()\00"
@INADDR_ANY = global i32 0
@.str.1 = [18 x i8] c"Error when bind()\00"
@.str.2 = [20 x i8] c"Error when listen()\00"
@.str.3 = [16 x i8] c"TeaPot Start...\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = load i32, i32* @AF_INET
%4 = load i32, i32* @SOCK_STREAM
%5 = tail call i32 @socket(i32 %3, i32 %4, i32 0)
%6 = icmp slt i32 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %2
%8 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
br label %9
9: ; preds = %7, %2
%10 = load i32, i32* @AF_INET
store i32 %10, i32* getelementptr inbounds (%struct.sockaddr_in, %struct.sockaddr_in* @main.server_address, i64 0, i32 2)
%11 = load i32, i32* @INADDR_ANY
%12 = tail call i32 @htonl(i32 %11)
store i32 %12, i32* getelementptr inbounds (%struct.sockaddr_in, %struct.sockaddr_in* @main.server_address, i64 0, i32 1, i32 0)
%13 = tail call i32 @htons(i32 6000)
store i32 %13, i32* getelementptr inbounds (%struct.sockaddr_in, %struct.sockaddr_in* @main.server_address, i64 0, i32 0)
%14 = tail call i64 @bind(i32 %5, %struct.sockaddr* bitcast (%struct.sockaddr_in* @main.server_address to %struct.sockaddr*), i32 12)
%15 = icmp slt i64 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %9
%17 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
br label %18
18: ; preds = %16, %9
%19 = tail call i64 @listen(i32 %5, i32 64)
%20 = icmp slt i64 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %18
%22 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
br label %23
23: ; preds = %21, %18
%24 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0))
%25 = tail call i32 @main_loop(i32 %5)
ret i32 0
}