#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 */
char egetc();
scalar_t__ rx_count();
int GetCommand(char *cmd, int maxlen) {
  int Done = 0;
  int Index = 0;
  while (!Done) {
    while (rx_count() == 0)
      ;
    cmd[Index] = egetc();
    if (cmd[Index] == '$')
      Done = 1;
    else {
      Index++;
      if (Index >= maxlen)
        return -1;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<GetCommand>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0x0,-0x18(%rbp)
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1153 <GetCommand+0x33>
jmp    11ce <GetCommand+0xae>
jmp    1158 <GetCommand+0x38>
mov    $0x0,%al
call   1030 <rx_count@plt>
cmp    $0x0,%rax
jne    116e <GetCommand+0x4e>
jmp    1158 <GetCommand+0x38>
mov    $0x0,%al
call   1040 <egetc@plt>
mov    %al,%dl
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x24,%eax
jne    11a3 <GetCommand+0x83>
movl   $0x1,-0x18(%rbp)
jmp    11c9 <GetCommand+0xa9>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jl     11c4 <GetCommand+0xa4>
movl   $0xffffffff,-0x4(%rbp)
jmp    11d5 <GetCommand+0xb5>
jmp    11c9 <GetCommand+0xa9>
jmp    113d <GetCommand+0x1d>
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    %esi,%r14d
mov    %rdi,%r15
xor    %ebx,%ebx
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1030 <rx_count@plt>
test   %rax,%rax
je     1140 <GetCommand+0x20>
xor    %eax,%eax
call   1040 <egetc@plt>
mov    %ebx,%ecx
mov    %al,(%r15,%rcx,1)
cmp    $0x24,%al
je     116a <GetCommand+0x4a>
add    $0x1,%ebx
cmp    %r14d,%ebx
jl     1140 <GetCommand+0x20>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @GetCommand(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32 0, i32* %6
store i32 0, i32* %7
br label %8
8: ; preds = %39, %2
%9 = load i32, i32* %6
%10 = icmp ne i32 %9, 0
%11 = xor i1 %10, true
br i1 %11, label %12, label %40
12: ; preds = %8
br label %13
13: ; preds = %16, %12
%14 = call i64 (...) @rx_count()
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %17
16: ; preds = %13
br label %13
17: ; preds = %13
%18 = call signext i8 (...) @egetc()
%19 = load i8*, i8** %4
%20 = load i32, i32* %7
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i8, i8* %19, i64 %21
store i8 %18, i8* %22
%23 = load i8*, i8** %4
%24 = load i32, i32* %7
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8, i8* %23, i64 %25
%27 = load i8, i8* %26
%28 = sext i8 %27 to i32
%29 = icmp eq i32 %28, 36
br i1 %29, label %30, label %31
30: ; preds = %17
store i32 1, i32* %6
br label %39
31: ; preds = %17
%32 = load i32, i32* %7
%33 = add nsw i32 %32, 1
store i32 %33, i32* %7
%34 = load i32, i32* %7
%35 = load i32, i32* %5
%36 = icmp sge i32 %34, %35
br i1 %36, label %37, label %38
37: ; preds = %31
store i32 -1, i32* %3
br label %41
38: ; preds = %31
br label %39
39: ; preds = %38, %30
br label %8
40: ; preds = %8
store i32 0, i32* %3
br label %41
41: ; preds = %40, %37
%42 = load i32, i32* %3
ret i32 %42
}

LLVM IR (-O2):
define i32 @GetCommand(i8* nocapture writeonly %0, i32 %1) {
br label %3
3: ; preds = %13, %2
%4 = phi i32 [ 0, %2 ], [ %14, %13 ]
br label %5
5: ; preds = %3, %5
%6 = tail call i64 (...) @rx_count()
%7 = icmp eq i64 %6, 0
br i1 %7, label %5, label %8
8: ; preds = %5
%9 = tail call signext i8 (...) @egetc()
%10 = zext i32 %4 to i64
%11 = getelementptr inbounds i8, i8* %0, i64 %10
store i8 %9, i8* %11
%12 = icmp eq i8 %9, 36
br i1 %12, label %16, label %13
13: ; preds = %8
%14 = add nuw nsw i32 %4, 1
%15 = icmp slt i32 %14, %1
br i1 %15, label %3, label %16
16: ; preds = %8, %13
%17 = phi i32 [ -1, %13 ], [ 0, %8 ]
ret i32 %17
}