#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') {
      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 = %44, %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 %49
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 %44
38: ; preds = %28
%39 = load i8*, i8** %7
%40 = load i32, i32* %6
%41 = add nsw i32 %40, -1
store i32 %41, i32* %6
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds i8, i8* %39, i64 %42
store i8 0, i8* %43
br label %49
44: ; preds = %28
%45 = load i8*, i8** %7
%46 = load i32, i32* %6
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds i8, i8* %45, i64 %47
store i8 0, i8* %48
br label %9
49: ; preds = %38, %9
%50 = load i8*, i8** %7
ret i8* %50
}

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 %34, label %6
6: ; preds = %2, %29
%7 = phi i64 [ %11, %29 ], [ 0, %2 ]
%8 = phi i32 [ %31, %29 ], [ %3, %2 ]
%9 = phi i32 [ %21, %29 ], [ 0, %2 ]
%10 = phi i8* [ %20, %29 ], [ 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 %26, label %29
26: ; preds = %19
%27 = and i64 %7, 4294967295
%28 = getelementptr inbounds i8, i8* %20, i64 %27
store i8 0, i8* %28
br label %34
29: ; preds = %19
%30 = getelementptr inbounds i8, i8* %20, i64 %11
store i8 0, i8* %30
%31 = tail call i32 %0(i8* %1)
%32 = load i32, i32* @EOF
%33 = icmp eq i32 %31, %32
br i1 %33, label %34, label %6
34: ; preds = %29, %2, %26
%35 = phi i8* [ %20, %26 ], [ null, %2 ], [ %20, %29 ]
ret i8* %35
}