#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*/ close(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ printf(char *);
int recv(int, char *, int, int /*<<< orphan*/);
int send(int, char *, int, int /*<<< orphan*/);
scalar_t__ strncmp(char *, char *, int);
void echo(int client_fd) {
  char in[512] = {'\0'};
  int in_size;
  if ((in_size = recv(client_fd, in, 512, 0)) < 0) {
    printf("recv() failed");
    exit(-1);
  }
  while (strncmp(in, "/quit", 5) != 0) {
    if (send(client_fd, in, in_size, 0) != in_size) {
      printf("send() failed");
      exit(-1);
    }
    if ((in_size = recv(client_fd, in, 512, 0)) < 0) {
      printf("recv() failed");
      exit(-1);
    }
  }
  close(client_fd);
  return;
}


x86 assembly (clang, -O0):
<echo>:
push   %rbp
mov    %rsp,%rbp
sub    $0x220,%rsp
mov    %edi,-0x4(%rbp)
lea    -0x210(%rbp),%rdi
xor    %esi,%esi
mov    $0x200,%edx
call   1070 <memset@plt>
mov    -0x4(%rbp),%edi
lea    -0x210(%rbp),%rsi
mov    $0x200,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,-0x214(%rbp)
cmp    $0x0,%eax
jge    11cc <echo+0x5c>
lea    0xe43(%rip),%rdi
call   1060 <printf@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>
jmp    11d1 <echo+0x61>
lea    -0x210(%rbp),%rdi
lea    0xe2f(%rip),%rsi
mov    $0x5,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%rax
je     126c <echo+0xfc>
mov    -0x4(%rbp),%edi
lea    -0x210(%rbp),%rsi
mov    -0x214(%rbp),%edx
xor    %ecx,%ecx
call   1050 <send@plt>
cmp    -0x214(%rbp),%eax
je     122c <echo+0xbc>
lea    0xdf7(%rip),%rdi
call   1060 <printf@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>
mov    -0x4(%rbp),%edi
lea    -0x210(%rbp),%rsi
mov    $0x200,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,-0x214(%rbp)
cmp    $0x0,%eax
jge    1267 <echo+0xf7>
lea    0xda8(%rip),%rdi
call   1060 <printf@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>
jmp    11d1 <echo+0x61>
mov    -0x4(%rbp),%edi
call   1080 <close@plt>
add    $0x220,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<echo>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x208,%rsp
mov    %edi,%r15d
mov    %rsp,%rbx
mov    $0x200,%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1070 <memset@plt>
mov    %r15d,%edi
mov    %rbx,%rsi
mov    $0x200,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
test   %eax,%eax
js     1200 <echo+0x90>
mov    %eax,%ebp
lea    0xe5d(%rip),%r14
mov    %rsp,%rbx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x5,%edx
call   1040 <strncmp@plt>
test   %rax,%rax
je     1209 <echo+0x99>
mov    %r15d,%edi
mov    %rbx,%rsi
mov    %ebp,%edx
xor    %ecx,%ecx
call   1050 <send@plt>
cmp    %ebp,%eax
jne    121f <echo+0xaf>
mov    %r15d,%edi
mov    %rbx,%rsi
mov    $0x200,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,%ebp
test   %eax,%eax
jns    11c0 <echo+0x50>
lea    0xdf9(%rip),%rdi
jmp    1226 <echo+0xb6>
mov    %r15d,%edi
call   1080 <close@plt>
add    $0x208,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xdee(%rip),%rdi
call   1060 <printf@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [14 x i8] c"recv() failed\00"
@.str.1 = [6 x i8] c"/quit\00"
@.str.2 = [14 x i8] c"send() failed\00"
define void @echo(i32 %0) {
%2 = alloca i32
%3 = alloca [512 x i8]
%4 = alloca i32
store i32 %0, i32* %2
%5 = bitcast [512 x i8]* %3 to i8*
%6 = load i32, i32* %2
%7 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%8 = call i32 @recv(i32 %6, i8* %7, i32 512, i32 0)
store i32 %8, i32* %4
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %13
10: ; preds = %1
%11 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%12 = call i32 @exit(i32 -1)
unreachable
13: ; preds = %1
br label %14
14: ; preds = %36, %13
%15 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%16 = call i64 @strncmp(i8* %15, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 5)
%17 = icmp ne i64 %16, 0
br i1 %17, label %18, label %37
18: ; preds = %14
%19 = load i32, i32* %2
%20 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%21 = load i32, i32* %4
%22 = call i32 @send(i32 %19, i8* %20, i32 %21, i32 0)
%23 = load i32, i32* %4
%24 = icmp ne i32 %22, %23
br i1 %24, label %25, label %28
25: ; preds = %18
%26 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%27 = call i32 @exit(i32 -1)
unreachable
28: ; preds = %18
%29 = load i32, i32* %2
%30 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%31 = call i32 @recv(i32 %29, i8* %30, i32 512, i32 0)
store i32 %31, i32* %4
%32 = icmp slt i32 %31, 0
br i1 %32, label %33, label %36
33: ; preds = %28
%34 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%35 = call i32 @exit(i32 -1)
unreachable
36: ; preds = %28
br label %14
37: ; preds = %14
%38 = load i32, i32* %2
%39 = call i32 @close(i32 %38)
ret void
}

LLVM IR (-O2):
@.str = [14 x i8] c"recv() failed\00"
@.str.1 = [6 x i8] c"/quit\00"
@.str.2 = [14 x i8] c"send() failed\00"
define void @echo(i32 %0) {
%2 = alloca [512 x i8]
%3 = getelementptr inbounds [512 x i8], [512 x i8]* %2, i64 0, i64 0
%4 = call i32 @recv(i32 %0, i8* %3, i32 512, i32 0)
%5 = icmp slt i32 %4, 0
br i1 %5, label %6, label %9
6: ; preds = %1
%7 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%8 = call i32 @exit(i32 -1)
unreachable
9: ; preds = %1, %19
%10 = phi i32 [ %20, %19 ], [ %4, %1 ]
%11 = call i64 @strncmp(i8* %3, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 5)
%12 = icmp eq i64 %11, 0
br i1 %12, label %25, label %13
13: ; preds = %9
%14 = call i32 @send(i32 %0, i8* %3, i32 %10, i32 0)
%15 = icmp eq i32 %14, %10
br i1 %15, label %19, label %16
16: ; preds = %13
%17 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%18 = call i32 @exit(i32 -1)
unreachable
19: ; preds = %13
%20 = call i32 @recv(i32 %0, i8* %3, i32 512, i32 0)
%21 = icmp slt i32 %20, 0
br i1 %21, label %22, label %9
22: ; preds = %19
%23 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%24 = call i32 @exit(i32 -1)
unreachable
25: ; preds = %9
%26 = call i32 @close(i32 %0)
ret void
}