#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 */
char *calloc(int, int);
int /*<<< orphan*/ free(char *);
char *generate_paragraph(int);
int /*<<< orphan*/ memcpy(char *, char *, unsigned int);
char *realloc(char *, unsigned int);
unsigned int strlen(char *);
char *generate_muspi_merol(const unsigned num_paragraphs) {
  char *muspi_merol, *paragraph;
  unsigned i, paragraph_len, cur_len = 0;
  muspi_merol = calloc(1, sizeof(char));
  for (i = 0; i < num_paragraphs; ++i) {
    paragraph = generate_paragraph(0 == i);
    paragraph_len = strlen(paragraph);
    muspi_merol = realloc(muspi_merol, (cur_len += paragraph_len) + 1);
    memcpy(&muspi_merol[cur_len - paragraph_len], paragraph,
           paragraph_len / sizeof(char));
    free(paragraph);
  }
  muspi_merol[cur_len] = '\0';
  return muspi_merol;
}


x86 assembly (clang, -O0):
<generate_muspi_merol>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0x24(%rbp)
mov    $0x1,%esi
mov    %esi,%edi
call   1050 <calloc@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x4(%rbp),%eax
jae    1208 <generate_muspi_merol+0xa8>
xor    %eax,%eax
cmp    -0x1c(%rbp),%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <generate_paragraph@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%esi
add    -0x24(%rbp),%esi
mov    %esi,-0x24(%rbp)
add    $0x1,%esi
call   1080 <realloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x24(%rbp),%eax
sub    -0x20(%rbp),%eax
mov    %eax,%eax
add    %rax,%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%eax
shr    $0x0,%rax
mov    %eax,%edx
call   1060 <memcpy@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1189 <generate_muspi_merol+0x29>
mov    -0x10(%rbp),%rax
mov    -0x24(%rbp),%ecx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<generate_muspi_merol>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edi,%ebx
mov    $0x1,%edi
mov    $0x1,%esi
call   1050 <calloc@plt>
mov    %rax,%r15
xor    %r14d,%r14d
test   %ebx,%ebx
je     11e9 <generate_muspi_merol+0x89>
xor    %ebp,%ebp
mov    %ebx,0x4(%rsp)
nopl   0x0(%rax)
mov    %r14d,%r12d
xor    %edi,%edi
test   %ebp,%ebp
sete   %dil
call   1070 <generate_paragraph@plt>
mov    %rax,%r13
mov    %rax,%rdi
call   1040 <strlen@plt>
mov    %eax,%ebx
lea    (%rbx,%r12,1),%r14d
lea    (%rbx,%r12,1),%esi
add    $0x1,%esi
mov    %r15,%rdi
call   1080 <realloc@plt>
mov    %rax,%r15
mov    %r12d,%edi
add    %rax,%rdi
mov    %r13,%rsi
mov    %ebx,%edx
mov    0x4(%rsp),%ebx
call   1060 <memcpy@plt>
mov    %r13,%rdi
call   1030 <free@plt>
add    $0x1,%ebp
cmp    %ebp,%ebx
jne    1190 <generate_muspi_merol+0x30>
mov    %r14d,%r14d
movb   $0x0,(%r15,%r14,1)
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i8* @generate_muspi_merol(i32 %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %2
store i32 0, i32* %7
%8 = call i8* @calloc(i32 1, i32 1)
store i8* %8, i8** %3
store i32 0, i32* %5
br label %9
9: ; preds = %40, %1
%10 = load i32, i32* %5
%11 = load i32, i32* %2
%12 = icmp ult i32 %10, %11
br i1 %12, label %13, label %43
13: ; preds = %9
%14 = load i32, i32* %5
%15 = icmp eq i32 0, %14
%16 = zext i1 %15 to i32
%17 = call i8* @generate_paragraph(i32 %16)
store i8* %17, i8** %4
%18 = load i8*, i8** %4
%19 = call i32 @strlen(i8* %18)
store i32 %19, i32* %6
%20 = load i8*, i8** %3
%21 = load i32, i32* %6
%22 = load i32, i32* %7
%23 = add i32 %22, %21
store i32 %23, i32* %7
%24 = add i32 %23, 1
%25 = call i8* @realloc(i8* %20, i32 %24)
store i8* %25, i8** %3
%26 = load i8*, i8** %3
%27 = load i32, i32* %7
%28 = load i32, i32* %6
%29 = sub i32 %27, %28
%30 = zext i32 %29 to i64
%31 = getelementptr inbounds i8, i8* %26, i64 %30
%32 = load i8*, i8** %4
%33 = load i32, i32* %6
%34 = zext i32 %33 to i64
%35 = udiv i64 %34, 1
%36 = trunc i64 %35 to i32
%37 = call i32 @memcpy(i8* %31, i8* %32, i32 %36)
%38 = load i8*, i8** %4
%39 = call i32 @free(i8* %38)
br label %40
40: ; preds = %13
%41 = load i32, i32* %5
%42 = add i32 %41, 1
store i32 %42, i32* %5
br label %9
43: ; preds = %9
%44 = load i8*, i8** %3
%45 = load i32, i32* %7
%46 = zext i32 %45 to i64
%47 = getelementptr inbounds i8, i8* %44, i64 %46
store i8 0, i8* %47
%48 = load i8*, i8** %3
ret i8* %48
}

LLVM IR (-O2):
define i8* @generate_muspi_merol(i32 %0) {
%2 = tail call dereferenceable_or_null(1) i8* @calloc(i32 1, i32 1)
%3 = icmp eq i32 %0, 0
br i1 %3, label %23, label %4
4: ; preds = %1, %4
%5 = phi i32 [ %12, %4 ], [ 0, %1 ]
%6 = phi i8* [ %14, %4 ], [ %2, %1 ]
%7 = phi i32 [ %19, %4 ], [ 0, %1 ]
%8 = icmp eq i32 %7, 0
%9 = zext i1 %8 to i32
%10 = tail call i8* @generate_paragraph(i32 %9)
%11 = tail call i32 @strlen(i8* %10)
%12 = add i32 %11, %5
%13 = add i32 %12, 1
%14 = tail call i8* @realloc(i8* %6, i32 %13)
%15 = zext i32 %5 to i64
%16 = getelementptr inbounds i8, i8* %14, i64 %15
%17 = tail call i32 @memcpy(i8* %16, i8* %10, i32 %11)
%18 = tail call i32 @free(i8* %10)
%19 = add nuw i32 %7, 1
%20 = icmp eq i32 %19, %0
br i1 %20, label %21, label %4
21: ; preds = %4
%22 = zext i32 %12 to i64
br label %23
23: ; preds = %21, %1
%24 = phi i8* [ %2, %1 ], [ %14, %21 ]
%25 = phi i64 [ 0, %1 ], [ %22, %21 ]
%26 = getelementptr inbounds i8, i8* %24, i64 %25
store i8 0, i8* %26
ret i8* %24
}