#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, char *, int);
int check_map(int fd) {
  char buf[1000001];
  int ret;
  ret = 0;
  if (fd == -1)
    return (0);
  if ((ret = read(fd, buf, 1000000)))
    buf[ret] = '\0';
  if (buf[ret - 1] != '\n')
    return (0);
  if (buf[ret - 1] == '\n' && buf[ret - 2] == '\n')
    return (0);
  return (1);
}


x86 assembly (clang, -O0):
<check_map>:
push   %rbp
mov    %rsp,%rbp
sub    $0xf4260,%rsp
mov    %edi,-0x8(%rbp)
movl   $0x0,-0xf4254(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
jne    113e <check_map+0x2e>
movl   $0x0,-0x4(%rbp)
jmp    11e3 <check_map+0xd3>
mov    -0x8(%rbp),%edi
lea    -0xf4250(%rbp),%rsi
mov    $0xf4240,%edx
call   1030 <read@plt>
mov    %eax,-0xf4254(%rbp)
cmp    $0x0,%eax
je     1170 <check_map+0x60>
movslq -0xf4254(%rbp),%rax
movb   $0x0,-0xf4250(%rbp,%rax,1)
mov    -0xf4254(%rbp),%eax
sub    $0x1,%eax
cltq
movsbl -0xf4250(%rbp,%rax,1),%eax
ff
cmp    $0xa,%eax
je     1198 <check_map+0x88>
movl   $0x0,-0x4(%rbp)
jmp    11e3 <check_map+0xd3>
mov    -0xf4254(%rbp),%eax
sub    $0x1,%eax
cltq
movsbl -0xf4250(%rbp,%rax,1),%eax
ff
cmp    $0xa,%eax
jne    11dc <check_map+0xcc>
mov    -0xf4254(%rbp),%eax
sub    $0x2,%eax
cltq
movsbl -0xf4250(%rbp,%rax,1),%eax
ff
cmp    $0xa,%eax
jne    11dc <check_map+0xcc>
movl   $0x0,-0x4(%rbp)
jmp    11e3 <check_map+0xd3>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xf4260,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_map>:
push   %r14
push   %rbx
sub    $0xf4248,%rsp
xor    %ebx,%ebx
cmp    $0xffffffff,%edi
je     114f <check_map+0x3f>
mov    %rsp,%r14
mov    %r14,%rsi
mov    $0xf4240,%edx
call   1030 <read@plt>
movslq %eax,%rcx
test   %eax,%eax
je     113c <check_map+0x2c>
movb   $0x0,(%rsp,%rcx,1)
cmpb   $0xa,-0x1(%rcx,%r14,1)
jne    114f <check_map+0x3f>
xor    %ebx,%ebx
cmpb   $0xa,-0x2(%rcx,%r14,1)
setne  %bl
mov    %ebx,%eax
add    $0xf4248,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
define i32 @check_map(i32 %0) {
%2 = alloca [1000001 x i8]
%3 = getelementptr inbounds [1000001 x i8], [1000001 x i8]* %2, i64 0, i64 0
%4 = icmp eq i32 %0, -1
br i1 %4, label %24, label %5
5: ; preds = %1
%6 = call i32 @read(i32 %0, i8* %3, i32 1000000)
%7 = icmp eq i32 %6, 0
br i1 %7, label %11, label %8
8: ; preds = %5
%9 = sext i32 %6 to i64
%10 = getelementptr inbounds [1000001 x i8], [1000001 x i8]* %2, i64 0, i64 %9
store i8 0, i8* %10
br label %11
11: ; preds = %8, %5
%12 = add nsw i32 %6, -1
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds [1000001 x i8], [1000001 x i8]* %2, i64 0, i64 %13
%15 = load i8, i8* %14
%16 = icmp eq i8 %15, 10
br i1 %16, label %17, label %24
17: ; preds = %11
%18 = add nsw i32 %6, -2
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds [1000001 x i8], [1000001 x i8]* %2, i64 0, i64 %19
%21 = load i8, i8* %20
%22 = icmp ne i8 %21, 10
%23 = zext i1 %22 to i32
br label %24
24: ; preds = %17, %11, %1
%25 = phi i32 [ 0, %1 ], [ 0, %11 ], [ %23, %17 ]
ret i32 %25
}