#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 read(int /*<<< orphan*/, unsigned char *, int);
int /*<<< orphan*/ write(int, ...);
int main() {
  unsigned char c;
  while (read(0, &c, 1) == 1 && c != '\n')
    write(1, &c, 1);
  write(1, "\n", 1);
  return c != '\n';
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
xor    %edi,%edi
lea    -0x5(%rbp),%rsi
mov    $0x1,%edx
call   1040 <read@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x1,%ecx
mov    %al,-0x6(%rbp)
jne    115c <main+0x3c>
movzbl -0x5(%rbp),%eax
cmp    $0xa,%eax
setne  %al
mov    %al,-0x6(%rbp)
mov    -0x6(%rbp),%al
test   $0x1,%al
jne    116c <main+0x4c>
jmp    1183 <main+0x63>
mov    $0x1,%edx
lea    -0x5(%rbp),%rsi
mov    %edx,%edi
mov    $0x0,%al
call   1030 <write@plt>
jmp    112f <main+0xf>
mov    $0x1,%edx
lea    0xe71(%rip),%rsi
mov    %edx,%edi
mov    $0x0,%al
call   1030 <write@plt>
movzbl -0x5(%rbp),%eax
cmp    $0xa,%eax
setne  %al
and    $0x1,%al
movzbl %al,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
lea    0xf(%rsp),%rsi
xor    %edi,%edi
mov    $0x1,%edx
call   1040 <read@plt>
cmp    $0x1,%eax
jne    117f <main+0x5f>
cmpb   $0xa,0xf(%rsp)
je     117f <main+0x5f>
lea    0xf(%rsp),%rbx
nopw   0x0(%rax,%rax,1)
mov    $0x1,%edi
mov    %rbx,%rsi
mov    $0x1,%edx
xor    %eax,%eax
call   1030 <write@plt>
xor    %edi,%edi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1040 <read@plt>
cmp    $0x1,%eax
jne    117f <main+0x5f>
cmpb   $0xa,0xf(%rsp)
jne    1150 <main+0x30>
lea    0xe7a(%rip),%rsi
mov    $0x1,%edi
mov    $0x1,%edx
xor    %eax,%eax
call   1030 <write@plt>
xor    %eax,%eax
cmpb   $0xa,0xf(%rsp)
setne  %al
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [2 x i8] c"\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8
store i32 0, i32* %1
br label %3
3: ; preds = %12, %0
%4 = call i32 @read(i32 0, i8* %2, i32 1)
%5 = icmp eq i32 %4, 1
br i1 %5, label %6, label %10
6: ; preds = %3
%7 = load i8, i8* %2
%8 = zext i8 %7 to i32
%9 = icmp ne i32 %8, 10
br label %10
10: ; preds = %6, %3
%11 = phi i1 [ false, %3 ], [ %9, %6 ]
br i1 %11, label %12, label %14
12: ; preds = %10
%13 = call i32 (i32, ...) @write(i32 1, i8* %2, i32 1)
br label %3
14: ; preds = %10
%15 = call i32 (i32, ...) @write(i32 1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 1)
%16 = load i8, i8* %2
%17 = zext i8 %16 to i32
%18 = icmp ne i32 %17, 10
%19 = zext i1 %18 to i32
ret i32 %19
}

LLVM IR (-O2):
@.str = [2 x i8] c"\0A\00"
define i32 @main() {
%1 = alloca i8
%2 = call i32 @read(i32 0, i8* %1, i32 1)
%3 = icmp eq i32 %2, 1
%4 = load i8, i8* %1
%5 = icmp ne i8 %4, 10
%6 = select i1 %3, i1 %5, i1 false
br i1 %6, label %7, label %14
7: ; preds = %0, %7
%8 = call i32 (i32, ...) @write(i32 1, i8* %1, i32 1)
%9 = call i32 @read(i32 0, i8* %1, i32 1)
%10 = icmp eq i32 %9, 1
%11 = load i8, i8* %1
%12 = icmp ne i8 %11, 10
%13 = select i1 %10, i1 %12, i1 false
br i1 %13, label %7, label %14
14: ; preds = %7, %0
%15 = call i32 (i32, ...) @write(i32 1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 1)
%16 = load i8, i8* %1
%17 = icmp ne i8 %16, 10
%18 = zext i1 %17 to i32
ret i32 %18
}