#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 interrupt(int, int, int /*<<< orphan*/, int /*<<< orphan*/,
               int /*<<< orphan*/);
void readString(char *store) {
  int cur = 0;
  store[cur] = interrupt(0x16, 0, 0, 0, 0);
  while (store[cur] != 0xd) {
    if (store[cur] == 0x8 && cur > 0) {
      interrupt(0x10, 0xe * 256 + store[cur], 0, 0, 0);
      interrupt(0x10, 0xe * 256 + ' ', 0, 0, 0);
      interrupt(0x10, 0xe * 256 + store[cur], 0, 0, 0);
      cur -= 1;
    } else if (store[cur] != 0x8) {
      interrupt(0x10, 0xe * 256 + *(store + cur), 0, 0, 0);
      cur++;
    }
    store[cur] = interrupt(0x16, 0, 0, 0, 0);
  }
  interrupt(0x10, 0xe * 256 + '\n', 0, 0, 0);
  interrupt(0x10, 0xe * 256 + '\r', 0, 0, 0);
  *(store + cur) = '\r';
  cur++;
  *(store + cur) = '\n';
  cur++;
  *(store + cur) = '\0';
  return;
}


x86 assembly (clang, -O0):
<readString>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    $0x16,%edi
xor    %r8d,%r8d
mov    %r8d,%esi
mov    %r8d,%edx
mov    %r8d,%ecx
call   1030 <interrupt@plt>
mov    %al,%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),%eax
cmp    $0xd,%eax
je     125a <readString+0x14a>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x8,%eax
jne    11ea <readString+0xda>
cmpl   $0x0,-0xc(%rbp)
jle    11ea <readString+0xda>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%esi
add    $0xe00,%esi
mov    $0x10,%edi
xor    %r8d,%r8d
mov    %r8d,%edx
mov    %r8d,%ecx
call   1030 <interrupt@plt>
mov    $0x10,%edi
mov    $0xe20,%esi
xor    %r8d,%r8d
mov    %r8d,%edx
mov    %r8d,%ecx
call   1030 <interrupt@plt>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%esi
add    $0xe00,%esi
mov    $0x10,%edi
xor    %r8d,%r8d
mov    %r8d,%edx
mov    %r8d,%ecx
call   1030 <interrupt@plt>
mov    -0xc(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1232 <readString+0x122>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x8,%eax
je     122d <readString+0x11d>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%esi
add    $0xe00,%esi
mov    $0x10,%edi
xor    %r8d,%r8d
mov    %r8d,%edx
mov    %r8d,%ecx
call   1030 <interrupt@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1232 <readString+0x122>
mov    $0x16,%edi
xor    %r8d,%r8d
mov    %r8d,%esi
mov    %r8d,%edx
mov    %r8d,%ecx
call   1030 <interrupt@plt>
mov    %al,%dl
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
jmp    1146 <readString+0x36>
mov    $0x10,%edi
mov    $0xe0a,%esi
xor    %r8d,%r8d
mov    %r8d,%edx
mov    %r8d,%ecx
call   1030 <interrupt@plt>
mov    $0x10,%edi
mov    $0xe0d,%esi
xor    %r8d,%r8d
mov    %r8d,%edx
mov    %r8d,%ecx
call   1030 <interrupt@plt>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movb   $0xd,(%rax,%rcx,1)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movb   $0xa,(%rax,%rcx,1)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readString>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%r14
xor    %ebp,%ebp
mov    $0x16,%edi
xor    %esi,%esi
xor    %edx,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1030 <interrupt@plt>
mov    %al,(%r14)
mov    %r14,%rbx
cmp    $0xd,%al
jne    1175 <readString+0x65>
mov    $0x10,%edi
mov    $0xe0a,%esi
xor    %edx,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1030 <interrupt@plt>
mov    $0x10,%edi
mov    $0xe0d,%esi
xor    %edx,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1030 <interrupt@plt>
movb   $0xd,(%rbx)
movslq %ebp,%rax
movw   $0xa,0x1(%rax,%r14,1)
pop    %rbx
pop    %r14
pop    %rbp
ret
xor    %ebp,%ebp
mov    %r14,%rbx
jmp    11f6 <readString+0xe6>
nopl   0x0(%rax)
mov    $0x10,%edi
mov    $0xe08,%esi
xor    %edx,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1030 <interrupt@plt>
mov    $0x10,%edi
mov    $0xe20,%esi
xor    %edx,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1030 <interrupt@plt>
movzbl (%rbx),%eax
mov    $0xffffffff,%ebx
movsbl %al,%esi
add    $0xe00,%esi
mov    $0x10,%edi
xor    %edx,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1030 <interrupt@plt>
add    %ebx,%ebp
mov    $0x16,%edi
xor    %esi,%esi
xor    %edx,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1030 <interrupt@plt>
movslq %ebp,%rcx
lea    (%r14,%rcx,1),%rbx
mov    %al,(%r14,%rcx,1)
cmp    $0xd,%al
je     1136 <readString+0x26>
cmp    $0x8,%al
jne    11fe <readString+0xee>
test   %ebp,%ebp
jg     1180 <readString+0x70>
mov    $0x1,%ebx
cmp    $0x8,%al
jne    11b4 <readString+0xa4>
jmp    11d0 <readString+0xc0>

LLVM IR (-O0):
define void @readString(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
store i8* %0, i8** %2
store i32 0, i32* %3
%4 = call signext i8 @interrupt(i32 22, i32 0, i32 0, i32 0, i32 0)
%5 = load i8*, i8** %2
%6 = load i32, i32* %3
%7 = sext i32 %6 to i64
%8 = getelementptr inbounds i8, i8* %5, i64 %7
store i8 %4, i8* %8
br label %9
9: ; preds = %68, %1
%10 = load i8*, i8** %2
%11 = load i32, i32* %3
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds i8, i8* %10, i64 %12
%14 = load i8, i8* %13
%15 = sext i8 %14 to i32
%16 = icmp ne i32 %15, 13
br i1 %16, label %17, label %74
17: ; preds = %9
%18 = load i8*, i8** %2
%19 = load i32, i32* %3
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i8, i8* %18, i64 %20
%22 = load i8, i8* %21
%23 = sext i8 %22 to i32
%24 = icmp eq i32 %23, 8
br i1 %24, label %25, label %48
25: ; preds = %17
%26 = load i32, i32* %3
%27 = icmp sgt i32 %26, 0
br i1 %27, label %28, label %48
28: ; preds = %25
%29 = load i8*, i8** %2
%30 = load i32, i32* %3
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i8, i8* %29, i64 %31
%33 = load i8, i8* %32
%34 = sext i8 %33 to i32
%35 = add nsw i32 3584, %34
%36 = call signext i8 @interrupt(i32 16, i32 %35, i32 0, i32 0, i32 0)
%37 = call signext i8 @interrupt(i32 16, i32 3616, i32 0, i32 0, i32 0)
%38 = load i8*, i8** %2
%39 = load i32, i32* %3
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i8, i8* %38, i64 %40
%42 = load i8, i8* %41
%43 = sext i8 %42 to i32
%44 = add nsw i32 3584, %43
%45 = call signext i8 @interrupt(i32 16, i32 %44, i32 0, i32 0, i32 0)
%46 = load i32, i32* %3
%47 = sub nsw i32 %46, 1
store i32 %47, i32* %3
br label %68
48: ; preds = %25, %17
%49 = load i8*, i8** %2
%50 = load i32, i32* %3
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds i8, i8* %49, i64 %51
%53 = load i8, i8* %52
%54 = sext i8 %53 to i32
%55 = icmp ne i32 %54, 8
br i1 %55, label %56, label %67
56: ; preds = %48
%57 = load i8*, i8** %2
%58 = load i32, i32* %3
%59 = sext i32 %58 to i64
%60 = getelementptr inbounds i8, i8* %57, i64 %59
%61 = load i8, i8* %60
%62 = sext i8 %61 to i32
%63 = add nsw i32 3584, %62
%64 = call signext i8 @interrupt(i32 16, i32 %63, i32 0, i32 0, i32 0)
%65 = load i32, i32* %3
%66 = add nsw i32 %65, 1
store i32 %66, i32* %3
br label %67
67: ; preds = %56, %48
br label %68
68: ; preds = %67, %28
%69 = call signext i8 @interrupt(i32 22, i32 0, i32 0, i32 0, i32 0)
%70 = load i8*, i8** %2
%71 = load i32, i32* %3
%72 = sext i32 %71 to i64
%73 = getelementptr inbounds i8, i8* %70, i64 %72
store i8 %69, i8* %73
br label %9
74: ; preds = %9
%75 = call signext i8 @interrupt(i32 16, i32 3594, i32 0, i32 0, i32 0)
%76 = call signext i8 @interrupt(i32 16, i32 3597, i32 0, i32 0, i32 0)
%77 = load i8*, i8** %2
%78 = load i32, i32* %3
%79 = sext i32 %78 to i64
%80 = getelementptr inbounds i8, i8* %77, i64 %79
store i8 13, i8* %80
%81 = load i32, i32* %3
%82 = add nsw i32 %81, 1
store i32 %82, i32* %3
%83 = load i8*, i8** %2
%84 = load i32, i32* %3
%85 = sext i32 %84 to i64
%86 = getelementptr inbounds i8, i8* %83, i64 %85
store i8 10, i8* %86
%87 = load i32, i32* %3
%88 = add nsw i32 %87, 1
store i32 %88, i32* %3
%89 = load i8*, i8** %2
%90 = load i32, i32* %3
%91 = sext i32 %90 to i64
%92 = getelementptr inbounds i8, i8* %89, i64 %91
store i8 0, i8* %92
ret void
}

LLVM IR (-O2):
define void @readString(i8* nocapture %0) {
%2 = tail call signext i8 @interrupt(i32 22, i32 0, i32 0, i32 0, i32 0)
store i8 %2, i8* %0
%3 = icmp eq i8 %2, 13
br i1 %3, label %29, label %4
4: ; preds = %1, %23
%5 = phi i8 [ %25, %23 ], [ %2, %1 ]
%6 = phi i8* [ %27, %23 ], [ %0, %1 ]
%7 = phi i32 [ %24, %23 ], [ 0, %1 ]
%8 = icmp eq i8 %5, 8
%9 = icmp sgt i32 %7, 0
%10 = select i1 %8, i1 %9, i1 false
br i1 %10, label %11, label %15
11: ; preds = %4
%12 = tail call signext i8 @interrupt(i32 16, i32 3592, i32 0, i32 0, i32 0)
%13 = tail call signext i8 @interrupt(i32 16, i32 3616, i32 0, i32 0, i32 0)
%14 = load i8, i8* %6
br label %16
15: ; preds = %4
br i1 %8, label %23, label %16
16: ; preds = %15, %11
%17 = phi i8 [ %14, %11 ], [ %5, %15 ]
%18 = phi i32 [ -1, %11 ], [ 1, %15 ]
%19 = sext i8 %17 to i32
%20 = add nsw i32 %19, 3584
%21 = tail call signext i8 @interrupt(i32 16, i32 %20, i32 0, i32 0, i32 0)
%22 = add nsw i32 %7, %18
br label %23
23: ; preds = %16, %15
%24 = phi i32 [ %7, %15 ], [ %22, %16 ]
%25 = tail call signext i8 @interrupt(i32 22, i32 0, i32 0, i32 0, i32 0)
%26 = sext i32 %24 to i64
%27 = getelementptr inbounds i8, i8* %0, i64 %26
store i8 %25, i8* %27
%28 = icmp eq i8 %25, 13
br i1 %28, label %29, label %4
29: ; preds = %23, %1
%30 = phi i32 [ 0, %1 ], [ %24, %23 ]
%31 = phi i8* [ %0, %1 ], [ %27, %23 ]
%32 = tail call signext i8 @interrupt(i32 16, i32 3594, i32 0, i32 0, i32 0)
%33 = tail call signext i8 @interrupt(i32 16, i32 3597, i32 0, i32 0, i32 0)
store i8 13, i8* %31
%34 = add nsw i32 %30, 1
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i8, i8* %0, i64 %35
store i8 10, i8* %36
%37 = add nsw i32 %30, 2
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i8, i8* %0, i64 %38
store i8 0, i8* %39
ret void
}