#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 max(int /*<<< orphan*/, int);
int /*<<< orphan*/ printChar(char);
char readChar();
void readString(char line[80]) {
  char chr;
  int i;
  char end_flag = 0;
  for (i = 0; i < 80 - 1;) {
    chr = readChar();
    switch (chr) {
    case 0x08:
      printChar(0x08);
      printChar(0x20);
      i--;
      i = max(0, i);
      break;
    case 0x0D:
      end_flag = 1;
      break;
    default:
      line[i] = chr;
      i++;
    }
    printChar(chr);
    line[i] = '\0';
    if (end_flag)
      break;
  }
}


x86 assembly (clang, -O0):
<readString>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movb   $0x0,-0x11(%rbp)
movl   $0x0,-0x10(%rbp)
cmpl   $0x4f,-0x10(%rbp)
jge    11f9 <readString+0xc9>
xor    %eax,%eax
call   1040 <readChar@plt>
mov    %al,-0x9(%rbp)
movsbl -0x9(%rbp),%eax
mov    %eax,-0x18(%rbp)
sub    $0x8,%eax
je     1181 <readString+0x51>
jmp    1170 <readString+0x40>
mov    -0x18(%rbp),%eax
sub    $0xd,%eax
je     11b0 <readString+0x80>
jmp    11b9 <readString+0x89>
mov    $0x8,%edi
call   1050 <printChar@plt>
mov    $0x20,%edi
call   1050 <printChar@plt>
mov    -0x10(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%esi
xor    %edi,%edi
call   1030 <max@plt>
mov    %eax,-0x10(%rbp)
jmp    11d0 <readString+0xa0>
movb   $0x1,-0x11(%rbp)
jmp    11d0 <readString+0xa0>
mov    -0x9(%rbp),%dl
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
movsbl -0x9(%rbp),%edi
call   1050 <printChar@plt>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
cmpb   $0x0,-0x11(%rbp)
je     11f4 <readString+0xc4>
jmp    11f9 <readString+0xc9>
jmp    1147 <readString+0x17>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readString>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
xor    %r15d,%r15d
nopl   (%rax)
xor    %ebp,%ebp
xor    %eax,%eax
call   1040 <readChar@plt>
movsbl %al,%ebx
cmp    $0xd,%ebx
je     118e <readString+0x5e>
cmp    $0x8,%ebx
jne    1180 <readString+0x50>
mov    $0x8,%edi
call   1050 <printChar@plt>
mov    $0x20,%edi
call   1050 <printChar@plt>
add    $0xffffffff,%r15d
xor    %edi,%edi
mov    %r15d,%esi
call   1030 <max@plt>
mov    %eax,%r15d
jmp    118b <readString+0x5b>
nopl   (%rax)
movslq %r15d,%rcx
mov    %al,(%r14,%rcx,1)
add    $0x1,%r15d
mov    $0x1,%bpl
mov    %ebx,%edi
call   1050 <printChar@plt>
movslq %r15d,%rax
movb   $0x0,(%r14,%rax,1)
test   %bpl,%bpl
je     11a8 <readString+0x78>
cmp    $0x4f,%r15d
jl     1140 <readString+0x10>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @readString(i8* %0) {
%2 = alloca i8*
%3 = alloca i8
%4 = alloca i32
%5 = alloca i8
store i8* %0, i8** %2
store i8 0, i8* %5
store i32 0, i32* %4
br label %6
6: ; preds = %39, %1
%7 = load i32, i32* %4
%8 = icmp slt i32 %7, 79
br i1 %8, label %9, label %40
9: ; preds = %6
%10 = call signext i8 (...) @readChar()
store i8 %10, i8* %3
%11 = load i8, i8* %3
%12 = sext i8 %11 to i32
switch i32 %12, label %21 [
i32 8, label %13
i32 13, label %20
]
13: ; preds = %9
%14 = call i32 @printChar(i8 signext 8)
%15 = call i32 @printChar(i8 signext 32)
%16 = load i32, i32* %4
%17 = add nsw i32 %16, -1
store i32 %17, i32* %4
%18 = load i32, i32* %4
%19 = call i32 @max(i32 0, i32 %18)
store i32 %19, i32* %4
br label %29
20: ; preds = %9
store i8 1, i8* %5
br label %29
21: ; preds = %9
%22 = load i8, i8* %3
%23 = load i8*, i8** %2
%24 = load i32, i32* %4
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8, i8* %23, i64 %25
store i8 %22, i8* %26
%27 = load i32, i32* %4
%28 = add nsw i32 %27, 1
store i32 %28, i32* %4
br label %29
29: ; preds = %21, %20, %13
%30 = load i8, i8* %3
%31 = call i32 @printChar(i8 signext %30)
%32 = load i8*, i8** %2
%33 = load i32, i32* %4
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i8, i8* %32, i64 %34
store i8 0, i8* %35
%36 = load i8, i8* %5
%37 = icmp ne i8 %36, 0
br i1 %37, label %38, label %39
38: ; preds = %29
br label %40
39: ; preds = %29
br label %6
40: ; preds = %38, %6
ret void
}

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