#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*/ FILE;

/* Variables and functions */
int EOF;
int /*<<< orphan*/ errno;
scalar_t__ ferror(int /*<<< orphan*/ *);
int getc(int /*<<< orphan*/ *);
int /*<<< orphan*/ isbinary();
int /*<<< orphan*/ resize_buffer(char **, int *, int);
int /*<<< orphan*/ set_binary();
int /*<<< orphan*/ set_error_msg(char *);
int /*<<< orphan*/ show_strerror(int /*<<< orphan*/, int /*<<< orphan*/);
const char *read_stream_line(FILE *fp, int *lenp, char *newline_added_now) {
  static char *buf = 0;
  static int bufsz = 0;
  int c, i = 0;
  while (1) {
    if (!resize_buffer(&buf, &bufsz, i + 2))
      return 0;
    c = getc(fp);
    if (c == EOF)
      break;
    buf[i++] = c;
    if (!c)
      set_binary();
    else if (c == '\n')
      break;
  }
  buf[i] = 0;
  if (c == EOF) {
    if (ferror(fp)) {
      show_strerror(0, errno);
      set_error_msg("Cannot read input file");
      return 0;
    } else if (i) {
      buf[i] = '\n';
      buf[i + 1] = 0;
      *newline_added_now = 1;
      if (!isbinary())
        ++i;
    }
  }
  *lenp = i;
  return buf;
}


x86 assembly (clang, -O0):
<read_stream_line>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%edx
add    $0x2,%edx
lea    0x2ec8(%rip),%rdi
lea    0x2ec9(%rip),%rsi
call   1070 <resize_buffer@plt>
cmp    $0x0,%eax
jne    11ba <read_stream_line+0x4a>
movq   $0x0,-0x8(%rbp)
jmp    12f6 <read_stream_line+0x186>
mov    -0x10(%rbp),%rdi
call   1080 <getc@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    0x2e18(%rip),%rcx
cmp    (%rcx),%eax
jne    11dd <read_stream_line+0x6d>
jmp    1229 <read_stream_line+0xb9>
mov    -0x24(%rbp),%eax
mov    %al,%dl
mov    0x2e77(%rip),%rax
mov    -0x28(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x28(%rbp)
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
cmpl   $0x0,-0x24(%rbp)
jne    1210 <read_stream_line+0xa0>
mov    $0x0,%al
call   1030 <set_binary@plt>
jmp    1224 <read_stream_line+0xb4>
cmpl   $0xa,-0x24(%rbp)
jne    121f <read_stream_line+0xaf>
jmp    1229 <read_stream_line+0xb9>
jmp    1224 <read_stream_line+0xb4>
jmp    118b <read_stream_line+0x1b>
mov    0x2e30(%rip),%rax
movslq -0x28(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x24(%rbp),%eax
mov    0x2da6(%rip),%rcx
cmp    (%rcx),%eax
jne    12e2 <read_stream_line+0x172>
mov    -0x10(%rbp),%rdi
call   1050 <ferror@plt>
cmp    $0x0,%rax
je     1286 <read_stream_line+0x116>
mov    0x2d74(%rip),%rax
mov    (%rax),%esi
xor    %edi,%edi
call   1090 <show_strerror@plt>
lea    0xd8c(%rip),%rdi
call   1060 <set_error_msg@plt>
movq   $0x0,-0x8(%rbp)
jmp    12f6 <read_stream_line+0x186>
cmpl   $0x0,-0x28(%rbp)
je     12d8 <read_stream_line+0x168>
mov    0x2dc9(%rip),%rax
movslq -0x28(%rbp),%rcx
movb   $0xa,(%rax,%rcx,1)
mov    0x2dba(%rip),%rax
mov    -0x28(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x20(%rbp),%rax
movb   $0x1,(%rax)
mov    $0x0,%al
call   1040 <isbinary@plt>
cmp    $0x0,%eax
jne    12d3 <read_stream_line+0x163>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    12d8 <read_stream_line+0x168>
jmp    12dd <read_stream_line+0x16d>
jmp    12e2 <read_stream_line+0x172>
mov    -0x28(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    0x2d6e(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_stream_line>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdx,%r14
mov    %rsi,%rbp
mov    %rdi,%rbx
lea    0x2ed2(%rip),%rdi
lea    0x2ed3(%rip),%rsi
mov    $0x2,%edx
call   1070 <resize_buffer@plt>
test   %eax,%eax
je     1258 <read_stream_line+0xe8>
mov    %r14,0x10(%rsp)
mov    %rbp,0x8(%rsp)
xor    %r12d,%r12d
mov    0x2e2d(%rip),%r15
lea    0x2e9e(%rip),%r13
lea    0x2e9f(%rip),%rbp
xor    %r14d,%r14d
jmp    11f2 <read_stream_line+0x82>
xchg   %ax,%ax
xor    %eax,%eax
call   1030 <set_binary@plt>
lea    0x3(%r14),%edx
mov    %r13,%rdi
mov    %rbp,%rsi
call   1070 <resize_buffer@plt>
add    $0x1,%r14
test   %eax,%eax
je     12a6 <read_stream_line+0x136>
mov    %rbx,%rdi
call   1080 <getc@plt>
cmp    (%r15),%eax
je     1217 <read_stream_line+0xa7>
mov    0x2e5a(%rip),%rcx
mov    %al,(%rcx,%r14,1)
test   %eax,%eax
je     11d0 <read_stream_line+0x60>
cmp    $0xa,%eax
jne    11d7 <read_stream_line+0x67>
add    $0x1,%r14
mov    0x2e42(%rip),%rcx
movslq %r14d,%rbp
movb   $0x0,(%rcx,%rbp,1)
cmp    (%r15),%eax
jne    1297 <read_stream_line+0x127>
mov    %rbx,%rdi
call   1050 <ferror@plt>
test   %rax,%rax
je     125d <read_stream_line+0xed>
mov    0x2d9a(%rip),%rax
mov    (%rax),%esi
xor    %r12d,%r12d
xor    %edi,%edi
call   1090 <show_strerror@plt>
lea    0xdaf(%rip),%rdi
call   1060 <set_error_msg@plt>
jmp    12a6 <read_stream_line+0x136>
xor    %r12d,%r12d
jmp    12a6 <read_stream_line+0x136>
test   %r14d,%r14d
je     1294 <read_stream_line+0x124>
mov    0x2df7(%rip),%rax
movb   $0xa,(%rax,%rbp,1)
mov    0x2dec(%rip),%rax
movb   $0x0,0x1(%rax,%rbp,1)
add    $0x1,%rbp
mov    0x10(%rsp),%rax
movb   $0x1,(%rax)
xor    %eax,%eax
call   1040 <isbinary@plt>
test   %eax,%eax
cmove  %ebp,%r14d
jmp    1297 <read_stream_line+0x127>
xor    %r14d,%r14d
mov    0x8(%rsp),%rax
mov    %r14d,(%rax)
mov    0x2dba(%rip),%r12
mov    %r12,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@read_stream_line.buf = internal global i8* null
@read_stream_line.bufsz = internal global i32 0
@EOF = global i32 0
@errno = global i32 0
@.str = [23 x i8] c"Cannot read input file\00"
define i8* @read_stream_line(i32* %0, i32* %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
store i32* %0, i32** %5
store i32* %1, i32** %6
store i8* %2, i8** %7
store i32 0, i32* %9
br label %10
10: ; preds = %3, %40
%11 = load i32, i32* %9
%12 = add nsw i32 %11, 2
%13 = call i32 @resize_buffer(i8** @read_stream_line.buf, i32* @read_stream_line.bufsz, i32 %12)
%14 = icmp ne i32 %13, 0
br i1 %14, label %16, label %15
15: ; preds = %10
store i8* null, i8** %4
br label %83
16: ; preds = %10
%17 = load i32*, i32** %5
%18 = call i32 @getc(i32* %17)
store i32 %18, i32* %8
%19 = load i32, i32* %8
%20 = load i32, i32* @EOF
%21 = icmp eq i32 %19, %20
br i1 %21, label %22, label %23
22: ; preds = %16
br label %41
23: ; preds = %16
%24 = load i32, i32* %8
%25 = trunc i32 %24 to i8
%26 = load i8*, i8** @read_stream_line.buf
%27 = load i32, i32* %9
%28 = add nsw i32 %27, 1
store i32 %28, i32* %9
%29 = sext i32 %27 to i64
%30 = getelementptr inbounds i8, i8* %26, i64 %29
store i8 %25, i8* %30
%31 = load i32, i32* %8
%32 = icmp ne i32 %31, 0
br i1 %32, label %35, label %33
33: ; preds = %23
%34 = call i32 (...) @set_binary()
br label %40
35: ; preds = %23
%36 = load i32, i32* %8
%37 = icmp eq i32 %36, 10
br i1 %37, label %38, label %39
38: ; preds = %35
br label %41
39: ; preds = %35
br label %40
40: ; preds = %39, %33
br label %10
41: ; preds = %38, %22
%42 = load i8*, i8** @read_stream_line.buf
%43 = load i32, i32* %9
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds i8, i8* %42, i64 %44
store i8 0, i8* %45
%46 = load i32, i32* %8
%47 = load i32, i32* @EOF
%48 = icmp eq i32 %46, %47
br i1 %48, label %49, label %79
49: ; preds = %41
%50 = load i32*, i32** %5
%51 = call i64 @ferror(i32* %50)
%52 = icmp ne i64 %51, 0
br i1 %52, label %53, label %57
53: ; preds = %49
%54 = load i32, i32* @errno
%55 = call i32 @show_strerror(i32 0, i32 %54)
%56 = call i32 @set_error_msg(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
store i8* null, i8** %4
br label %83
57: ; preds = %49
%58 = load i32, i32* %9
%59 = icmp ne i32 %58, 0
br i1 %59, label %60, label %77
60: ; preds = %57
%61 = load i8*, i8** @read_stream_line.buf
%62 = load i32, i32* %9
%63 = sext i32 %62 to i64
%64 = getelementptr inbounds i8, i8* %61, i64 %63
store i8 10, i8* %64
%65 = load i8*, i8** @read_stream_line.buf
%66 = load i32, i32* %9
%67 = add nsw i32 %66, 1
%68 = sext i32 %67 to i64
%69 = getelementptr inbounds i8, i8* %65, i64 %68
store i8 0, i8* %69
%70 = load i8*, i8** %7
store i8 1, i8* %70
%71 = call i32 (...) @isbinary()
%72 = icmp ne i32 %71, 0
br i1 %72, label %76, label %73
73: ; preds = %60
%74 = load i32, i32* %9
%75 = add nsw i32 %74, 1
store i32 %75, i32* %9
br label %76
76: ; preds = %73, %60
br label %77
77: ; preds = %76, %57
br label %78
78: ; preds = %77
br label %79
79: ; preds = %78, %41
%80 = load i32, i32* %9
%81 = load i32*, i32** %6
store i32 %80, i32* %81
%82 = load i8*, i8** @read_stream_line.buf
store i8* %82, i8** %4
br label %83
83: ; preds = %79, %53, %15
%84 = load i8*, i8** %4
ret i8* %84
}

LLVM IR (-O2):
@read_stream_line.buf = internal global i8* null
@read_stream_line.bufsz = internal global i32 0
@EOF = global i32 0
@errno = global i32 0
@.str = [23 x i8] c"Cannot read input file\00"
define i8* @read_stream_line(i32* nocapture %0, i32* nocapture writeonly %1, i8* nocapture writeonly %2) {
%4 = tail call i32 @resize_buffer(i8** @read_stream_line.buf, i32* @read_stream_line.bufsz, i32 2)
%5 = icmp eq i32 %4, 0
br i1 %5, label %54, label %6
6: ; preds = %3, %18
%7 = phi i64 [ %14, %18 ], [ 0, %3 ]
%8 = tail call i32 @getc(i32* %0)
%9 = load i32, i32* @EOF
%10 = icmp eq i32 %8, %9
br i1 %10, label %23, label %11
11: ; preds = %6
%12 = trunc i32 %8 to i8
%13 = load i8*, i8** @read_stream_line.buf
%14 = add nuw i64 %7, 1
%15 = getelementptr inbounds i8, i8* %13, i64 %7
store i8 %12, i8* %15
switch i32 %8, label %18 [
i32 0, label %16
i32 10, label %23
]
16: ; preds = %11
%17 = tail call i32 (...) @set_binary()
br label %18
18: ; preds = %11, %16
%19 = trunc i64 %7 to i32
%20 = add i32 %19, 3
%21 = tail call i32 @resize_buffer(i8** @read_stream_line.buf, i32* @read_stream_line.bufsz, i32 %20)
%22 = icmp eq i32 %21, 0
br i1 %22, label %54, label %6
23: ; preds = %11, %6
%24 = phi i64 [ %14, %11 ], [ %7, %6 ]
%25 = trunc i64 %24 to i32
%26 = load i8*, i8** @read_stream_line.buf
%27 = shl i64 %24, 32
%28 = ashr exact i64 %27, 32
%29 = getelementptr inbounds i8, i8* %26, i64 %28
store i8 0, i8* %29
%30 = load i32, i32* @EOF
%31 = icmp eq i32 %8, %30
br i1 %31, label %32, label %51
32: ; preds = %23
%33 = tail call i64 @ferror(i32* %0)
%34 = icmp eq i64 %33, 0
br i1 %34, label %39, label %35
35: ; preds = %32
%36 = load i32, i32* @errno
%37 = tail call i32 @show_strerror(i32 0, i32 %36)
%38 = tail call i32 @set_error_msg(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
br label %54
39: ; preds = %32
%40 = icmp eq i32 %25, 0
br i1 %40, label %51, label %41
41: ; preds = %39
%42 = load i8*, i8** @read_stream_line.buf
%43 = getelementptr inbounds i8, i8* %42, i64 %28
store i8 10, i8* %43
%44 = load i8*, i8** @read_stream_line.buf
%45 = add nsw i32 %25, 1
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds i8, i8* %44, i64 %46
store i8 0, i8* %47
store i8 1, i8* %2
%48 = tail call i32 (...) @isbinary()
%49 = icmp eq i32 %48, 0
%50 = select i1 %49, i32 %45, i32 %25
br label %51
51: ; preds = %41, %39, %23
%52 = phi i32 [ 0, %39 ], [ %25, %23 ], [ %50, %41 ]
store i32 %52, i32* %1
%53 = load i8*, i8** @read_stream_line.buf
br label %54
54: ; preds = %18, %3, %51, %35
%55 = phi i8* [ null, %35 ], [ %53, %51 ], [ null, %3 ], [ null, %18 ]
ret i8* %55
}