#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;
};

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ PF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int accept(int, struct sockaddr *, int *);
scalar_t__ bind(int, struct sockaddr *, int);
int /*<<< orphan*/ exit(int);
scalar_t__ fork();
int /*<<< orphan*/ handle_connection(int, struct sockaddr *);
int /*<<< orphan*/ htons(int);
scalar_t__ inet_pton(int /*<<< orphan*/, char *, int /*<<< orphan*/ *);
scalar_t__ listen(int, int);
int /*<<< orphan*/ perror(char *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  int s;
  int c;
  struct sockaddr_in addr;
  struct sockaddr client_addr;
  int client_addr_size;
  if ((s = socket(PF_INET, SOCK_STREAM, 0)) == -1) {
    perror("Socket");
    exit(1);
  }
  addr.sin_family = AF_INET;
  addr.sin_port = htons(1234);
  if (inet_pton(AF_INET, "127.0.0.1", &addr.sin_addr.s_addr) <= 0) {
    perror("inet_pton");
    exit(1);
  }
  if (bind(s, (struct sockaddr *)&addr, sizeof(struct sockaddr_in)) != 0) {
    perror("bind");
    exit(1);
  }
  if (listen(s, 10) != 0) {
    perror("listen");
    exit(1);
  }
  while (1) {
    c = accept(s, &client_addr, &client_addr_size);
    if (fork() == 0) {
      handle_connection(c, &client_addr);
    }
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e13(%rip),%rax
mov    (%rax),%edi
mov    0x2e12(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10c0 <socket@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
jne    11f1 <main+0x51>
lea    0xe1e(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    0x2df0(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    $0x4d2,%edi
call   1030 <htons@plt>
mov    %eax,-0x24(%rbp)
mov    0x2dd7(%rip),%rax
mov    (%rax),%edi
lea    -0x28(%rbp),%rdx
lea    0xde9(%rip),%rsi
call   1050 <inet_pton@plt>
cmp    $0x0,%rax
jg     1243 <main+0xa3>
lea    0xddd(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    -0x14(%rbp),%edi
lea    -0x28(%rbp),%rsi
mov    $0xc,%edx
call   1070 <bind@plt>
cmp    $0x0,%rax
je     1274 <main+0xd4>
lea    0xdb6(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    -0x14(%rbp),%edi
mov    $0xa,%esi
call   1060 <listen@plt>
cmp    $0x0,%rax
je     12a1 <main+0x101>
lea    0xd8e(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
jmp    12a6 <main+0x106>
mov    -0x14(%rbp),%edi
lea    -0x30(%rbp),%rsi
lea    -0x34(%rbp),%rdx
call   1090 <accept@plt>
mov    %eax,-0x18(%rbp)
mov    $0x0,%al
call   10b0 <fork@plt>
cmp    $0x0,%rax
jne    12d6 <main+0x136>
mov    -0x18(%rbp),%edi
lea    -0x30(%rbp),%rsi
call   1040 <handle_connection@plt>
jmp    12a6 <main+0x106>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    0x2e1f(%rip),%rax
mov    (%rax),%edi
mov    0x2e1e(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10c0 <socket@plt>
cmp    $0xffffffff,%eax
je     1268 <main+0xc8>
mov    %eax,%r14d
mov    0x2e12(%rip),%rbx
mov    (%rbx),%eax
mov    %eax,0x8(%rsp)
mov    $0x4d2,%edi
call   1030 <htons@plt>
mov    %eax,0x4(%rsp)
mov    (%rbx),%edi
lea    0xe14(%rip),%rsi
mov    %rsp,%rdx
call   1050 <inet_pton@plt>
test   %rax,%rax
jle    1271 <main+0xd1>
mov    %rsp,%rsi
mov    %r14d,%edi
mov    $0xc,%edx
call   1070 <bind@plt>
test   %rax,%rax
jne    127a <main+0xda>
mov    %r14d,%edi
mov    $0xa,%esi
call   1060 <listen@plt>
test   %rax,%rax
jne    1283 <main+0xe3>
lea    0x10(%rsp),%rbx
lea    0x14(%rsp),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r14d,%edi
mov    %rbx,%rsi
mov    %r15,%rdx
call   1090 <accept@plt>
mov    %eax,%ebp
xor    %eax,%eax
call   10b0 <fork@plt>
test   %rax,%rax
jne    1240 <main+0xa0>
mov    %ebp,%edi
mov    %rbx,%rsi
call   1040 <handle_connection@plt>
jmp    1240 <main+0xa0>
lea    0xd91(%rip),%rdi
jmp    128a <main+0xea>
lea    0xd99(%rip),%rdi
jmp    128a <main+0xea>
lea    0xd9a(%rip),%rdi
jmp    128a <main+0xea>
lea    0xd96(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%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 }
@PF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [7 x i8] c"Socket\00"
@AF_INET = global i32 0
@.str.1 = [10 x i8] c"127.0.0.1\00"
@.str.2 = [10 x i8] c"inet_pton\00"
@.str.3 = [5 x i8] c"bind\00"
@.str.4 = [7 x i8] c"listen\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca %struct.sockaddr_in
%9 = alloca %struct.sockaddr
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* @PF_INET
%12 = load i32, i32* @SOCK_STREAM
%13 = call i32 @socket(i32 %11, i32 %12, i32 0)
store i32 %13, i32* %6
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %18
15: ; preds = %2
%16 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%17 = call i32 @exit(i32 1)
unreachable
18: ; preds = %2
%19 = load i32, i32* @AF_INET
%20 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 2
store i32 %19, i32* %20
%21 = call i32 @htons(i32 1234)
%22 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 1
store i32 %21, i32* %22
%23 = load i32, i32* @AF_INET
%24 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 0
%25 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %24, i32 0, i32 0
%26 = call i64 @inet_pton(i32 %23, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32* %25)
%27 = icmp sle i64 %26, 0
br i1 %27, label %28, label %31
28: ; preds = %18
%29 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
%30 = call i32 @exit(i32 1)
unreachable
31: ; preds = %18
%32 = load i32, i32* %6
%33 = bitcast %struct.sockaddr_in* %8 to %struct.sockaddr*
%34 = call i64 @bind(i32 %32, %struct.sockaddr* %33, i32 12)
%35 = icmp ne i64 %34, 0
br i1 %35, label %36, label %39
36: ; preds = %31
%37 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%38 = call i32 @exit(i32 1)
unreachable
39: ; preds = %31
%40 = load i32, i32* %6
%41 = call i64 @listen(i32 %40, i32 10)
%42 = icmp ne i64 %41, 0
br i1 %42, label %43, label %46
43: ; preds = %39
%44 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
%45 = call i32 @exit(i32 1)
unreachable
46: ; preds = %39
br label %47
47: ; preds = %46, %55
%48 = load i32, i32* %6
%49 = call i32 @accept(i32 %48, %struct.sockaddr* %9, i32* %10)
store i32 %49, i32* %7
%50 = call i64 (...) @fork()
%51 = icmp eq i64 %50, 0
br i1 %51, label %52, label %55
52: ; preds = %47
%53 = load i32, i32* %7
%54 = call i32 @handle_connection(i32 %53, %struct.sockaddr* %9)
br label %55
55: ; preds = %52, %47
br label %47
}

LLVM IR (-O2):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@PF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [7 x i8] c"Socket\00"
@AF_INET = global i32 0
@.str.1 = [10 x i8] c"127.0.0.1\00"
@.str.2 = [10 x i8] c"inet_pton\00"
@.str.3 = [5 x i8] c"bind\00"
@.str.4 = [7 x i8] c"listen\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca %struct.sockaddr
%5 = alloca i32
%6 = bitcast %struct.sockaddr_in* %3 to i8*
%7 = bitcast %struct.sockaddr* %4 to i8*
%8 = bitcast i32* %5 to i8*
%9 = load i32, i32* @PF_INET
%10 = load i32, i32* @SOCK_STREAM
%11 = tail call i32 @socket(i32 %9, i32 %10, i32 0)
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %16
13: ; preds = %2
%14 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%15 = tail call i32 @exit(i32 1)
unreachable
16: ; preds = %2
%17 = load i32, i32* @AF_INET
%18 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %17, i32* %18
%19 = tail call i32 @htons(i32 1234)
%20 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1
store i32 %19, i32* %20
%21 = load i32, i32* @AF_INET
%22 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0, i32 0
%23 = call i64 @inet_pton(i32 %21, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32* %22)
%24 = icmp slt i64 %23, 1
br i1 %24, label %25, label %28
25: ; preds = %16
%26 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
%27 = call i32 @exit(i32 1)
unreachable
28: ; preds = %16
%29 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%30 = call i64 @bind(i32 %11, %struct.sockaddr* %29, i32 12)
%31 = icmp eq i64 %30, 0
br i1 %31, label %35, label %32
32: ; preds = %28
%33 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%34 = call i32 @exit(i32 1)
unreachable
35: ; preds = %28
%36 = call i64 @listen(i32 %11, i32 10)
%37 = icmp eq i64 %36, 0
br i1 %37, label %41, label %38
38: ; preds = %35
%39 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
%40 = call i32 @exit(i32 1)
unreachable
41: ; preds = %35, %47
%42 = call i32 @accept(i32 %11, %struct.sockaddr* %4, i32* %5)
%43 = call i64 (...) @fork()
%44 = icmp eq i64 %43, 0
br i1 %44, label %45, label %47
45: ; preds = %41
%46 = call i32 @handle_connection(i32 %42, %struct.sockaddr* %4)
br label %47
47: ; preds = %45, %41
br label %41
}