// File: /workspace/github_c_makefile_star2_O2/bluecmd[P]fst-example/example.c
// Function: main
int main() {
  void* fst = fstWriterCreate("example.fst", /* use_compressed_hier */ 1);
  fstWriterSetPackType(fst, FST_WR_PT_LZ4);
  fstWriterSetTimescale(fst, FST_TS_NS);
#ifdef FST_WRITER_PARALLEL
  fstWriterSetParallelMode(fst, true);
#endif

  fstWriterSetComment(fst, "Created by bluecmd/fst-example");
  fstWriterSetDate(fst, "2020-09-10");

  const char *enumNames[] = { "STATE1", "STATE2", "STATE3" };
  const char *enumValues[] = { "001", "010", "100" };
  fstEnumHandle enumMap = fstWriterCreateEnumTable(
      fst, "ExampleEnum", /* elements */ 3, 0, enumNames, enumValues);

  fstHandle varInt, varEnum, varString, varEvent;

  // Create a tree like this:
  //
  //  Example
  //   |
  //   |-Function
  //   |
  //   |-Aliases
  //
  fstWriterSetScope(fst, FST_ST_VCD_PROGRAM, "Example", NULL);
  fstWriterSetScope(fst, FST_ST_VCD_FUNCTION, "Function", NULL);

  varInt    = fstWriterCreateVar(fst, FST_VT_VCD_INTEGER, FST_VD_INPUT, 8, "integer", /* alias */ 0);
  varString = fstWriterCreateVar(fst, FST_VT_GEN_STRING, FST_VD_OUTPUT, 0, "string", /* alias */ 0);
  varEvent  = fstWriterCreateVar(fst, FST_VT_VCD_EVENT, FST_VD_OUTPUT, 1, "event", /* alias */ 0);

  // Activate enum for next variable defined
  fstWriterEmitEnumTableRef(fst, enumMap);
  varEnum   = fstWriterCreateVar(fst, FST_VT_SV_ENUM, FST_VD_INPUT, 3, "enum", /* alias */ 0);

  fstWriterSetUpscope(fst);
  fstWriterSetScope(fst, FST_ST_VCD_PACKAGE, "Aliases", NULL);
  // Alias of the "integer" variable above
  fstWriterCreateVar(fst, FST_VT_VCD_INTEGER, FST_VD_INPUT, 8, "integer", varInt);

  fstWriterEmitTimeChange(fst, 0);
  fstWriterEmitValueChange(fst, varInt, "zzzzxxxx");
  fstWriterEmitTimeChange(fst, 1);
  for (int i = 2; i < 1000;) {
    fstWriterEmitValueChange32(fst, varInt, 8, 100 + i);
    fstWriterEmitValueChange32(fst, varEvent, 1, 1);
    fstWriterEmitVariableLengthValueChange(fst, varString, "str1", 4);
    fstWriterEmitValueChange(fst, varEnum, "001");
    fstWriterEmitTimeChange(fst, i++);
    fstWriterEmitValueChange32(fst, varInt, 8, 100 + i);
    fstWriterEmitVariableLengthValueChange(fst, varString, "str2", 4);
    fstWriterEmitValueChange(fst, varEnum, "010");
    fstWriterEmitTimeChange(fst, i++);
    fstWriterEmitValueChange32(fst, varInt, 8, 100 + i);
    fstWriterEmitVariableLengthValueChange(fst, varString, NULL, 0); // z-equivalent for strings
    fstWriterEmitValueChange(fst, varEnum, "100");
    fstWriterEmitTimeChange(fst, i++);
  }

  fstWriterClose(fst);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
leaq 0xfb40(%rip), %rdi      # 0x12004
pushq $0x1
popq %r12
movl %r12d, %esi
callq 0x3324
movq %rax, %r14
pushq $0x2
popq %rbx
movq %rax, %rdi
movl %ebx, %esi
callq 0x5618
pushq $-0x9
popq %rsi
movq %r14, %rdi
callq 0x54c0
leaq 0xfb1e(%rip), %rsi      # 0x12010
movq %r14, %rdi
callq 0x541d
leaq 0xfb2e(%rip), %rsi      # 0x1202f
movq %r14, %rdi
callq 0x510f
movq 0x137b0(%rip), %rax     # 0x15cc0
leaq -0x70(%rbp), %r8
movq %rax, 0x10(%r8)
movaps 0x13791(%rip), %xmm0    # 0x15cb0
movaps %xmm0, (%r8)
movq 0x137b6(%rip), %rax     # 0x15ce0
leaq -0x50(%rbp), %r9
movq %rax, 0x10(%r9)
movaps 0x13797(%rip), %xmm0    # 0x15cd0
movaps %xmm0, (%r9)
leaq 0xfb17(%rip), %rsi      # 0x1205b
pushq $0x3
popq %rdx
movq %r14, %rdi
xorl %ecx, %ecx
callq 0x5bcd
movl %eax, %r15d
leaq 0xfb0c(%rip), %rdx      # 0x12067
pushq $0xb
popq %rsi
movq %r14, %rdi
xorl %ecx, %ecx
callq 0x59ed
leaq 0xfb00(%rip), %rdx      # 0x1206f
movq %r14, %rdi
movl %ebx, %esi
xorl %ecx, %ecx
callq 0x59ed
leaq 0x10457(%rip), %r8      # 0x129d9
pushq $0x8
popq %rcx
movq %r14, %rdi
movl %r12d, %esi
movl %r12d, %edx
xorl %r9d, %r9d
callq 0x5770
movl %eax, %r13d
leaq 0xfad8(%rip), %r8       # 0x12078
pushq $0x15
popq %rsi
movq %r14, %rdi
movl %ebx, %edx
xorl %ecx, %ecx
xorl %r9d, %r9d
callq 0x5770
movl %eax, -0x2c(%rbp)
leaq 0xfac3(%rip), %r8       # 0x1207f
movq %r14, %rdi
xorl %esi, %esi
movl %ebx, %edx
movl %r12d, %ecx
xorl %r9d, %r9d
callq 0x5770
movl %eax, -0x34(%rbp)
movq %r14, %rdi
movl %r15d, %esi
callq 0x5fca
leaq 0xfaa2(%rip), %r8       # 0x12085
pushq $0x1c
popq %rsi
movq %r14, %rdi
movl %r12d, %edx
pushq $0x3
popq %rcx
xorl %r9d, %r9d
callq 0x5770
movl %eax, -0x30(%rbp)
movq %r14, %rdi
callq 0x5a9f
leaq 0xfa81(%rip), %rdx      # 0x1208a
pushq $0xa
popq %rsi
movq %r14, %rdi
xorl %ecx, %ecx
callq 0x59ed
movq %r14, %rdi
movl %r12d, %esi
movl %r12d, %edx
pushq $0x8
popq %rcx
leaq 0x103b0(%rip), %r8      # 0x129d9
movl %r13d, %r9d
callq 0x5770
movq %r14, %rdi
xorl %esi, %esi
callq 0x4244
leaq 0xfa50(%rip), %rdx      # 0x12092
movq %r14, %rdi
movl %r13d, -0x38(%rbp)
movl %r13d, %esi
callq 0x4363
pushq $0x1
popq %r12
movl -0x38(%rbp), %ebx
movl -0x30(%rbp), %r13d
movq %r14, %rdi
movq %r12, %rsi
callq 0x4244
leaq 0x1(%r12), %r15
cmpq $0x3e8, %r15            # imm = 0x3E8
jae 0x2753
leal 0x65(%r12), %ecx
movq %r14, %rdi
movl %ebx, %esi
pushq $0x8
popq %rdx
callq 0x6158
movq %r14, %rdi
movl -0x34(%rbp), %esi
pushq $0x1
popq %rcx
movl %ecx, %edx
callq 0x6158
movq %r14, %rdi
movl -0x2c(%rbp), %esi
leaq 0xf9f3(%rip), %rdx      # 0x1209b
pushq $0x4
popq %rcx
callq 0x647c
movq %r14, %rdi
movl %r13d, %esi
leaq 0xf992(%rip), %rdx      # 0x1204f
callq 0x4363
movq %r14, %rdi
movq %r15, %rsi
callq 0x4244
leal 0x66(%r12), %ecx
movq %r14, %rdi
movl %ebx, %esi
pushq $0x8
popq %rdx
callq 0x6158
movq %r14, %rdi
movl -0x2c(%rbp), %esi
leaq 0xf9b4(%rip), %rdx      # 0x120a0
pushq $0x4
popq %rcx
callq 0x647c
movq %r14, %rdi
movl %r13d, %esi
leaq 0xf952(%rip), %rdx      # 0x12053
callq 0x4363
leaq 0x1(%r15), %rsi
movq %r14, %rdi
callq 0x4244
addl $0x67, %r12d
movq %r14, %rdi
movl %ebx, %esi
pushq $0x8
popq %rdx
movl %r12d, %ecx
callq 0x6158
movq %r14, %rdi
movl -0x2c(%rbp), %esi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x647c
movq %r14, %rdi
movl %r13d, %esi
leaq 0xf915(%rip), %rdx      # 0x12057
callq 0x4363
addq $0x2, %r15
movq %r15, %r12
jmp 0x265c
movq %r14, %rdi
callq 0x3872
xorl %eax, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq