#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();
int /*<<< orphan*/ keybFlush();
int getStr(char *str, int maxlen) {
  int i = -1;
  do {
    i++;
    str[i] = getchar();
  } while (i < maxlen && str[i] != '\n');
  if (str[i] != '\n') {
    keybFlush();
  }
  str[i] = 0;
  return i;
}


x86 assembly (clang, -O0):
<getStr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0xffffffff,-0x10(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
mov    $0x0,%al
call   1040 <getchar@plt>
mov    %al,%dl
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x10(%rbp),%ecx
xor    %eax,%eax
cmp    -0xc(%rbp),%ecx
mov    %al,-0x11(%rbp)
jge    1179 <getStr+0x59>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xa,%eax
setne  %al
mov    %al,-0x11(%rbp)
mov    -0x11(%rbp),%al
test   $0x1,%al
jne    1136 <getStr+0x16>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xa,%eax
je     11a0 <getStr+0x80>
mov    $0x0,%al
call   1030 <keybFlush@plt>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getStr>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
movslq %esi,%r15
xor    %r12d,%r12d
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r12,%rbx
xor    %eax,%eax
call   1040 <getchar@plt>
mov    %al,(%r14,%r12,1)
add    $0x1,%r12
cmp    %r15,%rbx
jge    115b <getStr+0x3b>
cmp    $0xa,%al
jne    1140 <getStr+0x20>
cmp    $0xa,%al
je     1166 <getStr+0x46>
xor    %eax,%eax
call   1030 <keybFlush@plt>
lea    -0x1(%r12),%eax
movb   $0x0,-0x1(%r14,%r12,1)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @getStr(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
store i32 -1, i32* %5
br label %6
6: ; preds = %26, %2
%7 = load i32, i32* %5
%8 = add nsw i32 %7, 1
store i32 %8, i32* %5
%9 = call signext i8 (...) @getchar()
%10 = load i8*, i8** %3
%11 = load i32, i32* %5
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds i8, i8* %10, i64 %12
store i8 %9, i8* %13
br label %14
14: ; preds = %6
%15 = load i32, i32* %5
%16 = load i32, i32* %4
%17 = icmp slt i32 %15, %16
br i1 %17, label %18, label %26
18: ; preds = %14
%19 = load i8*, i8** %3
%20 = load i32, i32* %5
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i8, i8* %19, i64 %21
%23 = load i8, i8* %22
%24 = sext i8 %23 to i32
%25 = icmp ne i32 %24, 10
br label %26
26: ; preds = %18, %14
%27 = phi i1 [ false, %14 ], [ %25, %18 ]
br i1 %27, label %6, label %28
28: ; preds = %26
%29 = load i8*, i8** %3
%30 = load i32, i32* %5
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i8, i8* %29, i64 %31
%33 = load i8, i8* %32
%34 = sext i8 %33 to i32
%35 = icmp ne i32 %34, 10
br i1 %35, label %36, label %38
36: ; preds = %28
%37 = call i32 (...) @keybFlush()
br label %38
38: ; preds = %36, %28
%39 = load i8*, i8** %3
%40 = load i32, i32* %5
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds i8, i8* %39, i64 %41
store i8 0, i8* %42
%43 = load i32, i32* %5
ret i32 %43
}

LLVM IR (-O2):
define i32 @getStr(i8* nocapture %0, i32 %1) {
%3 = sext i32 %1 to i64
br label %4
4: ; preds = %4, %2
%5 = phi i64 [ %6, %4 ], [ -1, %2 ]
%6 = add nsw i64 %5, 1
%7 = tail call signext i8 (...) @getchar()
%8 = getelementptr inbounds i8, i8* %0, i64 %6
store i8 %7, i8* %8
%9 = icmp sge i64 %6, %3
%10 = icmp eq i8 %7, 10
%11 = or i1 %9, %10
br i1 %11, label %12, label %4
12: ; preds = %4
br i1 %10, label %15, label %13
13: ; preds = %12
%14 = tail call i32 (...) @keybFlush()
br label %15
15: ; preds = %13, %12
%16 = getelementptr inbounds i8, i8* %0, i64 %6
%17 = trunc i64 %6 to i32
store i8 0, i8* %16
ret i32 %17
}