#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 socklen_t;
typedef int /*<<< orphan*/ servAddr;
typedef int /*<<< orphan*/ cliAddr;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ SOCK_STREAM;
int accept(int, struct sockaddr *, int *);
scalar_t__ bind(int, struct sockaddr *, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ htonl(int /*<<< orphan*/);
int /*<<< orphan*/ htons(int);
char *inet_ntoa(TYPE_1__);
scalar_t__ listen(int, int);
int /*<<< orphan*/ memset(struct sockaddr_in *, int /*<<< orphan*/, int);
int ntohs(int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ write(int, char *, int /*<<< orphan*/);
int main(void) {
  int server = 0;
  int client = 0;
  struct sockaddr_in servAddr;
  if ((server = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
    fprintf(stderr, "Can't not open socket.\n");
    exit(1);
  }
  memset(&servAddr, 0, sizeof(servAddr));
  servAddr.sin_family = AF_INET;
  servAddr.sin_port = htons(9527);
  servAddr.sin_addr.s_addr = htonl(INADDR_ANY);
  if (bind(server, (struct sockaddr *)&servAddr, sizeof(servAddr)) < 0) {
    fprintf(stderr, "Bind error");
    exit(1);
  }
  if (listen(server, 10) < 0) {
    fprintf(stderr, "Listen error");
    exit(1);
  }
  while (1) {
    char *buf = "Hello Socket.\n";
    struct sockaddr_in cliAddr;
    socklen_t len = sizeof(cliAddr);
    client = accept(server, (struct sockaddr *)&cliAddr, &len);
    fprintf(stderr, "Server: %s:%d Connected\n", inet_ntoa(cliAddr.sin_addr),
            ntohs(cliAddr.sin_port));
    write(client, buf, strlen(buf));
    close(client);
  }
  close(server);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    0x2de4(%rip),%rax
mov    (%rax),%edi
mov    0x2dbb(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1100 <socket@plt>
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
jge    1243 <main+0x63>
mov    0x2da7(%rip),%rax
mov    (%rax),%edi
lea    0xdce(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>
lea    -0x18(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1080 <memset@plt>
mov    0x2d8e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
mov    $0x2537,%edi
call   1060 <htons@plt>
mov    %eax,-0x18(%rbp)
mov    0x2d6d(%rip),%rax
mov    (%rax),%edi
call   1070 <htonl@plt>
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    $0xc,%edx
call   10d0 <bind@plt>
cmp    $0x0,%rax
jge    12b9 <main+0xd9>
mov    0x2d31(%rip),%rax
mov    (%rax),%edi
lea    0xd70(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>
mov    -0x8(%rbp),%edi
mov    $0xa,%esi
call   10b0 <listen@plt>
cmp    $0x0,%rax
jge    12f1 <main+0x111>
mov    0x2cf9(%rip),%rax
mov    (%rax),%edi
lea    0xd43(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>
jmp    12f6 <main+0x116>
lea    0xd33(%rip),%rax
mov    %rax,-0x20(%rbp)
movl   $0xc,-0x34(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x30(%rbp),%rsi
lea    -0x34(%rbp),%rdx
call   10e0 <accept@plt>
mov    %eax,-0xc(%rbp)
mov    0x2cae(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x54(%rbp)
mov    -0x2c(%rbp),%edi
call   1040 <inet_ntoa@plt>
mov    %rax,-0x50(%rbp)
mov    -0x30(%rbp),%edi
call   10c0 <ntohs@plt>
mov    -0x54(%rbp),%edi
mov    -0x50(%rbp),%rdx
mov    %eax,%ecx
lea    0xcf4(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x44(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x20(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x44(%rbp),%edi
mov    -0x40(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    -0xc(%rbp),%edi
call   1090 <close@plt>
jmp    12f6 <main+0x116>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    0x2df3(%rip),%rbp
mov    0x0(%rbp),%edi
mov    0x2dc9(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1100 <socket@plt>
test   %eax,%eax
js     12fa <main+0x11a>
mov    %eax,%r13d
lea    0x8(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1080 <memset@plt>
mov    0x0(%rbp),%eax
mov    %eax,0x10(%rsp)
mov    $0x2537,%edi
call   1060 <htons@plt>
mov    %eax,0x8(%rsp)
mov    0x2d9d(%rip),%rax
mov    (%rax),%edi
call   1070 <htonl@plt>
mov    %eax,0xc(%rsp)
mov    %r13d,%edi
mov    %rbx,%rsi
mov    $0xc,%edx
call   10d0 <bind@plt>
test   %rax,%rax
js     130c <main+0x12c>
mov    %r13d,%edi
mov    $0xa,%esi
call   10b0 <listen@plt>
test   %rax,%rax
js     131e <main+0x13e>
lea    0xdbb(%rip),%r12
lea    0xda5(%rip),%rbx
nopl   0x0(%rax,%rax,1)
movl   $0xc,0x4(%rsp)
mov    %r13d,%edi
lea    0x18(%rsp),%rsi
lea    0x4(%rsp),%rdx
call   10e0 <accept@plt>
mov    %eax,%ebp
mov    0x2d1d(%rip),%rax
mov    (%rax),%r14d
mov    0x1c(%rsp),%edi
call   1040 <inet_ntoa@plt>
mov    %rax,%r15
mov    0x18(%rsp),%edi
call   10c0 <ntohs@plt>
mov    %r14d,%edi
mov    %r12,%rsi
mov    %r15,%rdx
mov    %eax,%ecx
xor    %eax,%eax
call   10a0 <fprintf@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    %ebp,%edi
call   1090 <close@plt>
jmp    1290 <main+0xb0>
mov    0x2ccf(%rip),%rax
mov    (%rax),%edi
lea    0xcf6(%rip),%rsi
jmp    132e <main+0x14e>
mov    0x2cbd(%rip),%rax
mov    (%rax),%edi
lea    0xcfc(%rip),%rsi
jmp    132e <main+0x14e>
mov    0x2cab(%rip),%rax
mov    (%rax),%edi
lea    0xcf5(%rip),%rsi
xor    %eax,%eax
call   10a0 <fprintf@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, 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 = [24 x i8] c"Can't not open socket.\0A\00"
@INADDR_ANY = global i32 0
@.str.1 = [11 x i8] c"Bind error\00"
@.str.2 = [13 x i8] c"Listen error\00"
@.str.3 = [15 x i8] c"Hello Socket.\0A\00"
@.str.4 = [25 x i8] c"Server: %s:%d Connected\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca %struct.sockaddr_in
%5 = alloca i8*
%6 = alloca %struct.sockaddr_in
%7 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %2
store i32 0, i32* %3
%8 = load i32, i32* @AF_INET
%9 = load i32, i32* @SOCK_STREAM
%10 = call i32 @socket(i32 %8, i32 %9, i32 0)
store i32 %10, i32* %2
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %16
12: ; preds = %0
%13 = load i32, i32* @stderr
%14 = call i32 (i32, i8*, ...) @fprintf(i32 %13, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
%15 = call i32 @exit(i32 1)
unreachable
16: ; preds = %0
%17 = call i32 @memset(%struct.sockaddr_in* %4, i32 0, i32 12)
%18 = load i32, i32* @AF_INET
%19 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i32 0, i32 2
store i32 %18, i32* %19
%20 = call i32 @htons(i32 9527)
%21 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i32 0, i32 0
store i32 %20, i32* %21
%22 = load i32, i32* @INADDR_ANY
%23 = call i32 @htonl(i32 %22)
%24 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i32 0, i32 1
%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* %4 to %struct.sockaddr*
%28 = call i64 @bind(i32 %26, %struct.sockaddr* %27, i32 12)
%29 = icmp slt i64 %28, 0
br i1 %29, label %30, label %34
30: ; preds = %16
%31 = load i32, i32* @stderr
%32 = call i32 (i32, i8*, ...) @fprintf(i32 %31, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%33 = call i32 @exit(i32 1)
unreachable
34: ; preds = %16
%35 = load i32, i32* %2
%36 = call i64 @listen(i32 %35, i32 10)
%37 = icmp slt i64 %36, 0
br i1 %37, label %38, label %42
38: ; preds = %34
%39 = load i32, i32* @stderr
%40 = call i32 (i32, i8*, ...) @fprintf(i32 %39, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%41 = call i32 @exit(i32 1)
unreachable
42: ; preds = %34
br label %43
43: ; preds = %42, %43
store i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i8** %5
store i32 12, i32* %7
%44 = load i32, i32* %2
%45 = bitcast %struct.sockaddr_in* %6 to %struct.sockaddr*
%46 = call i32 @accept(i32 %44, %struct.sockaddr* %45, i32* %7)
store i32 %46, i32* %3
%47 = load i32, i32* @stderr
%48 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 1
%49 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %48, i32 0, i32 0
%50 = load i32, i32* %49
%51 = call i8* @inet_ntoa(i32 %50)
%52 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 0
%53 = load i32, i32* %52
%54 = call i32 @ntohs(i32 %53)
%55 = call i32 (i32, i8*, ...) @fprintf(i32 %47, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0), i8* %51, i32 %54)
%56 = load i32, i32* %3
%57 = load i8*, i8** %5
%58 = load i8*, i8** %5
%59 = call i32 @strlen(i8* %58)
%60 = call i32 @write(i32 %56, i8* %57, i32 %59)
%61 = load i32, i32* %3
%62 = call i32 @close(i32 %61)
br label %43
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, 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 = [24 x i8] c"Can't not open socket.\0A\00"
@INADDR_ANY = global i32 0
@.str.1 = [11 x i8] c"Bind error\00"
@.str.2 = [13 x i8] c"Listen error\00"
@.str.3 = [15 x i8] c"Hello Socket.\0A\00"
@.str.4 = [25 x i8] c"Server: %s:%d Connected\0A\00"
define i32 @main() {
%1 = alloca %struct.sockaddr_in
%2 = alloca %struct.sockaddr_in
%3 = alloca i32
%4 = bitcast %struct.sockaddr_in* %1 to i8*
%5 = load i32, i32* @AF_INET
%6 = load i32, i32* @SOCK_STREAM
%7 = tail call i32 @socket(i32 %5, i32 %6, i32 0)
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %13
9: ; preds = %0
%10 = load i32, i32* @stderr
%11 = tail call i32 (i32, i8*, ...) @fprintf(i32 %10, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
%12 = tail call i32 @exit(i32 1)
unreachable
13: ; preds = %0
%14 = call i32 @memset(%struct.sockaddr_in* %1, i32 0, i32 12)
%15 = load i32, i32* @AF_INET
%16 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 2
store i32 %15, i32* %16
%17 = call i32 @htons(i32 9527)
%18 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 0
store i32 %17, i32* %18
%19 = load i32, i32* @INADDR_ANY
%20 = call i32 @htonl(i32 %19)
%21 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 1, i32 0
store i32 %20, i32* %21
%22 = bitcast %struct.sockaddr_in* %1 to %struct.sockaddr*
%23 = call i64 @bind(i32 %7, %struct.sockaddr* %22, i32 12)
%24 = icmp slt i64 %23, 0
br i1 %24, label %25, label %29
25: ; preds = %13
%26 = load i32, i32* @stderr
%27 = call i32 (i32, i8*, ...) @fprintf(i32 %26, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%28 = call i32 @exit(i32 1)
unreachable
29: ; preds = %13
%30 = call i64 @listen(i32 %7, i32 10)
%31 = icmp slt i64 %30, 0
br i1 %31, label %38, label %32
32: ; preds = %29
%33 = bitcast %struct.sockaddr_in* %2 to i8*
%34 = bitcast i32* %3 to i8*
%35 = bitcast %struct.sockaddr_in* %2 to %struct.sockaddr*
%36 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 1, i32 0
%37 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 0
br label %42
38: ; preds = %29
%39 = load i32, i32* @stderr
%40 = call i32 (i32, i8*, ...) @fprintf(i32 %39, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%41 = call i32 @exit(i32 1)
unreachable
42: ; preds = %32, %42
store i32 12, i32* %3
%43 = call i32 @accept(i32 %7, %struct.sockaddr* %35, i32* %3)
%44 = load i32, i32* @stderr
%45 = load i32, i32* %36
%46 = call i8* @inet_ntoa(i32 %45)
%47 = load i32, i32* %37
%48 = call i32 @ntohs(i32 %47)
%49 = call i32 (i32, i8*, ...) @fprintf(i32 %44, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0), i8* %46, i32 %48)
%50 = call i32 @strlen(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0))
%51 = call i32 @write(i32 %43, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i32 %50)
%52 = call i32 @close(i32 %43)
br label %42
}