#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*/ diagnostics(int, char *, ...);
scalar_t__ isspace(char);
scalar_t__ malloc(size_t);
int /*<<< orphan*/ my_strlcpy(char *, char const *, size_t);
char *strstr(char const *, char *);
void HA_ExtractTemplateAndLines(const char *s, char **thetemplate,
                                char ***thelines, int *nl) {
  char *p, *ss, *HA_template = NULL;
  char **lines;
  int nlines, i;
  ss = (char *)s;
  nlines = 0;
  while ((p = strstr(ss, "\\cr"))) {
    nlines++;
    ss = p + 3;
  }
  nlines--;
  lines = (char **)malloc(nlines * sizeof(char *));
  p = strstr(s, "\\cr");
  if (p) {
    size_t n = p - s + 1;
    HA_template = (char *)malloc(n * sizeof(char));
    my_strlcpy(HA_template, s, n);
    diagnostics(4, "HA_template = '%s'", HA_template);
  }
  ss = p + 3;
  while (isspace(*ss))
    ss++;
  for (i = 0; i < nlines; i++) {
    p = strstr(ss, "\\cr");
    if (p) {
      size_t n = p - ss + 1;
      lines[i] = (char *)malloc(n * sizeof(char));
      my_strlcpy(lines[i], ss, n);
      diagnostics(4, "line[%2d] = '%s'", i, lines[i]);
    }
    ss = p + 3;
    while (isspace(*ss))
      ss++;
  }
  *nl = nlines;
  *thelines = lines;
  *thetemplate = HA_template;
}


x86 assembly (clang, -O0):
<HA_ExtractTemplateAndLines>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
movq   $0x0,-0x38(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x30(%rbp)
movl   $0x0,-0x44(%rbp)
mov    -0x30(%rbp),%rdi
lea    0xe76(%rip),%rsi
call   1070 <strstr@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
je     11b7 <HA_ExtractTemplateAndLines+0x67>
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
mov    -0x28(%rbp),%rax
add    $0x3,%rax
mov    %rax,-0x30(%rbp)
jmp    117f <HA_ExtractTemplateAndLines+0x2f>
mov    -0x44(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x44(%rbp)
movslq -0x44(%rbp),%rdi
shl    $0x3,%rdi
call   1060 <malloc@plt>
mov    %rax,-0x40(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe24(%rip),%rsi
call   1070 <strstr@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     123c <HA_ExtractTemplateAndLines+0xec>
mov    -0x28(%rbp),%rax
mov    -0x8(%rbp),%rcx
sub    %rcx,%rax
add    $0x1,%rax
mov    %rax,-0x50(%rbp)
mov    -0x50(%rbp),%rdi
shl    $0x0,%rdi
call   1060 <malloc@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x50(%rbp),%rdx
call   1030 <my_strlcpy@plt>
mov    -0x38(%rbp),%rdx
mov    $0x4,%edi
lea    0xdcf(%rip),%rsi
mov    $0x0,%al
call   1050 <diagnostics@plt>
mov    -0x28(%rbp),%rax
add    $0x3,%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
movsbl (%rax),%edi
call   1040 <isspace@plt>
cmp    $0x0,%rax
je     126f <HA_ExtractTemplateAndLines+0x11f>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    1248 <HA_ExtractTemplateAndLines+0xf8>
movl   $0x0,-0x48(%rbp)
mov    -0x48(%rbp),%eax
cmp    -0x44(%rbp),%eax
jge    1351 <HA_ExtractTemplateAndLines+0x201>
mov    -0x30(%rbp),%rdi
lea    0xd73(%rip),%rsi
call   1070 <strstr@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     130b <HA_ExtractTemplateAndLines+0x1bb>
mov    -0x28(%rbp),%rax
mov    -0x30(%rbp),%rcx
sub    %rcx,%rax
add    $0x1,%rax
mov    %rax,-0x58(%rbp)
mov    -0x58(%rbp),%rdi
shl    $0x0,%rdi
call   1060 <malloc@plt>
mov    %rax,%rdx
mov    -0x40(%rbp),%rax
movslq -0x48(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x40(%rbp),%rax
movslq -0x48(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x58(%rbp),%rdx
call   1030 <my_strlcpy@plt>
mov    -0x48(%rbp),%edx
mov    -0x40(%rbp),%rax
movslq -0x48(%rbp),%rcx
mov    (%rax,%rcx,8),%rcx
mov    $0x4,%edi
lea    0xd13(%rip),%rsi
mov    $0x0,%al
call   1050 <diagnostics@plt>
mov    -0x28(%rbp),%rax
add    $0x3,%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
movsbl (%rax),%edi
call   1040 <isspace@plt>
cmp    $0x0,%rax
je     133e <HA_ExtractTemplateAndLines+0x1ee>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    1317 <HA_ExtractTemplateAndLines+0x1c7>
jmp    1343 <HA_ExtractTemplateAndLines+0x1f3>
mov    -0x48(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x48(%rbp)
jmp    1276 <HA_ExtractTemplateAndLines+0x126>
mov    -0x44(%rbp),%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x40(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x38(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<HA_ExtractTemplateAndLines>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rcx,0x10(%rsp)
mov    %rdx,0x18(%rsp)
mov    %rsi,0x20(%rsp)
mov    %rdi,%r12
lea    0xe89(%rip),%rsi
call   1070 <strstr@plt>
xor    %ebx,%ebx
test   %rax,%rax
je     11a7 <HA_ExtractTemplateAndLines+0x57>
lea    0xe76(%rip),%rbp
nopw   0x0(%rax,%rax,1)
add    $0x1,%ebx
add    $0x3,%rax
mov    %rax,%rdi
mov    %rbp,%rsi
call   1070 <strstr@plt>
test   %rax,%rax
jne    1190 <HA_ExtractTemplateAndLines+0x40>
movslq %ebx,%rax
lea    -0x8(,%rax,8),%rdi
ff
call   1060 <malloc@plt>
mov    %rax,%r14
lea    0xe3f(%rip),%rsi
mov    %r12,%rdi
call   1070 <strstr@plt>
mov    %rax,%rbp
test   %rax,%rax
je     1211 <HA_ExtractTemplateAndLines+0xc1>
mov    %rbp,%r15
sub    %r12,%r15
add    $0x1,%r15
mov    %r15,%rdi
call   1060 <malloc@plt>
mov    %rax,%r13
mov    %rax,%rdi
mov    %r12,%rsi
mov    %r15,%rdx
call   1030 <my_strlcpy@plt>
lea    0xe09(%rip),%rsi
mov    $0x4,%edi
mov    %r13,0x8(%rsp)
mov    %r13,%rdx
xor    %eax,%eax
call   1050 <diagnostics@plt>
jmp    1218 <HA_ExtractTemplateAndLines+0xc8>
xor    %eax,%eax
mov    %rax,0x8(%rsp)
lea    -0x1(%rbx),%eax
mov    %eax,0x4(%rsp)
add    $0x2,%rbp
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movsbl 0x1(%rbp),%edi
add    $0x1,%rbp
call   1040 <isspace@plt>
test   %rax,%rax
jne    1230 <HA_ExtractTemplateAndLines+0xe0>
cmp    $0x2,%ebx
jl     12db <HA_ExtractTemplateAndLines+0x18b>
mov    0x4(%rsp),%ebx
xor    %r12d,%r12d
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rbp,%rdi
lea    0xd96(%rip),%rsi
call   1070 <strstr@plt>
mov    %rax,%r15
test   %rax,%rax
je     12b5 <HA_ExtractTemplateAndLines+0x165>
mov    %r15,%r13
sub    %rbp,%r13
add    $0x1,%r13
mov    %r13,%rdi
call   1060 <malloc@plt>
mov    %rax,(%r14,%r12,8)
mov    %rax,%rdi
mov    %rbp,%rsi
mov    %r13,%rdx
call   1030 <my_strlcpy@plt>
mov    (%r14,%r12,8),%rcx
mov    $0x4,%edi
lea    0xd6c(%rip),%rsi
mov    %r12d,%edx
xor    %eax,%eax
call   1050 <diagnostics@plt>
add    $0x2,%r15
mov    %r15,%rbp
nopl   0x0(%rax)
movsbl 0x1(%rbp),%edi
add    $0x1,%rbp
call   1040 <isspace@plt>
test   %rax,%rax
jne    12c0 <HA_ExtractTemplateAndLines+0x170>
add    $0x1,%r12
cmp    %rbx,%r12
jne    1260 <HA_ExtractTemplateAndLines+0x110>
mov    0x10(%rsp),%rax
mov    0x4(%rsp),%ecx
mov    %ecx,(%rax)
mov    0x18(%rsp),%rax
mov    %r14,(%rax)
mov    0x20(%rsp),%rax
mov    0x8(%rsp),%rcx
mov    %rcx,(%rax)
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"\\cr\00"
@.str.1 = [19 x i8] c"HA_template = '%s'\00"
@.str.2 = [17 x i8] c"line[%2d] = '%s'\00"
define void @HA_ExtractTemplateAndLines(i8* %0, i8** %1, i8*** %2, i32* %3) {
%5 = alloca i8*
%6 = alloca i8**
%7 = alloca i8***
%8 = alloca i32*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i8**
%13 = alloca i32
%14 = alloca i32
%15 = alloca i64
%16 = alloca i64
store i8* %0, i8** %5
store i8** %1, i8*** %6
store i8*** %2, i8**** %7
store i32* %3, i32** %8
store i8* null, i8** %11
%17 = load i8*, i8** %5
store i8* %17, i8** %10
store i32 0, i32* %13
br label %18
18: ; preds = %22, %4
%19 = load i8*, i8** %10
%20 = call i8* @strstr(i8* %19, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
store i8* %20, i8** %9
%21 = icmp ne i8* %20, null
br i1 %21, label %22, label %27
22: ; preds = %18
%23 = load i32, i32* %13
%24 = add nsw i32 %23, 1
store i32 %24, i32* %13
%25 = load i8*, i8** %9
%26 = getelementptr inbounds i8, i8* %25, i64 3
store i8* %26, i8** %10
br label %18
27: ; preds = %18
%28 = load i32, i32* %13
%29 = add nsw i32 %28, -1
store i32 %29, i32* %13
%30 = load i32, i32* %13
%31 = sext i32 %30 to i64
%32 = mul i64 %31, 8
%33 = call i64 @malloc(i64 %32)
%34 = inttoptr i64 %33 to i8**
store i8** %34, i8*** %12
%35 = load i8*, i8** %5
%36 = call i8* @strstr(i8* %35, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
store i8* %36, i8** %9
%37 = load i8*, i8** %9
%38 = icmp ne i8* %37, null
br i1 %38, label %39, label %56
39: ; preds = %27
%40 = load i8*, i8** %9
%41 = load i8*, i8** %5
%42 = ptrtoint i8* %40 to i64
%43 = ptrtoint i8* %41 to i64
%44 = sub i64 %42, %43
%45 = add nsw i64 %44, 1
store i64 %45, i64* %15
%46 = load i64, i64* %15
%47 = mul i64 %46, 1
%48 = call i64 @malloc(i64 %47)
%49 = inttoptr i64 %48 to i8*
store i8* %49, i8** %11
%50 = load i8*, i8** %11
%51 = load i8*, i8** %5
%52 = load i64, i64* %15
%53 = call i32 @my_strlcpy(i8* %50, i8* %51, i64 %52)
%54 = load i8*, i8** %11
%55 = call i32 (i32, i8*, ...) @diagnostics(i32 4, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* %54)
br label %56
56: ; preds = %39, %27
%57 = load i8*, i8** %9
%58 = getelementptr inbounds i8, i8* %57, i64 3
store i8* %58, i8** %10
br label %59
59: ; preds = %64, %56
%60 = load i8*, i8** %10
%61 = load i8, i8* %60
%62 = call i64 @isspace(i8 signext %61)
%63 = icmp ne i64 %62, 0
br i1 %63, label %64, label %67
64: ; preds = %59
%65 = load i8*, i8** %10
%66 = getelementptr inbounds i8, i8* %65, i32 1
store i8* %66, i8** %10
br label %59
67: ; preds = %59
store i32 0, i32* %14
br label %68
68: ; preds = %119, %67
%69 = load i32, i32* %14
%70 = load i32, i32* %13
%71 = icmp slt i32 %69, %70
br i1 %71, label %72, label %122
72: ; preds = %68
%73 = load i8*, i8** %10
%74 = call i8* @strstr(i8* %73, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
store i8* %74, i8** %9
%75 = load i8*, i8** %9
%76 = icmp ne i8* %75, null
br i1 %76, label %77, label %107
77: ; preds = %72
%78 = load i8*, i8** %9
%79 = load i8*, i8** %10
%80 = ptrtoint i8* %78 to i64
%81 = ptrtoint i8* %79 to i64
%82 = sub i64 %80, %81
%83 = add nsw i64 %82, 1
store i64 %83, i64* %16
%84 = load i64, i64* %16
%85 = mul i64 %84, 1
%86 = call i64 @malloc(i64 %85)
%87 = inttoptr i64 %86 to i8*
%88 = load i8**, i8*** %12
%89 = load i32, i32* %14
%90 = sext i32 %89 to i64
%91 = getelementptr inbounds i8*, i8** %88, i64 %90
store i8* %87, i8** %91
%92 = load i8**, i8*** %12
%93 = load i32, i32* %14
%94 = sext i32 %93 to i64
%95 = getelementptr inbounds i8*, i8** %92, i64 %94
%96 = load i8*, i8** %95
%97 = load i8*, i8** %10
%98 = load i64, i64* %16
%99 = call i32 @my_strlcpy(i8* %96, i8* %97, i64 %98)
%100 = load i32, i32* %14
%101 = load i8**, i8*** %12
%102 = load i32, i32* %14
%103 = sext i32 %102 to i64
%104 = getelementptr inbounds i8*, i8** %101, i64 %103
%105 = load i8*, i8** %104
%106 = call i32 (i32, i8*, ...) @diagnostics(i32 4, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i32 %100, i8* %105)
br label %107
107: ; preds = %77, %72
%108 = load i8*, i8** %9
%109 = getelementptr inbounds i8, i8* %108, i64 3
store i8* %109, i8** %10
br label %110
110: ; preds = %115, %107
%111 = load i8*, i8** %10
%112 = load i8, i8* %111
%113 = call i64 @isspace(i8 signext %112)
%114 = icmp ne i64 %113, 0
br i1 %114, label %115, label %118
115: ; preds = %110
%116 = load i8*, i8** %10
%117 = getelementptr inbounds i8, i8* %116, i32 1
store i8* %117, i8** %10
br label %110
118: ; preds = %110
br label %119
119: ; preds = %118
%120 = load i32, i32* %14
%121 = add nsw i32 %120, 1
store i32 %121, i32* %14
br label %68
122: ; preds = %68
%123 = load i32, i32* %13
%124 = load i32*, i32** %8
store i32 %123, i32* %124
%125 = load i8**, i8*** %12
%126 = load i8***, i8**** %7
store i8** %125, i8*** %126
%127 = load i8*, i8** %11
%128 = load i8**, i8*** %6
store i8* %127, i8** %128
ret void
}

LLVM IR (-O2):
@.str = [4 x i8] c"\\cr\00"
@.str.1 = [19 x i8] c"HA_template = '%s'\00"
@.str.2 = [17 x i8] c"line[%2d] = '%s'\00"
define void @HA_ExtractTemplateAndLines(i8* %0, i8** nocapture writeonly %1, i8*** nocapture writeonly %2, i32* nocapture writeonly %3) {
%5 = tail call i8* @strstr(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i8* %5, null
br i1 %6, label %14, label %7
7: ; preds = %4, %7
%8 = phi i8* [ %12, %7 ], [ %5, %4 ]
%9 = phi i32 [ %10, %7 ], [ 0, %4 ]
%10 = add nuw nsw i32 %9, 1
%11 = getelementptr inbounds i8, i8* %8, i64 3
%12 = tail call i8* @strstr(i8* dereferenceable(1) %11, i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%13 = icmp eq i8* %12, null
br i1 %13, label %14, label %7
14: ; preds = %7, %4
%15 = phi i32 [ 0, %4 ], [ %10, %7 ]
%16 = add nsw i32 %15, -1
%17 = sext i32 %16 to i64
%18 = shl nsw i64 %17, 3
%19 = tail call i64 @malloc(i64 %18)
%20 = inttoptr i64 %19 to i8**
%21 = tail call i8* @strstr(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%22 = icmp eq i8* %21, null
br i1 %22, label %32, label %23
23: ; preds = %14
%24 = ptrtoint i8* %21 to i64
%25 = ptrtoint i8* %0 to i64
%26 = sub i64 %24, %25
%27 = add nsw i64 %26, 1
%28 = tail call i64 @malloc(i64 %27)
%29 = inttoptr i64 %28 to i8*
%30 = tail call i32 @my_strlcpy(i8* %29, i8* %0, i64 %27)
%31 = tail call i32 (i32, i8*, ...) @diagnostics(i32 4, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* %29)
br label %32
32: ; preds = %23, %14
%33 = phi i8* [ %29, %23 ], [ null, %14 ]
%34 = getelementptr inbounds i8, i8* %21, i64 3
br label %35
35: ; preds = %35, %32
%36 = phi i8* [ %34, %32 ], [ %40, %35 ]
%37 = load i8, i8* %36
%38 = tail call i64 @isspace(i8 signext %37)
%39 = icmp eq i64 %38, 0
%40 = getelementptr inbounds i8, i8* %36, i64 1
br i1 %39, label %41, label %35
41: ; preds = %35
%42 = icmp sgt i32 %15, 1
br i1 %42, label %43, label %73
43: ; preds = %41
%44 = zext i32 %16 to i64
br label %45
45: ; preds = %43, %70
%46 = phi i64 [ 0, %43 ], [ %71, %70 ]
%47 = phi i8* [ %36, %43 ], [ %65, %70 ]
%48 = tail call i8* @strstr(i8* %47, i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%49 = icmp eq i8* %48, null
br i1 %49, label %62, label %50
50: ; preds = %45
%51 = ptrtoint i8* %48 to i64
%52 = ptrtoint i8* %47 to i64
%53 = sub i64 %51, %52
%54 = add nsw i64 %53, 1
%55 = tail call i64 @malloc(i64 %54)
%56 = inttoptr i64 %55 to i8*
%57 = getelementptr inbounds i8*, i8** %20, i64 %46
store i8* %56, i8** %57
%58 = tail call i32 @my_strlcpy(i8* %56, i8* %47, i64 %54)
%59 = load i8*, i8** %57
%60 = trunc i64 %46 to i32
%61 = tail call i32 (i32, i8*, ...) @diagnostics(i32 4, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i32 %60, i8* %59)
br label %62
62: ; preds = %50, %45
%63 = getelementptr inbounds i8, i8* %48, i64 3
br label %64
64: ; preds = %64, %62
%65 = phi i8* [ %63, %62 ], [ %69, %64 ]
%66 = load i8, i8* %65
%67 = tail call i64 @isspace(i8 signext %66)
%68 = icmp eq i64 %67, 0
%69 = getelementptr inbounds i8, i8* %65, i64 1
br i1 %68, label %70, label %64
70: ; preds = %64
%71 = add nuw nsw i64 %46, 1
%72 = icmp eq i64 %71, %44
br i1 %72, label %73, label %45
73: ; preds = %70, %41
store i32 %16, i32* %3
store i8** %20, i8*** %2
store i8* %33, i8** %1
ret void
}