// File: /workspace/github_c_makefile_star2_O1/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 0x12770(%rip), %rdi     # 0x15004
movl $0x1, %esi
callq 0x38f4
movq %rax, %rbx
movq %rax, %rdi
movl $0x2, %esi
callq 0x63cd
movq %rbx, %rdi
movl $0xfffffff7, %esi       # imm = 0xFFFFFFF7
callq 0x6207
leaq 0x1274e(%rip), %rsi     # 0x15010
movq %rbx, %rdi
callq 0x6164
leaq 0x1275e(%rip), %rsi     # 0x1502f
movq %rbx, %rdi
callq 0x5e07
movq 0x163e0(%rip), %rax     # 0x18cc0
leaq -0x80(%rbp), %r8
movq %rax, 0x10(%r8)
movaps 0x163c1(%rip), %xmm0    # 0x18cb0
movaps %xmm0, (%r8)
movq 0x163e6(%rip), %rax     # 0x18ce0
leaq -0x60(%rbp), %r9
movq %rax, 0x10(%r9)
movaps 0x163c7(%rip), %xmm0    # 0x18cd0
movaps %xmm0, (%r9)
leaq 0x12747(%rip), %rsi     # 0x1505b
movq %rbx, %rdi
movl $0x3, %edx
xorl %ecx, %ecx
callq 0x6956
movl %eax, %r12d
leaq 0x1273a(%rip), %rdx     # 0x15067
movq %rbx, %rdi
movl $0xb, %esi
xorl %ecx, %ecx
callq 0x6786
leaq 0x1272c(%rip), %rdx     # 0x1506f
movq %rbx, %rdi
movl $0x2, %esi
xorl %ecx, %ecx
callq 0x6786
leaq 0x13080(%rip), %r15     # 0x159d9
movq %rbx, %rdi
movl $0x1, %esi
movl $0x1, %edx
movl $0x8, %ecx
movq %r15, %r8
xorl %r9d, %r9d
callq 0x6506
movl %eax, %r14d
leaq 0x126f8(%rip), %r8      # 0x15078
movq %rbx, %rdi
movl $0x15, %esi
movl $0x2, %edx
xorl %ecx, %ecx
xorl %r9d, %r9d
callq 0x6506
movl %eax, -0x2c(%rbp)
leaq 0x126de(%rip), %r8      # 0x1507f
movq %rbx, %rdi
xorl %esi, %esi
movl $0x2, %edx
movl $0x1, %ecx
xorl %r9d, %r9d
callq 0x6506
movl %eax, -0x34(%rbp)
movq %rbx, %rdi
movl %r12d, %esi
callq 0x6d54
leaq 0x126b8(%rip), %r8      # 0x15085
movq %rbx, %rdi
movl $0x1c, %esi
movl $0x1, %edx
movl $0x3, %ecx
xorl %r9d, %r9d
callq 0x6506
movl %eax, -0x30(%rbp)
movq %rbx, %rdi
callq 0x682f
leaq 0x12691(%rip), %rdx     # 0x1508a
movq %rbx, %rdi
movl $0xa, %esi
xorl %ecx, %ecx
callq 0x6786
movq %rbx, %rdi
movl $0x1, %esi
movl $0x1, %edx
movl $0x8, %ecx
movq %r15, %r8
movl %r14d, %r9d
callq 0x6506
movq %rbx, %rdi
xorl %esi, %esi
callq 0x4c00
leaq 0x1265c(%rip), %rdx     # 0x15092
movq %rbx, %rdi
movl %r14d, -0x38(%rbp)
movl %r14d, %esi
callq 0x4cb2
movl $0x1, %esi
movq %rbx, -0x40(%rbp)
movq %rbx, %rdi
callq 0x4c00
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 0x6fe5
movq %r15, %rdi
movl -0x34(%rbp), %esi
movl $0x1, %edx
movl $0x1, %ecx
callq 0x6fe5
movq %r15, %rdi
movl -0x2c(%rbp), %esi
leaq 0x125f8(%rip), %rdx     # 0x1509b
movl $0x4, %ecx
callq 0x72c9
movq %r15, %rdi
movl %r13d, %esi
leaq 0x12595(%rip), %rdx     # 0x1504f
callq 0x4cb2
movq %r15, %rdi
movq %r14, %rsi
callq 0x4c00
leal -0x1(%r12), %ecx
movq %r15, %rdi
movl %ebx, %esi
movl $0x8, %edx
callq 0x6fe5
movq %r15, %rdi
movl -0x2c(%rbp), %esi
leaq 0x125b5(%rip), %rdx     # 0x150a0
movl $0x4, %ecx
callq 0x72c9
movq %r15, %rdi
movl %r13d, %esi
leaq 0x12551(%rip), %rdx     # 0x15053
callq 0x4cb2
leaq 0x1(%r14), %rsi
movq %r15, %rdi
callq 0x4c00
movq %r15, %rdi
movl %ebx, %esi
movl $0x8, %edx
movl %r12d, %ecx
callq 0x6fe5
movq %r15, %rdi
movl -0x2c(%rbp), %esi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x72c9
movq %r15, %rdi
movl %r13d, %esi
leaq 0x12516(%rip), %rdx     # 0x15057
callq 0x4cb2
leaq 0x2(%r14), %rsi
movq %r15, %rdi
callq 0x4c00
addl $0x3, %r12d
leaq 0x3(%r14), %rax
cmpq $0x3e5, %r14            # imm = 0x3E5
movq %rax, %r14
jb 0x2a6d
movq -0x40(%rbp), %rdi
callq 0x3f47
xorl %eax, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq