#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 size_t ssize_t;
typedef int /*<<< orphan*/ request;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ cmd_exec(int /*<<< orphan*/ *, char *, int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fdopen(int, char *);
int /*<<< orphan*/ net_remove_handler(int, void (*)(int, int));
size_t recv(int, char *, int, int /*<<< orphan*/);
void cmd_client_handler(int rc, int clientsock) {
  char request[256];
  ssize_t size;
  FILE *fp;
  if (rc <= 0) {
    return;
  }
  size = recv(clientsock, request, sizeof(request) - 1, 0);
  if (size > 0) {
    request[size] = '\0';
    fp = fdopen(clientsock, "w");
    cmd_exec(fp, request, 0);
    fclose(fp);
  } else {
    close(clientsock);
  }
  net_remove_handler(clientsock, &cmd_client_handler);
}


x86 assembly (clang, -O0):
<cmd_client_handler>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
cmpl   $0x0,-0x4(%rbp)
jg     1180 <cmd_client_handler+0x20>
jmp    120d <cmd_client_handler+0xad>
mov    -0x8(%rbp),%edi
lea    -0x110(%rbp),%rsi
mov    $0xff,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %rax,-0x118(%rbp)
cmpq   $0x0,-0x118(%rbp)
jbe    11f6 <cmd_client_handler+0x96>
mov    -0x118(%rbp),%rax
movb   $0x0,-0x110(%rbp,%rax,1)
mov    -0x8(%rbp),%edi
lea    0xe3c(%rip),%rsi
call   1080 <fdopen@plt>
mov    %rax,-0x120(%rbp)
mov    -0x120(%rbp),%rdi
lea    -0x110(%rbp),%rsi
xor    %edx,%edx
call   1050 <cmd_exec@plt>
mov    -0x120(%rbp),%rdi
call   1040 <fclose@plt>
jmp    11fe <cmd_client_handler+0x9e>
mov    -0x8(%rbp),%edi
call   1060 <close@plt>
mov    -0x8(%rbp),%edi
mov    0x2dd8(%rip),%rsi
call   1070 <net_remove_handler@plt>
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cmd_client_handler>:
test   %edi,%edi
jle    11d1 <cmd_client_handler+0x71>
push   %r14
push   %rbx
sub    $0x108,%rsp
mov    %esi,%ebx
mov    %rsp,%rsi
mov    %ebx,%edi
mov    $0xff,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
test   %rax,%rax
je     11b2 <cmd_client_handler+0x52>
movb   $0x0,(%rsp,%rax,1)
lea    0xe6f(%rip),%rsi
mov    %ebx,%edi
call   1080 <fdopen@plt>
mov    %rax,%r14
mov    %rsp,%rsi
mov    %rax,%rdi
xor    %edx,%edx
call   1050 <cmd_exec@plt>
mov    %r14,%rdi
call   1040 <fclose@plt>
jmp    11b9 <cmd_client_handler+0x59>
mov    %ebx,%edi
call   1060 <close@plt>
mov    0x2e20(%rip),%rsi
mov    %ebx,%edi
call   1070 <net_remove_handler@plt>
add    $0x108,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [2 x i8] c"w\00"
define void @cmd_client_handler(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca [256 x i8]
%6 = alloca i64
%7 = alloca i32*
store i32 %0, i32* %3
store i32 %1, i32* %4
%8 = load i32, i32* %3
%9 = icmp sle i32 %8, 0
br i1 %9, label %10, label %11
10: ; preds = %2
br label %33
11: ; preds = %2
%12 = load i32, i32* %4
%13 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%14 = call i64 @recv(i32 %12, i8* %13, i32 255, i32 0)
store i64 %14, i64* %6
%15 = load i64, i64* %6
%16 = icmp ugt i64 %15, 0
br i1 %16, label %17, label %27
17: ; preds = %11
%18 = load i64, i64* %6
%19 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 %18
store i8 0, i8* %19
%20 = load i32, i32* %4
%21 = call i32* @fdopen(i32 %20, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %21, i32** %7
%22 = load i32*, i32** %7
%23 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%24 = call i32 @cmd_exec(i32* %22, i8* %23, i32 0)
%25 = load i32*, i32** %7
%26 = call i32 @fclose(i32* %25)
br label %30
27: ; preds = %11
%28 = load i32, i32* %4
%29 = call i32 @close(i32 %28)
br label %30
30: ; preds = %27, %17
%31 = load i32, i32* %4
%32 = call i32 @net_remove_handler(i32 %31, void (i32, i32)* @cmd_client_handler)
br label %33
33: ; preds = %30, %10
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"w\00"
define void @cmd_client_handler(i32 %0, i32 %1) {
%3 = alloca [256 x i8]
%4 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%5 = icmp slt i32 %0, 1
br i1 %5, label %18, label %6
6: ; preds = %2
%7 = call i64 @recv(i32 %1, i8* %4, i32 255, i32 0)
%8 = icmp eq i64 %7, 0
br i1 %8, label %14, label %9
9: ; preds = %6
%10 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 %7
store i8 0, i8* %10
%11 = call i32* @fdopen(i32 %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%12 = call i32 @cmd_exec(i32* %11, i8* %4, i32 0)
%13 = call i32 @fclose(i32* %11)
br label %16
14: ; preds = %6
%15 = call i32 @close(i32 %1)
br label %16
16: ; preds = %14, %9
%17 = call i32 @net_remove_handler(i32 %1, void (i32, i32)* @cmd_client_handler)
br label %18
18: ; preds = %2, %16
ret void
}