#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 */
typedef struct TYPE_3__ TYPE_1__;

/* Type definitions */
struct TYPE_3__ {
  int rm_so;
  scalar_t__ rm_eo;
};
typedef TYPE_1__ regmatch_t;
typedef int /*<<< orphan*/ regex_t;

/* Variables and functions */
char *calloc(int, int);
int /*<<< orphan*/ free(char *);
char *realloc(char *, scalar_t__);
int /*<<< orphan*/ regcomp(int /*<<< orphan*/ *, char *, int /*<<< orphan*/);
int /*<<< orphan*/ regexec(int /*<<< orphan*/ *, char *, int, TYPE_1__ *,
                           int /*<<< orphan*/);
int /*<<< orphan*/ regfree(int /*<<< orphan*/ *);
int /*<<< orphan*/ strcat(char *, char *);
scalar_t__ strlen(char *);
char *split_paragraphs(char *string) {
  char *p = "\n<p>";
  char *out = calloc(1, 1);
  regex_t regex;
  regcomp(&regex, "\n\\s*\n", 0);
  regmatch_t matches[1];
  int start = 0;
  while (!regexec(&regex, string + start, 1, matches, 0)) {
    string[start + matches[0].rm_so] = 0;
    out = realloc(out, strlen(out) + strlen(string + start) + strlen(p));
    strcat(out, string + start);
    strcat(out, p);
    start += matches[0].rm_eo;
  }
  if (strlen(string + start) > 0) {
    out = realloc(out, strlen(out) + strlen(string + start) + 1);
    strcat(out, string + start);
  }
  regfree(&regex);
  free(string);
  return out;
}


x86 assembly (clang, -O0):
<split_paragraphs>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
lea    0xe6d(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    $0x1,%esi
mov    %esi,%edi
call   1070 <calloc@plt>
mov    %rax,-0x18(%rbp)
lea    -0x1c(%rbp),%rdi
lea    0xe53(%rip),%rsi
xor    %edx,%edx
call   1060 <regcomp@plt>
movl   $0x0,-0x34(%rbp)
mov    -0x8(%rbp),%rsi
movslq -0x34(%rbp),%rax
add    %rax,%rsi
lea    -0x30(%rbp),%rcx
lea    -0x1c(%rbp),%rdi
mov    $0x1,%edx
xor    %r8d,%r8d
call   1080 <regexec@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11f5 <split_paragraphs+0x75>
jmp    128a <split_paragraphs+0x10a>
mov    -0x8(%rbp),%rax
mov    -0x34(%rbp),%ecx
add    -0x30(%rbp),%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,-0x50(%rbp)
mov    -0x8(%rbp),%rdi
movslq -0x34(%rbp),%rax
add    %rax,%rdi
call   1050 <strlen@plt>
mov    %rax,%rcx
mov    -0x50(%rbp),%rax
add    %rcx,%rax
mov    %rax,-0x48(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x48(%rbp),%rsi
mov    -0x40(%rbp),%rdi
add    %rax,%rsi
call   1090 <realloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rsi
movslq -0x34(%rbp),%rax
add    %rax,%rsi
call   10a0 <strcat@plt>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   10a0 <strcat@plt>
mov    -0x28(%rbp),%rcx
movslq -0x34(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x34(%rbp)
jmp    11c0 <split_paragraphs+0x40>
mov    -0x8(%rbp),%rdi
movslq -0x34(%rbp),%rax
add    %rax,%rdi
call   1050 <strlen@plt>
cmp    $0x0,%rax
jle    12f5 <split_paragraphs+0x175>
mov    -0x18(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,-0x60(%rbp)
mov    -0x8(%rbp),%rdi
movslq -0x34(%rbp),%rax
add    %rax,%rdi
call   1050 <strlen@plt>
mov    -0x60(%rbp),%rsi
mov    -0x58(%rbp),%rdi
add    %rax,%rsi
add    $0x1,%rsi
call   1090 <realloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rsi
movslq -0x34(%rbp),%rax
add    %rax,%rsi
call   10a0 <strcat@plt>
lea    -0x1c(%rbp),%rdi
call   1040 <regfree@plt>
mov    -0x8(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%rax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<split_paragraphs>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rdi,%r14
mov    $0x1,%edi
mov    $0x1,%esi
call   1070 <calloc@plt>
mov    %rax,%r15
lea    0xe5b(%rip),%rsi
lea    0xc(%rsp),%rbx
xor    %r13d,%r13d
mov    %rbx,%rdi
xor    %edx,%edx
call   1060 <regcomp@plt>
lea    0x10(%rsp),%rcx
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x1,%edx
xor    %r8d,%r8d
call   1080 <regexec@plt>
test   %eax,%eax
je     11e0 <split_paragraphs+0x60>
mov    %r14,%rbx
jmp    1267 <split_paragraphs+0xe7>
lea    0x10(%rsp),%rbp
mov    %r14,%rbx
nopl   0x0(%rax,%rax,1)
movslq 0x10(%rsp),%rax
movslq %r13d,%r13
add    %r13,%rax
movb   $0x0,(%r14,%rax,1)
mov    %r15,%rdi
call   1050 <strlen@plt>
mov    %rax,%r12
mov    %rbx,%rdi
call   1050 <strlen@plt>
lea    (%r12,%rax,1),%rsi
add    $0x4,%rsi
mov    %r15,%rdi
call   1090 <realloc@plt>
mov    %rax,%r15
mov    %rax,%rdi
mov    %rbx,%rsi
call   10a0 <strcat@plt>
mov    %r15,%rdi
lea    0xdc5(%rip),%rsi
call   10a0 <strcat@plt>
add    0x18(%rsp),%r13d
movslq %r13d,%rbx
add    %r14,%rbx
lea    0xc(%rsp),%rdi
mov    %rbx,%rsi
mov    $0x1,%edx
mov    %rbp,%rcx
xor    %r8d,%r8d
call   1080 <regexec@plt>
test   %eax,%eax
je     11f0 <split_paragraphs+0x70>
mov    %rbx,%rdi
call   1050 <strlen@plt>
test   %rax,%rax
jle    129d <split_paragraphs+0x11d>
mov    %rax,%rbp
mov    %r15,%rdi
call   1050 <strlen@plt>
lea    (%rax,%rbp,1),%rsi
add    $0x1,%rsi
mov    %r15,%rdi
call   1090 <realloc@plt>
mov    %rax,%r15
mov    %rax,%rdi
mov    %rbx,%rsi
call   10a0 <strcat@plt>
lea    0xc(%rsp),%rdi
call   1040 <regfree@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %r15,%rax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.TYPE_3__ = type { i32, i64 }
@.str = [5 x i8] c"\0A<p>\00"
@.str.1 = [6 x i8] c"\0A\\s*\0A\00"
define i8* @split_paragraphs(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca [1 x %struct.TYPE_3__]
%7 = alloca i32
store i8* %0, i8** %2
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8** %3
%8 = call i8* @calloc(i32 1, i32 1)
store i8* %8, i8** %4
%9 = call i32 @regcomp(i32* %5, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 0)
store i32 0, i32* %7
br label %10
10: ; preds = %19, %1
%11 = load i8*, i8** %2
%12 = load i32, i32* %7
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds i8, i8* %11, i64 %13
%15 = getelementptr inbounds [1 x %struct.TYPE_3__], [1 x %struct.TYPE_3__]* %6, i64 0, i64 0
%16 = call i32 @regexec(i32* %5, i8* %14, i32 1, %struct.TYPE_3__* %15, i32 0)
%17 = icmp ne i32 %16, 0
%18 = xor i1 %17, true
br i1 %18, label %19, label %57
19: ; preds = %10
%20 = load i8*, i8** %2
%21 = load i32, i32* %7
%22 = getelementptr inbounds [1 x %struct.TYPE_3__], [1 x %struct.TYPE_3__]* %6, i64 0, i64 0
%23 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %22, i32 0, i32 0
%24 = load i32, i32* %23
%25 = add nsw i32 %21, %24
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i8, i8* %20, i64 %26
store i8 0, i8* %27
%28 = load i8*, i8** %4
%29 = load i8*, i8** %4
%30 = call i64 @strlen(i8* %29)
%31 = load i8*, i8** %2
%32 = load i32, i32* %7
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8, i8* %31, i64 %33
%35 = call i64 @strlen(i8* %34)
%36 = add nsw i64 %30, %35
%37 = load i8*, i8** %3
%38 = call i64 @strlen(i8* %37)
%39 = add nsw i64 %36, %38
%40 = call i8* @realloc(i8* %28, i64 %39)
store i8* %40, i8** %4
%41 = load i8*, i8** %4
%42 = load i8*, i8** %2
%43 = load i32, i32* %7
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds i8, i8* %42, i64 %44
%46 = call i32 @strcat(i8* %41, i8* %45)
%47 = load i8*, i8** %4
%48 = load i8*, i8** %3
%49 = call i32 @strcat(i8* %47, i8* %48)
%50 = getelementptr inbounds [1 x %struct.TYPE_3__], [1 x %struct.TYPE_3__]* %6, i64 0, i64 0
%51 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %50, i32 0, i32 1
%52 = load i64, i64* %51
%53 = load i32, i32* %7
%54 = sext i32 %53 to i64
%55 = add nsw i64 %54, %52
%56 = trunc i64 %55 to i32
store i32 %56, i32* %7
br label %10
57: ; preds = %10
%58 = load i8*, i8** %2
%59 = load i32, i32* %7
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds i8, i8* %58, i64 %60
%62 = call i64 @strlen(i8* %61)
%63 = icmp sgt i64 %62, 0
br i1 %63, label %64, label %82
64: ; preds = %57
%65 = load i8*, i8** %4
%66 = load i8*, i8** %4
%67 = call i64 @strlen(i8* %66)
%68 = load i8*, i8** %2
%69 = load i32, i32* %7
%70 = sext i32 %69 to i64
%71 = getelementptr inbounds i8, i8* %68, i64 %70
%72 = call i64 @strlen(i8* %71)
%73 = add nsw i64 %67, %72
%74 = add nsw i64 %73, 1
%75 = call i8* @realloc(i8* %65, i64 %74)
store i8* %75, i8** %4
%76 = load i8*, i8** %4
%77 = load i8*, i8** %2
%78 = load i32, i32* %7
%79 = sext i32 %78 to i64
%80 = getelementptr inbounds i8, i8* %77, i64 %79
%81 = call i32 @strcat(i8* %76, i8* %80)
br label %82
82: ; preds = %64, %57
%83 = call i32 @regfree(i32* %5)
%84 = load i8*, i8** %2
%85 = call i32 @free(i8* %84)
%86 = load i8*, i8** %4
ret i8* %86
}

LLVM IR (-O2):
%struct.TYPE_3__ = type { i32, i64 }
@.str = [5 x i8] c"\0A<p>\00"
@.str.1 = [6 x i8] c"\0A\\s*\0A\00"
define i8* @split_paragraphs(i8* %0) {
%2 = alloca i32
%3 = alloca [1 x %struct.TYPE_3__]
%4 = tail call dereferenceable_or_null(1) i8* @calloc(i32 1, i32 1)
%5 = bitcast i32* %2 to i8*
%6 = call i32 @regcomp(i32* %2, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 0)
%7 = bitcast [1 x %struct.TYPE_3__]* %3 to i8*
%8 = getelementptr inbounds [1 x %struct.TYPE_3__], [1 x %struct.TYPE_3__]* %3, i64 0, i64 0
%9 = call i32 @regexec(i32* %2, i8* %0, i32 1, %struct.TYPE_3__* %8, i32 0)
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %36
11: ; preds = %1
%12 = getelementptr inbounds [1 x %struct.TYPE_3__], [1 x %struct.TYPE_3__]* %3, i64 0, i64 0, i32 0
%13 = getelementptr inbounds [1 x %struct.TYPE_3__], [1 x %struct.TYPE_3__]* %3, i64 0, i64 0, i32 1
br label %14
14: ; preds = %11, %14
%15 = phi i8* [ %0, %11 ], [ %33, %14 ]
%16 = phi i32 [ 0, %11 ], [ %31, %14 ]
%17 = phi i8* [ %4, %11 ], [ %26, %14 ]
%18 = load i32, i32* %12
%19 = add nsw i32 %18, %16
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i8, i8* %0, i64 %20
store i8 0, i8* %21
%22 = call i64 @strlen(i8* dereferenceable(1) %17)
%23 = call i64 @strlen(i8* dereferenceable(1) %15)
%24 = add i64 %22, 4
%25 = add i64 %24, %23
%26 = call i8* @realloc(i8* %17, i64 %25)
%27 = call i32 @strcat(i8* %26, i8* %15)
%28 = call i32 @strcat(i8* %26, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%29 = load i64, i64* %13
%30 = trunc i64 %29 to i32
%31 = add i32 %16, %30
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8, i8* %0, i64 %32
%34 = call i32 @regexec(i32* %2, i8* %33, i32 1, %struct.TYPE_3__* %8, i32 0)
%35 = icmp eq i32 %34, 0
br i1 %35, label %14, label %36
36: ; preds = %14, %1
%37 = phi i8* [ %4, %1 ], [ %26, %14 ]
%38 = phi i8* [ %0, %1 ], [ %33, %14 ]
%39 = call i64 @strlen(i8* dereferenceable(1) %38)
%40 = icmp sgt i64 %39, 0
br i1 %40, label %41, label %47
41: ; preds = %36
%42 = call i64 @strlen(i8* dereferenceable(1) %37)
%43 = add nuw i64 %39, 1
%44 = add i64 %43, %42
%45 = call i8* @realloc(i8* %37, i64 %44)
%46 = call i32 @strcat(i8* %45, i8* %38)
br label %47
47: ; preds = %41, %36
%48 = phi i8* [ %45, %41 ], [ %37, %36 ]
%49 = call i32 @regfree(i32* %2)
%50 = call i32 @free(i8* %0)
ret i8* %48
}