#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 *HA_GetCellTemplateN(char const *, int, int, int);
int /*<<< orphan*/ free(char *);
scalar_t__ isspace(char);
scalar_t__ malloc(int);
scalar_t__ strncmp(char *, char *, int);
int /*<<< orphan*/ *strstr(char *, char *);
char *HA_AlignFromTemplate(const char *HA_template, int ncols, int tcols,
                           int trepeat) {
  char *s, *cell, *align;
  int i;
  align = (char *)malloc((ncols + 2) * sizeof(char));
  align[0] = '*';
  align[ncols + 1] = '\0';
  for (i = 1; i <= ncols; i++) {
    cell = HA_GetCellTemplateN(HA_template, i, tcols, trepeat);
    align[i] = 'l';
    s = cell;
    while (isspace(*s))
      s++;
    if (strncmp(s, "\\hfil", 5) == 0) {
      if (strstr(s + 5, "\\hfil") != NULL)
        align[i] = 'c';
      else
        align[i] = 'r';
    }
    free(cell);
  }
  return align;
}


x86 assembly (clang, -O0):
<HA_AlignFromTemplate>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
mov    -0xc(%rbp),%eax
add    $0x2,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
movb   $0x2a,(%rax)
mov    -0x30(%rbp),%rax
mov    -0xc(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
movl   $0x1,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0xc(%rbp),%eax
jg     127e <HA_AlignFromTemplate+0x11e>
mov    -0x8(%rbp),%rdi
mov    -0x34(%rbp),%esi
mov    -0x10(%rbp),%edx
mov    -0x14(%rbp),%ecx
call   1030 <HA_GetCellTemplateN@plt>
mov    %rax,-0x28(%rbp)
mov    -0x30(%rbp),%rax
movslq -0x34(%rbp),%rcx
movb   $0x6c,(%rax,%rcx,1)
mov    -0x28(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movsbl (%rax),%edi
call   1060 <isspace@plt>
cmp    $0x0,%rax
je     1208 <HA_AlignFromTemplate+0xa8>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    11e1 <HA_AlignFromTemplate+0x81>
mov    -0x20(%rbp),%rdi
lea    0xded(%rip),%rsi
mov    $0x5,%edx
call   1050 <strncmp@plt>
cmp    $0x0,%rax
jne    1267 <HA_AlignFromTemplate+0x107>
mov    -0x20(%rbp),%rdi
add    $0x5,%rdi
lea    0xdca(%rip),%rsi
call   1080 <strstr@plt>
cmp    $0x0,%rax
je     1256 <HA_AlignFromTemplate+0xf6>
mov    -0x30(%rbp),%rax
movslq -0x34(%rbp),%rcx
movb   $0x63,(%rax,%rcx,1)
jmp    1262 <HA_AlignFromTemplate+0x102>
mov    -0x30(%rbp),%rax
movslq -0x34(%rbp),%rcx
movb   $0x72,(%rax,%rcx,1)
jmp    1267 <HA_AlignFromTemplate+0x107>
mov    -0x28(%rbp),%rdi
call   1040 <free@plt>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    11ab <HA_AlignFromTemplate+0x4b>
mov    -0x30(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<HA_AlignFromTemplate>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %ecx,0x4(%rsp)
mov    %edx,(%rsp)
mov    %esi,%ebx
mov    %rdi,%r12
lea    0x2(%rbx),%edi
call   1070 <malloc@plt>
mov    %rax,%rbp
movb   $0x2a,(%rax)
lea    0x1(%rbx),%eax
movslq %eax,%rcx
movb   $0x0,0x0(%rbp,%rcx,1)
test   %ebx,%ebx
jle    1248 <HA_AlignFromTemplate+0xe8>
mov    %eax,%r15d
mov    $0x1,%ebx
jmp    11c5 <HA_AlignFromTemplate+0x65>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r14,%rdi
call   1040 <free@plt>
add    $0x1,%rbx
cmp    %r15,%rbx
je     1248 <HA_AlignFromTemplate+0xe8>
mov    %r12,%rdi
mov    %ebx,%esi
mov    (%rsp),%edx
mov    0x4(%rsp),%ecx
call   1030 <HA_GetCellTemplateN@plt>
mov    %rax,%r14
movb   $0x6c,0x0(%rbp,%rbx,1)
mov    %rax,%r13
add    $0xffffffffffffffff,%r13
cs nopw 0x0(%rax,%rax,1)
nop
movsbl 0x1(%r13),%edi
add    $0x1,%r13
call   1060 <isspace@plt>
test   %rax,%rax
jne    11f0 <HA_AlignFromTemplate+0x90>
mov    %r13,%rdi
lea    0xdf3(%rip),%rsi
mov    $0x5,%edx
call   1050 <strncmp@plt>
test   %rax,%rax
jne    11b0 <HA_AlignFromTemplate+0x50>
add    $0x5,%r13
mov    %r13,%rdi
lea    0xdd6(%rip),%rsi
call   1080 <strstr@plt>
test   %rax,%rax
mov    $0x63,%eax
mov    $0x72,%ecx
cmove  %ecx,%eax
mov    %al,0x0(%rbp,%rbx,1)
jmp    11b0 <HA_AlignFromTemplate+0x50>
mov    %rbp,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [6 x i8] c"\\hfil\00"
define i8* @HA_AlignFromTemplate(i8* %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i32
store i8* %0, i8** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%13 = load i32, i32* %6
%14 = add nsw i32 %13, 2
%15 = sext i32 %14 to i64
%16 = mul i64 %15, 1
%17 = trunc i64 %16 to i32
%18 = call i64 @malloc(i32 %17)
%19 = inttoptr i64 %18 to i8*
store i8* %19, i8** %11
%20 = load i8*, i8** %11
%21 = getelementptr inbounds i8, i8* %20, i64 0
store i8 42, i8* %21
%22 = load i8*, i8** %11
%23 = load i32, i32* %6
%24 = add nsw i32 %23, 1
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8, i8* %22, i64 %25
store i8 0, i8* %26
store i32 1, i32* %12
br label %27
27: ; preds = %73, %4
%28 = load i32, i32* %12
%29 = load i32, i32* %6
%30 = icmp sle i32 %28, %29
br i1 %30, label %31, label %76
31: ; preds = %27
%32 = load i8*, i8** %5
%33 = load i32, i32* %12
%34 = load i32, i32* %7
%35 = load i32, i32* %8
%36 = call i8* @HA_GetCellTemplateN(i8* %32, i32 %33, i32 %34, i32 %35)
store i8* %36, i8** %10
%37 = load i8*, i8** %11
%38 = load i32, i32* %12
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i8, i8* %37, i64 %39
store i8 108, i8* %40
%41 = load i8*, i8** %10
store i8* %41, i8** %9
br label %42
42: ; preds = %47, %31
%43 = load i8*, i8** %9
%44 = load i8, i8* %43
%45 = call i64 @isspace(i8 signext %44)
%46 = icmp ne i64 %45, 0
br i1 %46, label %47, label %50
47: ; preds = %42
%48 = load i8*, i8** %9
%49 = getelementptr inbounds i8, i8* %48, i32 1
store i8* %49, i8** %9
br label %42
50: ; preds = %42
%51 = load i8*, i8** %9
%52 = call i64 @strncmp(i8* %51, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 5)
%53 = icmp eq i64 %52, 0
br i1 %53, label %54, label %70
54: ; preds = %50
%55 = load i8*, i8** %9
%56 = getelementptr inbounds i8, i8* %55, i64 5
%57 = call i32* @strstr(i8* %56, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%58 = icmp ne i32* %57, null
br i1 %58, label %59, label %64
59: ; preds = %54
%60 = load i8*, i8** %11
%61 = load i32, i32* %12
%62 = sext i32 %61 to i64
%63 = getelementptr inbounds i8, i8* %60, i64 %62
store i8 99, i8* %63
br label %69
64: ; preds = %54
%65 = load i8*, i8** %11
%66 = load i32, i32* %12
%67 = sext i32 %66 to i64
%68 = getelementptr inbounds i8, i8* %65, i64 %67
store i8 114, i8* %68
br label %69
69: ; preds = %64, %59
br label %70
70: ; preds = %69, %50
%71 = load i8*, i8** %10
%72 = call i32 @free(i8* %71)
br label %73
73: ; preds = %70
%74 = load i32, i32* %12
%75 = add nsw i32 %74, 1
store i32 %75, i32* %12
br label %27
76: ; preds = %27
%77 = load i8*, i8** %11
ret i8* %77
}

LLVM IR (-O2):
@.str = [6 x i8] c"\\hfil\00"
define i8* @HA_AlignFromTemplate(i8* %0, i32 %1, i32 %2, i32 %3) {
%5 = add nsw i32 %1, 2
%6 = tail call i64 @malloc(i32 %5)
%7 = inttoptr i64 %6 to i8*
store i8 42, i8* %7
%8 = add i32 %1, 1
%9 = sext i32 %8 to i64
%10 = getelementptr inbounds i8, i8* %7, i64 %9
store i8 0, i8* %10
%11 = icmp slt i32 %1, 1
br i1 %11, label %37, label %12
12: ; preds = %4
%13 = zext i32 %8 to i64
br label %14
14: ; preds = %12, %33
%15 = phi i64 [ 1, %12 ], [ %35, %33 ]
%16 = trunc i64 %15 to i32
%17 = tail call i8* @HA_GetCellTemplateN(i8* %0, i32 %16, i32 %2, i32 %3)
%18 = getelementptr inbounds i8, i8* %7, i64 %15
store i8 108, i8* %18
br label %19
19: ; preds = %19, %14
%20 = phi i8* [ %17, %14 ], [ %24, %19 ]
%21 = load i8, i8* %20
%22 = tail call i64 @isspace(i8 signext %21)
%23 = icmp eq i64 %22, 0
%24 = getelementptr inbounds i8, i8* %20, i64 1
br i1 %23, label %25, label %19
25: ; preds = %19
%26 = tail call i64 @strncmp(i8* %20, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 5)
%27 = icmp eq i64 %26, 0
br i1 %27, label %28, label %33
28: ; preds = %25
%29 = getelementptr inbounds i8, i8* %20, i64 5
%30 = tail call i32* @strstr(i8* %29, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%31 = icmp eq i32* %30, null
%32 = select i1 %31, i8 114, i8 99
store i8 %32, i8* %18
br label %33
33: ; preds = %28, %25
%34 = tail call i32 @free(i8* %17)
%35 = add nuw nsw i64 %15, 1
%36 = icmp eq i64 %35, %13
br i1 %36, label %37, label %14
37: ; preds = %33, %4
ret i8* %7
}