#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*/ printf(char *, char *);
int read(int, char *, int);
int /*<<< orphan*/ strncasecmp(char *, char *, int);
int /*<<< orphan*/ write(int, char *, int);
void *echo_service(void *context) {
  int fd = (int)(long)context;
  char buf[10240 + 1];
  int ret;
  while ((ret = read(fd, buf, 10240)) > 0) {
    buf[ret] = 0;
    printf("your input: %s", buf);
    write(fd, buf, ret);
    if ((!strncasecmp(buf, "exit", 4)) || (!strncasecmp(buf, "quit", 4))) {
      break;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<echo_service>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2820,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%edi
lea    -0x2810(%rbp),%rsi
mov    $0x2800,%edx
call   1050 <read@plt>
mov    %eax,-0x2814(%rbp)
cmp    $0x0,%eax
jle    11fc <echo_service+0xbc>
movslq -0x2814(%rbp),%rax
movb   $0x0,-0x2810(%rbp,%rax,1)
lea    -0x2810(%rbp),%rsi
lea    0xe6a(%rip),%rdi
call   1040 <printf@plt>
mov    -0xc(%rbp),%edi
lea    -0x2810(%rbp),%rsi
mov    -0x2814(%rbp),%edx
call   1030 <write@plt>
lea    -0x2810(%rbp),%rdi
lea    0xe51(%rip),%rsi
mov    $0x4,%edx
call   1060 <strncasecmp@plt>
cmp    $0x0,%eax
je     11f2 <echo_service+0xb2>
lea    -0x2810(%rbp),%rdi
lea    0xe35(%rip),%rsi
mov    $0x4,%edx
call   1060 <strncasecmp@plt>
cmp    $0x0,%eax
jne    11f7 <echo_service+0xb7>
jmp    11fc <echo_service+0xbc>
jmp    1156 <echo_service+0x16>
xor    %eax,%eax
add    $0x2820,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<echo_service>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x2808,%rsp
mov    %rdi,%r14
mov    %rsp,%rbx
lea    0xea2(%rip),%r15
lea    0xeaa(%rip),%r12
lea    0xea8(%rip),%r13
nopl   0x0(%rax)
mov    %r14d,%edi
mov    %rbx,%rsi
mov    $0x2800,%edx
call   1050 <read@plt>
test   %eax,%eax
jle    11cc <echo_service+0x8c>
mov    %eax,%ebp
mov    %eax,%eax
movb   $0x0,(%rsp,%rax,1)
mov    %r15,%rdi
mov    %rbx,%rsi
call   1040 <printf@plt>
mov    %r14d,%edi
mov    %rbx,%rsi
mov    %ebp,%edx
call   1030 <write@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
mov    $0x4,%edx
call   1060 <strncasecmp@plt>
test   %eax,%eax
je     11cc <echo_service+0x8c>
mov    %rbx,%rdi
mov    %r13,%rsi
mov    $0x4,%edx
call   1060 <strncasecmp@plt>
test   %eax,%eax
jne    1170 <echo_service+0x30>
xor    %eax,%eax
add    $0x2808,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [15 x i8] c"your input: %s\00"
@.str.1 = [5 x i8] c"exit\00"
@.str.2 = [5 x i8] c"quit\00"
define i8* @echo_service(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca [10241 x i8]
%5 = alloca i32
store i8* %0, i8** %2
%6 = load i8*, i8** %2
%7 = ptrtoint i8* %6 to i64
%8 = trunc i64 %7 to i32
store i32 %8, i32* %3
br label %9
9: ; preds = %32, %1
%10 = load i32, i32* %3
%11 = getelementptr inbounds [10241 x i8], [10241 x i8]* %4, i64 0, i64 0
%12 = call i32 @read(i32 %10, i8* %11, i32 10240)
store i32 %12, i32* %5
%13 = icmp sgt i32 %12, 0
br i1 %13, label %14, label %33
14: ; preds = %9
%15 = load i32, i32* %5
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds [10241 x i8], [10241 x i8]* %4, i64 0, i64 %16
store i8 0, i8* %17
%18 = getelementptr inbounds [10241 x i8], [10241 x i8]* %4, i64 0, i64 0
%19 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* %18)
%20 = load i32, i32* %3
%21 = getelementptr inbounds [10241 x i8], [10241 x i8]* %4, i64 0, i64 0
%22 = load i32, i32* %5
%23 = call i32 @write(i32 %20, i8* %21, i32 %22)
%24 = getelementptr inbounds [10241 x i8], [10241 x i8]* %4, i64 0, i64 0
%25 = call i32 @strncasecmp(i8* %24, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 4)
%26 = icmp ne i32 %25, 0
br i1 %26, label %27, label %31
27: ; preds = %14
%28 = getelementptr inbounds [10241 x i8], [10241 x i8]* %4, i64 0, i64 0
%29 = call i32 @strncasecmp(i8* %28, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 4)
%30 = icmp ne i32 %29, 0
br i1 %30, label %32, label %31
31: ; preds = %27, %14
br label %33
32: ; preds = %27
br label %9
33: ; preds = %31, %9
ret i8* null
}

LLVM IR (-O2):
@.str = [15 x i8] c"your input: %s\00"
@.str.1 = [5 x i8] c"exit\00"
@.str.2 = [5 x i8] c"quit\00"
define noalias i8* @echo_service(i8* %0) {
%2 = alloca [10241 x i8]
%3 = ptrtoint i8* %0 to i64
%4 = trunc i64 %3 to i32
%5 = getelementptr inbounds [10241 x i8], [10241 x i8]* %2, i64 0, i64 0
br label %6
6: ; preds = %16, %1
%7 = call i32 @read(i32 %4, i8* %5, i32 10240)
%8 = icmp sgt i32 %7, 0
br i1 %8, label %9, label %19
9: ; preds = %6
%10 = zext i32 %7 to i64
%11 = getelementptr inbounds [10241 x i8], [10241 x i8]* %2, i64 0, i64 %10
store i8 0, i8* %11
%12 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* %5)
%13 = call i32 @write(i32 %4, i8* %5, i32 %7)
%14 = call i32 @strncasecmp(i8* %5, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 4)
%15 = icmp eq i32 %14, 0
br i1 %15, label %19, label %16
16: ; preds = %9
%17 = call i32 @strncasecmp(i8* %5, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 4)
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %6
19: ; preds = %9, %16, %6
ret i8* null
}