#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 */
int accept(int, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ getchar();
int /*<<< orphan*/ perror(char *);
int recv(int, char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ send(int, char *, int, int /*<<< orphan*/);
scalar_t__ strncmp(char *, char *, int);
void servlet(int server) {
  int bytes;
  char buffer[1024];
  for (;;) {
    int client = accept(server, 0, 0);
    if (client > 0) {
      do {
        bytes = recv(client, buffer, sizeof(buffer), 0);
        if (bytes > 0)
          send(client, buffer, bytes, 0);
      } while (bytes > 0 && strncmp("bye\r", buffer, 4) != 0);
      close(client);
    } else {
      perror("accept()");
      getchar();
    }
  }
}


x86 assembly (clang, -O0):
<servlet>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
xor    %edx,%edx
mov    %edx,%esi
call   1090 <accept@plt>
mov    %eax,-0x414(%rbp)
cmpl   $0x0,-0x414(%rbp)
jle    1239 <servlet+0xc9>
jmp    11a2 <servlet+0x32>
mov    -0x414(%rbp),%edi
lea    -0x410(%rbp),%rsi
mov    $0x400,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jle    11df <servlet+0x6f>
mov    -0x414(%rbp),%edi
lea    -0x410(%rbp),%rsi
mov    -0x8(%rbp),%edx
xor    %ecx,%ecx
call   1050 <send@plt>
jmp    11e4 <servlet+0x74>
xor    %eax,%eax
cmpl   $0x0,-0x8(%rbp)
mov    %al,-0x415(%rbp)
jle    121b <servlet+0xab>
lea    -0x410(%rbp),%rsi
lea    0xdfc(%rip),%rdi
mov    $0x4,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x415(%rbp)
mov    -0x415(%rbp),%al
test   $0x1,%al
jne    11a2 <servlet+0x32>
mov    -0x414(%rbp),%edi
call   1060 <close@plt>
jmp    124c <servlet+0xdc>
lea    0xdc5(%rip),%rdi
call   1080 <perror@plt>
mov    $0x0,%al
call   1070 <getchar@plt>
jmp    117e <servlet+0xe>

x86 assembly (clang, -O2):
<servlet>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x400,%rsp
mov    %edi,%r14d
mov    %rsp,%rbx
lea    0xe74(%rip),%r12
lea    0xe72(%rip),%r15
jmp    11a7 <servlet+0x37>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %ebp,%edi
call   1060 <close@plt>
mov    %r14d,%edi
xor    %esi,%esi
xor    %edx,%edx
call   1090 <accept@plt>
test   %eax,%eax
jle    11fa <servlet+0x8a>
mov    %eax,%ebp
nopl   0x0(%rax)
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x400,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
test   %eax,%eax
jle    11a0 <servlet+0x30>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1050 <send@plt>
mov    %r12,%rdi
mov    %rbx,%rsi
mov    $0x4,%edx
call   1040 <strncmp@plt>
test   %rax,%rax
jne    11c0 <servlet+0x50>
jmp    11a0 <servlet+0x30>
mov    %r15,%rdi
call   1080 <perror@plt>
xor    %eax,%eax
call   1070 <getchar@plt>
jmp    11a7 <servlet+0x37>

LLVM IR (-O0):
@.str = [5 x i8] c"bye\0D\00"
@.str.1 = [9 x i8] c"accept()\00"
define void @servlet(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca [1024 x i8]
%5 = alloca i32
store i32 %0, i32* %2
br label %6
6: ; preds = %39, %1
%7 = load i32, i32* %2
%8 = call i32 @accept(i32 %7, i32 0, i32 0)
store i32 %8, i32* %5
%9 = load i32, i32* %5
%10 = icmp sgt i32 %9, 0
br i1 %10, label %11, label %36
11: ; preds = %6
br label %12
12: ; preds = %31, %11
%13 = load i32, i32* %5
%14 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%15 = call i32 @recv(i32 %13, i8* %14, i32 1024, i32 0)
store i32 %15, i32* %3
%16 = load i32, i32* %3
%17 = icmp sgt i32 %16, 0
br i1 %17, label %18, label %23
18: ; preds = %12
%19 = load i32, i32* %5
%20 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%21 = load i32, i32* %3
%22 = call i32 @send(i32 %19, i8* %20, i32 %21, i32 0)
br label %23
23: ; preds = %18, %12
br label %24
24: ; preds = %23
%25 = load i32, i32* %3
%26 = icmp sgt i32 %25, 0
br i1 %26, label %27, label %31
27: ; preds = %24
%28 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%29 = call i64 @strncmp(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %28, i32 4)
%30 = icmp ne i64 %29, 0
br label %31
31: ; preds = %27, %24
%32 = phi i1 [ false, %24 ], [ %30, %27 ]
br i1 %32, label %12, label %33
33: ; preds = %31
%34 = load i32, i32* %5
%35 = call i32 @close(i32 %34)
br label %39
36: ; preds = %6
%37 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%38 = call i32 (...) @getchar()
br label %39
39: ; preds = %36, %33
br label %6
}

LLVM IR (-O2):
@.str = [5 x i8] c"bye\0D\00"
@.str.1 = [9 x i8] c"accept()\00"
define void @servlet(i32 %0) {
%2 = alloca [1024 x i8]
%3 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
br label %4
4: ; preds = %19, %1
%5 = call i32 @accept(i32 %0, i32 0, i32 0)
%6 = icmp sgt i32 %5, 0
br i1 %6, label %7, label %16
7: ; preds = %4, %10
%8 = call i32 @recv(i32 %5, i8* %3, i32 1024, i32 0)
%9 = icmp sgt i32 %8, 0
br i1 %9, label %10, label %14
10: ; preds = %7
%11 = call i32 @send(i32 %5, i8* %3, i32 %8, i32 0)
%12 = call i64 @strncmp(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %3, i32 4)
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %7
14: ; preds = %7, %10
%15 = call i32 @close(i32 %5)
br label %19
16: ; preds = %4
%17 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%18 = call i32 (...) @getchar()
br label %19
19: ; preds = %16, %14
br label %4
}