#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 /*<<< orphan*/ nextLine();
int /*<<< orphan*/ printChar(char);
char readChar();
void readString(char str[]) {
  int i;
  char current = 0;
  for (i = 0; i < 80; i++)
    str[i] = 0x0;
  i = 0;
  while (current != 0xD) {
    current = readChar();
    if (current == 0x8 && i > 0) {
      printChar(current);
      printChar(0x0);
      printChar(current);
      i--;
    } else if (i < 80 - 1 && current != 0x8 && current != 0xD) {
      str[i] = current;
      printChar(str[i]);
      i++;
    }
  }
  nextLine();
  str[80] = 0;
}


x86 assembly (clang, -O0):
<readString>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
movb   $0x0,-0xd(%rbp)
movl   $0x0,-0xc(%rbp)
cmpl   $0x50,-0xc(%rbp)
jge    116b <readString+0x3b>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1147 <readString+0x17>
movl   $0x0,-0xc(%rbp)
movsbl -0xd(%rbp),%eax
cmp    $0xd,%eax
je     121d <readString+0xed>
mov    $0x0,%al
call   1030 <readChar@plt>
mov    %al,-0xd(%rbp)
movsbl -0xd(%rbp),%eax
cmp    $0x8,%eax
jne    11c7 <readString+0x97>
cmpl   $0x0,-0xc(%rbp)
jle    11c7 <readString+0x97>
movsbl -0xd(%rbp),%edi
call   1040 <printChar@plt>
xor    %edi,%edi
call   1040 <printChar@plt>
movsbl -0xd(%rbp),%edi
call   1040 <printChar@plt>
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
jmp    1218 <readString+0xe8>
cmpl   $0x4f,-0xc(%rbp)
jge    1213 <readString+0xe3>
movsbl -0xd(%rbp),%eax
cmp    $0x8,%eax
je     1213 <readString+0xe3>
movsbl -0xd(%rbp),%eax
cmp    $0xd,%eax
je     1213 <readString+0xe3>
mov    -0xd(%rbp),%dl
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1040 <printChar@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1218 <readString+0xe8>
jmp    1172 <readString+0x42>
mov    $0x0,%al
call   1050 <nextLine@plt>
mov    -0x8(%rbp),%rax
movb   $0x0,0x50(%rax)
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readString>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%r14
xorps  %xmm0,%xmm0
movups %xmm0,0x40(%rdi)
movups %xmm0,0x30(%rdi)
movups %xmm0,0x20(%rdi)
movups %xmm0,0x10(%rdi)
movups %xmm0,(%rdi)
xor    %ebp,%ebp
jmp    1183 <readString+0x53>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    $0x8,%edi
call   1040 <printChar@plt>
xor    %edi,%edi
call   1040 <printChar@plt>
mov    $0x8,%edi
call   1040 <printChar@plt>
add    $0xffffffff,%ebp
cmp    $0xd,%bl
je     11b7 <readString+0x87>
xor    %eax,%eax
call   1030 <readChar@plt>
mov    %eax,%ebx
cmp    $0x8,%al
jne    1194 <readString+0x64>
test   %ebp,%ebp
jg     1160 <readString+0x30>
cmp    $0x4e,%ebp
jg     117e <readString+0x4e>
cmp    $0x8,%bl
je     117e <readString+0x4e>
cmp    $0xd,%bl
je     117e <readString+0x4e>
movslq %ebp,%rax
mov    %bl,(%r14,%rax,1)
movsbl %bl,%edi
call   1040 <printChar@plt>
add    $0x1,%ebp
jmp    117e <readString+0x4e>
xor    %eax,%eax
call   1050 <nextLine@plt>
movb   $0x0,0x50(%r14)
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define void @readString(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i8
store i8* %0, i8** %2
store i8 0, i8* %4
store i32 0, i32* %3
br label %5
5: ; preds = %13, %1
%6 = load i32, i32* %3
%7 = icmp slt i32 %6, 80
br i1 %7, label %8, label %16
8: ; preds = %5
%9 = load i8*, i8** %2
%10 = load i32, i32* %3
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds i8, i8* %9, i64 %11
store i8 0, i8* %12
br label %13
13: ; preds = %8
%14 = load i32, i32* %3
%15 = add nsw i32 %14, 1
store i32 %15, i32* %3
br label %5
16: ; preds = %5
store i32 0, i32* %3
br label %17
17: ; preds = %63, %16
%18 = load i8, i8* %4
%19 = sext i8 %18 to i32
%20 = icmp ne i32 %19, 13
br i1 %20, label %21, label %64
21: ; preds = %17
%22 = call signext i8 (...) @readChar()
store i8 %22, i8* %4
%23 = load i8, i8* %4
%24 = sext i8 %23 to i32
%25 = icmp eq i32 %24, 8
br i1 %25, label %26, label %37
26: ; preds = %21
%27 = load i32, i32* %3
%28 = icmp sgt i32 %27, 0
br i1 %28, label %29, label %37
29: ; preds = %26
%30 = load i8, i8* %4
%31 = call i32 @printChar(i8 signext %30)
%32 = call i32 @printChar(i8 signext 0)
%33 = load i8, i8* %4
%34 = call i32 @printChar(i8 signext %33)
%35 = load i32, i32* %3
%36 = add nsw i32 %35, -1
store i32 %36, i32* %3
br label %63
37: ; preds = %26, %21
%38 = load i32, i32* %3
%39 = icmp slt i32 %38, 79
br i1 %39, label %40, label %62
40: ; preds = %37
%41 = load i8, i8* %4
%42 = sext i8 %41 to i32
%43 = icmp ne i32 %42, 8
br i1 %43, label %44, label %62
44: ; preds = %40
%45 = load i8, i8* %4
%46 = sext i8 %45 to i32
%47 = icmp ne i32 %46, 13
br i1 %47, label %48, label %62
48: ; preds = %44
%49 = load i8, i8* %4
%50 = load i8*, i8** %2
%51 = load i32, i32* %3
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds i8, i8* %50, i64 %52
store i8 %49, i8* %53
%54 = load i8*, i8** %2
%55 = load i32, i32* %3
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds i8, i8* %54, i64 %56
%58 = load i8, i8* %57
%59 = call i32 @printChar(i8 signext %58)
%60 = load i32, i32* %3
%61 = add nsw i32 %60, 1
store i32 %61, i32* %3
br label %62
62: ; preds = %48, %44, %40, %37
br label %63
63: ; preds = %62, %29
br label %17
64: ; preds = %17
%65 = call i32 (...) @nextLine()
%66 = load i8*, i8** %2
%67 = getelementptr inbounds i8, i8* %66, i64 80
store i8 0, i8* %67
ret void
}

LLVM IR (-O2):
define void @readString(i8* nocapture writeonly %0) {
br label %2
2: ; preds = %1, %22
%3 = phi i32 [ %23, %22 ], [ 0, %1 ]
%4 = tail call signext i8 (...) @readChar()
%5 = icmp eq i8 %4, 8
%6 = icmp sgt i32 %3, 0
%7 = select i1 %5, i1 %6, i1 false
br i1 %7, label %8, label %13
8: ; preds = %2
%9 = tail call i32 @printChar(i8 signext 8)
%10 = tail call i32 @printChar(i8 signext 0)
%11 = tail call i32 @printChar(i8 signext 8)
%12 = add nsw i32 %3, -1
br label %22
13: ; preds = %2
%14 = freeze i32 %3
%15 = icmp slt i32 %14, 79
br i1 %15, label %16, label %22
16: ; preds = %13
switch i8 %4, label %17 [
i8 13, label %22
i8 8, label %22
]
17: ; preds = %16
%18 = sext i32 %14 to i64
%19 = getelementptr inbounds i8, i8* %0, i64 %18
store i8 %4, i8* %19
%20 = tail call i32 @printChar(i8 signext %4)
%21 = add nsw i32 %14, 1
br label %22
22: ; preds = %16, %16, %13, %17, %8
%23 = phi i32 [ %12, %8 ], [ %21, %17 ], [ %14, %16 ], [ %14, %13 ], [ %14, %16 ]
%24 = icmp eq i8 %4, 13
br i1 %24, label %25, label %2
25: ; preds = %22
%26 = tail call i32 (...) @nextLine()
%27 = getelementptr inbounds i8, i8* %0, i64 80
store i8 0, i8* %27
ret void
}