#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*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ uci_debug(char *);
int /*<<< orphan*/ uci_parse_cmd(char *);
int /*<<< orphan*/ uci_quit();
char *util_trim_str(char *);
void uci_input() {
  uci_debug("Getting input..");
  char buf[4096];
  if (!fgets(buf, 4096, stdin)) {
    uci_debug("fgets returned 0..");
    uci_quit();
  } else {
    char *cmd = util_trim_str(buf);
    uci_parse_cmd(cmd);
  }
}


x86 assembly (clang, -O0):
<uci_input>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1010,%rsp
lea    0xe9e(%rip),%rdi
call   1070 <uci_debug@plt>
lea    -0x1000(%rbp),%rdi
mov    0x2e73(%rip),%rax
mov    (%rax),%edx
mov    $0x1000,%esi
call   1030 <fgets@plt>
cmp    $0x0,%eax
jne    11a2 <uci_input+0x52>
lea    0xe7f(%rip),%rdi
call   1070 <uci_debug@plt>
mov    $0x0,%al
call   1040 <uci_quit@plt>
jmp    11c1 <uci_input+0x71>
lea    -0x1000(%rbp),%rdi
call   1060 <util_trim_str@plt>
mov    %rax,-0x1008(%rbp)
mov    -0x1008(%rbp),%rdi
call   1050 <uci_parse_cmd@plt>
add    $0x1010,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<uci_input>:
sub    $0x1008,%rsp
lea    0xea2(%rip),%rdi
call   1070 <uci_debug@plt>
mov    0x2e7e(%rip),%rax
mov    (%rax),%edx
mov    %rsp,%rdi
mov    $0x1000,%esi
call   1030 <fgets@plt>
test   %eax,%eax
je     1195 <uci_input+0x45>
mov    %rsp,%rdi
call   1060 <util_trim_str@plt>
mov    %rax,%rdi
call   1050 <uci_parse_cmd@plt>
add    $0x1008,%rsp
ret
lea    0xe74(%rip),%rdi
call   1070 <uci_debug@plt>
xor    %eax,%eax
call   1040 <uci_quit@plt>
add    $0x1008,%rsp
ret

LLVM IR (-O0):
@.str = [16 x i8] c"Getting input..\00"
@stdin = global i32 0
@.str.1 = [19 x i8] c"fgets returned 0..\00"
define void @uci_input() {
%1 = alloca [4096 x i8]
%2 = alloca i8*
%3 = call i32 @uci_debug(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%4 = getelementptr inbounds [4096 x i8], [4096 x i8]* %1, i64 0, i64 0
%5 = load i32, i32* @stdin
%6 = call i32 @fgets(i8* %4, i32 4096, i32 %5)
%7 = icmp ne i32 %6, 0
br i1 %7, label %11, label %8
8: ; preds = %0
%9 = call i32 @uci_debug(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
%10 = call i32 (...) @uci_quit()
br label %16
11: ; preds = %0
%12 = getelementptr inbounds [4096 x i8], [4096 x i8]* %1, i64 0, i64 0
%13 = call i8* @util_trim_str(i8* %12)
store i8* %13, i8** %2
%14 = load i8*, i8** %2
%15 = call i32 @uci_parse_cmd(i8* %14)
br label %16
16: ; preds = %11, %8
ret void
}

LLVM IR (-O2):
@.str = [16 x i8] c"Getting input..\00"
@stdin = global i32 0
@.str.1 = [19 x i8] c"fgets returned 0..\00"
define void @uci_input() {
%1 = alloca [4096 x i8]
%2 = tail call i32 @uci_debug(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%3 = getelementptr inbounds [4096 x i8], [4096 x i8]* %1, i64 0, i64 0
%4 = load i32, i32* @stdin
%5 = call i32 @fgets(i8* %3, i32 4096, i32 %4)
%6 = icmp eq i32 %5, 0
br i1 %6, label %7, label %10
7: ; preds = %0
%8 = call i32 @uci_debug(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
%9 = call i32 (...) @uci_quit()
br label %13
10: ; preds = %0
%11 = call i8* @util_trim_str(i8* %3)
%12 = call i32 @uci_parse_cmd(i8* %11)
br label %13
13: ; preds = %10, %7
ret void
}