// File: /workspace/github_c_makefile_star2_O0/videolan[P]bitstream/examples/dvb_gen_si.c
// Function: generate_cat
static void generate_cat(void) {
    // Generate empty cat
    uint8_t *cat = psi_allocate();
    uint8_t *desc;
    uint8_t desc_loop[DESCS_HEADER_SIZE + DESCS_MAX_SIZE];
    uint8_t desc_counter;

    cat_init(cat);
    cat_set_length(cat, 0);
    psi_set_version(cat, 0);
    psi_set_current(cat);
    psi_set_crc(cat);
    output_psi_section(cat, CAT_PID, &cc);

    // Increase CAT version
    psi_set_version(cat, 1);
    psi_set_current(cat);
    psi_set_crc(cat);
    output_psi_section(cat, CAT_PID, &cc);

    // Add couple of descriptors to CAT
    psi_set_version(cat, 2);
    psi_set_current(cat);
    psi_set_length(cat, PSI_MAX_SIZE);

    descs_set_length(desc_loop, DESCS_MAX_SIZE);
    desc_counter = 0;

    desc = descs_get_desc(desc_loop, desc_counter++);
    build_desc09(desc);

    desc = descs_get_desc(desc_loop, desc_counter++);
    build_desc09(desc);

    desc = descs_get_desc(desc_loop, desc_counter++);
    build_desc09(desc);

    // Finish descriptor generation
    desc = descs_get_desc(desc_loop, desc_counter); // Get next descriptor pos
    descs_set_length(desc_loop, desc - desc_loop - DESCS_HEADER_SIZE);
    cat_set_desclength(cat, descs_get_length(desc_loop));
    // Put descriptor loop into CAT
    memcpy(cat_get_descl(cat), desc_loop + DESCS_HEADER_SIZE,
        descs_get_length(desc_loop));

    psi_set_crc(cat);
    output_psi_section(cat, CAT_PID, &cc);

    free(cat);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x1040, %rsp           # imm = 0x1040
callq 0x4f30
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rdi
callq 0x58e0
movq -0x8(%rbp), %rdi
xorl %esi, %esi
callq 0x5940
movq -0x8(%rbp), %rdi
xorl %esi, %esi
callq 0x4ff0
movq -0x8(%rbp), %rdi
callq 0x5020
movq -0x8(%rbp), %rdi
callq 0x5080
movq -0x8(%rbp), %rdi
movl $0x1, %esi
leaq 0x1fb64(%rip), %rdx     # 0x210b9
callq 0x5170
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x4ff0
movq -0x8(%rbp), %rdi
callq 0x5020
movq -0x8(%rbp), %rdi
callq 0x5080
movq -0x8(%rbp), %rdi
movl $0x1, %esi
leaq 0x1fb2f(%rip), %rdx     # 0x210b9
callq 0x5170
movq -0x8(%rbp), %rdi
movl $0x2, %esi
callq 0x4ff0
movq -0x8(%rbp), %rdi
callq 0x5020
movq -0x8(%rbp), %rdi
movl $0x3fd, %esi            # imm = 0x3FD
callq 0x5290
leaq -0x1020(%rbp), %rdi
movl $0xfff, %esi            # imm = 0xFFF
callq 0x5970
movb $0x0, -0x1021(%rbp)
leaq -0x1020(%rbp), %rdi
movb -0x1021(%rbp), %al
movb %al, %cl
addb $0x1, %cl
movb %cl, -0x1021(%rbp)
leaq 0x4445(%rip), %rdx      # 0x5a30
movzbl %al, %esi
callq 0x59c0
movq %rax, -0x10(%rbp)
movq -0x10(%rbp), %rdi
callq 0x5a70
leaq -0x1020(%rbp), %rdi
movb -0x1021(%rbp), %al
movb %al, %cl
addb $0x1, %cl
movb %cl, -0x1021(%rbp)
leaq 0x4411(%rip), %rdx      # 0x5a30
movzbl %al, %esi
callq 0x59c0
movq %rax, -0x10(%rbp)
movq -0x10(%rbp), %rdi
callq 0x5a70
leaq -0x1020(%rbp), %rdi
movb -0x1021(%rbp), %al
movb %al, %cl
addb $0x1, %cl
movb %cl, -0x1021(%rbp)
leaq 0x43dd(%rip), %rdx      # 0x5a30
movzbl %al, %esi
callq 0x59c0
movq %rax, -0x10(%rbp)
movq -0x10(%rbp), %rdi
callq 0x5a70
leaq -0x1020(%rbp), %rdi
leaq 0x43ba(%rip), %rdx      # 0x5a30
movzbl -0x1021(%rbp), %esi
callq 0x59c0
movq %rax, -0x10(%rbp)
leaq -0x1020(%rbp), %rdi
movq -0x10(%rbp), %rax
leaq -0x1020(%rbp), %rcx
subq %rcx, %rax
subq $0x2, %rax
movzwl %ax, %esi
callq 0x5970
movq -0x8(%rbp), %rax
movq %rax, -0x1040(%rbp)
leaq -0x1020(%rbp), %rdi
callq 0x5ae0
movq -0x1040(%rbp), %rdi
movzwl %ax, %esi
callq 0x5ab0
movq -0x8(%rbp), %rdi
callq 0x5b10
movq %rax, -0x1038(%rbp)
leaq -0x1020(%rbp), %rax
addq $0x2, %rax
movq %rax, -0x1030(%rbp)
leaq -0x1020(%rbp), %rdi
callq 0x5ae0
movq -0x1038(%rbp), %rdi
movq -0x1030(%rbp), %rsi
movzwl %ax, %eax
movl %eax, %edx
callq 0x1090
movq -0x8(%rbp), %rdi
callq 0x5080
movq -0x8(%rbp), %rdi
movl $0x1, %esi
leaq 0x1f98d(%rip), %rdx     # 0x210b9
callq 0x5170
movq -0x8(%rbp), %rdi
callq 0x1030
addq $0x1040, %rsp           # imm = 0x1040
popq %rbp
retq
nopw %cs:(%rax,%rax)