#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 getchar();
int /*<<< orphan*/ putString(char *);
int /*<<< orphan*/ putchar(char);
int strlen(char *);
void getLine(char *prompt, char *line, int max) {
  int index;
  char c;
  putString(prompt);
  putString(line);
  index = strlen(line);
  while (1) {
    c = getchar();
    switch (c) {
    case '\r':
      putchar('\n');
      line[index] = '\0';
      return;
    case '\b':
    case 0x7F:
      if (index == 0) {
        break;
      }
      putchar('\b');
      putchar(' ');
      putchar('\b');
      index--;
      break;
    default:
      if (c == '\t') {
        c = ' ';
      }
      if (c < 0x20 || c > 0x7E) {
        break;
      }
      putchar(c);
      line[index++] = c;
      break;
    }
  }
}


x86 assembly (clang, -O0):
<getLine>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
call   1060 <putString@plt>
mov    -0x10(%rbp),%rdi
call   1060 <putString@plt>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x18(%rbp)
xor    %eax,%eax
call   1050 <getchar@plt>
mov    %al,-0x19(%rbp)
movsbl -0x19(%rbp),%eax
mov    %eax,-0x20(%rbp)
sub    $0x8,%eax
je     11ce <getLine+0x8e>
jmp    1190 <getLine+0x50>
mov    -0x20(%rbp),%eax
sub    $0xd,%eax
je     11b2 <getLine+0x72>
jmp    11a1 <getLine+0x61>
mov    -0x20(%rbp),%eax
sub    $0x7f,%eax
je     11ce <getLine+0x8e>
jmp    1209 <getLine+0xc9>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
add    $0x20,%rsp
pop    %rbp
ret
cmpl   $0x0,-0x18(%rbp)
jne    11dd <getLine+0x9d>
jmp    125a <getLine+0x11a>
mov    $0x8,%edi
call   1030 <putchar@plt>
mov    $0x20,%edi
call   1030 <putchar@plt>
mov    $0x8,%edi
call   1030 <putchar@plt>
mov    -0x18(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x18(%rbp)
jmp    125a <getLine+0x11a>
movsbl -0x19(%rbp),%eax
cmp    $0x9,%eax
jne    121a <getLine+0xda>
movb   $0x20,-0x19(%rbp)
movsbl -0x19(%rbp),%eax
cmp    $0x20,%eax
jl     1234 <getLine+0xf4>
movsbl -0x19(%rbp),%eax
cmp    $0x7e,%eax
jle    1239 <getLine+0xf9>
jmp    125a <getLine+0x11a>
movsbl -0x19(%rbp),%edi
call   1030 <putchar@plt>
mov    -0x19(%rbp),%dl
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x18(%rbp)
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
jmp    1171 <getLine+0x31>

x86 assembly (clang, -O2):
<getLine>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
call   1060 <putString@plt>
mov    %r14,%rdi
call   1060 <putString@plt>
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    $0x20,%ebp
mov    %eax,%r15d
nopw   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1050 <getchar@plt>
movsbl %al,%ecx
cmp    $0x8,%ecx
je     11b0 <getLine+0x70>
cmp    $0x7f,%ecx
je     11b0 <getLine+0x70>
cmp    $0xd,%ecx
je     11de <getLine+0x9e>
cmp    $0x9,%al
movzbl %al,%ebx
cmove  %ebp,%ebx
lea    -0x7f(%rbx),%eax
cmp    $0xa1,%al
jb     1170 <getLine+0x30>
movsbl %bl,%edi
call   1030 <putchar@plt>
movslq %r15d,%rax
add    $0x1,%r15d
mov    %bl,(%r14,%rax,1)
mov    %r15d,%eax
jmp    1164 <getLine+0x24>
xor    %eax,%eax
test   %r15d,%r15d
je     1164 <getLine+0x24>
mov    $0x8,%edi
call   1030 <putchar@plt>
mov    $0x20,%edi
call   1030 <putchar@plt>
mov    $0x8,%edi
call   1030 <putchar@plt>
add    $0xffffffff,%r15d
mov    %r15d,%eax
jmp    1164 <getLine+0x24>
mov    $0xa,%edi
call   1030 <putchar@plt>
movslq %r15d,%rax
movb   $0x0,(%r14,%rax,1)
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @getLine(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%9 = load i8*, i8** %4
%10 = call i32 @putString(i8* %9)
%11 = load i8*, i8** %5
%12 = call i32 @putString(i8* %11)
%13 = load i8*, i8** %5
%14 = call i32 @strlen(i8* %13)
store i32 %14, i32* %7
br label %15
15: ; preds = %3, %58
%16 = call signext i8 (...) @getchar()
store i8 %16, i8* %8
%17 = load i8, i8* %8
%18 = sext i8 %17 to i32
switch i32 %18, label %35 [
i32 13, label %19
i32 8, label %25
i32 127, label %25
]
19: ; preds = %15
%20 = call i32 @putchar(i8 signext 10)
%21 = load i8*, i8** %5
%22 = load i32, i32* %7
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* %21, i64 %23
store i8 0, i8* %24
ret void
25: ; preds = %15, %15
%26 = load i32, i32* %7
%27 = icmp eq i32 %26, 0
br i1 %27, label %28, label %29
28: ; preds = %25
br label %58
29: ; preds = %25
%30 = call i32 @putchar(i8 signext 8)
%31 = call i32 @putchar(i8 signext 32)
%32 = call i32 @putchar(i8 signext 8)
%33 = load i32, i32* %7
%34 = add nsw i32 %33, -1
store i32 %34, i32* %7
br label %58
35: ; preds = %15
%36 = load i8, i8* %8
%37 = sext i8 %36 to i32
%38 = icmp eq i32 %37, 9
br i1 %38, label %39, label %40
39: ; preds = %35
store i8 32, i8* %8
br label %40
40: ; preds = %39, %35
%41 = load i8, i8* %8
%42 = sext i8 %41 to i32
%43 = icmp slt i32 %42, 32
br i1 %43, label %48, label %44
44: ; preds = %40
%45 = load i8, i8* %8
%46 = sext i8 %45 to i32
%47 = icmp sgt i32 %46, 126
br i1 %47, label %48, label %49
48: ; preds = %44, %40
br label %58
49: ; preds = %44
%50 = load i8, i8* %8
%51 = call i32 @putchar(i8 signext %50)
%52 = load i8, i8* %8
%53 = load i8*, i8** %5
%54 = load i32, i32* %7
%55 = add nsw i32 %54, 1
store i32 %55, i32* %7
%56 = sext i32 %54 to i64
%57 = getelementptr inbounds i8, i8* %53, i64 %56
store i8 %52, i8* %57
br label %58
58: ; preds = %49, %48, %29, %28
br label %15
}

LLVM IR (-O2):
define void @getLine(i8* %0, i8* %1, i32 %2) {
%4 = tail call i32 @putString(i8* %0)
%5 = tail call i32 @putString(i8* %1)
%6 = tail call i32 @strlen(i8* %1)
br label %7
7: ; preds = %33, %3
%8 = phi i32 [ %6, %3 ], [ %34, %33 ]
br label %9
9: ; preds = %7, %23
%10 = tail call signext i8 (...) @getchar()
%11 = sext i8 %10 to i32
switch i32 %11, label %23 [
i32 13, label %12
i32 8, label %16
i32 127, label %16
]
12: ; preds = %9
%13 = tail call i32 @putchar(i8 signext 10)
%14 = sext i32 %8 to i64
%15 = getelementptr inbounds i8, i8* %1, i64 %14
store i8 0, i8* %15
ret void
16: ; preds = %9, %9
%17 = icmp eq i32 %8, 0
br i1 %17, label %33, label %18
18: ; preds = %16
%19 = tail call i32 @putchar(i8 signext 8)
%20 = tail call i32 @putchar(i8 signext 32)
%21 = tail call i32 @putchar(i8 signext 8)
%22 = add nsw i32 %8, -1
br label %33
23: ; preds = %9
%24 = icmp eq i8 %10, 9
%25 = select i1 %24, i8 32, i8 %10
%26 = add i8 %25, -127
%27 = icmp ult i8 %26, -95
br i1 %27, label %9, label %28
28: ; preds = %23
%29 = tail call i32 @putchar(i8 signext %25)
%30 = add nsw i32 %8, 1
%31 = sext i32 %8 to i64
%32 = getelementptr inbounds i8, i8* %1, i64 %31
store i8 %25, i8* %32
br label %33
33: ; preds = %28, %16, %18
%34 = phi i32 [ %22, %18 ], [ 0, %16 ], [ %30, %28 ]
br label %7
}