#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*/ printf(char *, char);
void nhap_xau(char str[]) {
  int i = 0;
  do {
    str[i] = getch();
    printf("%c", str[i]);
    i++;
  } while (str[i--] != '\t' || str[i--] != 13);
  str[i - 1] = '\0';
}


x86 assembly (clang, -O0):
<nhap_xau>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    $0x0,%al
call   1040 <getch@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
lea    0xeaa(%rip),%rdi
movsbl (%rax,%rcx,1),%esi
call   1030 <printf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
mov    %ecx,%edx
add    $0xffffffff,%edx
mov    %edx,-0xc(%rbp)
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%ecx
mov    $0x1,%al
cmp    $0x9,%ecx
mov    %al,-0xd(%rbp)
jne    11ab <nhap_xau+0x8b>
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
mov    %ecx,%edx
add    $0xffffffff,%edx
mov    %edx,-0xc(%rbp)
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xd,%eax
setne  %al
mov    %al,-0xd(%rbp)
mov    -0xd(%rbp),%al
test   $0x1,%al
jne    1133 <nhap_xau+0x13>
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<nhap_xau>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r15
lea    0xed1(%rip),%r14
xor    %eax,%eax
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %rax,%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
xor    %eax,%eax
call   1040 <getch@plt>
mov    %al,(%r15,%rbx,1)
movsbl %al,%esi
mov    %r14,%rdi
call   1030 <printf@plt>
cmpb   $0x9,0x1(%r15,%rbx,1)
jne    1150 <nhap_xau+0x30>
lea    -0x1(%rbx),%rax
cmpb   $0xd,(%r15,%rbx,1)
jne    1140 <nhap_xau+0x20>
add    $0xfffffffe,%ebx
movslq %ebx,%rax
movb   $0x0,(%r15,%rax,1)
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%c\00"
define void @nhap_xau(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
store i8* %0, i8** %2
store i32 0, i32* %3
br label %4
4: ; preds = %36, %1
%5 = call signext i8 (...) @getch()
%6 = load i8*, i8** %2
%7 = load i32, i32* %3
%8 = sext i32 %7 to i64
%9 = getelementptr inbounds i8, i8* %6, i64 %8
store i8 %5, i8* %9
%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 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8 signext %14)
%16 = load i32, i32* %3
%17 = add nsw i32 %16, 1
store i32 %17, i32* %3
br label %18
18: ; preds = %4
%19 = load i8*, i8** %2
%20 = load i32, i32* %3
%21 = add nsw i32 %20, -1
store i32 %21, i32* %3
%22 = sext i32 %20 to i64
%23 = getelementptr inbounds i8, i8* %19, i64 %22
%24 = load i8, i8* %23
%25 = sext i8 %24 to i32
%26 = icmp ne i32 %25, 9
br i1 %26, label %36, label %27
27: ; preds = %18
%28 = load i8*, i8** %2
%29 = load i32, i32* %3
%30 = add nsw i32 %29, -1
store i32 %30, i32* %3
%31 = sext i32 %29 to i64
%32 = getelementptr inbounds i8, i8* %28, i64 %31
%33 = load i8, i8* %32
%34 = sext i8 %33 to i32
%35 = icmp ne i32 %34, 13
br label %36
36: ; preds = %27, %18
%37 = phi i1 [ true, %18 ], [ %35, %27 ]
br i1 %37, label %4, label %38
38: ; preds = %36
%39 = load i8*, i8** %2
%40 = load i32, i32* %3
%41 = sub nsw i32 %40, 1
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds i8, i8* %39, i64 %42
store i8 0, i8* %43
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"%c\00"
define void @nhap_xau(i8* nocapture %0) {
br label %2
2: ; preds = %12, %1
%3 = phi i64 [ %13, %12 ], [ 0, %1 ]
%4 = getelementptr inbounds i8, i8* %0, i64 %3
%5 = add nsw i64 %3, 1
%6 = getelementptr inbounds i8, i8* %0, i64 %5
br label %7
7: ; preds = %2, %7
%8 = tail call signext i8 (...) @getch()
store i8 %8, i8* %4
%9 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8 signext %8)
%10 = load i8, i8* %6
%11 = icmp eq i8 %10, 9
br i1 %11, label %12, label %7
12: ; preds = %7
%13 = add i64 %3, -1
%14 = load i8, i8* %4
%15 = icmp eq i8 %14, 13
br i1 %15, label %16, label %2
16: ; preds = %12
%17 = shl i64 %3, 32
%18 = add i64 %17, -8589934592
%19 = ashr exact i64 %18, 32
%20 = getelementptr inbounds i8, i8* %0, i64 %19
store i8 0, i8* %20
ret void
}