#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 /*<<< orphan*/ free(char *);
char *read_paragraph(int (*)(void *), void *);
scalar_t__ strlen(char *);
void stub1(void *, char *);
void by_paragraph(int (*read)(void *), void *in, void (*write)(void *, char *),
                  void *out) {
  while (1) {
    char *line = read_paragraph(read, in);
    if ((line == NULL) || (strlen(line) == 0)) {
      return;
    }
    (*write)(out, line);
    free(line);
  }
}


x86 assembly (clang, -O0):
<by_paragraph>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <read_paragraph@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     1177 <by_paragraph+0x47>
mov    -0x28(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x0,%rax
jne    117d <by_paragraph+0x4d>
add    $0x30,%rsp
pop    %rbp
ret
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   *%rax
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
jmp    1148 <by_paragraph+0x18>

x86 assembly (clang, -O2):
<by_paragraph>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rcx,%r14
mov    %rdx,%r15
mov    %rsi,%r12
mov    %rdi,%r13
call   1040 <read_paragraph@plt>
test   %rax,%rax
je     1179 <by_paragraph+0x59>
mov    %rax,%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
cmpb   $0x0,(%rbx)
je     1179 <by_paragraph+0x59>
mov    %r14,%rdi
mov    %rbx,%rsi
call   *%r15
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r13,%rdi
mov    %r12,%rsi
call   1040 <read_paragraph@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1150 <by_paragraph+0x30>
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @by_paragraph(i32 (i8*)* %0, i8* %1, void (i8*, i8*)* %2, i8* %3) {
%5 = alloca i32 (i8*)*
%6 = alloca i8*
%7 = alloca void (i8*, i8*)*
%8 = alloca i8*
%9 = alloca i8*
store i32 (i8*)* %0, i32 (i8*)** %5
store i8* %1, i8** %6
store void (i8*, i8*)* %2, void (i8*, i8*)** %7
store i8* %3, i8** %8
br label %10
10: ; preds = %4, %21
%11 = load i32 (i8*)*, i32 (i8*)** %5
%12 = load i8*, i8** %6
%13 = call i8* @read_paragraph(i32 (i8*)* %11, i8* %12)
store i8* %13, i8** %9
%14 = load i8*, i8** %9
%15 = icmp eq i8* %14, null
br i1 %15, label %20, label %16
16: ; preds = %10
%17 = load i8*, i8** %9
%18 = call i64 @strlen(i8* %17)
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %21
20: ; preds = %16, %10
ret void
21: ; preds = %16
%22 = load void (i8*, i8*)*, void (i8*, i8*)** %7
%23 = load i8*, i8** %8
%24 = load i8*, i8** %9
%25 = load i8*, i8** %9
%26 = call i32 @free(i8* %25)
br label %10
}

LLVM IR (-O2):
define void @by_paragraph(i32 (i8*)* %0, i8* %1, void (i8*, i8*)* nocapture %2, i8* %3) {
%5 = tail call i8* @read_paragraph(i32 (i8*)* %0, i8* %1)
%6 = icmp eq i8* %5, null
br i1 %6, label %15, label %7
7: ; preds = %4, %11
%8 = phi i8* [ %13, %11 ], [ %5, %4 ]
%9 = load i8, i8* %8
%10 = icmp eq i8 %9, 0
br i1 %10, label %15, label %11
11: ; preds = %7
tail call void %2(i8* %3, i8* %8)
%12 = tail call i32 @free(i8* %8)
%13 = tail call i8* @read_paragraph(i32 (i8*)* %0, i8* %1)
%14 = icmp eq i8* %13, null
br i1 %14, label %15, label %7
15: ; preds = %11, %7, %4
ret void
}