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

/* Variables and functions */
int /*<<< orphan*/ feof(int /*<<< orphan*/);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ *fmemopen(char *, int /*<<< orphan*/, char *);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ strnlen(char *, int);
int /*<<< orphan*/ write_grammar(int /*<<< orphan*/ *, int /*<<< orphan*/);
int main(int argc, char **argv) {
  char buf[(1 << 20)];
  char *cur = buf;
  while (!feof(stdin) && cur - buf < sizeof(buf) &&
         fgets(cur, sizeof(buf) - (cur - buf) - 1, stdin) != NULL)
    cur += strnlen(cur, sizeof(buf) - (cur - buf));
  FILE *grammar = fmemopen(buf, strlen(buf), "r");
  write_grammar(grammar, stdout);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x100030,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x100010(%rbp),%rax
mov    %rax,-0x100018(%rbp)
mov    0x2e5a(%rip),%rax
mov    (%rax),%edi
call   1080 <feof@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x100021(%rbp)
jne    120f <main+0xaf>
mov    -0x100018(%rbp),%rcx
lea    -0x100010(%rbp),%rax
sub    %rax,%rcx
xor    %eax,%eax
cmp    $0x100000,%rcx
mov    %al,-0x100021(%rbp)
jae    120f <main+0xaf>
mov    -0x100018(%rbp),%rdi
mov    -0x100018(%rbp),%rcx
lea    -0x100010(%rbp),%rax
sub    %rax,%rcx
mov    $0x100000,%eax
sub    %rcx,%rax
sub    $0x1,%rax
mov    %eax,%esi
mov    0x2ded(%rip),%rax
mov    (%rax),%edx
call   1070 <fgets@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x100021(%rbp)
mov    -0x100021(%rbp),%al
test   $0x1,%al
jne    1222 <main+0xc2>
jmp    1264 <main+0x104>
mov    -0x100018(%rbp),%rdi
mov    -0x100018(%rbp),%rcx
lea    -0x100010(%rbp),%rax
sub    %rax,%rcx
mov    $0x100000,%eax
sub    %rcx,%rax
mov    %eax,%esi
call   1060 <strnlen@plt>
mov    %eax,%ecx
mov    -0x100018(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x100018(%rbp)
jmp    1187 <main+0x27>
lea    -0x100010(%rbp),%rax
mov    %rax,-0x100030(%rbp)
lea    -0x100010(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x100030(%rbp),%rdi
mov    %eax,%esi
lea    0xd72(%rip),%rdx
call   1040 <fmemopen@plt>
mov    %rax,-0x100020(%rbp)
mov    -0x100020(%rbp),%rdi
mov    0x2d30(%rip),%rax
mov    (%rax),%esi
call   1030 <write_grammar@plt>
xor    %eax,%eax
add    $0x100030,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x100008,%rsp
mov    0x2e73(%rip),%r14
mov    (%r14),%edi
call   1080 <feof@plt>
test   %eax,%eax
je     11bf <main+0x5f>
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1050 <strlen@plt>
lea    0xe6d(%rip),%rdx
mov    %rbx,%rdi
mov    %eax,%esi
call   1040 <fmemopen@plt>
mov    0x2e34(%rip),%rcx
mov    (%rcx),%esi
mov    %rax,%rdi
call   1030 <write_grammar@plt>
xor    %eax,%eax
add    $0x100008,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
mov    %rsp,%r15
mov    %r15,%r12
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r12,%rbx
sub    %r15,%rbx
cmp    $0xfffff,%rbx
ja     1181 <main+0x21>
mov    $0xfffff,%esi
sub    %ebx,%esi
mov    (%r14),%edx
mov    %r12,%rdi
call   1070 <fgets@plt>
test   %rax,%rax
je     1181 <main+0x21>
mov    $0x100000,%esi
sub    %ebx,%esi
mov    %r12,%rdi
call   1060 <strnlen@plt>
cltq
add    %rax,%r12
mov    (%r14),%edi
call   1080 <feof@plt>
test   %eax,%eax
je     11d0 <main+0x70>
jmp    1181 <main+0x21>

LLVM IR (-O0):
@stdin = global i32 0
@.str = [2 x i8] c"r\00"
@stdout = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [1048576 x i8]
%7 = alloca i8*
%8 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = getelementptr inbounds [1048576 x i8], [1048576 x i8]* %6, i64 0, i64 0
store i8* %9, i8** %7
br label %10
10: ; preds = %36, %2
%11 = load i32, i32* @stdin
%12 = call i32 @feof(i32 %11)
%13 = icmp ne i32 %12, 0
br i1 %13, label %34, label %14
14: ; preds = %10
%15 = load i8*, i8** %7
%16 = getelementptr inbounds [1048576 x i8], [1048576 x i8]* %6, i64 0, i64 0
%17 = ptrtoint i8* %15 to i64
%18 = ptrtoint i8* %16 to i64
%19 = sub i64 %17, %18
%20 = icmp ult i64 %19, 1048576
br i1 %20, label %21, label %34
21: ; preds = %14
%22 = load i8*, i8** %7
%23 = load i8*, i8** %7
%24 = getelementptr inbounds [1048576 x i8], [1048576 x i8]* %6, i64 0, i64 0
%25 = ptrtoint i8* %23 to i64
%26 = ptrtoint i8* %24 to i64
%27 = sub i64 %25, %26
%28 = sub i64 1048576, %27
%29 = sub i64 %28, 1
%30 = trunc i64 %29 to i32
%31 = load i32, i32* @stdin
%32 = call i32* @fgets(i8* %22, i32 %30, i32 %31)
%33 = icmp ne i32* %32, null
br label %34
34: ; preds = %21, %14, %10
%35 = phi i1 [ false, %14 ], [ false, %10 ], [ %33, %21 ]
br i1 %35, label %36, label %49
36: ; preds = %34
%37 = load i8*, i8** %7
%38 = load i8*, i8** %7
%39 = getelementptr inbounds [1048576 x i8], [1048576 x i8]* %6, i64 0, i64 0
%40 = ptrtoint i8* %38 to i64
%41 = ptrtoint i8* %39 to i64
%42 = sub i64 %40, %41
%43 = sub i64 1048576, %42
%44 = trunc i64 %43 to i32
%45 = call i32 @strnlen(i8* %37, i32 %44)
%46 = load i8*, i8** %7
%47 = sext i32 %45 to i64
%48 = getelementptr inbounds i8, i8* %46, i64 %47
store i8* %48, i8** %7
br label %10
49: ; preds = %34
%50 = getelementptr inbounds [1048576 x i8], [1048576 x i8]* %6, i64 0, i64 0
%51 = getelementptr inbounds [1048576 x i8], [1048576 x i8]* %6, i64 0, i64 0
%52 = call i32 @strlen(i8* %51)
%53 = call i32* @fmemopen(i8* %50, i32 %52, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %53, i32** %8
%54 = load i32*, i32** %8
%55 = load i32, i32* @stdout
%56 = call i32 @write_grammar(i32* %54, i32 %55)
ret i32 0
}

LLVM IR (-O2):
@stdin = global i32 0
@.str = [2 x i8] c"r\00"
@stdout = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [1048576 x i8]
%4 = getelementptr inbounds [1048576 x i8], [1048576 x i8]* %3, i64 0, i64 0
%5 = load i32, i32* @stdin
%6 = call i32 @feof(i32 %5)
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %29
8: ; preds = %2
%9 = ptrtoint [1048576 x i8]* %3 to i64
br label %10
10: ; preds = %8, %21
%11 = phi i8* [ %4, %8 ], [ %25, %21 ]
%12 = ptrtoint i8* %11 to i64
%13 = sub i64 %12, %9
%14 = icmp ult i64 %13, 1048576
br i1 %14, label %15, label %29
15: ; preds = %10
%16 = trunc i64 %13 to i32
%17 = sub nuw nsw i32 1048575, %16
%18 = load i32, i32* @stdin
%19 = call i32* @fgets(i8* %11, i32 %17, i32 %18)
%20 = icmp eq i32* %19, null
br i1 %20, label %29, label %21
21: ; preds = %15
%22 = sub nuw nsw i32 1048576, %16
%23 = call i32 @strnlen(i8* %11, i32 %22)
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8, i8* %11, i64 %24
%26 = load i32, i32* @stdin
%27 = call i32 @feof(i32 %26)
%28 = icmp eq i32 %27, 0
br i1 %28, label %10, label %29
29: ; preds = %15, %10, %21, %2
%30 = call i32 @strlen(i8* %4)
%31 = call i32* @fmemopen(i8* %4, i32 %30, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%32 = load i32, i32* @stdout
%33 = call i32 @write_grammar(i32* %31, i32 %32)
ret i32 0
}