#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 getchar();
void CmdGetLineNoEcho(char *s) {
  int i = 0;
  int c = 0;
  for (;;) {
    c = getchar();
    switch (c) {
    case ('M' & 0x1f):
    case ('J' & 0x1f):
      s[i] = '\0';
      return;
    default:
      s[i] = c;
      i++;
      break;
    }
  }
}


x86 assembly (clang, -O0):
<CmdGetLineNoEcho>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
xor    %eax,%eax
call   1030 <getchar@plt>
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x14(%rbp)
sub    $0xa,%eax
je     1159 <CmdGetLineNoEcho+0x49>
jmp    1148 <CmdGetLineNoEcho+0x38>
mov    -0x14(%rbp),%eax
sub    $0xd,%eax
jne    116b <CmdGetLineNoEcho+0x5b>
jmp    1159 <CmdGetLineNoEcho+0x49>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
add    $0x20,%rsp
pop    %rbp
ret
mov    -0x10(%rbp),%eax
mov    %al,%dl
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    112a <CmdGetLineNoEcho+0x1a>

x86 assembly (clang, -O2):
<CmdGetLineNoEcho>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
xor    %ebx,%ebx
nopl   0x0(%rax)
xor    %eax,%eax
call   1030 <getchar@plt>
cmp    $0xd,%eax
je     113b <CmdGetLineNoEcho+0x2b>
cmp    $0xa,%eax
je     113b <CmdGetLineNoEcho+0x2b>
mov    %al,(%r14,%rbx,1)
add    $0x1,%rbx
jmp    1120 <CmdGetLineNoEcho+0x10>
mov    %ebx,%eax
movb   $0x0,(%r14,%rax,1)
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define void @CmdGetLineNoEcho(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
store i8* %0, i8** %2
store i32 0, i32* %3
store i32 0, i32* %4
br label %5
5: ; preds = %22, %1
%6 = call i32 (...) @getchar()
store i32 %6, i32* %4
%7 = load i32, i32* %4
switch i32 %7, label %13 [
i32 13, label %8
i32 10, label %8
]
8: ; preds = %5, %5
%9 = load i8*, i8** %2
%10 = load i32, i32* %3
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds i8, i8* %9, i64 %11
store i8 0, i8* %12
ret void
13: ; preds = %5
%14 = load i32, i32* %4
%15 = trunc i32 %14 to i8
%16 = load i8*, i8** %2
%17 = load i32, i32* %3
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8, i8* %16, i64 %18
store i8 %15, i8* %19
%20 = load i32, i32* %3
%21 = add nsw i32 %20, 1
store i32 %21, i32* %3
br label %22
22: ; preds = %13
br label %5
}

LLVM IR (-O2):
define void @CmdGetLineNoEcho(i8* nocapture writeonly %0) {
br label %2
2: ; preds = %8, %1
%3 = phi i64 [ %11, %8 ], [ 0, %1 ]
%4 = tail call i32 (...) @getchar()
switch i32 %4, label %8 [
i32 13, label %5
i32 10, label %5
]
5: ; preds = %2, %2
%6 = and i64 %3, 4294967295
%7 = getelementptr inbounds i8, i8* %0, i64 %6
store i8 0, i8* %7
ret void
8: ; preds = %2
%9 = trunc i32 %4 to i8
%10 = getelementptr inbounds i8, i8* %0, i64 %3
store i8 %9, i8* %10
%11 = add nuw i64 %3, 1
br label %2
}