#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*/ printf(char *, char *, char *);
int /*<<< orphan*/ putchar(char);
int strlen(char *);
void getLine(char *prompt, char *line, int max) {
  int index;
  char c;
  printf("%s%s", prompt, 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),%rsi
mov    -0x10(%rbp),%rdx
lea    0xe9e(%rip),%rdi
call   1050 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x18(%rbp)
xor    %eax,%eax
call   1060 <getchar@plt>
mov    %al,-0x19(%rbp)
movsbl -0x19(%rbp),%eax
mov    %eax,-0x20(%rbp)
sub    $0x8,%eax
je     11d0 <getLine+0x90>
jmp    1192 <getLine+0x52>
mov    -0x20(%rbp),%eax
sub    $0xd,%eax
je     11b4 <getLine+0x74>
jmp    11a3 <getLine+0x63>
mov    -0x20(%rbp),%eax
sub    $0x7f,%eax
je     11d0 <getLine+0x90>
jmp    120b <getLine+0xcb>
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    11df <getLine+0x9f>
jmp    125c <getLine+0x11c>
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    125c <getLine+0x11c>
movsbl -0x19(%rbp),%eax
cmp    $0x9,%eax
jne    121c <getLine+0xdc>
movb   $0x20,-0x19(%rbp)
movsbl -0x19(%rbp),%eax
cmp    $0x20,%eax
jl     1236 <getLine+0xf6>
movsbl -0x19(%rbp),%eax
cmp    $0x7e,%eax
jle    123b <getLine+0xfb>
jmp    125c <getLine+0x11c>
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    1173 <getLine+0x33>

x86 assembly (clang, -O2):
<getLine>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rsi
lea    0xeac(%rip),%rdi
mov    %r14,%rdx
call   1050 <printf@plt>
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    $0x20,%ebp
mov    %eax,%r15d
nopl   0x0(%rax)
xor    %eax,%eax
call   1060 <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    1169 <getLine+0x29>
xor    %eax,%eax
test   %r15d,%r15d
je     1169 <getLine+0x29>
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    1169 <getLine+0x29>
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):
@.str = [5 x i8] c"%s%s\00"
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 = load i8*, i8** %5
%11 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %9, i8* %10)
%12 = load i8*, i8** %5
%13 = call i32 @strlen(i8* %12)
store i32 %13, i32* %7
br label %14
14: ; preds = %3, %57
%15 = call signext i8 (...) @getchar()
store i8 %15, i8* %8
%16 = load i8, i8* %8
%17 = sext i8 %16 to i32
switch i32 %17, label %34 [
i32 13, label %18
i32 8, label %24
i32 127, label %24
]
18: ; preds = %14
%19 = call i32 @putchar(i8 signext 10)
%20 = load i8*, i8** %5
%21 = load i32, i32* %7
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8, i8* %20, i64 %22
store i8 0, i8* %23
ret void
24: ; preds = %14, %14
%25 = load i32, i32* %7
%26 = icmp eq i32 %25, 0
br i1 %26, label %27, label %28
27: ; preds = %24
br label %57
28: ; preds = %24
%29 = call i32 @putchar(i8 signext 8)
%30 = call i32 @putchar(i8 signext 32)
%31 = call i32 @putchar(i8 signext 8)
%32 = load i32, i32* %7
%33 = add nsw i32 %32, -1
store i32 %33, i32* %7
br label %57
34: ; preds = %14
%35 = load i8, i8* %8
%36 = sext i8 %35 to i32
%37 = icmp eq i32 %36, 9
br i1 %37, label %38, label %39
38: ; preds = %34
store i8 32, i8* %8
br label %39
39: ; preds = %38, %34
%40 = load i8, i8* %8
%41 = sext i8 %40 to i32
%42 = icmp slt i32 %41, 32
br i1 %42, label %47, label %43
43: ; preds = %39
%44 = load i8, i8* %8
%45 = sext i8 %44 to i32
%46 = icmp sgt i32 %45, 126
br i1 %46, label %47, label %48
47: ; preds = %43, %39
br label %57
48: ; preds = %43
%49 = load i8, i8* %8
%50 = call i32 @putchar(i8 signext %49)
%51 = load i8, i8* %8
%52 = load i8*, i8** %5
%53 = load i32, i32* %7
%54 = add nsw i32 %53, 1
store i32 %54, i32* %7
%55 = sext i32 %53 to i64
%56 = getelementptr inbounds i8, i8* %52, i64 %55
store i8 %51, i8* %56
br label %57
57: ; preds = %48, %47, %28, %27
br label %14
}

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