#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*/ fileno(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
scalar_t__ isatty(int /*<<< orphan*/);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ stdout;
int getcmd(char *buf, int nbuf) {
  if (isatty(fileno(stdin)))
    fprintf(stdout, "cs6233> ");
  memset(buf, 0, nbuf);
  fgets(buf, nbuf, stdin);
  if (buf[0] == 0)
    return -1;
  return 0;
}


x86 assembly (clang, -O0):
<getcmd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    0x2e82(%rip),%rax
mov    (%rax),%edi
call   1070 <fileno@plt>
mov    %eax,%edi
call   1030 <isatty@plt>
cmp    $0x0,%rax
je     1193 <getcmd+0x43>
mov    0x2e53(%rip),%rax
mov    (%rax),%edi
lea    0xe72(%rip),%rsi
call   1060 <fprintf@plt>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%edx
xor    %esi,%esi
call   1040 <memset@plt>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    0x2e39(%rip),%rax
mov    (%rax),%edx
call   1050 <fgets@plt>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    11d2 <getcmd+0x82>
movl   $0xffffffff,-0x4(%rbp)
jmp    11d9 <getcmd+0x89>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getcmd>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%ebp
mov    %rdi,%rbx
mov    0x2e88(%rip),%r14
mov    (%r14),%edi
call   1070 <fileno@plt>
mov    %eax,%edi
call   1030 <isatty@plt>
test   %rax,%rax
je     1189 <getcmd+0x39>
mov    0x2e5d(%rip),%rax
mov    (%rax),%edi
lea    0xe7c(%rip),%rsi
call   1060 <fprintf@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    %ebp,%edx
call   1040 <memset@plt>
mov    (%r14),%edx
mov    %rbx,%rdi
mov    %ebp,%esi
call   1050 <fgets@plt>
cmpb   $0x1,(%rbx)
sbb    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@stdin = global i32 0
@stdout = global i32 0
@.str = [9 x i8] c"cs6233> \00"
define i32 @getcmd(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
%6 = load i32, i32* @stdin
%7 = call i32 @fileno(i32 %6)
%8 = call i64 @isatty(i32 %7)
%9 = icmp ne i64 %8, 0
br i1 %9, label %10, label %13
10: ; preds = %2
%11 = load i32, i32* @stdout
%12 = call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
br label %13
13: ; preds = %10, %2
%14 = load i8*, i8** %4
%15 = load i32, i32* %5
%16 = call i32 @memset(i8* %14, i32 0, i32 %15)
%17 = load i8*, i8** %4
%18 = load i32, i32* %5
%19 = load i32, i32* @stdin
%20 = call i32 @fgets(i8* %17, i32 %18, i32 %19)
%21 = load i8*, i8** %4
%22 = getelementptr inbounds i8, i8* %21, i64 0
%23 = load i8, i8* %22
%24 = sext i8 %23 to i32
%25 = icmp eq i32 %24, 0
br i1 %25, label %26, label %27
26: ; preds = %13
store i32 -1, i32* %3
br label %28
27: ; preds = %13
store i32 0, i32* %3
br label %28
28: ; preds = %27, %26
%29 = load i32, i32* %3
ret i32 %29
}

LLVM IR (-O2):
@stdin = global i32 0
@stdout = global i32 0
@.str = [9 x i8] c"cs6233> \00"
define i32 @getcmd(i8* %0, i32 %1) {
%3 = load i32, i32* @stdin
%4 = tail call i32 @fileno(i32 %3)
%5 = tail call i64 @isatty(i32 %4)
%6 = icmp eq i64 %5, 0
br i1 %6, label %10, label %7
7: ; preds = %2
%8 = load i32, i32* @stdout
%9 = tail call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
br label %10
10: ; preds = %7, %2
%11 = tail call i32 @memset(i8* %0, i32 0, i32 %1)
%12 = load i32, i32* @stdin
%13 = tail call i32 @fgets(i8* %0, i32 %1, i32 %12)
%14 = load i8, i8* %0
%15 = icmp eq i8 %14, 0
%16 = sext i1 %15 to i32
ret i32 %16
}