#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;
char *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 = realloc(buffer, buffer_size + 1);
    }
    if ((buffer[length - 1] = ch) == '\n') {
      buffer[--length] = '\0';
      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     11c9 <read_paragraph+0xb9>
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    11b8 <read_paragraph+0xa8>
mov    -0x20(%rbp),%rax
mov    -0x18(%rbp),%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x18(%rbp)
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    11c9 <read_paragraph+0xb9>
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,%r14
mov    %rsi,0x10(%rsp)
mov    %rsi,%rdi
call   *%r14
mov    0x2eb5(%rip),%r15
xor    %ebx,%ebx
cmp    (%r15),%eax
jne    113f <read_paragraph+0x2f>
xor    %r12d,%r12d
jmp    11a1 <read_paragraph+0x91>
mov    %eax,%ebp
xor    %r13d,%r13d
xor    %r12d,%r12d
mov    %r14,0x8(%rsp)
nopl   0x0(%rax)
movslq %ebx,%rax
cmp    %rax,%r13
jl     1174 <read_paragraph+0x64>
lea    0x64(%rbx),%r14d
add    $0x65,%ebx
mov    %r12,%rdi
mov    %ebx,%esi
call   1030 <realloc@plt>
mov    %rax,%r12
mov    %r14d,%ebx
mov    0x8(%rsp),%r14
mov    %bpl,(%r12,%r13,1)
cmp    $0xa,%bpl
je     1199 <read_paragraph+0x89>
movb   $0x0,0x1(%r12,%r13,1)
mov    0x10(%rsp),%rdi
call   *%r14
mov    %eax,%ebp
add    $0x1,%r13
cmp    (%r15),%eax
jne    1150 <read_paragraph+0x40>
jmp    11a1 <read_paragraph+0x91>
mov    %r13d,%eax
movb   $0x0,(%r12,%rax,1)
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 = %43, %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 %48
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 %27
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 i8* @realloc(i8* %23, i32 %25)
store i8* %26, i8** %7
br label %27
27: ; preds = %20, %15
%28 = load i32, i32* %8
%29 = trunc i32 %28 to i8
%30 = load i8*, i8** %7
%31 = load i32, i32* %6
%32 = sub nsw i32 %31, 1
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8, i8* %30, i64 %33
store i8 %29, i8* %34
%35 = sext i8 %29 to i32
%36 = icmp eq i32 %35, 10
br i1 %36, label %37, label %43
37: ; preds = %27
%38 = load i8*, i8** %7
%39 = load i32, i32* %6
%40 = add nsw i32 %39, -1
store i32 %40, i32* %6
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds i8, i8* %38, i64 %41
store i8 0, i8* %42
br label %48
43: ; preds = %27
%44 = load i8*, i8** %7
%45 = load i32, i32* %6
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds i8, i8* %44, i64 %46
store i8 0, i8* %47
br label %9
48: ; preds = %37, %9
%49 = load i8*, i8** %7
ret i8* %49
}

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 %33, label %6
6: ; preds = %2, %28
%7 = phi i64 [ %11, %28 ], [ 0, %2 ]
%8 = phi i32 [ %30, %28 ], [ %3, %2 ]
%9 = phi i32 [ %20, %28 ], [ 0, %2 ]
%10 = phi i8* [ %19, %28 ], [ null, %2 ]
%11 = add nuw i64 %7, 1
%12 = sext i32 %9 to i64
%13 = icmp slt i64 %7, %12
br i1 %13, label %18, label %14
14: ; preds = %6
%15 = add nsw i32 %9, 100
%16 = add nsw i32 %9, 101
%17 = tail call i8* @realloc(i8* %10, i32 %16)
br label %18
18: ; preds = %14, %6
%19 = phi i8* [ %17, %14 ], [ %10, %6 ]
%20 = phi i32 [ %15, %14 ], [ %9, %6 ]
%21 = trunc i32 %8 to i8
%22 = getelementptr inbounds i8, i8* %19, i64 %7
store i8 %21, i8* %22
%23 = and i32 %8, 255
%24 = icmp eq i32 %23, 10
br i1 %24, label %25, label %28
25: ; preds = %18
%26 = and i64 %7, 4294967295
%27 = getelementptr inbounds i8, i8* %19, i64 %26
store i8 0, i8* %27
br label %33
28: ; preds = %18
%29 = getelementptr inbounds i8, i8* %19, i64 %11
store i8 0, i8* %29
%30 = tail call i32 %0(i8* %1)
%31 = load i32, i32* @EOF
%32 = icmp eq i32 %30, %31
br i1 %32, label %33, label %6
33: ; preds = %28, %2, %25
%34 = phi i8* [ %19, %25 ], [ null, %2 ], [ %19, %28 ]
ret i8* %34
}