#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 is_a_backspace(unsigned char);
scalar_t__ is_a_return(unsigned char);
char *strdup(unsigned char *);
unsigned char terminal_get_and_echo_char(unsigned char, unsigned char,
                                         unsigned char, unsigned char);
char *input_line_and_echo_char(unsigned char e, unsigned char rubout,
                               unsigned char size) {
  unsigned char c = 0;
  unsigned char i = 0;
  unsigned char buf[64];
  buf[0] = '\0';
  while (is_a_return(c) == 0) {
    c = terminal_get_and_echo_char(i, size, e, rubout);
    if (is_a_backspace(c) == 1) {
      if (i > 0) {
        --i;
        buf[i] = '\0';
      }
    } else if (is_a_return(c) == 0) {
      if (i < size) {
        buf[i] = c;
        ++i;
        buf[i] = '\0';
      } else {
        buf[i] = c;
      }
    }
  }
  return strdup(buf);
}


x86 assembly (clang, -O0):
<input_line_and_echo_char>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %dl,%al
mov    %sil,%cl
mov    %dil,%dl
mov    %dl,-0x1(%rbp)
mov    %cl,-0x2(%rbp)
mov    %al,-0x3(%rbp)
movb   $0x0,-0x4(%rbp)
movb   $0x0,-0x5(%rbp)
movb   $0x0,-0x50(%rbp)
movzbl -0x4(%rbp),%edi
call   1050 <is_a_return@plt>
cmp    $0x0,%rax
jne    1229 <input_line_and_echo_char+0xe9>
mov    -0x5(%rbp),%dl
mov    -0x3(%rbp),%cl
mov    -0x1(%rbp),%al
movzbl %dl,%edi
movzbl %cl,%esi
movzbl %al,%edx
movzbl -0x2(%rbp),%ecx
call   1030 <terminal_get_and_echo_char@plt>
mov    %al,-0x4(%rbp)
movzbl -0x4(%rbp),%edi
call   1040 <is_a_backspace@plt>
cmp    $0x1,%eax
jne    11cb <input_line_and_echo_char+0x8b>
movzbl -0x5(%rbp),%eax
cmp    $0x0,%eax
jle    11c6 <input_line_and_echo_char+0x86>
mov    -0x5(%rbp),%al
add    $0xff,%al
mov    %al,-0x5(%rbp)
movzbl -0x5(%rbp),%eax
movb   $0x0,-0x50(%rbp,%rax,1)
jmp    1224 <input_line_and_echo_char+0xe4>
movzbl -0x4(%rbp),%edi
call   1050 <is_a_return@plt>
cmp    $0x0,%rax
jne    121f <input_line_and_echo_char+0xdf>
movzbl -0x5(%rbp),%eax
movzbl -0x3(%rbp),%ecx
cmp    %ecx,%eax
jge    120f <input_line_and_echo_char+0xcf>
mov    -0x4(%rbp),%cl
movzbl -0x5(%rbp),%eax
mov    %cl,-0x50(%rbp,%rax,1)
mov    -0x5(%rbp),%al
add    $0x1,%al
mov    %al,-0x5(%rbp)
movzbl -0x5(%rbp),%eax
movb   $0x0,-0x50(%rbp,%rax,1)
jmp    121a <input_line_and_echo_char+0xda>
mov    -0x4(%rbp),%cl
movzbl -0x5(%rbp),%eax
mov    %cl,-0x50(%rbp,%rax,1)
jmp    121f <input_line_and_echo_char+0xdf>
jmp    1224 <input_line_and_echo_char+0xe4>
jmp    1165 <input_line_and_echo_char+0x25>
lea    -0x50(%rbp),%rdi
call   1060 <strdup@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<input_line_and_echo_char>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x58,%rsp
mov    %edx,0x8(%rsp)
mov    %esi,%ebx
mov    %edi,%ebp
movb   $0x0,0x10(%rsp)
xor    %edi,%edi
call   1050 <is_a_return@plt>
test   %rax,%rax
je     1180 <input_line_and_echo_char+0x40>
lea    0x10(%rsp),%rdi
call   1060 <strdup@plt>
add    $0x58,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %r15d,%r15d
movzbl 0x8(%rsp),%eax
mov    %eax,0xc(%rsp)
movzbl %bpl,%r12d
movzbl %bl,%r13d
jmp    11bf <input_line_and_echo_char+0x7f>
cs nopw 0x0(%rax,%rax,1)
mov    $0xff,%al
test   %r15b,%r15b
je     1202 <input_line_and_echo_char+0xc2>
add    %al,%r15b
movzbl %r15b,%eax
movb   $0x0,0x10(%rsp,%rax,1)
mov    %ebx,%edi
call   1050 <is_a_return@plt>
test   %rax,%rax
jne    1167 <input_line_and_echo_char+0x27>
movzbl %r15b,%ebp
mov    %ebp,%edi
mov    0xc(%rsp),%esi
mov    %r12d,%edx
mov    %r13d,%ecx
call   1030 <terminal_get_and_echo_char@plt>
mov    %eax,%r14d
movzbl %al,%ebx
mov    %ebx,%edi
call   1040 <is_a_backspace@plt>
cmp    $0x1,%eax
je     11a0 <input_line_and_echo_char+0x60>
mov    %ebx,%edi
call   1050 <is_a_return@plt>
test   %rax,%rax
jne    11b3 <input_line_and_echo_char+0x73>
mov    %r14b,0x10(%rsp,%rbp,1)
mov    $0x1,%al
cmp    0x8(%rsp),%bpl
jb     11a7 <input_line_and_echo_char+0x67>
jmp    11b3 <input_line_and_echo_char+0x73>
xor    %r15d,%r15d
jmp    11b3 <input_line_and_echo_char+0x73>

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

LLVM IR (-O2):
define noalias i8* @input_line_and_echo_char(i8 zeroext %0, i8 zeroext %1, i8 zeroext %2) {
%4 = alloca [64 x i8]
%5 = getelementptr inbounds [64 x i8], [64 x i8]* %4, i64 0, i64 0
store i8 0, i8* %5
%6 = tail call i64 @is_a_return(i8 zeroext 0)
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %31
8: ; preds = %3, %27
%9 = phi i8 [ %28, %27 ], [ 0, %3 ]
%10 = tail call zeroext i8 @terminal_get_and_echo_char(i8 zeroext %9, i8 zeroext %2, i8 zeroext %0, i8 zeroext %1)
%11 = tail call i32 @is_a_backspace(i8 zeroext %10)
%12 = icmp eq i32 %11, 1
br i1 %12, label %13, label %15
13: ; preds = %8
%14 = icmp eq i8 %9, 0
br i1 %14, label %27, label %22
15: ; preds = %8
%16 = tail call i64 @is_a_return(i8 zeroext %10)
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %27
18: ; preds = %15
%19 = icmp ult i8 %9, %2
%20 = zext i8 %9 to i64
%21 = getelementptr inbounds [64 x i8], [64 x i8]* %4, i64 0, i64 %20
store i8 %10, i8* %21
br i1 %19, label %22, label %27
22: ; preds = %18, %13
%23 = phi i8 [ -1, %13 ], [ 1, %18 ]
%24 = add i8 %9, %23
%25 = zext i8 %24 to i64
%26 = getelementptr inbounds [64 x i8], [64 x i8]* %4, i64 0, i64 %25
store i8 0, i8* %26
br label %27
27: ; preds = %22, %18, %15, %13
%28 = phi i8 [ 0, %13 ], [ %9, %15 ], [ %9, %18 ], [ %24, %22 ]
%29 = tail call i64 @is_a_return(i8 zeroext %10)
%30 = icmp eq i64 %29, 0
br i1 %30, label %8, label %31
31: ; preds = %27, %3
%32 = call i8* @strdup(i8* %5)
ret i8* %32
}