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

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int read(int, char *, int);
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ write(int, char *, int);
void do_service(int fd) {
  char recvbuf[200];
  while (1) {
    memset(recvbuf, 0, sizeof(recvbuf));
    int ret = read(fd, recvbuf, sizeof(recvbuf));
    if (-1 == ret) {
      do {
        perror("read");
        exit(EXIT_FAILURE);
      } while (0);
    } else if (0 == ret) {
      printf("client closed \n");
      break;
    }
    fputs(recvbuf, stdout);
    write(fd, recvbuf, ret);
  }
}


x86 assembly (clang, -O0):
<do_service>:
push   %rbp
mov    %rsp,%rbp
sub    $0xe0,%rsp
mov    %edi,-0x4(%rbp)
lea    -0xd0(%rbp),%rdi
xor    %esi,%esi
mov    $0xc8,%edx
call   1060 <memset@plt>
mov    -0x4(%rbp),%edi
lea    -0xd0(%rbp),%rsi
mov    $0xc8,%edx
call   1070 <read@plt>
mov    %eax,-0xd4(%rbp)
mov    $0xffffffff,%eax
cmp    -0xd4(%rbp),%eax
jne    11db <do_service+0x6b>
jmp    11c1 <do_service+0x51>
lea    0xe38(%rip),%rdi
call   1080 <perror@plt>
mov    0x2e0c(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
xor    %eax,%eax
cmp    -0xd4(%rbp),%eax
jne    11fa <do_service+0x8a>
lea    0xe15(%rip),%rdi
call   1040 <printf@plt>
jmp    122e <do_service+0xbe>
jmp    11ff <do_service+0x8f>
lea    -0xd0(%rbp),%rdi
mov    0x2dcb(%rip),%rax
mov    (%rax),%esi
call   1050 <fputs@plt>
mov    -0x4(%rbp),%edi
lea    -0xd0(%rbp),%rsi
mov    -0xd4(%rbp),%edx
call   1030 <write@plt>
jmp    117e <do_service+0xe>
add    $0xe0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_service>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0xc8,%rsp
mov    %edi,%r14d
mov    %rsp,%rbx
mov    0x2e4e(%rip),%r15
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0xc8,%edx
call   1060 <memset@plt>
mov    %r14d,%edi
mov    %rbx,%rsi
mov    $0xc8,%edx
call   1070 <read@plt>
test   %eax,%eax
je     11d4 <do_service+0x64>
mov    %eax,%ebp
cmp    $0xffffffff,%eax
je     11ee <do_service+0x7e>
mov    (%r15),%esi
mov    %rbx,%rdi
call   1050 <fputs@plt>
mov    %r14d,%edi
mov    %rbx,%rsi
mov    %ebp,%edx
call   1040 <write@plt>
jmp    1190 <do_service+0x20>
lea    0xe2a(%rip),%rdi
call   1030 <puts@plt>
add    $0xc8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe0b(%rip),%rdi
call   1080 <perror@plt>
mov    0x2ddf(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [5 x i8] c"read\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [16 x i8] c"client closed \0A\00"
@stdout = global i32 0
define void @do_service(i32 %0) {
%2 = alloca i32
%3 = alloca [200 x i8]
%4 = alloca i32
store i32 %0, i32* %2
br label %5
5: ; preds = %1, %25
%6 = getelementptr inbounds [200 x i8], [200 x i8]* %3, i64 0, i64 0
%7 = call i32 @memset(i8* %6, i32 0, i32 200)
%8 = load i32, i32* %2
%9 = getelementptr inbounds [200 x i8], [200 x i8]* %3, i64 0, i64 0
%10 = call i32 @read(i32 %8, i8* %9, i32 200)
store i32 %10, i32* %4
%11 = load i32, i32* %4
%12 = icmp eq i32 -1, %11
br i1 %12, label %13, label %19
13: ; preds = %5
br label %14
14: ; preds = %13
%15 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%16 = load i32, i32* @EXIT_FAILURE
%17 = call i32 @exit(i32 %16)
unreachable
18: ; No predecessors!
br label %25
19: ; preds = %5
%20 = load i32, i32* %4
%21 = icmp eq i32 0, %20
br i1 %21, label %22, label %24
22: ; preds = %19
%23 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
br label %33
24: ; preds = %19
br label %25
25: ; preds = %24, %18
%26 = getelementptr inbounds [200 x i8], [200 x i8]* %3, i64 0, i64 0
%27 = load i32, i32* @stdout
%28 = call i32 @fputs(i8* %26, i32 %27)
%29 = load i32, i32* %2
%30 = getelementptr inbounds [200 x i8], [200 x i8]* %3, i64 0, i64 0
%31 = load i32, i32* %4
%32 = call i32 @write(i32 %29, i8* %30, i32 %31)
br label %5
33: ; preds = %22
ret void
}

LLVM IR (-O2):
@.str = [5 x i8] c"read\00"
@EXIT_FAILURE = global i32 0
@stdout = global i32 0
@str = [15 x i8] c"client closed \00"
define void @do_service(i32 %0) {
%2 = alloca [200 x i8]
%3 = getelementptr inbounds [200 x i8], [200 x i8]* %2, i64 0, i64 0
br label %4
4: ; preds = %11, %1
%5 = call i32 @memset(i8* %3, i32 0, i32 200)
%6 = call i32 @read(i32 %0, i8* %3, i32 200)
switch i32 %6, label %11 [
i32 -1, label %7
i32 0, label %15
]
7: ; preds = %4
%8 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%9 = load i32, i32* @EXIT_FAILURE
%10 = call i32 @exit(i32 %9)
unreachable
11: ; preds = %4
%12 = load i32, i32* @stdout
%13 = call i32 @fputs(i8* %3, i32 %12)
%14 = call i32 @write(i32 %0, i8* %3, i32 %6)
br label %4
15: ; preds = %4
%16 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str, i64 0, i64 0))
ret void
}