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

/* Variables and functions */
int /*<<< orphan*/ cmd_exec(int /*<<< orphan*/, char *, int);
char *fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ stdout;
void cmd_console_handler(int rc, int fd) {
  char request[256];
  char *ptr;
  if (rc <= 0) {
    return;
  }
  ptr = fgets(request, sizeof(request), stdin);
  if (ptr == NULL) {
    return;
  }
  cmd_exec(stdout, request, 1);
}


x86 assembly (clang, -O0):
<cmd_console_handler>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
cmpl   $0x0,-0x4(%rbp)
jg     1140 <cmd_console_handler+0x20>
jmp    118e <cmd_console_handler+0x6e>
lea    -0x110(%rbp),%rdi
mov    0x2e9a(%rip),%rax
mov    (%rax),%edx
mov    $0x100,%esi
call   1040 <fgets@plt>
mov    %rax,-0x118(%rbp)
cmpq   $0x0,-0x118(%rbp)
jne    1174 <cmd_console_handler+0x54>
jmp    118e <cmd_console_handler+0x6e>
mov    0x2e5d(%rip),%rax
mov    (%rax),%edi
lea    -0x110(%rbp),%rsi
mov    $0x1,%edx
call   1030 <cmd_exec@plt>
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cmd_console_handler>:
sub    $0x108,%rsp
test   %edi,%edi
jle    115c <cmd_console_handler+0x3c>
mov    0x2eb6(%rip),%rax
mov    (%rax),%edx
mov    %rsp,%rdi
mov    $0x100,%esi
call   1040 <fgets@plt>
test   %rax,%rax
je     115c <cmd_console_handler+0x3c>
mov    0x2e8b(%rip),%rax
mov    (%rax),%edi
mov    %rsp,%rsi
mov    $0x1,%edx
call   1030 <cmd_exec@plt>
add    $0x108,%rsp
ret

LLVM IR (-O0):
@stdin = global i32 0
@stdout = global i32 0
define void @cmd_console_handler(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca [256 x i8]
%6 = alloca i8*
store i32 %0, i32* %3
store i32 %1, i32* %4
%7 = load i32, i32* %3
%8 = icmp sle i32 %7, 0
br i1 %8, label %9, label %10
9: ; preds = %2
br label %21
10: ; preds = %2
%11 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%12 = load i32, i32* @stdin
%13 = call i8* @fgets(i8* %11, i32 256, i32 %12)
store i8* %13, i8** %6
%14 = load i8*, i8** %6
%15 = icmp eq i8* %14, null
br i1 %15, label %16, label %17
16: ; preds = %10
br label %21
17: ; preds = %10
%18 = load i32, i32* @stdout
%19 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%20 = call i32 @cmd_exec(i32 %18, i8* %19, i32 1)
br label %21
21: ; preds = %17, %16, %9
ret void
}

LLVM IR (-O2):
@stdin = global i32 0
@stdout = global i32 0
define void @cmd_console_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 %13, label %6
6: ; preds = %2
%7 = load i32, i32* @stdin
%8 = call i8* @fgets(i8* %4, i32 256, i32 %7)
%9 = icmp eq i8* %8, null
br i1 %9, label %13, label %10
10: ; preds = %6
%11 = load i32, i32* @stdout
%12 = call i32 @cmd_exec(i32 %11, i8* %4, i32 1)
br label %13
13: ; preds = %6, %2, %10
ret void
}