#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 */
int getchar();
char *malloc(int);
int /*<<< orphan*/ putchar(int);
char *readLine() {
  int bufferIndex = 0;
  char *buff = malloc(80 + 1);
  int c;
  while ((c = getchar()) != '\n') {
    if (c == '\b') {
      if (bufferIndex != 0) {
        bufferIndex--;
        putchar('\b');
      }
    } else if (c != -1) {
      if (bufferIndex <= 80) {
        buff[bufferIndex++] = c;
      }
      putchar(c);
    }
  }
  buff[bufferIndex] = '\0';
  return buff;
}


x86 assembly (clang, -O0):
<readLine>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x51,%edi
call   1050 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    $0x0,%al
call   1040 <getchar@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xa,%eax
je     11cc <readLine+0x9c>
cmpl   $0x8,-0x14(%rbp)
jne    118c <readLine+0x5c>
cmpl   $0x0,-0x4(%rbp)
je     1187 <readLine+0x57>
mov    -0x4(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x4(%rbp)
mov    $0x8,%edi
call   1030 <putchar@plt>
jmp    11c7 <readLine+0x97>
cmpl   $0xffffffff,-0x14(%rbp)
je     11c2 <readLine+0x92>
cmpl   $0x50,-0x4(%rbp)
jg     11ba <readLine+0x8a>
mov    -0x14(%rbp),%eax
mov    %al,%dl
mov    -0x10(%rbp),%rax
mov    -0x4(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x4(%rbp)
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x14(%rbp),%edi
call   1030 <putchar@plt>
jmp    11c7 <readLine+0x97>
jmp    114d <readLine+0x1d>
mov    -0x10(%rbp),%rax
movslq -0x4(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readLine>:
push   %rbp
push   %rbx
push   %rax
mov    $0x51,%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
xor    %eax,%eax
mov    %eax,%ebp
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
xor    %eax,%eax
call   1040 <getchar@plt>
cmp    $0xffffffff,%eax
je     1150 <readLine+0x20>
cmp    $0xa,%eax
je     1199 <readLine+0x69>
cmp    $0x8,%eax
jne    1180 <readLine+0x50>
mov    $0x0,%eax
test   %ebp,%ebp
je     1142 <readLine+0x12>
add    $0xffffffff,%ebp
mov    $0x8,%eax
jmp    118e <readLine+0x5e>
nopl   0x0(%rax)
cmp    $0x50,%ebp
jg     118e <readLine+0x5e>
movslq %ebp,%rcx
add    $0x1,%ebp
mov    %al,(%rbx,%rcx,1)
mov    %eax,%edi
call   1030 <putchar@plt>
mov    %ebp,%eax
jmp    1142 <readLine+0x12>
movslq %ebp,%rax
movb   $0x0,(%rbx,%rax,1)
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

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

LLVM IR (-O2):
define noalias i8* @readLine() {
%1 = tail call dereferenceable_or_null(81) i8* @malloc(i32 81)
br label %2
2: ; preds = %8, %0
%3 = phi i32 [ 0, %0 ], [ %9, %8 ]
br label %4
4: ; preds = %2, %4
%5 = tail call i32 (...) @getchar()
switch i32 %5, label %12 [
i32 10, label %23
i32 8, label %6
i32 -1, label %4
]
6: ; preds = %4
%7 = icmp eq i32 %3, 0
br i1 %7, label %8, label %10
8: ; preds = %6, %19
%9 = phi i32 [ %21, %19 ], [ 0, %6 ]
br label %2
10: ; preds = %6
%11 = add nsw i32 %3, -1
br label %19
12: ; preds = %4
%13 = icmp slt i32 %3, 81
br i1 %13, label %14, label %19
14: ; preds = %12
%15 = trunc i32 %5 to i8
%16 = add nsw i32 %3, 1
%17 = sext i32 %3 to i64
%18 = getelementptr inbounds i8, i8* %1, i64 %17
store i8 %15, i8* %18
br label %19
19: ; preds = %12, %14, %10
%20 = phi i32 [ 8, %10 ], [ %5, %14 ], [ %5, %12 ]
%21 = phi i32 [ %11, %10 ], [ %16, %14 ], [ %3, %12 ]
%22 = tail call i32 @putchar(i32 %20)
br label %8
23: ; preds = %4
%24 = sext i32 %3 to i64
%25 = getelementptr inbounds i8, i8* %1, i64 %24
store i8 0, i8* %25
ret i8* %1
}