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

/* Variables and functions */
scalar_t__ do_line(char *, size_t);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int, ...);
scalar_t__ memchr(char *, char, size_t);
char *memmove(char *, char *, size_t);
scalar_t__ read(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ stdout;
int main(int argc, char *argv[]) {
  char buffer[4096];
  char *s;
  size_t length;
  int line;
  s = buffer;
  length = 0;
  line = 0;
  do {
    char *nl = (char *)memchr(s, '\n', length);
    if (nl == NULL) {
      ssize_t len1;
      if (length == sizeof(buffer)) {
        fprintf(stdout, "Line %d too long: more than %zu characters\n",
                line + 1, sizeof(buffer));
        return -1;
      }
      s = memmove(buffer, s, length);
      len1 = read(0, s + length, sizeof(buffer) - length);
      length += len1;
      if (len1 == 0)
        break;
      continue;
    }
    line++;
    if (do_line(s, nl - s)) {
      fprintf(stdout, "Line %d error\n", line);
      return -1;
    }
    length -= nl - s + 1;
    s = nl + 1;
  } while (1);
  if (do_line(s, length)) {
    fprintf(stdout, "Line %d error\n", line);
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1040,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x1010(%rbp),%rax
mov    %rax,-0x1018(%rbp)
movq   $0x0,-0x1020(%rbp)
movl   $0x0,-0x1024(%rbp)
mov    -0x1018(%rbp),%rdi
mov    -0x1020(%rbp),%rdx
mov    $0xa,%esi
call   1030 <memchr@plt>
mov    %rax,-0x1030(%rbp)
cmpq   $0x0,-0x1030(%rbp)
jne    1273 <main+0x123>
cmpq   $0x1000,-0x1020(%rbp)
jne    11fb <main+0xab>
mov    0x2e0f(%rip),%rax
mov    (%rax),%edi
mov    -0x1024(%rbp),%edx
add    $0x1,%edx
lea    0xe1d(%rip),%rsi
mov    $0x1000,%ecx
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1366 <main+0x216>
lea    -0x1010(%rbp),%rdi
mov    -0x1018(%rbp),%rsi
mov    -0x1020(%rbp),%rdx
call   1060 <memmove@plt>
mov    %rax,-0x1018(%rbp)
mov    -0x1018(%rbp),%rsi
add    -0x1020(%rbp),%rsi
mov    $0x1000,%eax
sub    -0x1020(%rbp),%rax
mov    %eax,%edx
xor    %edi,%edi
call   1040 <read@plt>
mov    %rax,-0x1038(%rbp)
mov    -0x1038(%rbp),%rax
add    -0x1020(%rbp),%rax
mov    %rax,-0x1020(%rbp)
cmpq   $0x0,-0x1038(%rbp)
jne    126e <main+0x11e>
jmp    1319 <main+0x1c9>
jmp    130a <main+0x1ba>
mov    -0x1024(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1024(%rbp)
mov    -0x1018(%rbp),%rdi
mov    -0x1030(%rbp),%rsi
mov    -0x1018(%rbp),%rax
sub    %rax,%rsi
call   1070 <do_line@plt>
cmp    $0x0,%rax
je     12d2 <main+0x182>
mov    0x2d30(%rip),%rax
mov    (%rax),%edi
mov    -0x1024(%rbp),%edx
lea    0xd6d(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1366 <main+0x216>
mov    -0x1030(%rbp),%rcx
mov    -0x1018(%rbp),%rax
sub    %rax,%rcx
add    $0x1,%rcx
mov    -0x1020(%rbp),%rax
sub    %rcx,%rax
mov    %rax,-0x1020(%rbp)
mov    -0x1030(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x1018(%rbp)
mov    $0x1,%al
test   $0x1,%al
jne    118c <main+0x3c>
jmp    1319 <main+0x1c9>
mov    -0x1018(%rbp),%rdi
mov    -0x1020(%rbp),%rsi
call   1070 <do_line@plt>
cmp    $0x0,%rax
je     135f <main+0x20f>
mov    0x2ca3(%rip),%rax
mov    (%rax),%edi
mov    -0x1024(%rbp),%edx
lea    0xce0(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1366 <main+0x216>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1040,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1008,%rsp
mov    %rsp,%r15
xor    %ebx,%ebx
xor    %r14d,%r14d
mov    %r15,%r12
nopl   0x0(%rax)
mov    %r12,%rdi
mov    $0xa,%esi
mov    %rbx,%rdx
call   1030 <memchr@plt>
test   %rax,%rax
jne    11bb <main+0x6b>
cmp    $0x1000,%rbx
je     11e7 <main+0x97>
mov    %r15,%rdi
mov    %r12,%rsi
mov    %rbx,%rdx
call   1060 <memmove@plt>
lea    (%rsp,%rbx,1),%rsi
mov    $0x1000,%edx
sub    %ebx,%edx
xor    %edi,%edi
call   1040 <read@plt>
add    %rax,%rbx
mov    %r15,%r12
test   %rax,%rax
jne    1170 <main+0x20>
jmp    120c <main+0xbc>
mov    %rax,%rbp
add    $0x1,%r14d
mov    %rax,%r13
sub    %r12,%r13
mov    %r12,%rdi
mov    %r13,%rsi
call   1070 <do_line@plt>
test   %rax,%rax
jne    121c <main+0xcc>
not    %r13
add    %r13,%rbx
add    $0x1,%rbp
mov    %rbp,%r12
jmp    1170 <main+0x20>
mov    0x2df2(%rip),%rax
mov    (%rax),%edi
add    $0x1,%r14d
lea    0xe05(%rip),%rsi
mov    $0x1000,%ecx
mov    %r14d,%edx
xor    %eax,%eax
call   1050 <fprintf@plt>
jmp    1236 <main+0xe6>
mov    %rsp,%rdi
mov    %rbx,%rsi
call   1070 <do_line@plt>
test   %rax,%rax
je     124d <main+0xfd>
mov    0x2dbd(%rip),%rax
mov    (%rax),%edi
lea    0xe00(%rip),%rsi
mov    %r14d,%edx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0xffffffff,%eax
add    $0x1008,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %eax,%eax
jmp    123b <main+0xeb>

LLVM IR (-O0):
@stdout = global i32 0
@.str = [44 x i8] c"Line %d too long: more than %zu characters\0A\00"
@.str.1 = [15 x i8] c"Line %d error\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [4096 x i8]
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
store i8* %12, i8** %7
store i64 0, i64* %8
store i32 0, i32* %9
br label %13
13: ; preds = %73, %2
%14 = load i8*, i8** %7
%15 = load i64, i64* %8
%16 = call i64 @memchr(i8* %14, i8 signext 10, i64 %15)
%17 = inttoptr i64 %16 to i8*
store i8* %17, i8** %10
%18 = load i8*, i8** %10
%19 = icmp eq i8* %18, null
br i1 %19, label %20, label %47
20: ; preds = %13
%21 = load i64, i64* %8
%22 = icmp eq i64 %21, 4096
br i1 %22, label %23, label %28
23: ; preds = %20
%24 = load i32, i32* @stdout
%25 = load i32, i32* %9
%26 = add nsw i32 %25, 1
%27 = call i32 (i32, i8*, i32, ...) @fprintf(i32 %24, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0), i32 %26, i64 4096)
store i32 -1, i32* %3
br label %84
28: ; preds = %20
%29 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
%30 = load i8*, i8** %7
%31 = load i64, i64* %8
%32 = call i8* @memmove(i8* %29, i8* %30, i64 %31)
store i8* %32, i8** %7
%33 = load i8*, i8** %7
%34 = load i64, i64* %8
%35 = getelementptr inbounds i8, i8* %33, i64 %34
%36 = load i64, i64* %8
%37 = sub i64 4096, %36
%38 = trunc i64 %37 to i32
%39 = call i64 @read(i32 0, i8* %35, i32 %38)
store i64 %39, i64* %11
%40 = load i64, i64* %11
%41 = load i64, i64* %8
%42 = add i64 %41, %40
store i64 %42, i64* %8
%43 = load i64, i64* %11
%44 = icmp eq i64 %43, 0
br i1 %44, label %45, label %46
45: ; preds = %28
br label %74
46: ; preds = %28
br label %73
47: ; preds = %13
%48 = load i32, i32* %9
%49 = add nsw i32 %48, 1
store i32 %49, i32* %9
%50 = load i8*, i8** %7
%51 = load i8*, i8** %10
%52 = load i8*, i8** %7
%53 = ptrtoint i8* %51 to i64
%54 = ptrtoint i8* %52 to i64
%55 = sub i64 %53, %54
%56 = call i64 @do_line(i8* %50, i64 %55)
%57 = icmp ne i64 %56, 0
br i1 %57, label %58, label %62
58: ; preds = %47
%59 = load i32, i32* @stdout
%60 = load i32, i32* %9
%61 = call i32 (i32, i8*, i32, ...) @fprintf(i32 %59, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32 %60)
store i32 -1, i32* %3
br label %84
62: ; preds = %47
%63 = load i8*, i8** %10
%64 = load i8*, i8** %7
%65 = ptrtoint i8* %63 to i64
%66 = ptrtoint i8* %64 to i64
%67 = sub i64 %65, %66
%68 = add nsw i64 %67, 1
%69 = load i64, i64* %8
%70 = sub i64 %69, %68
store i64 %70, i64* %8
%71 = load i8*, i8** %10
%72 = getelementptr inbounds i8, i8* %71, i64 1
store i8* %72, i8** %7
br label %73
73: ; preds = %62, %46
br i1 true, label %13, label %74
74: ; preds = %73, %45
%75 = load i8*, i8** %7
%76 = load i64, i64* %8
%77 = call i64 @do_line(i8* %75, i64 %76)
%78 = icmp ne i64 %77, 0
br i1 %78, label %79, label %83
79: ; preds = %74
%80 = load i32, i32* @stdout
%81 = load i32, i32* %9
%82 = call i32 (i32, i8*, i32, ...) @fprintf(i32 %80, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32 %81)
store i32 -1, i32* %3
br label %84
83: ; preds = %74
store i32 0, i32* %3
br label %84
84: ; preds = %83, %79, %58, %23
%85 = load i32, i32* %3
ret i32 %85
}

LLVM IR (-O2):
@stdout = global i32 0
@.str = [44 x i8] c"Line %d too long: more than %zu characters\0A\00"
@.str.1 = [15 x i8] c"Line %d error\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [4096 x i8]
%4 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 0
br label %5
5: ; preds = %37, %2
%6 = phi i64 [ %39, %37 ], [ 0, %2 ]
%7 = phi i32 [ %29, %37 ], [ 0, %2 ]
%8 = phi i8* [ %40, %37 ], [ %4, %2 ]
br label %9
9: ; preds = %5, %20
%10 = phi i64 [ %25, %20 ], [ %6, %5 ]
%11 = phi i8* [ %4, %20 ], [ %8, %5 ]
%12 = call i64 @memchr(i8* %11, i8 signext 10, i64 %10)
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %27
14: ; preds = %9
%15 = icmp eq i64 %10, 4096
br i1 %15, label %16, label %20
16: ; preds = %14
%17 = load i32, i32* @stdout
%18 = add nuw nsw i32 %7, 1
%19 = call i32 (i32, i8*, i32, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0), i32 %18, i64 4096)
br label %47
20: ; preds = %14
%21 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 %10
%22 = trunc i64 %10 to i32
%23 = sub i32 4096, %22
%24 = call i64 @read(i32 0, i8* %21, i32 %23)
%25 = add i64 %24, %10
%26 = icmp eq i64 %24, 0
br i1 %26, label %41, label %9
27: ; preds = %9
%28 = inttoptr i64 %12 to i8*
%29 = add nuw nsw i32 %7, 1
%30 = ptrtoint i8* %11 to i64
%31 = sub i64 %12, %30
%32 = call i64 @do_line(i8* %11, i64 %31)
%33 = icmp eq i64 %32, 0
br i1 %33, label %37, label %34
34: ; preds = %27
%35 = load i32, i32* @stdout
%36 = call i32 (i32, i8*, i32, ...) @fprintf(i32 %35, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32 %29)
br label %47
37: ; preds = %27
%38 = xor i64 %31, -1
%39 = add i64 %10, %38
%40 = getelementptr inbounds i8, i8* %28, i64 1
br label %5
41: ; preds = %20
%42 = call i64 @do_line(i8* %4, i64 %25)
%43 = icmp eq i64 %42, 0
br i1 %43, label %47, label %44
44: ; preds = %41
%45 = load i32, i32* @stdout
%46 = call i32 (i32, i8*, i32, ...) @fprintf(i32 %45, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32 %7)
br label %47
47: ; preds = %16, %34, %41, %44
%48 = phi i32 [ -1, %44 ], [ 0, %41 ], [ -1, %34 ], [ -1, %16 ]
ret i32 %48
}