#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 *my_strdup(char *);
char *strstr(char const *, char *);
char *HA_ExpandCellWithTemplate(const char *HA_template, const char *cell) {
  char buffer[500];
  char *s, *t, *b, *text;
  t = (char *)HA_template;
  b = buffer;
  if ((s = strstr(cell, "\\omit")) != 0) {
    text = my_strdup(s + 5);
    return text;
  }
  while (*t != '\0') {
    if (*t != '#') {
      *b = *t;
      b++;
    } else {
      s = (char *)cell;
      while (*s) {
        *b = *s;
        b++;
        s++;
      }
    }
    t++;
  }
  *b = '\0';
  text = my_strdup(buffer);
  return text;
}


x86 assembly (clang, -O0):
<HA_ExpandCellWithTemplate>:
push   %rbp
mov    %rsp,%rbp
sub    $0x230,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x220(%rbp)
lea    -0x210(%rbp),%rax
mov    %rax,-0x228(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xea9(%rip),%rsi
call   1040 <strstr@plt>
mov    %rax,-0x218(%rbp)
cmp    $0x0,%rax
je     1194 <HA_ExpandCellWithTemplate+0x74>
mov    -0x218(%rbp),%rdi
add    $0x5,%rdi
call   1030 <my_strdup@plt>
mov    %rax,-0x230(%rbp)
mov    -0x230(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1282 <HA_ExpandCellWithTemplate+0x162>
jmp    1199 <HA_ExpandCellWithTemplate+0x79>
mov    -0x220(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     125a <HA_ExpandCellWithTemplate+0x13a>
mov    -0x220(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x23,%eax
je     11e8 <HA_ExpandCellWithTemplate+0xc8>
mov    -0x220(%rbp),%rax
mov    (%rax),%cl
mov    -0x228(%rbp),%rax
mov    %cl,(%rax)
mov    -0x228(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x228(%rbp)
jmp    1243 <HA_ExpandCellWithTemplate+0x123>
mov    -0x18(%rbp),%rax
mov    %rax,-0x218(%rbp)
mov    -0x218(%rbp),%rax
cmpb   $0x0,(%rax)
je     123e <HA_ExpandCellWithTemplate+0x11e>
mov    -0x218(%rbp),%rax
mov    (%rax),%cl
mov    -0x228(%rbp),%rax
mov    %cl,(%rax)
mov    -0x228(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x228(%rbp)
mov    -0x218(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x218(%rbp)
jmp    11f3 <HA_ExpandCellWithTemplate+0xd3>
jmp    1243 <HA_ExpandCellWithTemplate+0x123>
mov    -0x220(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x220(%rbp)
jmp    1199 <HA_ExpandCellWithTemplate+0x79>
mov    -0x228(%rbp),%rax
movb   $0x0,(%rax)
lea    -0x210(%rbp),%rdi
call   1030 <my_strdup@plt>
mov    %rax,-0x230(%rbp)
mov    -0x230(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x230,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<HA_ExpandCellWithTemplate>:
push   %r14
push   %rbx
sub    $0x1f8,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
lea    0xec9(%rip),%rsi
mov    %r14,%rdi
call   1040 <strstr@plt>
test   %rax,%rax
je     115a <HA_ExpandCellWithTemplate+0x3a>
add    $0x5,%rax
mov    %rax,%rdi
add    $0x1f8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <my_strdup@plt>
mov    %rsp,%rax
lea    0x1(%r14),%rsi
jmp    1174 <HA_ExpandCellWithTemplate+0x54>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
add    $0x1,%rbx
mov    (%rbx),%cl
cmp    $0x23,%cl
je     1190 <HA_ExpandCellWithTemplate+0x70>
test   %cl,%cl
je     11b3 <HA_ExpandCellWithTemplate+0x93>
mov    %cl,(%rax)
add    $0x1,%rax
add    $0x1,%rbx
jmp    1174 <HA_ExpandCellWithTemplate+0x54>
nopl   0x0(%rax,%rax,1)
mov    (%r14),%cl
mov    %rsi,%rdx
test   %cl,%cl
je     1170 <HA_ExpandCellWithTemplate+0x50>
nopw   0x0(%rax,%rax,1)
mov    %cl,(%rax)
add    $0x1,%rax
movzbl (%rdx),%ecx
add    $0x1,%rdx
test   %cl,%cl
jne    11a0 <HA_ExpandCellWithTemplate+0x80>
jmp    1170 <HA_ExpandCellWithTemplate+0x50>
movb   $0x0,(%rax)
mov    %rsp,%rdi
call   1030 <my_strdup@plt>
add    $0x1f8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [6 x i8] c"\\omit\00"
define i8* @HA_ExpandCellWithTemplate(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca [500 x i8]
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
%11 = load i8*, i8** %4
store i8* %11, i8** %8
%12 = getelementptr inbounds [500 x i8], [500 x i8]* %6, i64 0, i64 0
store i8* %12, i8** %9
%13 = load i8*, i8** %5
%14 = call i8* @strstr(i8* %13, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
store i8* %14, i8** %7
%15 = icmp ne i8* %14, null
br i1 %15, label %16, label %21
16: ; preds = %2
%17 = load i8*, i8** %7
%18 = getelementptr inbounds i8, i8* %17, i64 5
%19 = call i8* @my_strdup(i8* %18)
store i8* %19, i8** %10
%20 = load i8*, i8** %10
store i8* %20, i8** %3
br label %61
21: ; preds = %2
br label %22
22: ; preds = %53, %21
%23 = load i8*, i8** %8
%24 = load i8, i8* %23
%25 = sext i8 %24 to i32
%26 = icmp ne i32 %25, 0
br i1 %26, label %27, label %56
27: ; preds = %22
%28 = load i8*, i8** %8
%29 = load i8, i8* %28
%30 = sext i8 %29 to i32
%31 = icmp ne i32 %30, 35
br i1 %31, label %32, label %38
32: ; preds = %27
%33 = load i8*, i8** %8
%34 = load i8, i8* %33
%35 = load i8*, i8** %9
store i8 %34, i8* %35
%36 = load i8*, i8** %9
%37 = getelementptr inbounds i8, i8* %36, i32 1
store i8* %37, i8** %9
br label %53
38: ; preds = %27
%39 = load i8*, i8** %5
store i8* %39, i8** %7
br label %40
40: ; preds = %44, %38
%41 = load i8*, i8** %7
%42 = load i8, i8* %41
%43 = icmp ne i8 %42, 0
br i1 %43, label %44, label %52
44: ; preds = %40
%45 = load i8*, i8** %7
%46 = load i8, i8* %45
%47 = load i8*, i8** %9
store i8 %46, i8* %47
%48 = load i8*, i8** %9
%49 = getelementptr inbounds i8, i8* %48, i32 1
store i8* %49, i8** %9
%50 = load i8*, i8** %7
%51 = getelementptr inbounds i8, i8* %50, i32 1
store i8* %51, i8** %7
br label %40
52: ; preds = %40
br label %53
53: ; preds = %52, %32
%54 = load i8*, i8** %8
%55 = getelementptr inbounds i8, i8* %54, i32 1
store i8* %55, i8** %8
br label %22
56: ; preds = %22
%57 = load i8*, i8** %9
store i8 0, i8* %57
%58 = getelementptr inbounds [500 x i8], [500 x i8]* %6, i64 0, i64 0
%59 = call i8* @my_strdup(i8* %58)
store i8* %59, i8** %10
%60 = load i8*, i8** %10
store i8* %60, i8** %3
br label %61
61: ; preds = %56, %16
%62 = load i8*, i8** %3
ret i8* %62
}

LLVM IR (-O2):
@.str = [6 x i8] c"\\omit\00"
define i8* @HA_ExpandCellWithTemplate(i8* nocapture %0, i8* %1) {
%3 = alloca [500 x i8]
%4 = getelementptr inbounds [500 x i8], [500 x i8]* %3, i64 0, i64 0
%5 = tail call i8* @strstr(i8* dereferenceable(1) %1, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i8* %5, null
br i1 %6, label %10, label %7
7: ; preds = %2
%8 = getelementptr inbounds i8, i8* %5, i64 5
%9 = tail call i8* @my_strdup(i8* %8)
br label %32
10: ; preds = %2, %27
%11 = phi i8* [ %29, %27 ], [ %0, %2 ]
%12 = phi i8* [ %28, %27 ], [ %4, %2 ]
%13 = load i8, i8* %11
switch i8 %13, label %17 [
i8 0, label %30
i8 35, label %14
]
14: ; preds = %10
%15 = load i8, i8* %1
%16 = icmp eq i8 %15, 0
br i1 %16, label %27, label %19
17: ; preds = %10
store i8 %13, i8* %12
%18 = getelementptr inbounds i8, i8* %12, i64 1
br label %27
19: ; preds = %14, %19
%20 = phi i8 [ %25, %19 ], [ %15, %14 ]
%21 = phi i8* [ %23, %19 ], [ %12, %14 ]
%22 = phi i8* [ %24, %19 ], [ %1, %14 ]
store i8 %20, i8* %21
%23 = getelementptr inbounds i8, i8* %21, i64 1
%24 = getelementptr inbounds i8, i8* %22, i64 1
%25 = load i8, i8* %24
%26 = icmp eq i8 %25, 0
br i1 %26, label %27, label %19
27: ; preds = %19, %14, %17
%28 = phi i8* [ %18, %17 ], [ %12, %14 ], [ %23, %19 ]
%29 = getelementptr inbounds i8, i8* %11, i64 1
br label %10
30: ; preds = %10
store i8 0, i8* %12
%31 = call i8* @my_strdup(i8* %4)
br label %32
32: ; preds = %30, %7
%33 = phi i8* [ %9, %7 ], [ %31, %30 ]
ret i8* %33
}