#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 */
typedef int /*<<< orphan*/ buffer;

/* Variables and functions */
scalar_t__ EEXIST;
int EXIT_SUCCESS;
int /*<<< orphan*/ O_RDWR;
int /*<<< orphan*/ STDOUT_FILENO;
int S_IFREG;
int S_IRWXU;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ die(char *);
scalar_t__ errno;
scalar_t__ mknod(char *, int, int /*<<< orphan*/);
int open(char *, int /*<<< orphan*/);
int read(int, char *, int);
int /*<<< orphan*/ remove(char *);
int /*<<< orphan*/ write(int /*<<< orphan*/, char *, int);
int main(int argc, char **argv) {
  char buffer[65535];
  int client_fd, size;
  if (mknod("/net/tcp/*!10000", S_IFREG | S_IRWXU, 0) < 0 && errno != EEXIST)
    die("mknod");
  while (1) {
    client_fd = open("/net/tcp/*!10000", O_RDWR);
    if (client_fd < 0)
      die("read");
    do {
      size = read(client_fd, buffer, sizeof(buffer));
      if (size < 0)
        die("read");
      write(STDOUT_FILENO, buffer, size);
    } while (size != 0);
    close(client_fd);
  }
  remove("/net/tcp/*!10000");
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10020,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e50(%rip),%rax
mov    (%rax),%esi
mov    0x2e57(%rip),%rax
or     (%rax),%esi
lea    0xe6e(%rip),%rdi
xor    %edx,%edx
call   1060 <mknod@plt>
cmp    $0x0,%rax
jge    11c9 <main+0x69>
mov    0x2e0e(%rip),%rax
mov    (%rax),%rax
mov    0x2e0c(%rip),%rcx
cmp    (%rcx),%rax
je     11c9 <main+0x69>
lea    0xe4d(%rip),%rdi
call   1080 <die@plt>
jmp    11ce <main+0x6e>
mov    0x2e03(%rip),%rax
mov    (%rax),%esi
lea    0xe22(%rip),%rdi
call   1070 <open@plt>
mov    %eax,-0x10014(%rbp)
cmpl   $0x0,-0x10014(%rbp)
jge    1202 <main+0xa2>
lea    0xe1a(%rip),%rdi
call   1080 <die@plt>
jmp    1207 <main+0xa7>
mov    -0x10014(%rbp),%edi
lea    -0x10010(%rbp),%rsi
mov    $0xffff,%edx
call   1050 <read@plt>
mov    %eax,-0x10018(%rbp)
cmpl   $0x0,-0x10018(%rbp)
jge    123d <main+0xdd>
lea    0xddf(%rip),%rdi
call   1080 <die@plt>
mov    0x2dac(%rip),%rax
mov    (%rax),%edi
lea    -0x10010(%rbp),%rsi
mov    -0x10018(%rbp),%edx
call   1030 <write@plt>
cmpl   $0x0,-0x10018(%rbp)
jne    1207 <main+0xa7>
mov    -0x10014(%rbp),%edi
call   1040 <close@plt>
jmp    11ce <main+0x6e>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10008,%rsp
mov    0x2e58(%rip),%rax
mov    0x2e61(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
lea    0xe76(%rip),%rdi
xor    %edx,%edx
call   1060 <mknod@plt>
test   %rax,%rax
jns    11b8 <main+0x58>
mov    0x2e1b(%rip),%rax
mov    (%rax),%rax
mov    0x2e19(%rip),%rcx
cmp    (%rcx),%rax
je     11b8 <main+0x58>
lea    0xe5e(%rip),%rdi
call   1080 <die@plt>
lea    0xe41(%rip),%r14
lea    0xe51(%rip),%r15
mov    %rsp,%r12
mov    0x2e20(%rip),%r13
jmp    11e7 <main+0x87>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %ebp,%edi
call   1040 <close@plt>
mov    0x2dea(%rip),%rax
mov    (%rax),%esi
mov    %r14,%rdi
call   1070 <open@plt>
mov    %eax,%ebp
test   %eax,%eax
jns    1222 <main+0xc2>
mov    %r15,%rdi
call   1080 <die@plt>
jmp    1222 <main+0xc2>
nopl   0x0(%rax,%rax,1)
mov    0x0(%r13),%edi
mov    %r12,%rsi
mov    %ebx,%edx
call   1030 <write@plt>
test   %ebx,%ebx
je     11e0 <main+0x80>
mov    %ebp,%edi
mov    %r12,%rsi
mov    $0xffff,%edx
call   1050 <read@plt>
mov    %eax,%ebx
test   %eax,%eax
jns    1210 <main+0xb0>
mov    %r15,%rdi
call   1080 <die@plt>
jmp    1210 <main+0xb0>

LLVM IR (-O0):
@.str = [17 x i8] c"/net/tcp/*!10000\00"
@S_IFREG = global i32 0
@S_IRWXU = global i32 0
@errno = global i64 0
@EEXIST = global i64 0
@.str.1 = [6 x i8] c"mknod\00"
@O_RDWR = global i32 0
@.str.2 = [5 x i8] c"read\00"
@STDOUT_FILENO = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [65535 x i8]
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* @S_IFREG
%10 = load i32, i32* @S_IRWXU
%11 = or i32 %9, %10
%12 = call i64 @mknod(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 %11, i32 0)
%13 = icmp slt i64 %12, 0
br i1 %13, label %14, label %20
14: ; preds = %2
%15 = load i64, i64* @errno
%16 = load i64, i64* @EEXIST
%17 = icmp ne i64 %15, %16
br i1 %17, label %18, label %20
18: ; preds = %14
%19 = call i32 @die(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
br label %20
20: ; preds = %18, %14, %2
br label %21
21: ; preds = %20, %45
%22 = load i32, i32* @O_RDWR
%23 = call i32 @open(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 %22)
store i32 %23, i32* %7
%24 = load i32, i32* %7
%25 = icmp slt i32 %24, 0
br i1 %25, label %26, label %28
26: ; preds = %21
%27 = call i32 @die(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
br label %28
28: ; preds = %26, %21
br label %29
29: ; preds = %42, %28
%30 = load i32, i32* %7
%31 = getelementptr inbounds [65535 x i8], [65535 x i8]* %6, i64 0, i64 0
%32 = call i32 @read(i32 %30, i8* %31, i32 65535)
store i32 %32, i32* %8
%33 = load i32, i32* %8
%34 = icmp slt i32 %33, 0
br i1 %34, label %35, label %37
35: ; preds = %29
%36 = call i32 @die(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
br label %37
37: ; preds = %35, %29
%38 = load i32, i32* @STDOUT_FILENO
%39 = getelementptr inbounds [65535 x i8], [65535 x i8]* %6, i64 0, i64 0
%40 = load i32, i32* %8
%41 = call i32 @write(i32 %38, i8* %39, i32 %40)
br label %42
42: ; preds = %37
%43 = load i32, i32* %8
%44 = icmp ne i32 %43, 0
br i1 %44, label %29, label %45
45: ; preds = %42
%46 = load i32, i32* %7
%47 = call i32 @close(i32 %46)
br label %21
}

LLVM IR (-O2):
@.str = [17 x i8] c"/net/tcp/*!10000\00"
@S_IFREG = global i32 0
@S_IRWXU = global i32 0
@errno = global i64 0
@EEXIST = global i64 0
@.str.1 = [6 x i8] c"mknod\00"
@O_RDWR = global i32 0
@.str.2 = [5 x i8] c"read\00"
@STDOUT_FILENO = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [65535 x i8]
%4 = getelementptr inbounds [65535 x i8], [65535 x i8]* %3, i64 0, i64 0
%5 = load i32, i32* @S_IFREG
%6 = load i32, i32* @S_IRWXU
%7 = or i32 %6, %5
%8 = tail call i64 @mknod(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 %7, i32 0)
%9 = icmp slt i64 %8, 0
br i1 %9, label %10, label %16
10: ; preds = %2
%11 = load i64, i64* @errno
%12 = load i64, i64* @EEXIST
%13 = icmp eq i64 %11, %12
br i1 %13, label %16, label %14
14: ; preds = %10
%15 = tail call i32 @die(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
br label %16
16: ; preds = %14, %10, %2
br label %17
17: ; preds = %16, %33
%18 = load i32, i32* @O_RDWR
%19 = tail call i32 @open(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 %18)
%20 = icmp slt i32 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %17
%22 = tail call i32 @die(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
br label %23
23: ; preds = %21, %17
br label %24
24: ; preds = %23, %29
%25 = call i32 @read(i32 %19, i8* %4, i32 65535)
%26 = icmp slt i32 %25, 0
br i1 %26, label %27, label %29
27: ; preds = %24
%28 = tail call i32 @die(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
br label %29
29: ; preds = %27, %24
%30 = load i32, i32* @STDOUT_FILENO
%31 = call i32 @write(i32 %30, i8* %4, i32 %25)
%32 = icmp eq i32 %25, 0
br i1 %32, label %33, label %24
33: ; preds = %29
%34 = tail call i32 @close(i32 %19)
br label %17
}