#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*/ exit(int /*<<< orphan*/);
char getch();
int /*<<< orphan*/ putchar(char);
void inputstr(char *a, int len) {
  int i = 0;
  char b;
getchstr:
  while ((b = getch()) != 13) {
    if (b == 3) {
      exit(0);
    }
    if (b != 127) {
      if (i > len) {
        goto getchstr;
      }
      putchar(b);
      a[i] = b;
      i++;
    } else {
      if (i > 0) {
        i--;
        putchar('\b');
        putchar(' ');
        putchar('\b');
      }
    }
  }
  if (i == 0) {
    goto getchstr;
  }
  a[i] = '\0';
  putchar('\n');
}


x86 assembly (clang, -O0):
<inputstr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
jmp    114b <inputstr+0x1b>
mov    $0x0,%al
call   1040 <getch@plt>
mov    %al,-0x11(%rbp)
movsbl %al,%eax
cmp    $0xd,%eax
je     11f3 <inputstr+0xc3>
movsbl -0x11(%rbp),%eax
cmp    $0x3,%eax
jne    1175 <inputstr+0x45>
xor    %edi,%edi
call   1050 <exit@plt>
movsbl -0x11(%rbp),%eax
cmp    $0x7f,%eax
je     11b8 <inputstr+0x88>
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jle    1193 <inputstr+0x63>
jmp    1146 <inputstr+0x16>
movsbl -0x11(%rbp),%edi
call   1030 <putchar@plt>
mov    -0x11(%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)
jmp    11ee <inputstr+0xbe>
cmpl   $0x0,-0x10(%rbp)
jle    11e9 <inputstr+0xb9>
mov    -0x10(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x10(%rbp)
mov    $0x8,%edi
call   1030 <putchar@plt>
mov    $0x20,%edi
call   1030 <putchar@plt>
mov    $0x8,%edi
call   1030 <putchar@plt>
jmp    11ee <inputstr+0xbe>
jmp    114b <inputstr+0x1b>
cmpl   $0x0,-0x10(%rbp)
jne    1202 <inputstr+0xd2>
jmp    1146 <inputstr+0x16>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    $0xa,%edi
call   1030 <putchar@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<inputstr>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%r15d
mov    %rdi,%r14
xor    %eax,%eax
jmp    1173 <inputstr+0x43>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
add    $0xffffffff,%ebp
mov    $0x8,%edi
call   1030 <putchar@plt>
mov    $0x20,%edi
call   1030 <putchar@plt>
mov    $0x8,%edi
call   1030 <putchar@plt>
mov    %ebp,%eax
mov    %eax,%ebp
jmp    1184 <inputstr+0x54>
nopw   0x0(%rax,%rax,1)
test   %ebp,%ebp
jg     1150 <inputstr+0x20>
xor    %eax,%eax
call   1040 <getch@plt>
cmp    $0x7f,%al
je     1180 <inputstr+0x50>
mov    %eax,%ebx
cmp    $0xd,%al
je     11c0 <inputstr+0x90>
cmp    $0x3,%bl
je     11e5 <inputstr+0xb5>
cmp    %r15d,%ebp
jg     1184 <inputstr+0x54>
movsbl %bl,%edi
call   1030 <putchar@plt>
movslq %ebp,%rax
mov    %bl,(%r14,%rax,1)
add    $0x1,%ebp
mov    %ebp,%eax
jmp    1173 <inputstr+0x43>
cs nopw 0x0(%rax,%rax,1)
nop
mov    $0x0,%eax
test   %ebp,%ebp
je     1173 <inputstr+0x43>
movslq %ebp,%rax
movb   $0x0,(%r14,%rax,1)
mov    $0xa,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <putchar@plt>
xor    %edi,%edi
call   1050 <exit@plt>

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

LLVM IR (-O2):
define void @inputstr(i8* nocapture writeonly %0, i32 %1) {
br label %3
3: ; preds = %17, %2
%4 = phi i32 [ 0, %2 ], [ %18, %17 ]
%5 = icmp sgt i32 %4, 0
%6 = icmp sgt i32 %4, %1
br label %7
7: ; preds = %20, %3
%8 = tail call signext i8 (...) @getch()
switch i8 %8, label %11 [
i8 13, label %26
i8 3, label %9
i8 127, label %19
]
9: ; preds = %7
%10 = tail call i32 @exit(i32 0)
unreachable
11: ; preds = %7
br i1 %6, label %20, label %12
12: ; preds = %11
%13 = tail call i32 @putchar(i8 signext %8)
%14 = sext i32 %4 to i64
%15 = getelementptr inbounds i8, i8* %0, i64 %14
store i8 %8, i8* %15
%16 = add nsw i32 %4, 1
br label %17
17: ; preds = %12, %21, %26
%18 = phi i32 [ 0, %26 ], [ %22, %21 ], [ %16, %12 ]
br label %3
19: ; preds = %7
br i1 %5, label %21, label %20
20: ; preds = %19, %11
br label %7
21: ; preds = %19
%22 = add nsw i32 %4, -1
%23 = tail call i32 @putchar(i8 signext 8)
%24 = tail call i32 @putchar(i8 signext 32)
%25 = tail call i32 @putchar(i8 signext 8)
br label %17
26: ; preds = %7
%27 = icmp eq i32 %4, 0
br i1 %27, label %17, label %28
28: ; preds = %26
%29 = sext i32 %4 to i64
%30 = getelementptr inbounds i8, i8* %0, i64 %29
store i8 0, i8* %30
%31 = tail call i32 @putchar(i8 signext 10)
ret void
}