#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 CONSOL_GetCh();
int /*<<< orphan*/ CONSOL_Printf(char *);
int /*<<< orphan*/ CONSOL_SendCh(char);
void CONSOL_GetString(char *pbString) {
  char *pbString2 = pbString;
  char bC;
  while ((bC = CONSOL_GetCh()) != '\r') {
    if (bC == '\b') {
      if ((int)pbString2 < (int)pbString) {
        CONSOL_Printf("\b \b");
        pbString--;
      }
    } else {
      *pbString++ = bC;
      CONSOL_SendCh(bC);
    }
  }
  *pbString = '\0';
  CONSOL_SendCh('\n');
}


x86 assembly (clang, -O0):
<CONSOL_GetString>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    $0x0,%al
call   1030 <CONSOL_GetCh@plt>
mov    %al,-0x11(%rbp)
movsbl %al,%eax
cmp    $0xd,%eax
je     11b6 <CONSOL_GetString+0x86>
movsbl -0x11(%rbp),%eax
cmp    $0x8,%eax
jne    1194 <CONSOL_GetString+0x64>
mov    -0x10(%rbp),%rax
mov    -0x8(%rbp),%rcx
cmp    %ecx,%eax
jge    118f <CONSOL_GetString+0x5f>
lea    0xe82(%rip),%rdi
call   1040 <CONSOL_Printf@plt>
mov    -0x8(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x8(%rbp)
jmp    11b1 <CONSOL_GetString+0x81>
mov    -0x11(%rbp),%cl
mov    -0x8(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x8(%rbp)
mov    %cl,(%rax)
movsbl -0x11(%rbp),%edi
call   1050 <CONSOL_SendCh@plt>
jmp    1144 <CONSOL_GetString+0x14>
mov    -0x8(%rbp),%rax
movb   $0x0,(%rax)
mov    $0xa,%edi
call   1050 <CONSOL_SendCh@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<CONSOL_GetString>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r15
lea    0xec1(%rip),%r14
mov    %rdi,%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
xor    %eax,%eax
call   1030 <CONSOL_GetCh@plt>
cmp    $0x8,%al
jne    116e <CONSOL_GetString+0x3e>
cmp    %ebx,%r15d
jge    1150 <CONSOL_GetString+0x20>
mov    %r14,%rdi
call   1040 <CONSOL_Printf@plt>
add    $0xffffffffffffffff,%rbx
jmp    1150 <CONSOL_GetString+0x20>
cmp    $0xd,%al
je     1182 <CONSOL_GetString+0x52>
mov    %al,(%rbx)
add    $0x1,%rbx
movsbl %al,%edi
call   1050 <CONSOL_SendCh@plt>
jmp    1150 <CONSOL_GetString+0x20>
movb   $0x0,(%rbx)
mov    $0xa,%edi
pop    %rbx
pop    %r14
pop    %r15
jmp    1050 <CONSOL_SendCh@plt>

LLVM IR (-O0):
@.str = [4 x i8] c"\08 \08\00"
define void @CONSOL_GetString(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8
store i8* %0, i8** %2
%5 = load i8*, i8** %2
store i8* %5, i8** %3
br label %6
6: ; preds = %31, %1
%7 = call signext i8 (...) @CONSOL_GetCh()
store i8 %7, i8* %4
%8 = sext i8 %7 to i32
%9 = icmp ne i32 %8, 13
br i1 %9, label %10, label %32
10: ; preds = %6
%11 = load i8, i8* %4
%12 = sext i8 %11 to i32
%13 = icmp eq i32 %12, 8
br i1 %13, label %14, label %25
14: ; preds = %10
%15 = load i8*, i8** %3
%16 = ptrtoint i8* %15 to i32
%17 = load i8*, i8** %2
%18 = ptrtoint i8* %17 to i32
%19 = icmp slt i32 %16, %18
br i1 %19, label %20, label %24
20: ; preds = %14
%21 = call i32 @CONSOL_Printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%22 = load i8*, i8** %2
%23 = getelementptr inbounds i8, i8* %22, i32 -1
store i8* %23, i8** %2
br label %24
24: ; preds = %20, %14
br label %31
25: ; preds = %10
%26 = load i8, i8* %4
%27 = load i8*, i8** %2
%28 = getelementptr inbounds i8, i8* %27, i32 1
store i8* %28, i8** %2
store i8 %26, i8* %27
%29 = load i8, i8* %4
%30 = call i32 @CONSOL_SendCh(i8 signext %29)
br label %31
31: ; preds = %25, %24
br label %6
32: ; preds = %6
%33 = load i8*, i8** %2
store i8 0, i8* %33
%34 = call i32 @CONSOL_SendCh(i8 signext 10)
ret void
}

LLVM IR (-O2):
@.str = [4 x i8] c"\08 \08\00"
define void @CONSOL_GetString(i8* %0) {
%2 = ptrtoint i8* %0 to i64
%3 = trunc i64 %2 to i32
br label %4
4: ; preds = %15, %1
%5 = phi i8* [ %0, %1 ], [ %16, %15 ]
%6 = ptrtoint i8* %5 to i64
%7 = trunc i64 %6 to i32
%8 = icmp slt i32 %3, %7
br label %9
9: ; preds = %4, %11
%10 = tail call signext i8 (...) @CONSOL_GetCh()
switch i8 %10, label %17 [
i8 13, label %20
i8 8, label %11
]
11: ; preds = %9
br i1 %8, label %12, label %9
12: ; preds = %11
%13 = tail call i32 @CONSOL_Printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%14 = getelementptr inbounds i8, i8* %5, i64 -1
br label %15
15: ; preds = %12, %17
%16 = phi i8* [ %18, %17 ], [ %14, %12 ]
br label %4
17: ; preds = %9
%18 = getelementptr inbounds i8, i8* %5, i64 1
store i8 %10, i8* %5
%19 = tail call i32 @CONSOL_SendCh(i8 signext %10)
br label %15
20: ; preds = %9
store i8 0, i8* %5
%21 = tail call i32 @CONSOL_SendCh(i8 signext 10)
ret void
}