#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*/ error(char *);
int /*<<< orphan*/ execute_command(unsigned char, int);
int read(int, unsigned char *, int);
void client_thread(void *clientfd_pointer) {
  int clientfd = *((int *)clientfd_pointer);
  unsigned char command = -1;
  int readno = read(clientfd, &command, sizeof(unsigned char));
  if (readno < 0) {
    error("ERROR reading data from client");
  }
  execute_command(command, clientfd);
  close(clientfd);
}


x86 assembly (clang, -O0):
<client_thread>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0xc(%rbp)
movb   $0xff,-0xd(%rbp)
mov    -0xc(%rbp),%edi
lea    -0xd(%rbp),%rsi
mov    $0x1,%edx
call   1040 <read@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1183 <client_thread+0x43>
lea    0xe82(%rip),%rdi
call   1050 <error@plt>
mov    -0xd(%rbp),%al
mov    -0xc(%rbp),%esi
movzbl %al,%edi
call   1060 <execute_command@plt>
mov    -0xc(%rbp),%edi
call   1030 <close@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<client_thread>:
push   %rbx
sub    $0x10,%rsp
mov    (%rdi),%ebx
movb   $0xff,0xf(%rsp)
lea    0xf(%rsp),%rsi
mov    %ebx,%edi
mov    $0x1,%edx
call   1040 <read@plt>
test   %eax,%eax
jns    116d <client_thread+0x2d>
lea    0xe98(%rip),%rdi
call   1050 <error@plt>
movzbl 0xf(%rsp),%edi
mov    %ebx,%esi
call   1060 <execute_command@plt>
mov    %ebx,%edi
add    $0x10,%rsp
pop    %rbx
jmp    1030 <close@plt>

LLVM IR (-O0):
@.str = [31 x i8] c"ERROR reading data from client\00"
define void @client_thread(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i8
%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* %3
store i8 -1, i8* %4
%9 = load i32, i32* %3
%10 = call i32 @read(i32 %9, i8* %4, i32 1)
store i32 %10, i32* %5
%11 = load i32, i32* %5
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %1
%14 = call i32 @error(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
br label %15
15: ; preds = %13, %1
%16 = load i8, i8* %4
%17 = load i32, i32* %3
%18 = call i32 @execute_command(i8 zeroext %16, i32 %17)
%19 = load i32, i32* %3
%20 = call i32 @close(i32 %19)
ret void
}

LLVM IR (-O2):
@.str = [31 x i8] c"ERROR reading data from client\00"
define void @client_thread(i8* nocapture %0) {
%2 = alloca i8
%3 = bitcast i8* %0 to i32*
%4 = load i32, i32* %3
store i8 -1, i8* %2
%5 = call i32 @read(i32 %4, i8* %2, i32 1)
%6 = icmp slt i32 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %1
%8 = tail call i32 @error(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
br label %9
9: ; preds = %7, %1
%10 = load i8, i8* %2
%11 = tail call i32 @execute_command(i8 zeroext %10, i32 %4)
%12 = tail call i32 @close(i32 %4)
ret void
}