#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*/ memset(char *, char, int);
scalar_t__ qfits_is_boolean(char *);
scalar_t__ qfits_is_complex(char *);
scalar_t__ qfits_is_float(char *);
scalar_t__ qfits_is_int(char *);
char const *qfits_pretty_string(char *);
int /*<<< orphan*/ sprintf(char *, char *, ...);
int /*<<< orphan*/ strcmp(char const *, char *);
int /*<<< orphan*/ strcpy(char *, char const *);
int strlen(char const *);
int /*<<< orphan*/ strncmp(char const *, char *, int);
int /*<<< orphan*/ strncpy(char *, char const *, int);
void qfits_card_build(char *line, const char *key, const char *val,
                      const char *com) {
  int len;
  int hierarch = 0;
  char cval[81];
  char cval2[81];
  char cval_q[81];
  char ccom[81];
  char safe_line[512];
  int i, j;
  if (line == NULL || key == NULL)
    return;
  memset(line, ' ', 80);
  if (key == NULL)
    return;
  if (!strcmp(key, "END")) {
    sprintf(line, "END");
    return;
  }
  if (!strcmp(key, "HISTORY") || !strcmp(key, "COMMENT") ||
      !strncmp(key, "        ", 8)) {
    sprintf(line, "%s ", key);
    if (val == NULL)
      return;
    len = strlen(val);
    if (len > 72)
      len = 72;
    strncpy(line + 8, val, len);
    return;
  }
  if (val == NULL)
    cval[0] = (char)0;
  else if (strlen(val) < 1)
    cval[0] = (char)0;
  else
    strcpy(cval, val);
  if (com == NULL)
    strcpy(ccom, "no comment");
  else
    strcpy(ccom, com);
  if (!strncmp(key, "HIERARCH", 8))
    hierarch++;
  if (qfits_is_int(cval) || qfits_is_float(cval) || qfits_is_boolean(cval) ||
      qfits_is_complex(cval)) {
    if (hierarch)
      sprintf(safe_line, "%-29s= %s / %s", key, cval, ccom);
    else
      sprintf(safe_line, "%-8.8s= %20s / %-48s", key, cval, ccom);
    strncpy(line, safe_line, 80);
    line[80] = (char)0;
    return;
  }
  if (cval[0] == 0) {
    if (hierarch) {
      sprintf(safe_line, "%-29s=                    / %s", key, ccom);
    } else {
      sprintf(safe_line, "%-8.8s=                      / %-48s", key, ccom);
    }
    strncpy(line, safe_line, 80);
    line[80] = (char)0;
    return;
  }
  memset(cval_q, 0, 81);
  strcpy(cval2, qfits_pretty_string(cval));
  j = 0;
  i = 0;
  while (cval2[i] != (char)0) {
    if (cval2[i] == '\'') {
      cval_q[j] = '\'';
      j++;
      cval_q[j] = '\'';
    } else {
      cval_q[j] = cval2[i];
    }
    i++;
    j++;
  }
  if (hierarch) {
    sprintf(safe_line, "%-29s= '%s' / %s", key, cval_q, ccom);
    if (strlen(key) + strlen(cval_q) + 3 >= 80)
      safe_line[79] = '\'';
  } else {
    sprintf(safe_line, "%-8.8s= '%-8s' / %s", key, cval_q, ccom);
  }
  strncpy(line, safe_line, 80);
  line[80] = (char)0;
  return;
}


x86 assembly (clang, -O0):
<qfits_card_build>:
push   %rbp
mov    %rsp,%rbp
sub    $0x3c0,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
movl   $0x0,-0x28(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     11f8 <qfits_card_build+0x38>
cmpq   $0x0,-0x10(%rbp)
jne    11fd <qfits_card_build+0x3d>
jmp    167a <qfits_card_build+0x4ba>
mov    -0x8(%rbp),%rdi
mov    $0x20,%esi
mov    $0x50,%edx
call   1080 <memset@plt>
cmpq   $0x0,-0x10(%rbp)
jne    1220 <qfits_card_build+0x60>
jmp    167a <qfits_card_build+0x4ba>
mov    -0x10(%rbp),%rdi
lea    0xdd5(%rip),%rsi
call   10a0 <strcmp@plt>
cmp    $0x0,%eax
jne    1250 <qfits_card_build+0x90>
mov    -0x8(%rbp),%rdi
lea    0xdbc(%rip),%rsi
mov    $0x0,%al
call   10d0 <sprintf@plt>
jmp    167a <qfits_card_build+0x4ba>
mov    -0x10(%rbp),%rdi
lea    0xda9(%rip),%rsi
call   10a0 <strcmp@plt>
cmp    $0x0,%eax
je     12a0 <qfits_card_build+0xe0>
mov    -0x10(%rbp),%rdi
lea    0xd98(%rip),%rsi
call   10a0 <strcmp@plt>
cmp    $0x0,%eax
je     12a0 <qfits_card_build+0xe0>
mov    -0x10(%rbp),%rdi
lea    0xd87(%rip),%rsi
mov    $0x8,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%eax
jne    12fc <qfits_card_build+0x13c>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xd6e(%rip),%rsi
mov    $0x0,%al
call   10d0 <sprintf@plt>
cmpq   $0x0,-0x18(%rbp)
jne    12c6 <qfits_card_build+0x106>
jmp    167a <qfits_card_build+0x4ba>
mov    -0x18(%rbp),%rdi
call   1070 <strlen@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x48,-0x24(%rbp)
jle    12e3 <qfits_card_build+0x123>
movl   $0x48,-0x24(%rbp)
mov    -0x8(%rbp),%rdi
add    $0x8,%rdi
mov    -0x18(%rbp),%rsi
mov    -0x24(%rbp),%edx
call   1030 <strncpy@plt>
jmp    167a <qfits_card_build+0x4ba>
cmpq   $0x0,-0x18(%rbp)
jne    1310 <qfits_card_build+0x150>
movb   $0x0,-0x80(%rbp)
jmp    133d <qfits_card_build+0x17d>
mov    -0x18(%rbp),%rdi
call   1070 <strlen@plt>
cmp    $0x1,%eax
jge    132b <qfits_card_build+0x16b>
movb   $0x0,-0x80(%rbp)
jmp    1338 <qfits_card_build+0x178>
lea    -0x80(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <strcpy@plt>
jmp    133d <qfits_card_build+0x17d>
cmpq   $0x0,-0x20(%rbp)
jne    1360 <qfits_card_build+0x1a0>
lea    -0x1a0(%rbp),%rdi
lea    0xccb(%rip),%rsi
call   1050 <strcpy@plt>
jmp    1370 <qfits_card_build+0x1b0>
lea    -0x1a0(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1050 <strcpy@plt>
mov    -0x10(%rbp),%rdi
lea    0xcb1(%rip),%rsi
mov    $0x8,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%eax
jne    1397 <qfits_card_build+0x1d7>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
lea    -0x80(%rbp),%rdi
call   10b0 <qfits_is_int@plt>
cmp    $0x0,%rax
jne    13e3 <qfits_card_build+0x223>
lea    -0x80(%rbp),%rdi
call   10c0 <qfits_is_float@plt>
cmp    $0x0,%rax
jne    13e3 <qfits_card_build+0x223>
lea    -0x80(%rbp),%rdi
call   10e0 <qfits_is_boolean@plt>
cmp    $0x0,%rax
jne    13e3 <qfits_card_build+0x223>
lea    -0x80(%rbp),%rdi
call   1090 <qfits_is_complex@plt>
cmp    $0x0,%rax
je     145c <qfits_card_build+0x29c>
cmpl   $0x0,-0x28(%rbp)
je     1416 <qfits_card_build+0x256>
lea    -0x3a0(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    -0x80(%rbp),%rcx
lea    -0x1a0(%rbp),%r8
lea    0xc2b(%rip),%rsi
mov    $0x0,%al
call   10d0 <sprintf@plt>
jmp    143a <qfits_card_build+0x27a>
lea    -0x3a0(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    -0x80(%rbp),%rcx
lea    -0x1a0(%rbp),%r8
lea    0xc11(%rip),%rsi
mov    $0x0,%al
call   10d0 <sprintf@plt>
mov    -0x8(%rbp),%rdi
lea    -0x3a0(%rbp),%rsi
mov    $0x50,%edx
call   1030 <strncpy@plt>
mov    -0x8(%rbp),%rax
movb   $0x0,0x50(%rax)
jmp    167a <qfits_card_build+0x4ba>
movsbl -0x80(%rbp),%eax
cmp    $0x0,%eax
jne    14da <qfits_card_build+0x31a>
cmpl   $0x0,-0x28(%rbp)
je     1498 <qfits_card_build+0x2d8>
lea    -0x3a0(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    -0x1a0(%rbp),%rcx
lea    0xbcd(%rip),%rsi
mov    $0x0,%al
call   10d0 <sprintf@plt>
jmp    14b8 <qfits_card_build+0x2f8>
lea    -0x3a0(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    -0x1a0(%rbp),%rcx
lea    0xbc7(%rip),%rsi
mov    $0x0,%al
call   10d0 <sprintf@plt>
mov    -0x8(%rbp),%rdi
lea    -0x3a0(%rbp),%rsi
mov    $0x50,%edx
call   1030 <strncpy@plt>
mov    -0x8(%rbp),%rax
movb   $0x0,0x50(%rax)
jmp    167a <qfits_card_build+0x4ba>
lea    -0x140(%rbp),%rdi
xor    %esi,%esi
mov    $0x51,%edx
call   1080 <memset@plt>
lea    -0xe0(%rbp),%rax
mov    %rax,-0x3b0(%rbp)
lea    -0x80(%rbp),%rdi
call   1060 <qfits_pretty_string@plt>
mov    -0x3b0(%rbp),%rdi
mov    %rax,%rsi
call   1050 <strcpy@plt>
movl   $0x0,-0x3a8(%rbp)
movl   $0x0,-0x3a4(%rbp)
movslq -0x3a4(%rbp),%rax
movsbl -0xe0(%rbp,%rax,1),%eax
ff
cmp    $0x0,%eax
je     15c8 <qfits_card_build+0x408>
movslq -0x3a4(%rbp),%rax
movsbl -0xe0(%rbp,%rax,1),%eax
ff
cmp    $0x27,%eax
jne    1589 <qfits_card_build+0x3c9>
movslq -0x3a8(%rbp),%rax
movb   $0x27,-0x140(%rbp,%rax,1)
27
mov    -0x3a8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3a8(%rbp)
movslq -0x3a8(%rbp),%rax
movb   $0x27,-0x140(%rbp,%rax,1)
27
jmp    15a5 <qfits_card_build+0x3e5>
movslq -0x3a4(%rbp),%rax
mov    -0xe0(%rbp,%rax,1),%cl
movslq -0x3a8(%rbp),%rax
mov    %cl,-0x140(%rbp,%rax,1)
mov    -0x3a4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3a4(%rbp)
mov    -0x3a8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3a8(%rbp)
jmp    1527 <qfits_card_build+0x367>
cmpl   $0x0,-0x28(%rbp)
je     1636 <qfits_card_build+0x476>
lea    -0x3a0(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    -0x140(%rbp),%rcx
lea    -0x1a0(%rbp),%r8
lea    0xaab(%rip),%rsi
mov    $0x0,%al
call   10d0 <sprintf@plt>
mov    -0x10(%rbp),%rdi
call   1070 <strlen@plt>
mov    %eax,-0x3b4(%rbp)
lea    -0x140(%rbp),%rdi
call   1070 <strlen@plt>
mov    %eax,%ecx
mov    -0x3b4(%rbp),%eax
add    %ecx,%eax
add    $0x3,%eax
cmp    $0x50,%eax
jl     1631 <qfits_card_build+0x471>
movb   $0x27,-0x351(%rbp)
jmp    165d <qfits_card_build+0x49d>
lea    -0x3a0(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    -0x140(%rbp),%rcx
lea    -0x1a0(%rbp),%r8
lea    0xa58(%rip),%rsi
mov    $0x0,%al
call   10d0 <sprintf@plt>
mov    -0x8(%rbp),%rdi
lea    -0x3a0(%rbp),%rsi
mov    $0x50,%edx
call   1030 <strncpy@plt>
mov    -0x8(%rbp),%rax
movb   $0x0,0x50(%rax)
add    $0x3c0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<qfits_card_build>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x380,%rsp
test   %rdi,%rdi
je     1386 <qfits_card_build+0x1c6>
mov    %rsi,%r15
test   %rsi,%rsi
je     1386 <qfits_card_build+0x1c6>
mov    %rcx,%r12
mov    %rdx,%rbx
mov    %rdi,%r14
mov    $0x20,%esi
mov    $0x50,%edx
call   1080 <memset@plt>
lea    0xdfd(%rip),%rsi
mov    %r15,%rdi
call   10a0 <strcmp@plt>
test   %eax,%eax
je     12d2 <qfits_card_build+0x112>
lea    0xdea(%rip),%rsi
mov    %r15,%rdi
call   10a0 <strcmp@plt>
test   %eax,%eax
je     1284 <qfits_card_build+0xc4>
lea    0xddf(%rip),%rsi
mov    %r15,%rdi
call   10a0 <strcmp@plt>
test   %eax,%eax
je     1284 <qfits_card_build+0xc4>
lea    0xdd4(%rip),%rsi
mov    %r15,%rdi
mov    $0x8,%edx
call   1040 <strncmp@plt>
test   %eax,%eax
je     1284 <qfits_card_build+0xc4>
test   %rbx,%rbx
je     12de <qfits_card_build+0x11e>
mov    %rbx,%rdi
call   1070 <strlen@plt>
test   %eax,%eax
jle    12de <qfits_card_build+0x11e>
mov    %rsp,%rdi
mov    %rbx,%rsi
call   1050 <strcpy@plt>
test   %r12,%r12
jne    12e7 <qfits_card_build+0x127>
lea    0xda4(%rip),%rsi
lea    0x60(%rsp),%rdi
jmp    12ef <qfits_card_build+0x12f>
lea    0xd92(%rip),%rsi
mov    %r14,%rdi
mov    %r15,%rdx
xor    %eax,%eax
call   10d0 <sprintf@plt>
test   %rbx,%rbx
je     1386 <qfits_card_build+0x1c6>
mov    %rbx,%rdi
call   1070 <strlen@plt>
cmp    $0x48,%eax
mov    $0x48,%edx
cmovl  %eax,%edx
add    $0x8,%r14
mov    %r14,%rdi
mov    %rbx,%rsi
add    $0x380,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <strncpy@plt>
movl   $0x444e45,(%r14)
jmp    1386 <qfits_card_build+0x1c6>
movb   $0x0,(%rsp)
test   %r12,%r12
je     1276 <qfits_card_build+0xb6>
lea    0x60(%rsp),%rdi
mov    %r12,%rsi
call   1050 <strcpy@plt>
lea    0xd31(%rip),%rsi
mov    %r15,%rdi
mov    $0x8,%edx
call   1040 <strncmp@plt>
mov    %eax,%r12d
mov    %rsp,%rdi
call   10b0 <qfits_is_int@plt>
test   %rax,%rax
jne    133f <qfits_card_build+0x17f>
mov    %rsp,%rdi
call   10c0 <qfits_is_float@plt>
test   %rax,%rax
jne    133f <qfits_card_build+0x17f>
mov    %rsp,%rdi
call   10e0 <qfits_is_boolean@plt>
test   %rax,%rax
jne    133f <qfits_card_build+0x17f>
mov    %rsp,%rdi
call   1090 <qfits_is_complex@plt>
test   %rax,%rax
je     1396 <qfits_card_build+0x1d6>
test   %r12d,%r12d
lea    0xcec(%rip),%rax
lea    0xcf4(%rip),%rsi
cmove  %rax,%rsi
lea    0x180(%rsp),%rbx
mov    %rsp,%rcx
lea    0x60(%rsp),%r8
mov    %rbx,%rdi
mov    %r15,%rdx
xor    %eax,%eax
call   10d0 <sprintf@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    $0x50,%edx
call   1030 <strncpy@plt>
movb   $0x0,0x50(%r14)
add    $0x380,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
cmpb   $0x0,(%rsp)
je     142c <qfits_card_build+0x26c>
lea    0xc0(%rsp),%rdi
xor    %ebp,%ebp
xor    %esi,%esi
mov    $0x51,%edx
call   1080 <memset@plt>
mov    %rsp,%rdi
call   1060 <qfits_pretty_string@plt>
lea    0x120(%rsp),%rbx
mov    %rbx,%rdi
mov    %rax,%rsi
call   1050 <strcpy@plt>
jmp    13f4 <qfits_card_build+0x234>
movslq %ebp,%rbp
movb   $0x27,0xc0(%rsp,%rbp,1)
27
add    $0x1,%ebp
mov    $0x27,%al
movslq %ebp,%rbp
mov    %al,0xc0(%rsp,%rbp,1)
add    $0x1,%ebp
add    $0x1,%rbx
movzbl (%rbx),%eax
cmp    $0x27,%al
je     13d3 <qfits_card_build+0x213>
test   %al,%al
jne    13e3 <qfits_card_build+0x223>
test   %r12d,%r12d
je     1460 <qfits_card_build+0x2a0>
lea    0xca3(%rip),%rsi
lea    0x180(%rsp),%rdi
lea    0xc0(%rsp),%rcx
lea    0x60(%rsp),%r8
mov    %r15,%rdx
xor    %eax,%eax
call   10d0 <sprintf@plt>
jmp    14aa <qfits_card_build+0x2ea>
test   %r12d,%r12d
lea    0xc23(%rip),%rax
lea    0xc3b(%rip),%rsi
cmove  %rax,%rsi
lea    0x180(%rsp),%rbx
lea    0x60(%rsp),%rcx
mov    %rbx,%rdi
mov    %r15,%rdx
xor    %eax,%eax
call   10d0 <sprintf@plt>
jmp    1371 <qfits_card_build+0x1b1>
lea    0xc36(%rip),%rsi
lea    0x180(%rsp),%rdi
lea    0xc0(%rsp),%rbx
lea    0x60(%rsp),%r8
mov    %r15,%rdx
mov    %rbx,%rcx
xor    %eax,%eax
call   10d0 <sprintf@plt>
mov    %r15,%rdi
call   1070 <strlen@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1070 <strlen@plt>
add    %ebp,%eax
cmp    $0x4d,%eax
jl     14aa <qfits_card_build+0x2ea>
movb   $0x27,0x1cf(%rsp)
27
lea    0x180(%rsp),%rsi
mov    %r14,%rdi
jmp    1377 <qfits_card_build+0x1b7>

LLVM IR (-O0):
@.str = [4 x i8] c"END\00"
@.str.1 = [8 x i8] c"HISTORY\00"
@.str.2 = [8 x i8] c"COMMENT\00"
@.str.3 = [9 x i8] c" \00"
@.str.4 = [4 x i8] c"%s \00"
@.str.5 = [11 x i8] c"no comment\00"
@.str.6 = [9 x i8] c"HIERARCH\00"
@.str.7 = [15 x i8] c"%-29s= %s / %s\00"
@.str.8 = [21 x i8] c"%-8.8s= %20s / %-48s\00"
@.str.9 = [31 x i8] c"%-29s= / %s\00"
@.str.10 = [37 x i8] c"%-8.8s= / %-48s\00"
@.str.11 = [17 x i8] c"%-29s= '%s' / %s\00"
@.str.12 = [20 x i8] c"%-8.8s= '%-8s' / %s\00"
define void @qfits_card_build(i8* %0, i8* %1, i8* %2, i8* %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
%11 = alloca [81 x i8]
%12 = alloca [81 x i8]
%13 = alloca [81 x i8]
%14 = alloca [81 x i8]
%15 = alloca [512 x i8]
%16 = alloca i32
%17 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
store i8* %3, i8** %8
store i32 0, i32* %10
%18 = load i8*, i8** %5
%19 = icmp eq i8* %18, null
br i1 %19, label %23, label %20
20: ; preds = %4
%21 = load i8*, i8** %6
%22 = icmp eq i8* %21, null
br i1 %22, label %23, label %24
23: ; preds = %20, %4
br label %236
24: ; preds = %20
%25 = load i8*, i8** %5
%26 = call i32 @memset(i8* %25, i8 signext 32, i32 80)
%27 = load i8*, i8** %6
%28 = icmp eq i8* %27, null
br i1 %28, label %29, label %30
29: ; preds = %24
br label %236
30: ; preds = %24
%31 = load i8*, i8** %6
%32 = call i32 @strcmp(i8* %31, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%33 = icmp ne i32 %32, 0
br i1 %33, label %37, label %34
34: ; preds = %30
%35 = load i8*, i8** %5
%36 = call i32 (i8*, i8*, ...) @sprintf(i8* %35, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
br label %236
37: ; preds = %30
%38 = load i8*, i8** %6
%39 = call i32 @strcmp(i8* %38, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%40 = icmp ne i32 %39, 0
br i1 %40, label %41, label %49
41: ; preds = %37
%42 = load i8*, i8** %6
%43 = call i32 @strcmp(i8* %42, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%44 = icmp ne i32 %43, 0
br i1 %44, label %45, label %49
45: ; preds = %41
%46 = load i8*, i8** %6
%47 = call i32 @strncmp(i8* %46, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i32 8)
%48 = icmp ne i32 %47, 0
br i1 %48, label %68, label %49
49: ; preds = %45, %41, %37
%50 = load i8*, i8** %5
%51 = load i8*, i8** %6
%52 = call i32 (i8*, i8*, ...) @sprintf(i8* %50, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %51)
%53 = load i8*, i8** %7
%54 = icmp eq i8* %53, null
br i1 %54, label %55, label %56
55: ; preds = %49
br label %236
56: ; preds = %49
%57 = load i8*, i8** %7
%58 = call i32 @strlen(i8* %57)
store i32 %58, i32* %9
%59 = load i32, i32* %9
%60 = icmp sgt i32 %59, 72
br i1 %60, label %61, label %62
61: ; preds = %56
store i32 72, i32* %9
br label %62
62: ; preds = %61, %56
%63 = load i8*, i8** %5
%64 = getelementptr inbounds i8, i8* %63, i64 8
%65 = load i8*, i8** %7
%66 = load i32, i32* %9
%67 = call i32 @strncpy(i8* %64, i8* %65, i32 %66)
br label %236
68: ; preds = %45
%69 = load i8*, i8** %7
%70 = icmp eq i8* %69, null
br i1 %70, label %71, label %73
71: ; preds = %68
%72 = getelementptr inbounds [81 x i8], [81 x i8]* %11, i64 0, i64 0
store i8 0, i8* %72
br label %84
73: ; preds = %68
%74 = load i8*, i8** %7
%75 = call i32 @strlen(i8* %74)
%76 = icmp slt i32 %75, 1
br i1 %76, label %77, label %79
77: ; preds = %73
%78 = getelementptr inbounds [81 x i8], [81 x i8]* %11, i64 0, i64 0
store i8 0, i8* %78
br label %83
79: ; preds = %73
%80 = getelementptr inbounds [81 x i8], [81 x i8]* %11, i64 0, i64 0
%81 = load i8*, i8** %7
%82 = call i32 @strcpy(i8* %80, i8* %81)
br label %83
83: ; preds = %79, %77
br label %84
84: ; preds = %83, %71
%85 = load i8*, i8** %8
%86 = icmp eq i8* %85, null
br i1 %86, label %87, label %90
87: ; preds = %84
%88 = getelementptr inbounds [81 x i8], [81 x i8]* %14, i64 0, i64 0
%89 = call i32 @strcpy(i8* %88, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0))
br label %94
90: ; preds = %84
%91 = getelementptr inbounds [81 x i8], [81 x i8]* %14, i64 0, i64 0
%92 = load i8*, i8** %8
%93 = call i32 @strcpy(i8* %91, i8* %92)
br label %94
94: ; preds = %90, %87
%95 = load i8*, i8** %6
%96 = call i32 @strncmp(i8* %95, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0), i32 8)
%97 = icmp ne i32 %96, 0
br i1 %97, label %101, label %98
98: ; preds = %94
%99 = load i32, i32* %10
%100 = add nsw i32 %99, 1
store i32 %100, i32* %10
br label %101
101: ; preds = %98, %94
%102 = getelementptr inbounds [81 x i8], [81 x i8]* %11, i64 0, i64 0
%103 = call i64 @qfits_is_int(i8* %102)
%104 = icmp ne i64 %103, 0
br i1 %104, label %117, label %105
105: ; preds = %101
%106 = getelementptr inbounds [81 x i8], [81 x i8]* %11, i64 0, i64 0
%107 = call i64 @qfits_is_float(i8* %106)
%108 = icmp ne i64 %107, 0
br i1 %108, label %117, label %109
109: ; preds = %105
%110 = getelementptr inbounds [81 x i8], [81 x i8]* %11, i64 0, i64 0
%111 = call i64 @qfits_is_boolean(i8* %110)
%112 = icmp ne i64 %111, 0
br i1 %112, label %117, label %113
113: ; preds = %109
%114 = getelementptr inbounds [81 x i8], [81 x i8]* %11, i64 0, i64 0
%115 = call i64 @qfits_is_complex(i8* %114)
%116 = icmp ne i64 %115, 0
br i1 %116, label %117, label %138
117: ; preds = %113, %109, %105, %101
%118 = load i32, i32* %10
%119 = icmp ne i32 %118, 0
br i1 %119, label %120, label %126
120: ; preds = %117
%121 = getelementptr inbounds [512 x i8], [512 x i8]* %15, i64 0, i64 0
%122 = load i8*, i8** %6
%123 = getelementptr inbounds [81 x i8], [81 x i8]* %11, i64 0, i64 0
%124 = getelementptr inbounds [81 x i8], [81 x i8]* %14, i64 0, i64 0
%125 = call i32 (i8*, i8*, ...) @sprintf(i8* %121, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.7, i64 0, i64 0), i8* %122, i8* %123, i8* %124)
br label %132
126: ; preds = %117
%127 = getelementptr inbounds [512 x i8], [512 x i8]* %15, i64 0, i64 0
%128 = load i8*, i8** %6
%129 = getelementptr inbounds [81 x i8], [81 x i8]* %11, i64 0, i64 0
%130 = getelementptr inbounds [81 x i8], [81 x i8]* %14, i64 0, i64 0
%131 = call i32 (i8*, i8*, ...) @sprintf(i8* %127, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.8, i64 0, i64 0), i8* %128, i8* %129, i8* %130)
br label %132
132: ; preds = %126, %120
%133 = load i8*, i8** %5
%134 = getelementptr inbounds [512 x i8], [512 x i8]* %15, i64 0, i64 0
%135 = call i32 @strncpy(i8* %133, i8* %134, i32 80)
%136 = load i8*, i8** %5
%137 = getelementptr inbounds i8, i8* %136, i64 80
store i8 0, i8* %137
br label %236
138: ; preds = %113
%139 = getelementptr inbounds [81 x i8], [81 x i8]* %11, i64 0, i64 0
%140 = load i8, i8* %139
%141 = sext i8 %140 to i32
%142 = icmp eq i32 %141, 0
br i1 %142, label %143, label %162
143: ; preds = %138
%144 = load i32, i32* %10
%145 = icmp ne i32 %144, 0
br i1 %145, label %146, label %151
146: ; preds = %143
%147 = getelementptr inbounds [512 x i8], [512 x i8]* %15, i64 0, i64 0
%148 = load i8*, i8** %6
%149 = getelementptr inbounds [81 x i8], [81 x i8]* %14, i64 0, i64 0
%150 = call i32 (i8*, i8*, ...) @sprintf(i8* %147, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.9, i64 0, i64 0), i8* %148, i8* %149)
br label %156
151: ; preds = %143
%152 = getelementptr inbounds [512 x i8], [512 x i8]* %15, i64 0, i64 0
%153 = load i8*, i8** %6
%154 = getelementptr inbounds [81 x i8], [81 x i8]* %14, i64 0, i64 0
%155 = call i32 (i8*, i8*, ...) @sprintf(i8* %152, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.10, i64 0, i64 0), i8* %153, i8* %154)
br label %156
156: ; preds = %151, %146
%157 = load i8*, i8** %5
%158 = getelementptr inbounds [512 x i8], [512 x i8]* %15, i64 0, i64 0
%159 = call i32 @strncpy(i8* %157, i8* %158, i32 80)
%160 = load i8*, i8** %5
%161 = getelementptr inbounds i8, i8* %160, i64 80
store i8 0, i8* %161
br label %236
162: ; preds = %138
%163 = getelementptr inbounds [81 x i8], [81 x i8]* %13, i64 0, i64 0
%164 = call i32 @memset(i8* %163, i8 signext 0, i32 81)
%165 = getelementptr inbounds [81 x i8], [81 x i8]* %12, i64 0, i64 0
%166 = getelementptr inbounds [81 x i8], [81 x i8]* %11, i64 0, i64 0
%167 = call i8* @qfits_pretty_string(i8* %166)
%168 = call i32 @strcpy(i8* %165, i8* %167)
store i32 0, i32* %17
store i32 0, i32* %16
br label %169
169: ; preds = %200, %162
%170 = load i32, i32* %16
%171 = sext i32 %170 to i64
%172 = getelementptr inbounds [81 x i8], [81 x i8]* %12, i64 0, i64 %171
%173 = load i8, i8* %172
%174 = sext i8 %173 to i32
%175 = icmp ne i32 %174, 0
br i1 %175, label %176, label %205
176: ; preds = %169
%177 = load i32, i32* %16
%178 = sext i32 %177 to i64
%179 = getelementptr inbounds [81 x i8], [81 x i8]* %12, i64 0, i64 %178
%180 = load i8, i8* %179
%181 = sext i8 %180 to i32
%182 = icmp eq i32 %181, 39
br i1 %182, label %183, label %192
183: ; preds = %176
%184 = load i32, i32* %17
%185 = sext i32 %184 to i64
%186 = getelementptr inbounds [81 x i8], [81 x i8]* %13, i64 0, i64 %185
store i8 39, i8* %186
%187 = load i32, i32* %17
%188 = add nsw i32 %187, 1
store i32 %188, i32* %17
%189 = load i32, i32* %17
%190 = sext i32 %189 to i64
%191 = getelementptr inbounds [81 x i8], [81 x i8]* %13, i64 0, i64 %190
store i8 39, i8* %191
br label %200
192: ; preds = %176
%193 = load i32, i32* %16
%194 = sext i32 %193 to i64
%195 = getelementptr inbounds [81 x i8], [81 x i8]* %12, i64 0, i64 %194
%196 = load i8, i8* %195
%197 = load i32, i32* %17
%198 = sext i32 %197 to i64
%199 = getelementptr inbounds [81 x i8], [81 x i8]* %13, i64 0, i64 %198
store i8 %196, i8* %199
br label %200
200: ; preds = %192, %183
%201 = load i32, i32* %16
%202 = add nsw i32 %201, 1
store i32 %202, i32* %16
%203 = load i32, i32* %17
%204 = add nsw i32 %203, 1
store i32 %204, i32* %17
br label %169
205: ; preds = %169
%206 = load i32, i32* %10
%207 = icmp ne i32 %206, 0
br i1 %207, label %208, label %224
208: ; preds = %205
%209 = getelementptr inbounds [512 x i8], [512 x i8]* %15, i64 0, i64 0
%210 = load i8*, i8** %6
%211 = getelementptr inbounds [81 x i8], [81 x i8]* %13, i64 0, i64 0
%212 = getelementptr inbounds [81 x i8], [81 x i8]* %14, i64 0, i64 0
%213 = call i32 (i8*, i8*, ...) @sprintf(i8* %209, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.11, i64 0, i64 0), i8* %210, i8* %211, i8* %212)
%214 = load i8*, i8** %6
%215 = call i32 @strlen(i8* %214)
%216 = getelementptr inbounds [81 x i8], [81 x i8]* %13, i64 0, i64 0
%217 = call i32 @strlen(i8* %216)
%218 = add nsw i32 %215, %217
%219 = add nsw i32 %218, 3
%220 = icmp sge i32 %219, 80
br i1 %220, label %221, label %223
221: ; preds = %208
%222 = getelementptr inbounds [512 x i8], [512 x i8]* %15, i64 0, i64 79
store i8 39, i8* %222
br label %223
223: ; preds = %221, %208
br label %230
224: ; preds = %205
%225 = getelementptr inbounds [512 x i8], [512 x i8]* %15, i64 0, i64 0
%226 = load i8*, i8** %6
%227 = getelementptr inbounds [81 x i8], [81 x i8]* %13, i64 0, i64 0
%228 = getelementptr inbounds [81 x i8], [81 x i8]* %14, i64 0, i64 0
%229 = call i32 (i8*, i8*, ...) @sprintf(i8* %225, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.12, i64 0, i64 0), i8* %226, i8* %227, i8* %228)
br label %230
230: ; preds = %224, %223
%231 = load i8*, i8** %5
%232 = getelementptr inbounds [512 x i8], [512 x i8]* %15, i64 0, i64 0
%233 = call i32 @strncpy(i8* %231, i8* %232, i32 80)
%234 = load i8*, i8** %5
%235 = getelementptr inbounds i8, i8* %234, i64 80
store i8 0, i8* %235
br label %236
236: ; preds = %230, %156, %132, %62, %55, %34, %29, %23
ret void
}

LLVM IR (-O2):
@.str = [4 x i8] c"END\00"
@.str.1 = [8 x i8] c"HISTORY\00"
@.str.2 = [8 x i8] c"COMMENT\00"
@.str.3 = [9 x i8] c" \00"
@.str.4 = [4 x i8] c"%s \00"
@.str.5 = [11 x i8] c"no comment\00"
@.str.6 = [9 x i8] c"HIERARCH\00"
@.str.7 = [15 x i8] c"%-29s= %s / %s\00"
@.str.8 = [21 x i8] c"%-8.8s= %20s / %-48s\00"
@.str.9 = [31 x i8] c"%-29s= / %s\00"
@.str.10 = [37 x i8] c"%-8.8s= / %-48s\00"
@.str.11 = [17 x i8] c"%-29s= '%s' / %s\00"
@.str.12 = [20 x i8] c"%-8.8s= '%-8s' / %s\00"
define void @qfits_card_build(i8* %0, i8* %1, i8* %2, i8* %3) {
%5 = alloca [81 x i8]
%6 = alloca [81 x i8]
%7 = alloca [81 x i8]
%8 = alloca [81 x i8]
%9 = alloca [512 x i8]
%10 = getelementptr inbounds [81 x i8], [81 x i8]* %5, i64 0, i64 0
%11 = getelementptr inbounds [81 x i8], [81 x i8]* %6, i64 0, i64 0
%12 = getelementptr inbounds [81 x i8], [81 x i8]* %7, i64 0, i64 0
%13 = getelementptr inbounds [81 x i8], [81 x i8]* %8, i64 0, i64 0
%14 = getelementptr inbounds [512 x i8], [512 x i8]* %9, i64 0, i64 0
%15 = icmp eq i8* %0, null
%16 = icmp eq i8* %1, null
%17 = or i1 %15, %16
br i1 %17, label %118, label %18
18: ; preds = %4
%19 = tail call i32 @memset(i8* %0, i8 signext 32, i32 80)
%20 = tail call i32 @strcmp(i8* dereferenceable(1) %1, i8* dereferenceable(4) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%21 = icmp eq i32 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %18
%23 = bitcast i8* %0 to i32*
store i32 4476485, i32* %23
br label %118
24: ; preds = %18
%25 = tail call i32 @strcmp(i8* dereferenceable(1) %1, i8* dereferenceable(8) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%26 = icmp eq i32 %25, 0
br i1 %26, label %33, label %27
27: ; preds = %24
%28 = tail call i32 @strcmp(i8* dereferenceable(1) %1, i8* dereferenceable(8) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%29 = icmp eq i32 %28, 0
br i1 %29, label %33, label %30
30: ; preds = %27
%31 = tail call i32 @strncmp(i8* %1, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i32 8)
%32 = icmp eq i32 %31, 0
br i1 %32, label %33, label %42
33: ; preds = %30, %27, %24
%34 = tail call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %1)
%35 = icmp eq i8* %2, null
br i1 %35, label %118, label %36
36: ; preds = %33
%37 = tail call i32 @strlen(i8* %2)
%38 = icmp slt i32 %37, 72
%39 = select i1 %38, i32 %37, i32 72
%40 = getelementptr inbounds i8, i8* %0, i64 8
%41 = tail call i32 @strncpy(i8* %40, i8* %2, i32 %39)
br label %118
42: ; preds = %30
%43 = icmp eq i8* %2, null
br i1 %43, label %44, label %45
44: ; preds = %42
store i8 0, i8* %10
br label %51
45: ; preds = %42
%46 = tail call i32 @strlen(i8* %2)
%47 = icmp slt i32 %46, 1
br i1 %47, label %48, label %49
48: ; preds = %45
store i8 0, i8* %10
br label %51
49: ; preds = %45
%50 = call i32 @strcpy(i8* %10, i8* %2)
br label %51
51: ; preds = %48, %49, %44
%52 = icmp eq i8* %3, null
br i1 %52, label %53, label %55
53: ; preds = %51
%54 = call i32 @strcpy(i8* %13, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0))
br label %57
55: ; preds = %51
%56 = call i32 @strcpy(i8* %13, i8* %3)
br label %57
57: ; preds = %55, %53
%58 = call i32 @strncmp(i8* %1, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0), i32 8)
%59 = icmp eq i32 %58, 0
%60 = call i64 @qfits_is_int(i8* %10)
%61 = icmp eq i64 %60, 0
br i1 %61, label %62, label %71
62: ; preds = %57
%63 = call i64 @qfits_is_float(i8* %10)
%64 = icmp eq i64 %63, 0
br i1 %64, label %65, label %71
65: ; preds = %62
%66 = call i64 @qfits_is_boolean(i8* %10)
%67 = icmp eq i64 %66, 0
br i1 %67, label %68, label %71
68: ; preds = %65
%69 = call i64 @qfits_is_complex(i8* %10)
%70 = icmp eq i64 %69, 0
br i1 %70, label %76, label %71
71: ; preds = %68, %65, %62, %57
%72 = select i1 %59, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.8, i64 0, i64 0)
%73 = call i32 (i8*, i8*, ...) @sprintf(i8* %14, i8* dereferenceable(1) %72, i8* %1, i8* %10, i8* %13)
%74 = call i32 @strncpy(i8* %0, i8* %14, i32 80)
%75 = getelementptr inbounds i8, i8* %0, i64 80
store i8 0, i8* %75
br label %118
76: ; preds = %68
%77 = load i8, i8* %10
%78 = icmp eq i8 %77, 0
br i1 %78, label %79, label %84
79: ; preds = %76
%80 = select i1 %59, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.9, i64 0, i64 0), i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.10, i64 0, i64 0)
%81 = call i32 (i8*, i8*, ...) @sprintf(i8* %14, i8* dereferenceable(1) %80, i8* %1, i8* %13)
%82 = call i32 @strncpy(i8* %0, i8* %14, i32 80)
%83 = getelementptr inbounds i8, i8* %0, i64 80
store i8 0, i8* %83
br label %118
84: ; preds = %76
%85 = call i32 @memset(i8* %12, i8 signext 0, i32 81)
%86 = call i8* @qfits_pretty_string(i8* %10)
%87 = call i32 @strcpy(i8* %11, i8* %86)
br label %88
88: ; preds = %97, %84
%89 = phi i64 [ %102, %97 ], [ 0, %84 ]
%90 = phi i32 [ %103, %97 ], [ 0, %84 ]
%91 = getelementptr inbounds [81 x i8], [81 x i8]* %6, i64 0, i64 %89
%92 = load i8, i8* %91
switch i8 %92, label %97 [
i8 0, label %104
i8 39, label %93
]
93: ; preds = %88
%94 = sext i32 %90 to i64
%95 = getelementptr inbounds [81 x i8], [81 x i8]* %7, i64 0, i64 %94
store i8 39, i8* %95
%96 = add nsw i32 %90, 1
br label %97
97: ; preds = %88, %93
%98 = phi i32 [ %96, %93 ], [ %90, %88 ]
%99 = phi i8 [ 39, %93 ], [ %92, %88 ]
%100 = sext i32 %98 to i64
%101 = getelementptr inbounds [81 x i8], [81 x i8]* %7, i64 0, i64 %100
store i8 %99, i8* %101
%102 = add nuw i64 %89, 1
%103 = add nsw i32 %98, 1
br label %88
104: ; preds = %88
br i1 %59, label %105, label %113
105: ; preds = %104
%106 = call i32 (i8*, i8*, ...) @sprintf(i8* %14, i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.11, i64 0, i64 0), i8* %1, i8* %12, i8* %13)
%107 = call i32 @strlen(i8* %1)
%108 = call i32 @strlen(i8* %12)
%109 = add nsw i32 %108, %107
%110 = icmp sgt i32 %109, 76
br i1 %110, label %111, label %115
111: ; preds = %105
%112 = getelementptr inbounds [512 x i8], [512 x i8]* %9, i64 0, i64 79
store i8 39, i8* %112
br label %115
113: ; preds = %104
%114 = call i32 (i8*, i8*, ...) @sprintf(i8* %14, i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.12, i64 0, i64 0), i8* %1, i8* %12, i8* %13)
br label %115
115: ; preds = %105, %111, %113
%116 = call i32 @strncpy(i8* %0, i8* %14, i32 80)
%117 = getelementptr inbounds i8, i8* %0, i64 80
store i8 0, i8* %117
br label %118
118: ; preds = %33, %4, %115, %79, %71, %36, %22
ret void
}