#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 getchar();
void GetText(char *txt, unsigned int len) {
  unsigned int i = 0;
  char c = 0;
  while (c = getchar()) {
    if (c == '\n' || i > len - 1)
      return;
    txt[i++] = c;
  }
}


x86 assembly (clang, -O0):
<GetText>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
movb   $0x0,-0x11(%rbp)
mov    $0x0,%al
call   1030 <getchar@plt>
mov    %al,-0x11(%rbp)
cmp    $0x0,%al
je     117b <GetText+0x6b>
movsbl -0x11(%rbp),%eax
cmp    $0xa,%eax
je     115a <GetText+0x4a>
mov    -0x10(%rbp),%eax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jbe    115f <GetText+0x4f>
jmp    117b <GetText+0x6b>
mov    -0x11(%rbp),%dl
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x10(%rbp)
mov    %ecx,%ecx
mov    %dl,(%rax,%rcx,1)
jmp    112a <GetText+0x1a>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<GetText>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%ebx
mov    %rdi,%r14
add    $0xffffffff,%ebx
xor    %ebp,%ebp
xchg   %ax,%ax
xor    %eax,%eax
call   1030 <getchar@plt>
test   %al,%al
je     113e <GetText+0x2e>
cmp    $0xa,%al
je     113e <GetText+0x2e>
cmp    %ebx,%ebp
ja     113e <GetText+0x2e>
mov    %ebp,%ecx
add    $0x1,%ebp
mov    %al,(%r14,%rcx,1)
jmp    1120 <GetText+0x10>
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define void @GetText(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
store i8 0, i8* %6
br label %7
7: ; preds = %20, %2
%8 = call signext i8 (...) @getchar()
store i8 %8, i8* %6
%9 = icmp ne i8 %8, 0
br i1 %9, label %10, label %27
10: ; preds = %7
%11 = load i8, i8* %6
%12 = sext i8 %11 to i32
%13 = icmp eq i32 %12, 10
br i1 %13, label %19, label %14
14: ; preds = %10
%15 = load i32, i32* %5
%16 = load i32, i32* %4
%17 = sub i32 %16, 1
%18 = icmp ugt i32 %15, %17
br i1 %18, label %19, label %20
19: ; preds = %14, %10
br label %27
20: ; preds = %14
%21 = load i8, i8* %6
%22 = load i8*, i8** %3
%23 = load i32, i32* %5
%24 = add i32 %23, 1
store i32 %24, i32* %5
%25 = zext i32 %23 to i64
%26 = getelementptr inbounds i8, i8* %22, i64 %25
store i8 %21, i8* %26
br label %7
27: ; preds = %19, %7
ret void
}

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