// File: /workspace/github_c_makefile_star2_O3/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 $0x58, %rsp
leaq 0xf890(%rip), %rdi      # 0x14004
movl $0x1, %esi
callq 0x52d8
movq %rax, %rbx
movq %rax, %rdi
movl $0x2, %esi
callq 0x7dbe
movq %rbx, %rdi
movl $0xfffffff7, %esi       # imm = 0xFFFFFFF7
callq 0x7c09
leaq 0xf86e(%rip), %rsi      # 0x14010
movq %rbx, %rdi
callq 0x7b66
leaq 0xf87e(%rip), %rsi      # 0x1402f
movq %rbx, %rdi
callq 0x7809
movq 0x13500(%rip), %rax     # 0x17cc0
leaq -0x80(%rbp), %r8
movq %rax, 0x10(%r8)
movaps 0x134e1(%rip), %xmm0    # 0x17cb0
movaps %xmm0, (%r8)
movq 0x13506(%rip), %rax     # 0x17ce0
leaq -0x60(%rbp), %r9
movq %rax, 0x10(%r9)
movaps 0x134e7(%rip), %xmm0    # 0x17cd0
movaps %xmm0, (%r9)
leaq 0xf867(%rip), %rsi      # 0x1405b
movq %rbx, %rdi
movl $0x3, %edx
xorl %ecx, %ecx
callq 0x8371
movl %eax, %r12d
leaq 0xf85a(%rip), %rdx      # 0x14067
movq %rbx, %rdi
movl $0xb, %esi
xorl %ecx, %ecx
callq 0x818f
leaq 0xf84c(%rip), %rdx      # 0x1406f
movq %rbx, %rdi
movl $0x2, %esi
xorl %ecx, %ecx
callq 0x818f
leaq 0x101a0(%rip), %r15     # 0x149d9
movq %rbx, %rdi
movl $0x1, %esi
movl $0x1, %edx
movl $0x8, %ecx
movq %r15, %r8
xorl %r9d, %r9d
callq 0x7ef7
movl %eax, %r14d
leaq 0xf818(%rip), %r8       # 0x14078
movq %rbx, %rdi
movl $0x15, %esi
movl $0x2, %edx
xorl %ecx, %ecx
xorl %r9d, %r9d
callq 0x7ef7
movl %eax, -0x2c(%rbp)
leaq 0xf7fe(%rip), %r8       # 0x1407f
movq %rbx, %rdi
xorl %esi, %esi
movl $0x2, %edx
movl $0x1, %ecx
xorl %r9d, %r9d
callq 0x7ef7
movl %eax, -0x34(%rbp)
movq %rbx, %rdi
movl %r12d, %esi
callq 0x8764
leaq 0xf7d8(%rip), %r8       # 0x14085
movq %rbx, %rdi
movl $0x1c, %esi
movl $0x1, %edx
movl $0x3, %ecx
xorl %r9d, %r9d
callq 0x7ef7
movl %eax, -0x30(%rbp)
movq %rbx, %rdi
callq 0x8241
leaq 0xf7b1(%rip), %rdx      # 0x1408a
movq %rbx, %rdi
movl $0xa, %esi
xorl %ecx, %ecx
callq 0x818f
movq %rbx, %rdi
movl $0x1, %esi
movl $0x1, %edx
movl $0x8, %ecx
movq %r15, %r8
movl %r14d, %r9d
callq 0x7ef7
movq %rbx, %rdi
xorl %esi, %esi
callq 0x65af
leaq 0xf77c(%rip), %rdx      # 0x14092
movq %rbx, %rdi
movl %r14d, -0x38(%rbp)
movl %r14d, %esi
callq 0x665a
movl $0x1, %esi
movq %rbx, -0x40(%rbp)
movq %rbx, %rdi
callq 0x65af
movl $0x2, %r14d
movl $0x68, %r12d
movq -0x40(%rbp), %r15
movl -0x38(%rbp), %ebx
movl -0x30(%rbp), %r13d
leal -0x2(%r12), %ecx
movq %r15, %rdi
movl %ebx, %esi
movl $0x8, %edx
callq 0x89f1
movq %r15, %rdi
movl -0x34(%rbp), %esi
movl $0x1, %edx
movl $0x1, %ecx
callq 0x89f1
movq %r15, %rdi
movl -0x2c(%rbp), %esi
leaq 0xf718(%rip), %rdx      # 0x1409b
movl $0x4, %ecx
callq 0x8ceb
movq %r15, %rdi
movl %r13d, %esi
leaq 0xf6b5(%rip), %rdx      # 0x1404f
callq 0x665a
movq %r15, %rdi
movq %r14, %rsi
callq 0x65af
leal -0x1(%r12), %ecx
movq %r15, %rdi
movl %ebx, %esi
movl $0x8, %edx
callq 0x89f1
movq %r15, %rdi
movl -0x2c(%rbp), %esi
leaq 0xf6d5(%rip), %rdx      # 0x140a0
movl $0x4, %ecx
callq 0x8ceb
movq %r15, %rdi
movl %r13d, %esi
leaq 0xf671(%rip), %rdx      # 0x14053
callq 0x665a
leaq 0x1(%r14), %rsi
movq %r15, %rdi
callq 0x65af
movq %r15, %rdi
movl %ebx, %esi
movl $0x8, %edx
movl %r12d, %ecx
callq 0x89f1
movq %r15, %rdi
movl -0x2c(%rbp), %esi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x8ceb
movq %r15, %rdi
movl %r13d, %esi
leaq 0xf636(%rip), %rdx      # 0x14057
callq 0x665a
leaq 0x2(%r14), %rsi
movq %r15, %rdi
callq 0x65af
addl $0x3, %r12d
leaq 0x3(%r14), %rax
cmpq $0x3e5, %r14            # imm = 0x3E5
movq %rax, %r14
jb 0x494d
movq -0x40(%rbp), %rdi
callq 0x58fb
xorl %eax, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq