#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 getch();
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, char);
void readStrNoEnter(char *str, int maxSize) {
  memset(str, 0, maxSize * sizeof(char));
  for (int i = 0; i < maxSize - 1; i++) {
    str[i] = getch();
    if (str[i] == '\x1b')
      i--;
    else if (str[i] != '\n')
      printf("%c", str[i]);
    else {
      str[i] = '\0';
      break;
    }
  }
}


x86 assembly (clang, -O0):
<readStrNoEnter>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
movslq -0xc(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%edx
xor    %esi,%esi
call   1040 <memset@plt>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    11fe <readStrNoEnter+0xce>
mov    $0x0,%al
call   1050 <getch@plt>
mov    %al,%dl
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x1b,%eax
jne    11a3 <readStrNoEnter+0x73>
mov    -0x10(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x10(%rbp)
jmp    11eb <readStrNoEnter+0xbb>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xa,%eax
je     11d5 <readStrNoEnter+0xa5>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
lea    0xe39(%rip),%rdi
movsbl (%rax,%rcx,1),%esi
call   1030 <printf@plt>
jmp    11e6 <readStrNoEnter+0xb6>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    11fe <readStrNoEnter+0xce>
jmp    11eb <readStrNoEnter+0xbb>
jmp    11f0 <readStrNoEnter+0xc0>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    115b <readStrNoEnter+0x2b>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readStrNoEnter>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%r15
xor    %esi,%esi
mov    %ebp,%edx
call   1040 <memset@plt>
cmp    $0x2,%ebp
jl     1192 <readStrNoEnter+0x62>
add    $0xffffffff,%ebp
lea    0xeac(%rip),%r14
xor    %ebx,%ebx
jmp    116a <readStrNoEnter+0x3a>
nopl   0x0(%rax,%rax,1)
add    $0xffffffff,%ebx
add    $0x1,%ebx
cmp    %ebp,%ebx
jge    1192 <readStrNoEnter+0x62>
xor    %eax,%eax
call   1050 <getch@plt>
movslq %ebx,%rcx
mov    %al,(%r15,%rcx,1)
cmp    $0x1b,%al
je     1160 <readStrNoEnter+0x30>
cmp    $0xa,%al
je     118d <readStrNoEnter+0x5d>
movsbl %al,%esi
mov    %r14,%rdi
call   1030 <printf@plt>
jmp    1163 <readStrNoEnter+0x33>
movb   $0x0,(%r15,%rcx,1)
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [3 x i8] c"%c\00"
define void @readStrNoEnter(i8* %0, i32 %1) {
%3 = tail call i32 @memset(i8* %0, i32 0, i32 %1)
%4 = add nsw i32 %1, -1
%5 = icmp sgt i32 %1, 1
br i1 %5, label %6, label %21
6: ; preds = %2, %17
%7 = phi i32 [ %19, %17 ], [ 0, %2 ]
%8 = tail call signext i8 (...) @getch()
%9 = sext i32 %7 to i64
%10 = getelementptr inbounds i8, i8* %0, i64 %9
store i8 %8, i8* %10
switch i8 %8, label %13 [
i8 27, label %11
i8 10, label %15
]
11: ; preds = %6
%12 = add nsw i32 %7, -1
br label %17
13: ; preds = %6
%14 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8 signext %8)
br label %17
15: ; preds = %6
%16 = getelementptr inbounds i8, i8* %0, i64 %9
store i8 0, i8* %16
br label %21
17: ; preds = %11, %13
%18 = phi i32 [ %12, %11 ], [ %7, %13 ]
%19 = add nsw i32 %18, 1
%20 = icmp slt i32 %19, %4
br i1 %20, label %6, label %21
21: ; preds = %17, %2, %15
ret void
}