#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 */
struct boss_state {
  int dummy;
};

/* Variables and functions */
char *fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int input_interpreter(char *, struct boss_state *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdin;
int strlen(char *);
int prompt_for_command(struct boss_state *boss, char *line, int line_size) {
  int l, ret;
  char *line_res;
  while (1) {
    fprintf(stderr, "+++ Enter a command and its parameters :\n");
    line_res = fgets(line, line_size - 1, stdin);
    if (line_res == NULL)
      return (0);
    l = strlen(line);
    if (l == 0) {
      line[0] = '\n';
      line[1] = 0;
    } else if (line[l - 1] != '\n') {
      line[l] = '\n';
      line[l + 1] = 0;
    }
    ret = input_interpreter(line, boss);
    if (ret == 0)
      return (1);
    if (ret < 0)
      return (-1);
  }
}


x86 assembly (clang, -O0):
<prompt_for_command>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    0x2e7e(%rip),%rax
mov    (%rax),%edi
lea    0xe9d(%rip),%rsi
call   1060 <fprintf@plt>
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
sub    $0x1,%esi
mov    0x2e6f(%rip),%rax
mov    (%rax),%edx
call   1050 <fgets@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    119b <prompt_for_command+0x5b>
movl   $0x0,-0x4(%rbp)
jmp    1242 <prompt_for_command+0x102>
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jne    11c5 <prompt_for_command+0x85>
mov    -0x18(%rbp),%rax
movb   $0xa,(%rax)
mov    -0x18(%rbp),%rax
movb   $0x0,0x1(%rax)
jmp    1201 <prompt_for_command+0xc1>
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xa,%eax
je     11fc <prompt_for_command+0xbc>
mov    -0x18(%rbp),%rax
movslq -0x20(%rbp),%rcx
movb   $0xa,(%rax,%rcx,1)
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    1201 <prompt_for_command+0xc1>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <input_interpreter@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jne    1227 <prompt_for_command+0xe7>
movl   $0x1,-0x4(%rbp)
jmp    1242 <prompt_for_command+0x102>
cmpl   $0x0,-0x24(%rbp)
jge    123d <prompt_for_command+0xfd>
movl   $0xffffffff,-0x4(%rbp)
jmp    1242 <prompt_for_command+0x102>
jmp    1153 <prompt_for_command+0x13>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<prompt_for_command>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%ebp
mov    %rsi,%rbx
mov    %rdi,%r14
add    $0xffffffff,%ebp
lea    0x1(%rsi),%rax
mov    %rax,(%rsp)
mov    0x2e73(%rip),%r13
lea    0xe94(%rip),%r15
mov    0x2e75(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    0x0(%r13),%edi
mov    %r15,%rsi
call   1060 <fprintf@plt>
mov    (%r12),%edx
mov    %rbx,%rdi
mov    %ebp,%esi
call   1050 <fgets@plt>
test   %rax,%rax
je     11f2 <prompt_for_command+0xb2>
mov    %rbx,%rdi
call   1030 <strlen@plt>
test   %eax,%eax
je     11d0 <prompt_for_command+0x90>
cltq
cmpb   $0xa,-0x1(%rax,%rbx,1)
je     11da <prompt_for_command+0x9a>
movb   $0xa,(%rbx,%rax,1)
add    %rbx,%rax
add    $0x1,%rax
jmp    11d7 <prompt_for_command+0x97>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movb   $0xa,(%rbx)
mov    (%rsp),%rax
movb   $0x0,(%rax)
mov    %rbx,%rdi
mov    %r14,%rsi
call   1040 <input_interpreter@plt>
test   %eax,%eax
je     11f6 <prompt_for_command+0xb6>
jns    1180 <prompt_for_command+0x40>
mov    $0xffffffff,%eax
jmp    11fb <prompt_for_command+0xbb>
xor    %eax,%eax
jmp    11fb <prompt_for_command+0xbb>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.boss_state = type { i32 }
@stderr = global i32 0
@.str = [42 x i8] c"+++ Enter a command and its parameters :\0A\00"
@stdin = global i32 0
define i32 @prompt_for_command(%struct.boss_state* %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca %struct.boss_state*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8*
store %struct.boss_state* %0, %struct.boss_state** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
br label %11
11: ; preds = %3, %63
%12 = load i32, i32* @stderr
%13 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0))
%14 = load i8*, i8** %6
%15 = load i32, i32* %7
%16 = sub nsw i32 %15, 1
%17 = load i32, i32* @stdin
%18 = call i8* @fgets(i8* %14, i32 %16, i32 %17)
store i8* %18, i8** %10
%19 = load i8*, i8** %10
%20 = icmp eq i8* %19, null
br i1 %20, label %21, label %22
21: ; preds = %11
store i32 0, i32* %4
br label %64
22: ; preds = %11
%23 = load i8*, i8** %6
%24 = call i32 @strlen(i8* %23)
store i32 %24, i32* %8
%25 = load i32, i32* %8
%26 = icmp eq i32 %25, 0
br i1 %26, label %27, label %32
27: ; preds = %22
%28 = load i8*, i8** %6
%29 = getelementptr inbounds i8, i8* %28, i64 0
store i8 10, i8* %29
%30 = load i8*, i8** %6
%31 = getelementptr inbounds i8, i8* %30, i64 1
store i8 0, i8* %31
br label %52
32: ; preds = %22
%33 = load i8*, i8** %6
%34 = load i32, i32* %8
%35 = sub nsw i32 %34, 1
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i8, i8* %33, i64 %36
%38 = load i8, i8* %37
%39 = sext i8 %38 to i32
%40 = icmp ne i32 %39, 10
br i1 %40, label %41, label %51
41: ; preds = %32
%42 = load i8*, i8** %6
%43 = load i32, i32* %8
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds i8, i8* %42, i64 %44
store i8 10, i8* %45
%46 = load i8*, i8** %6
%47 = load i32, i32* %8
%48 = add nsw i32 %47, 1
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds i8, i8* %46, i64 %49
store i8 0, i8* %50
br label %51
51: ; preds = %41, %32
br label %52
52: ; preds = %51, %27
%53 = load i8*, i8** %6
%54 = load %struct.boss_state*, %struct.boss_state** %5
%55 = call i32 @input_interpreter(i8* %53, %struct.boss_state* %54)
store i32 %55, i32* %9
%56 = load i32, i32* %9
%57 = icmp eq i32 %56, 0
br i1 %57, label %58, label %59
58: ; preds = %52
store i32 1, i32* %4
br label %64
59: ; preds = %52
%60 = load i32, i32* %9
%61 = icmp slt i32 %60, 0
br i1 %61, label %62, label %63
62: ; preds = %59
store i32 -1, i32* %4
br label %64
63: ; preds = %59
br label %11
64: ; preds = %62, %58, %21
%65 = load i32, i32* %4
ret i32 %65
}

LLVM IR (-O2):
%struct.boss_state = type { i32 }
@stderr = global i32 0
@.str = [42 x i8] c"+++ Enter a command and its parameters :\0A\00"
@stdin = global i32 0
define i32 @prompt_for_command(%struct.boss_state* %0, i8* %1, i32 %2) {
%4 = add nsw i32 %2, -1
%5 = getelementptr inbounds i8, i8* %1, i64 1
br label %6
6: ; preds = %33, %3
%7 = load i32, i32* @stderr
%8 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0))
%9 = load i32, i32* @stdin
%10 = tail call i8* @fgets(i8* %1, i32 %4, i32 %9)
%11 = icmp eq i8* %10, null
br i1 %11, label %35, label %12
12: ; preds = %6
%13 = tail call i32 @strlen(i8* %1)
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %16
15: ; preds = %12
store i8 10, i8* %1
br label %28
16: ; preds = %12
%17 = add nsw i32 %13, -1
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8, i8* %1, i64 %18
%20 = load i8, i8* %19
%21 = icmp eq i8 %20, 10
br i1 %21, label %30, label %22
22: ; preds = %16
%23 = sext i32 %13 to i64
%24 = getelementptr inbounds i8, i8* %1, i64 %23
store i8 10, i8* %24
%25 = add nsw i32 %13, 1
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i8, i8* %1, i64 %26
br label %28
28: ; preds = %15, %22
%29 = phi i8* [ %27, %22 ], [ %5, %15 ]
store i8 0, i8* %29
br label %30
30: ; preds = %28, %16
%31 = tail call i32 @input_interpreter(i8* %1, %struct.boss_state* %0)
%32 = icmp eq i32 %31, 0
br i1 %32, label %35, label %33
33: ; preds = %30
%34 = icmp slt i32 %31, 0
br i1 %34, label %35, label %6
35: ; preds = %33, %30, %6
%36 = phi i32 [ 0, %6 ], [ 1, %30 ], [ -1, %33 ]
ret i32 %36
}