#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*/ pthread_exit(int /*<<< orphan*/ *);
scalar_t__ read(int, char *, int);
int /*<<< orphan*/ strcpy(char *, char *);
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ write(int, char *, int /*<<< orphan*/);
void startCommandLineListener(int socket) {
  char buffer[256];
  for (;;) {
    strcpy(buffer, "Type 'X' to quit\n");
    write((int)socket, buffer, strlen(buffer));
    if (read((int)socket, buffer, 255) > 0) {
      if (buffer[0] == 'X') {
        close((int)socket);
        pthread_exit(NULL);
      }
    }
  }
}


x86 assembly (clang, -O0):
<startCommandLineListener>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
mov    %edi,-0x4(%rbp)
lea    -0x110(%rbp),%rdi
lea    0xe84(%rip),%rsi
call   1030 <strcpy@plt>
mov    -0x4(%rbp),%eax
mov    %eax,-0x11c(%rbp)
lea    -0x110(%rbp),%rax
mov    %rax,-0x118(%rbp)
lea    -0x110(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x11c(%rbp),%edi
mov    -0x118(%rbp),%rsi
mov    %eax,%edx
call   1040 <write@plt>
mov    -0x4(%rbp),%edi
lea    -0x110(%rbp),%rsi
mov    $0xff,%edx
call   1070 <read@plt>
cmp    $0x0,%rax
jle    11fc <startCommandLineListener+0x9c>
movsbl -0x110(%rbp),%eax
cmp    $0x58,%eax
jne    11f7 <startCommandLineListener+0x97>
mov    -0x4(%rbp),%edi
call   1060 <close@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1080 <pthread_exit@plt>
jmp    11fc <startCommandLineListener+0x9c>
jmp    116e <startCommandLineListener+0xe>

x86 assembly (clang, -O2):
<startCommandLineListener>:
push   %r15
push   %r14
push   %rbx
sub    $0x100,%rsp
mov    %edi,%ebx
lea    0xe8b(%rip),%r14
mov    %rsp,%r15
nopl   0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    %r14,%rsi
call   1030 <strcpy@plt>
mov    %r15,%rdi
call   1050 <strlen@plt>
mov    %ebx,%edi
mov    %r15,%rsi
mov    %eax,%edx
call   1040 <write@plt>
mov    %ebx,%edi
mov    %r15,%rsi
mov    $0xff,%edx
call   1070 <read@plt>
test   %rax,%rax
jle    1180 <startCommandLineListener+0x20>
cmpb   $0x58,(%rsp)
jne    1180 <startCommandLineListener+0x20>
mov    %ebx,%edi
call   1060 <close@plt>
xor    %edi,%edi
call   1080 <pthread_exit@plt>
jmp    1180 <startCommandLineListener+0x20>

LLVM IR (-O0):
@.str = [18 x i8] c"Type 'X' to quit\0A\00"
define void @startCommandLineListener(i32 %0) {
%2 = alloca i32
%3 = alloca [256 x i8]
store i32 %0, i32* %2
br label %4
4: ; preds = %26, %1
%5 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%6 = call i32 @strcpy(i8* %5, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%7 = load i32, i32* %2
%8 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%9 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%10 = call i32 @strlen(i8* %9)
%11 = call i32 @write(i32 %7, i8* %8, i32 %10)
%12 = load i32, i32* %2
%13 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%14 = call i64 @read(i32 %12, i8* %13, i32 255)
%15 = icmp sgt i64 %14, 0
br i1 %15, label %16, label %26
16: ; preds = %4
%17 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%18 = load i8, i8* %17
%19 = sext i8 %18 to i32
%20 = icmp eq i32 %19, 88
br i1 %20, label %21, label %25
21: ; preds = %16
%22 = load i32, i32* %2
%23 = call i32 @close(i32 %22)
%24 = call i32 @pthread_exit(i32* null)
br label %25
25: ; preds = %21, %16
br label %26
26: ; preds = %25, %4
br label %4
}

LLVM IR (-O2):
@.str = [18 x i8] c"Type 'X' to quit\0A\00"
define void @startCommandLineListener(i32 %0) {
%2 = alloca [256 x i8]
%3 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
br label %4
4: ; preds = %16, %1
%5 = call i32 @strcpy(i8* %3, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%6 = call i32 @strlen(i8* %3)
%7 = call i32 @write(i32 %0, i8* %3, i32 %6)
%8 = call i64 @read(i32 %0, i8* %3, i32 255)
%9 = icmp sgt i64 %8, 0
%10 = load i8, i8* %3
%11 = icmp eq i8 %10, 88
%12 = select i1 %9, i1 %11, i1 false
br i1 %12, label %13, label %16
13: ; preds = %4
%14 = call i32 @close(i32 %0)
%15 = call i32 @pthread_exit(i32* null)
br label %16
16: ; preds = %13, %4
br label %4
}