#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 EOF;
scalar_t__ realloc(char *, int);
int stub1(void *);
char *read_paragraph(int (*read)(void *), void *stream) {
  int buffer_size = 0, length = 0;
  char *buffer = NULL;
  int ch;
  while ((ch = (*read)(stream)) != EOF) {
    if (++length > buffer_size) {
      buffer_size += 100;
      buffer = (char *)realloc(buffer, buffer_size + 1);
    }
    if ((buffer[length - 1] = ch) == '\n') {
      break;
    }
    buffer[length] = '\0';
  }
  return buffer;
}


x86 assembly (clang, -O0):
<read_paragraph>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rdi
call   *%rax
mov    %eax,-0x24(%rbp)
mov    0x2e9e(%rip),%rcx
cmp    (%rcx),%eax
je     11b5 <read_paragraph+0xa5>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
cmp    -0x14(%rbp),%eax
jle    1180 <read_paragraph+0x70>
mov    -0x14(%rbp),%eax
add    $0x64,%eax
mov    %eax,-0x14(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x14(%rbp),%esi
add    $0x1,%esi
call   1030 <realloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x24(%rbp),%eax
mov    -0x20(%rbp),%rcx
mov    -0x18(%rbp),%edx
sub    $0x1,%edx
movslq %edx,%rdx
mov    %al,(%rcx,%rdx,1)
movsbl %al,%eax
cmp    $0xa,%eax
jne    11a4 <read_paragraph+0x94>
jmp    11b5 <read_paragraph+0xa5>
mov    -0x20(%rbp),%rax
movslq -0x18(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    1136 <read_paragraph+0x26>
mov    -0x20(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_paragraph>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%r15
mov    %rsi,0x10(%rsp)
mov    %rsi,%rdi
call   *%r15
mov    0x2eb5(%rip),%r14
xor    %ebx,%ebx
cmp    (%r14),%eax
jne    113f <read_paragraph+0x2f>
xor    %r12d,%r12d
jmp    1197 <read_paragraph+0x87>
mov    %eax,%ebp
xor    %r13d,%r13d
xor    %r12d,%r12d
mov    %r15,0x8(%rsp)
nopl   0x0(%rax)
movslq %ebx,%rax
cmp    %rax,%r13
jl     1174 <read_paragraph+0x64>
lea    0x64(%rbx),%r15d
add    $0x65,%ebx
mov    %r12,%rdi
mov    %ebx,%esi
call   1030 <realloc@plt>
mov    %rax,%r12
mov    %r15d,%ebx
mov    0x8(%rsp),%r15
mov    %bpl,(%r12,%r13,1)
cmp    $0xa,%bpl
je     1197 <read_paragraph+0x87>
movb   $0x0,0x1(%r12,%r13,1)
mov    0x10(%rsp),%rdi
call   *%r15
mov    %eax,%ebp
add    $0x1,%r13
cmp    (%r14),%eax
jne    1150 <read_paragraph+0x40>
mov    %r12,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@EOF = global i32 0
define i8* @read_paragraph(i32 (i8*)* nocapture %0, i8* %1) {
%3 = tail call i32 %0(i8* %1)
%4 = load i32, i32* @EOF
%5 = icmp eq i32 %3, %4
br i1 %5, label %31, label %6
6: ; preds = %2, %26
%7 = phi i64 [ %11, %26 ], [ 0, %2 ]
%8 = phi i32 [ %28, %26 ], [ %3, %2 ]
%9 = phi i32 [ %21, %26 ], [ 0, %2 ]
%10 = phi i8* [ %20, %26 ], [ null, %2 ]
%11 = add nuw i64 %7, 1
%12 = sext i32 %9 to i64
%13 = icmp slt i64 %7, %12
br i1 %13, label %19, label %14
14: ; preds = %6
%15 = add nsw i32 %9, 100
%16 = add nsw i32 %9, 101
%17 = tail call i64 @realloc(i8* %10, i32 %16)
%18 = inttoptr i64 %17 to i8*
br label %19
19: ; preds = %14, %6
%20 = phi i8* [ %18, %14 ], [ %10, %6 ]
%21 = phi i32 [ %15, %14 ], [ %9, %6 ]
%22 = trunc i32 %8 to i8
%23 = getelementptr inbounds i8, i8* %20, i64 %7
store i8 %22, i8* %23
%24 = and i32 %8, 255
%25 = icmp eq i32 %24, 10
br i1 %25, label %31, label %26
26: ; preds = %19
%27 = getelementptr inbounds i8, i8* %20, i64 %11
store i8 0, i8* %27
%28 = tail call i32 %0(i8* %1)
%29 = load i32, i32* @EOF
%30 = icmp eq i32 %28, %29
br i1 %30, label %31, label %6
31: ; preds = %26, %19, %2
%32 = phi i8* [ null, %2 ], [ %20, %19 ], [ %20, %26 ]
ret i8* %32
}