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

/* Type definitions */

/* Variables and functions */
int accept_inet_stream_socket(int, int /*<<< orphan*/, int /*<<< orphan*/,
                              int /*<<< orphan*/, int /*<<< orphan*/,
                              int /*<<< orphan*/, int /*<<< orphan*/);
char *calloc(int, int);
int create_inet_server_socket(char *, char *, int, int, int /*<<< orphan*/);
int destroy_inet_socket(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ perror(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char *);
int read(int, char *, int);
int main(void) {
  int cfd, sfd, ret;
  char *buf = calloc(16, 1);
  ret = sfd = create_inet_server_socket("::", "55555", 1, 4, 0);
  if (ret < 0) {
    perror(0);
    exit(1);
  }
  ret = cfd = accept_inet_stream_socket(sfd, 0, 0, 0, 0, 0, 0);
  if (ret < 0) {
    perror(0);
    exit(1);
  }
  ret = read(cfd, buf, 15);
  if (ret < 0) {
    perror(0);
    exit(1);
  }
  printf("%s\n", buf);
  ret = destroy_inet_socket(sfd);
  if (ret < 0) {
    perror(0);
    exit(1);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x10,%edi
mov    $0x1,%esi
call   1070 <calloc@plt>
mov    %rax,-0x18(%rbp)
lea    0xe57(%rip),%rdi
lea    0xe53(%rip),%rsi
mov    $0x1,%edx
mov    $0x4,%ecx
xor    %r8d,%r8d
call   1080 <create_inet_server_socket@plt>
mov    %eax,-0xc(%rbp)
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jge    11e3 <main+0x63>
xor    %edi,%edi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    -0xc(%rbp),%edi
xor    %r9d,%r9d
mov    %r9d,%esi
mov    %r9d,%edx
mov    %r9d,%ecx
mov    %r9d,%r8d
movl   $0x0,(%rsp)
call   1030 <accept_inet_stream_socket@plt>
mov    %eax,-0x8(%rbp)
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jge    1222 <main+0xa2>
xor    %edi,%edi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    -0x8(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    $0xf,%edx
call   1060 <read@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jge    1251 <main+0xd1>
xor    %edi,%edi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    -0x18(%rbp),%rsi
lea    0xdad(%rip),%rdi
call   1050 <printf@plt>
mov    -0xc(%rbp),%edi
call   1040 <destroy_inet_socket@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jge    1287 <main+0x107>
xor    %edi,%edi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
mov    $0x10,%edi
mov    $0x1,%esi
call   1070 <calloc@plt>
mov    %rax,%rbx
lea    0xe64(%rip),%rdi
lea    0xe60(%rip),%rsi
mov    $0x1,%edx
mov    $0x4,%ecx
xor    %r8d,%r8d
call   1080 <create_inet_server_socket@plt>
test   %eax,%eax
js     120f <main+0x8f>
mov    %eax,%ebp
movl   $0x0,(%rsp)
mov    %eax,%edi
xor    %esi,%esi
xor    %edx,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
xor    %r9d,%r9d
call   1030 <accept_inet_stream_socket@plt>
test   %eax,%eax
js     120f <main+0x8f>
mov    %eax,%edi
mov    %rbx,%rsi
mov    $0xf,%edx
call   1060 <read@plt>
test   %eax,%eax
js     120f <main+0x8f>
lea    0xe16(%rip),%rdi
mov    %rbx,%rsi
call   1050 <printf@plt>
mov    %ebp,%edi
call   1040 <destroy_inet_socket@plt>
test   %eax,%eax
js     120f <main+0x8f>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
xor    %edi,%edi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"::\00"
@.str.1 = [6 x i8] c"55555\00"
@.str.2 = [4 x i8] c"%s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
store i32 0, i32* %1
%6 = call i8* @calloc(i32 16, i32 1)
store i8* %6, i8** %5
%7 = call i32 @create_inet_server_socket(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 1, i32 4, i32 0)
store i32 %7, i32* %3
store i32 %7, i32* %4
%8 = load i32, i32* %4
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %13
10: ; preds = %0
%11 = call i32 @perror(i32 0)
%12 = call i32 @exit(i32 1)
unreachable
13: ; preds = %0
%14 = load i32, i32* %3
%15 = call i32 @accept_inet_stream_socket(i32 %14, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0)
store i32 %15, i32* %2
store i32 %15, i32* %4
%16 = load i32, i32* %4
%17 = icmp slt i32 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %13
%19 = call i32 @perror(i32 0)
%20 = call i32 @exit(i32 1)
unreachable
21: ; preds = %13
%22 = load i32, i32* %2
%23 = load i8*, i8** %5
%24 = call i32 @read(i32 %22, i8* %23, i32 15)
store i32 %24, i32* %4
%25 = load i32, i32* %4
%26 = icmp slt i32 %25, 0
br i1 %26, label %27, label %30
27: ; preds = %21
%28 = call i32 @perror(i32 0)
%29 = call i32 @exit(i32 1)
unreachable
30: ; preds = %21
%31 = load i8*, i8** %5
%32 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %31)
%33 = load i32, i32* %3
%34 = call i32 @destroy_inet_socket(i32 %33)
store i32 %34, i32* %4
%35 = load i32, i32* %4
%36 = icmp slt i32 %35, 0
br i1 %36, label %37, label %40
37: ; preds = %30
%38 = call i32 @perror(i32 0)
%39 = call i32 @exit(i32 1)
unreachable
40: ; preds = %30
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"::\00"
@.str.1 = [6 x i8] c"55555\00"
@.str.2 = [4 x i8] c"%s\0A\00"
define i32 @main() {
%1 = tail call dereferenceable_or_null(16) i8* @calloc(i32 16, i32 1)
%2 = tail call i32 @create_inet_server_socket(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 1, i32 4, i32 0)
%3 = icmp slt i32 %2, 0
br i1 %3, label %4, label %7
4: ; preds = %0
%5 = tail call i32 @perror(i32 0)
%6 = tail call i32 @exit(i32 1)
unreachable
7: ; preds = %0
%8 = tail call i32 @accept_inet_stream_socket(i32 %2, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0)
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %13
10: ; preds = %7
%11 = tail call i32 @perror(i32 0)
%12 = tail call i32 @exit(i32 1)
unreachable
13: ; preds = %7
%14 = tail call i32 @read(i32 %8, i8* %1, i32 15)
%15 = icmp slt i32 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %13
%17 = tail call i32 @perror(i32 0)
%18 = tail call i32 @exit(i32 1)
unreachable
19: ; preds = %13
%20 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %1)
%21 = tail call i32 @destroy_inet_socket(i32 %2)
%22 = icmp slt i32 %21, 0
br i1 %22, label %23, label %26
23: ; preds = %19
%24 = tail call i32 @perror(i32 0)
%25 = tail call i32 @exit(i32 1)
unreachable
26: ; preds = %19
ret i32 0
}