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

/* Variables and functions */
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ *stdin;
int /*<<< orphan*/ stdout;
int strlen(char *);
int getCommand(FILE *source, char *command) {
  if (source == stdin) {
    printf("@> ");
    fflush(stdout);
  }
  if (!fgets(command, 250, source)) {
    if (source == stdin)
      printf("\n");
    return 1;
  }
  command[strlen(command) - 1] = '\0';
  return 0;
}


x86 assembly (clang, -O0):
<getCommand>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x2e8d(%rip),%rcx
cmp    (%rcx),%rax
jne    117e <getCommand+0x3e>
lea    0xe95(%rip),%rdi
call   1040 <printf@plt>
mov    0x2e61(%rip),%rax
mov    (%rax),%edi
call   1060 <fflush@plt>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0xfa,%esi
call   1050 <fgets@plt>
cmp    $0x0,%eax
jne    11c5 <getCommand+0x85>
mov    -0x10(%rbp),%rax
mov    0x2e44(%rip),%rcx
cmp    (%rcx),%rax
jne    11b9 <getCommand+0x79>
lea    0xe50(%rip),%rdi
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    11ed <getCommand+0xad>
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getCommand>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
mov    0x2e84(%rip),%r15
cmp    %rdi,(%r15)
jne    1183 <getCommand+0x33>
lea    0xe90(%rip),%rdi
call   1050 <printf@plt>
mov    0x2e5c(%rip),%rax
mov    (%rax),%edi
call   1070 <fflush@plt>
mov    %r14,%rdi
mov    $0xfa,%esi
mov    %rbx,%rdx
call   1060 <fgets@plt>
test   %eax,%eax
je     11ab <getCommand+0x5b>
mov    %r14,%rdi
call   1040 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%r14,1)
xor    %ebp,%ebp
jmp    11bf <getCommand+0x6f>
mov    $0x1,%ebp
cmp    %rbx,(%r15)
jne    11bf <getCommand+0x6f>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@stdin = global i32* null
@.str = [4 x i8] c"@> \00"
@stdout = global i32 0
define i32 @getCommand(i32* nocapture %0, i8* %1) {
%3 = load i32*, i32** @stdin
%4 = icmp eq i32* %3, %0
br i1 %4, label %5, label %9
5: ; preds = %2
%6 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%7 = load i32, i32* @stdout
%8 = tail call i32 @fflush(i32 %7)
br label %9
9: ; preds = %5, %2
%10 = tail call i32 @fgets(i8* %1, i32 250, i32* %0)
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %17
12: ; preds = %9
%13 = load i32*, i32** @stdin
%14 = icmp eq i32* %13, %0
br i1 %14, label %15, label %22
15: ; preds = %12
%16 = tail call i32 @putchar(i32 10)
br label %22
17: ; preds = %9
%18 = tail call i32 @strlen(i8* %1)
%19 = add nsw i32 %18, -1
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i8, i8* %1, i64 %20
store i8 0, i8* %21
br label %22
22: ; preds = %12, %15, %17
%23 = phi i32 [ 0, %17 ], [ 1, %15 ], [ 1, %12 ]
ret i32 %23
}