#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 /*<<< orphan*/ flush();
int readline(int);
int readstr(char *p, int t) {
  static int c;
  t *= 10;
  flush();
  while (((c = readline(t)) != 13) && (c != (-2))) {
    if (c != 10)
      *p++ = c;
  }
  *p = 0;
  return c;
}


x86 assembly (clang, -O0):
<readstr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
imul   $0xa,-0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    $0x0,%al
call   1030 <flush@plt>
mov    -0xc(%rbp),%edi
call   1040 <readline@plt>
mov    %eax,%ecx
mov    %ecx,0x2ee7(%rip)
xor    %eax,%eax
cmp    $0xd,%ecx
mov    %al,-0xd(%rbp)
je     1168 <readstr+0x48>
cmpl   $0xfffffffe,0x2ed2(%rip)
setne  %al
mov    %al,-0xd(%rbp)
mov    -0xd(%rbp),%al
test   $0x1,%al
jne    1178 <readstr+0x58>
jmp    11a3 <readstr+0x83>
cmpl   $0xa,0x2eb5(%rip)
je     119e <readstr+0x7e>
mov    0x2ea9(%rip),%eax
mov    %al,%cl
mov    -0x8(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x8(%rbp)
mov    %cl,(%rax)
jmp    113d <readstr+0x1d>
mov    -0x8(%rbp),%rax
movb   $0x0,(%rax)
mov    0x2e84(%rip),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readstr>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
add    %esi,%esi
lea    (%rsi,%rsi,4),%ebp
xor    %eax,%eax
call   1030 <flush@plt>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %ebp,%edi
call   1040 <readline@plt>
cmp    $0xa,%eax
je     1140 <readstr+0x20>
cmp    $0xfffffffe,%eax
je     115e <readstr+0x3e>
cmp    $0xd,%eax
je     115e <readstr+0x3e>
mov    %al,(%rbx)
add    $0x1,%rbx
jmp    1140 <readstr+0x20>
movb   $0x0,(%rbx)
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@readstr.c = internal global i32 0
define i32 @readstr(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
%5 = load i32, i32* %4
%6 = mul nsw i32 %5, 10
store i32 %6, i32* %4
%7 = call i32 (...) @flush()
br label %8
8: ; preds = %25, %2
%9 = load i32, i32* %4
%10 = call i32 @readline(i32 %9)
store i32 %10, i32* @readstr.c
%11 = icmp ne i32 %10, 13
br i1 %11, label %12, label %15
12: ; preds = %8
%13 = load i32, i32* @readstr.c
%14 = icmp ne i32 %13, -2
br label %15
15: ; preds = %12, %8
%16 = phi i1 [ false, %8 ], [ %14, %12 ]
br i1 %16, label %17, label %26
17: ; preds = %15
%18 = load i32, i32* @readstr.c
%19 = icmp ne i32 %18, 10
br i1 %19, label %20, label %25
20: ; preds = %17
%21 = load i32, i32* @readstr.c
%22 = trunc i32 %21 to i8
%23 = load i8*, i8** %3
%24 = getelementptr inbounds i8, i8* %23, i32 1
store i8* %24, i8** %3
store i8 %22, i8* %23
br label %25
25: ; preds = %20, %17
br label %8
26: ; preds = %15
%27 = load i8*, i8** %3
store i8 0, i8* %27
%28 = load i32, i32* @readstr.c
ret i32 %28
}

LLVM IR (-O2):
define i32 @readstr(i8* nocapture writeonly %0, i32 %1) {
%3 = mul nsw i32 %1, 10
%4 = tail call i32 (...) @flush()
br label %5
5: ; preds = %9, %2
%6 = phi i8* [ %11, %9 ], [ %0, %2 ]
br label %7
7: ; preds = %5, %7
%8 = tail call i32 @readline(i32 %3)
switch i32 %8, label %9 [
i32 -2, label %12
i32 13, label %12
i32 10, label %7
]
9: ; preds = %7
%10 = trunc i32 %8 to i8
%11 = getelementptr inbounds i8, i8* %6, i64 1
store i8 %10, i8* %6
br label %5
12: ; preds = %7, %7
store i8 0, i8* %6
ret i32 %8
}