#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 */
typedef int /*<<< orphan*/ buffer;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fileno(int /*<<< orphan*/ *);
scalar_t__ isatty(int /*<<< orphan*/);
int strlen(char *);
int /*<<< orphan*/ tl1_parse_line(char *);
int /*<<< orphan*/ tl1_rl_readline(int /*<<< orphan*/ *);
int tl1parsestream(FILE *tl1stream) {
  char buffer[256];
  if (isatty(fileno(tl1stream))) {
    tl1_rl_readline(tl1stream);
  } else {
    while (fgets(buffer, sizeof(buffer), tl1stream) != NULL) {
      int len = strlen(buffer);
      if (buffer[len - 1] == '\n') {
        buffer[len - 1] = '\0';
      }
      tl1_parse_line(buffer);
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<tl1parsestream>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1070 <fileno@plt>
mov    %eax,%edi
call   1040 <isatty@plt>
cmp    $0x0,%rax
je     1197 <tl1parsestream+0x37>
mov    -0x8(%rbp),%rdi
call   1030 <tl1_rl_readline@plt>
jmp    1212 <tl1parsestream+0xb2>
jmp    119c <tl1parsestream+0x3c>
lea    -0x110(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    $0x100,%esi
call   1060 <fgets@plt>
cmp    $0x0,%rax
je     120d <tl1parsestream+0xad>
lea    -0x110(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x114(%rbp)
mov    -0x114(%rbp),%eax
sub    $0x1,%eax
cltq
movsbl -0x110(%rbp,%rax,1),%eax
ff
cmp    $0xa,%eax
jne    11fc <tl1parsestream+0x9c>
mov    -0x114(%rbp),%eax
sub    $0x1,%eax
cltq
movb   $0x0,-0x110(%rbp,%rax,1)
lea    -0x110(%rbp),%rdi
call   1080 <tl1_parse_line@plt>
jmp    119c <tl1parsestream+0x3c>
jmp    1212 <tl1parsestream+0xb2>
xor    %eax,%eax
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tl1parsestream>:
push   %r14
push   %rbx
sub    $0x108,%rsp
mov    %rdi,%r14
call   1070 <fileno@plt>
mov    %eax,%edi
call   1040 <isatty@plt>
test   %rax,%rax
je     1193 <tl1parsestream+0x33>
mov    %r14,%rdi
call   1030 <tl1_rl_readline@plt>
xor    %eax,%eax
add    $0x108,%rsp
pop    %rbx
pop    %r14
ret
mov    %rsp,%rbx
jmp    11a8 <tl1parsestream+0x48>
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1080 <tl1_parse_line@plt>
mov    %rbx,%rdi
mov    $0x100,%esi
mov    %r14,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     1186 <tl1parsestream+0x26>
mov    %rbx,%rdi
call   1050 <strlen@plt>
cltq
cmpb   $0xa,-0x1(%rax,%rbx,1)
jne    11a0 <tl1parsestream+0x40>
movb   $0x0,-0x1(%rsp,%rax,1)
jmp    11a0 <tl1parsestream+0x40>

LLVM IR (-O0):
define i32 @tl1parsestream(i32* %0) {
%2 = alloca i32*
%3 = alloca [256 x i8]
%4 = alloca i32
store i32* %0, i32** %2
%5 = load i32*, i32** %2
%6 = call i32 @fileno(i32* %5)
%7 = call i64 @isatty(i32 %6)
%8 = icmp ne i64 %7, 0
br i1 %8, label %9, label %12
9: ; preds = %1
%10 = load i32*, i32** %2
%11 = call i32 @tl1_rl_readline(i32* %10)
br label %37
12: ; preds = %1
br label %13
13: ; preds = %33, %12
%14 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%15 = load i32*, i32** %2
%16 = call i32* @fgets(i8* %14, i32 256, i32* %15)
%17 = icmp ne i32* %16, null
br i1 %17, label %18, label %36
18: ; preds = %13
%19 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%20 = call i32 @strlen(i8* %19)
store i32 %20, i32* %4
%21 = load i32, i32* %4
%22 = sub nsw i32 %21, 1
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 %23
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
%27 = icmp eq i32 %26, 10
br i1 %27, label %28, label %33
28: ; preds = %18
%29 = load i32, i32* %4
%30 = sub nsw i32 %29, 1
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 %31
store i8 0, i8* %32
br label %33
33: ; preds = %28, %18
%34 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%35 = call i32 @tl1_parse_line(i8* %34)
br label %13
36: ; preds = %13
br label %37
37: ; preds = %36, %9
ret i32 0
}

LLVM IR (-O2):
define i32 @tl1parsestream(i32* %0) {
%2 = alloca [256 x i8]
%3 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%4 = tail call i32 @fileno(i32* %0)
%5 = tail call i64 @isatty(i32 %4)
%6 = icmp eq i64 %5, 0
br i1 %6, label %7, label %10
7: ; preds = %1
%8 = call i32* @fgets(i8* %3, i32 256, i32* %0)
%9 = icmp eq i32* %8, null
br i1 %9, label %24, label %12
10: ; preds = %1
%11 = tail call i32 @tl1_rl_readline(i32* %0)
br label %24
12: ; preds = %7, %20
%13 = call i32 @strlen(i8* %3)
%14 = add nsw i32 %13, -1
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 %15
%17 = load i8, i8* %16
%18 = icmp eq i8 %17, 10
br i1 %18, label %19, label %20
19: ; preds = %12
store i8 0, i8* %16
br label %20
20: ; preds = %19, %12
%21 = call i32 @tl1_parse_line(i8* %3)
%22 = call i32* @fgets(i8* %3, i32 256, i32* %0)
%23 = icmp eq i32* %22, null
br i1 %23, label %24, label %12
24: ; preds = %20, %7, %10
ret i32 0
}