#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 /*<<< orphan*/ SIGTERM;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ getppid();
int /*<<< orphan*/ kill(int /*<<< orphan*/, int /*<<< orphan*/);
int read(int, char *, int);
int /*<<< orphan*/ tcp_done(int);
int /*<<< orphan*/ write(int, char *, int);
void doserver(int sock) {
  char c;
  int n = 0;
  while (read(sock, &c, 1) == 1) {
    write(sock, &c, 1);
    n++;
  }
  if (n == 0) {
    tcp_done(3962);
    kill(getppid(), SIGTERM);
    exit(0);
  }
}


x86 assembly (clang, -O0):
<doserver>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x5(%rbp),%rsi
mov    $0x1,%edx
call   1050 <read@plt>
cmp    $0x1,%eax
jne    11ab <doserver+0x4b>
mov    -0x4(%rbp),%edi
lea    -0x5(%rbp),%rsi
mov    $0x1,%edx
call   1040 <write@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1172 <doserver+0x12>
cmpl   $0x0,-0xc(%rbp)
jne    11dd <doserver+0x7d>
mov    $0xf7a,%edi
call   1030 <tcp_done@plt>
mov    $0x0,%al
call   1070 <getppid@plt>
mov    %eax,%edi
mov    0x2e19(%rip),%rax
mov    (%rax),%esi
call   1060 <kill@plt>
xor    %edi,%edi
call   1080 <exit@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<doserver>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebx
lea    0xf(%rsp),%rsi
mov    $0x1,%edx
call   1050 <read@plt>
cmp    $0x1,%eax
jne    11c2 <doserver+0x62>
mov    %eax,%r14d
lea    0xf(%rsp),%rbp
cs nopw 0x0(%rax,%rax,1)
mov    %ebx,%edi
mov    %rbp,%rsi
mov    $0x1,%edx
call   1040 <write@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
mov    $0x1,%edx
call   1050 <read@plt>
cmp    $0x1,%eax
je     1190 <doserver+0x30>
cmp    $0x1,%r14d
jne    11c2 <doserver+0x62>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    $0xf7a,%edi
call   1030 <tcp_done@plt>
xor    %eax,%eax
call   1070 <getppid@plt>
mov    0x2e0e(%rip),%rcx
mov    (%rcx),%esi
mov    %eax,%edi
call   1060 <kill@plt>
xor    %edi,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@SIGTERM = global i32 0
define void @doserver(i32 %0) {
%2 = alloca i32
%3 = alloca i8
%4 = alloca i32
store i32 %0, i32* %2
store i32 0, i32* %4
br label %5
5: ; preds = %9, %1
%6 = load i32, i32* %2
%7 = call i32 @read(i32 %6, i8* %3, i32 1)
%8 = icmp eq i32 %7, 1
br i1 %8, label %9, label %14
9: ; preds = %5
%10 = load i32, i32* %2
%11 = call i32 @write(i32 %10, i8* %3, i32 1)
%12 = load i32, i32* %4
%13 = add nsw i32 %12, 1
store i32 %13, i32* %4
br label %5
14: ; preds = %5
%15 = load i32, i32* %4
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %23
17: ; preds = %14
%18 = call i32 @tcp_done(i32 3962)
%19 = call i32 (...) @getppid()
%20 = load i32, i32* @SIGTERM
%21 = call i32 @kill(i32 %19, i32 %20)
%22 = call i32 @exit(i32 0)
unreachable
23: ; preds = %14
ret void
}

LLVM IR (-O2):
@SIGTERM = global i32 0
define void @doserver(i32 %0) {
%2 = alloca i8
%3 = call i32 @read(i32 %0, i8* %2, i32 1)
%4 = icmp eq i32 %3, 1
br i1 %4, label %5, label %10
5: ; preds = %1, %5
%6 = call i32 @write(i32 %0, i8* %2, i32 1)
%7 = call i32 @read(i32 %0, i8* %2, i32 1)
%8 = icmp eq i32 %7, 1
br i1 %8, label %5, label %9
9: ; preds = %5
br i1 %4, label %16, label %10
10: ; preds = %1, %9
%11 = tail call i32 @tcp_done(i32 3962)
%12 = tail call i32 (...) @getppid()
%13 = load i32, i32* @SIGTERM
%14 = tail call i32 @kill(i32 %12, i32 %13)
%15 = tail call i32 @exit(i32 0)
unreachable
16: ; preds = %9
ret void
}