#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*/ exit(int);
int /*<<< orphan*/ isatty(int /*<<< orphan*/);
int read(int /*<<< orphan*/, char *, int);
void getinp(char *p, int l) {
  char *ep = p + l - 1;
  int e;
  while ((e = read(0, p, 1)) == 1) {
    if (*p == '\n') {
      *p = 0;
      return;
    }
    if (p < ep)
      p++;
  }
  if (e || !isatty(0))
    exit(1);
  *p = 0;
  return;
}


x86 assembly (clang, -O0):
<getinp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
add    %rcx,%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rsi
xor    %edi,%edi
mov    $0x1,%edx
call   1040 <read@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x1,%eax
jne    11a9 <getinp+0x79>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0xa,%eax
jne    118a <getinp+0x5a>
mov    -0x8(%rbp),%rax
movb   $0x0,(%rax)
jmp    11d4 <getinp+0xa4>
mov    -0x8(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    11a4 <getinp+0x74>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    1152 <getinp+0x22>
cmpl   $0x0,-0x1c(%rbp)
jne    11c3 <getinp+0x93>
xor    %edi,%edi
call   1030 <isatty@plt>
cmp    $0x0,%eax
jne    11cd <getinp+0x9d>
mov    $0x1,%edi
call   1050 <exit@plt>
mov    -0x8(%rbp),%rax
movb   $0x0,(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getinp>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
movslq %esi,%rax
lea    (%rdi,%rax,1),%r14
add    $0xffffffffffffffff,%r14
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
xor    %edi,%edi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1040 <read@plt>
cmp    $0x1,%eax
jne    1172 <getinp+0x42>
cmpb   $0xa,(%rbx)
je     1181 <getinp+0x51>
cmp    %r14,%rbx
adc    $0x0,%rbx
jmp    1150 <getinp+0x20>
test   %eax,%eax
jne    118c <getinp+0x5c>
xor    %edi,%edi
call   1030 <isatty@plt>
test   %eax,%eax
je     118c <getinp+0x5c>
movb   $0x0,(%rbx)
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    $0x1,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
define void @getinp(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
%7 = load i8*, i8** %3
%8 = load i32, i32* %4
%9 = sext i32 %8 to i64
%10 = getelementptr inbounds i8, i8* %7, i64 %9
%11 = getelementptr inbounds i8, i8* %10, i64 -1
store i8* %11, i8** %5
br label %12
12: ; preds = %30, %2
%13 = load i8*, i8** %3
%14 = call i32 @read(i32 0, i8* %13, i32 1)
store i32 %14, i32* %6
%15 = icmp eq i32 %14, 1
br i1 %15, label %16, label %31
16: ; preds = %12
%17 = load i8*, i8** %3
%18 = load i8, i8* %17
%19 = sext i8 %18 to i32
%20 = icmp eq i32 %19, 10
br i1 %20, label %21, label %23
21: ; preds = %16
%22 = load i8*, i8** %3
store i8 0, i8* %22
br label %41
23: ; preds = %16
%24 = load i8*, i8** %3
%25 = load i8*, i8** %5
%26 = icmp ult i8* %24, %25
br i1 %26, label %27, label %30
27: ; preds = %23
%28 = load i8*, i8** %3
%29 = getelementptr inbounds i8, i8* %28, i32 1
store i8* %29, i8** %3
br label %30
30: ; preds = %27, %23
br label %12
31: ; preds = %12
%32 = load i32, i32* %6
%33 = icmp ne i32 %32, 0
br i1 %33, label %37, label %34
34: ; preds = %31
%35 = call i32 @isatty(i32 0)
%36 = icmp ne i32 %35, 0
br i1 %36, label %39, label %37
37: ; preds = %34, %31
%38 = call i32 @exit(i32 1)
unreachable
39: ; preds = %34
%40 = load i8*, i8** %3
store i8 0, i8* %40
br label %41
41: ; preds = %39, %21
ret void
}

LLVM IR (-O2):
define void @getinp(i8* %0, i32 %1) {
%3 = sext i32 %1 to i64
%4 = getelementptr inbounds i8, i8* %0, i64 %3
%5 = getelementptr inbounds i8, i8* %4, i64 -1
br label %6
6: ; preds = %12, %2
%7 = phi i8* [ %0, %2 ], [ %15, %12 ]
%8 = tail call i32 @read(i32 0, i8* %7, i32 1)
switch i32 %8, label %19 [
i32 1, label %9
i32 0, label %16
]
9: ; preds = %6
%10 = load i8, i8* %7
%11 = icmp eq i8 %10, 10
br i1 %11, label %21, label %12
12: ; preds = %9
%13 = icmp ult i8* %7, %5
%14 = zext i1 %13 to i64
%15 = getelementptr i8, i8* %7, i64 %14
br label %6
16: ; preds = %6
%17 = tail call i32 @isatty(i32 0)
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %6, %16
%20 = tail call i32 @exit(i32 1)
unreachable
21: ; preds = %9, %16
store i8 0, i8* %7
ret void
}