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

/* Variables and functions */
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ printf(char *);
int recv(int, char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ send(int, char *, int, int /*<<< orphan*/);
scalar_t__ strncmp(char *, char *, int);
void *ServerThread(void *arg) {
  char buf[100];
  int bytes_read;
  int fd = *(int *)arg;
  for (;;) {
    bytes_read = recv(fd, buf, sizeof(buf), 0);
    send(fd, buf, bytes_read, 0);
    if (strncmp(buf, "q", 1) == 0)
      break;
  }
  printf("Connection Close!\n");
  close(fd);
  return arg;
}


x86 assembly (clang, -O0):
<ServerThread>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x78(%rbp)
mov    -0x78(%rbp),%edi
lea    -0x70(%rbp),%rsi
mov    $0x64,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,-0x74(%rbp)
mov    -0x78(%rbp),%edi
lea    -0x70(%rbp),%rsi
mov    -0x74(%rbp),%edx
xor    %ecx,%ecx
call   1050 <send@plt>
lea    -0x70(%rbp),%rdi
lea    0xe66(%rip),%rsi
mov    $0x1,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%rax
jne    11b3 <ServerThread+0x63>
jmp    11b8 <ServerThread+0x68>
jmp    1168 <ServerThread+0x18>
lea    0xe43(%rip),%rdi
call   1060 <printf@plt>
mov    -0x78(%rbp),%edi
call   1070 <close@plt>
mov    -0x8(%rbp),%rax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ServerThread>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x68,%rsp
mov    %rdi,%r14
mov    (%rdi),%ebp
mov    %rsp,%rbx
lea    0xe97(%rip),%r15
nopl   0x0(%rax)
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x64,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1060 <send@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    $0x1,%edx
call   1040 <strncmp@plt>
test   %rax,%rax
jne    1170 <ServerThread+0x20>
lea    0xe57(%rip),%rdi
call   1050 <puts@plt>
mov    %ebp,%edi
call   1070 <close@plt>
mov    %r14,%rax
add    $0x68,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"q\00"
@.str.1 = [19 x i8] c"Connection Close!\0A\00"
define i8* @ServerThread(i8* %0) {
%2 = alloca i8*
%3 = alloca [100 x i8]
%4 = alloca i32
%5 = alloca i32
store i8* %0, i8** %2
%6 = load i8*, i8** %2
%7 = bitcast i8* %6 to i32*
%8 = load i32, i32* %7
store i32 %8, i32* %5
br label %9
9: ; preds = %21, %1
%10 = load i32, i32* %5
%11 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%12 = call i32 @recv(i32 %10, i8* %11, i32 100, i32 0)
store i32 %12, i32* %4
%13 = load i32, i32* %5
%14 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%15 = load i32, i32* %4
%16 = call i32 @send(i32 %13, i8* %14, i32 %15, i32 0)
%17 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%18 = call i64 @strncmp(i8* %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 1)
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %21
20: ; preds = %9
br label %22
21: ; preds = %9
br label %9
22: ; preds = %20
%23 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
%24 = load i32, i32* %5
%25 = call i32 @close(i32 %24)
%26 = load i8*, i8** %2
ret i8* %26
}

LLVM IR (-O2):
@.str = [2 x i8] c"q\00"
@str = [18 x i8] c"Connection Close!\00"
define i8* @ServerThread(i8* returned %0) {
%2 = alloca [100 x i8]
%3 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%4 = bitcast i8* %0 to i32*
%5 = load i32, i32* %4
br label %6
6: ; preds = %6, %1
%7 = call i32 @recv(i32 %5, i8* %3, i32 100, i32 0)
%8 = call i32 @send(i32 %5, i8* %3, i32 %7, i32 0)
%9 = call i64 @strncmp(i8* %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 1)
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %6
11: ; preds = %6
%12 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str, i64 0, i64 0))
%13 = call i32 @close(i32 %5)
ret i8* %0
}