// File: /workspace/github_c_makefile_star2_O0/videolan[P]bitstream/examples/dvb_gen_si.c
// Function: generate_bat
static void generate_bat(void) {
    uint8_t *bat = psi_allocate();
    uint8_t *bat_tsloop;
    uint8_t *desc_loop, *desc;
    uint8_t desc_counter;

    // Generate empty BAT
    bat_init(bat);
    psi_set_version(bat, 0);
    psi_set_current(bat);
    bat_set_bouquet_id(bat, onid);
    bat_set_length(bat, 2);

    bat_set_desclength(bat, 0);

    bat_tsloop = bat_get_header2(bat);
    bath_init(bat_tsloop);
    bath_set_tslength(bat_tsloop, 0);

    psi_set_crc(bat);

    output_psi_section(bat, BAT_PID, &cc);

    // Add descriptors and transport stream loop
    bat_init(bat);
    psi_set_version(bat, 1);
    psi_set_current(bat);
    bat_set_bouquet_id(bat, onid);
    bat_set_length(bat, PSI_MAX_SIZE);
    bat_set_desclength(bat, 0);

    {
        // Add descriptors to bouquet descriptors
        bat_set_desclength(bat, DESCS_MAX_SIZE);

        desc_counter = 0;
        desc_loop = bat_get_descs(bat);

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

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

        // Finish descriptor generation
        desc = descs_get_desc(desc_loop, desc_counter); // Get next descriptor pos
        bat_set_desclength(bat, desc - desc_loop - DESCS_HEADER_SIZE);
        bat_set_length(bat, 2 + bat_get_desclength(bat));
    }

    // Process transport stream loop
    bat_tsloop = bat_get_header2(bat);
    bath_init(bat_tsloop);
    bat_set_length(bat, PSI_MAX_SIZE); // This needed so bat_get_ts works
    {
        uint8_t *bat_n;
        uint8_t bat_n_counter = 0;

        bat_n = bat_get_ts(bat, bat_n_counter++);
        batn_init(bat_n);
        batn_set_tsid(bat_n, tsid);
        batn_set_onid(bat_n, onid);
        batn_set_desclength(bat_n, 0);
        {
            // Add descriptors to transport_stream_n
            desc_counter = 0;
            desc_loop = batn_get_descs(bat_n);
            descs_set_length(desc_loop, DESCS_MAX_SIZE); // This is needed so descs_get_desc(x, n) works

            desc = descs_get_desc(desc_loop, desc_counter++);
            build_desc41(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);
        }

        bat_n = bat_get_ts(bat, bat_n_counter++);
        batn_init(bat_n);
        batn_set_tsid(bat_n, tsid + 100);
        batn_set_onid(bat_n, onid + 100);
        batn_set_desclength(bat_n, 0);

        bat_n = bat_get_ts(bat, bat_n_counter++);
        batn_init(bat_n);
        batn_set_tsid(bat_n, tsid + 200);
        batn_set_onid(bat_n, onid + 200);
        batn_set_desclength(bat_n, 0);
        {
            // Add descriptors to transport_stream_n
            desc_counter = 0;
            desc_loop = batn_get_descs(bat_n);
            descs_set_length(desc_loop, DESCS_MAX_SIZE); // This is needed so descs_get_desc(x, n) works

            desc = descs_get_desc(desc_loop, desc_counter++);
            build_desc41(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);
        }

        bat_n = bat_get_ts(bat, bat_n_counter++);
        batn_init(bat_n);
        batn_set_tsid(bat_n, tsid + 300);
        batn_set_onid(bat_n, onid + 300);
        batn_set_desclength(bat_n, 0);

        // Set transport_stream_loop length
        bat_n = bat_get_ts(bat, bat_n_counter); // Get last ts
        bath_set_tslength(bat_tsloop, bat_n - bat_tsloop - BAT_HEADER2_SIZE);
    }
    // Set BAT length
    bat_set_length(bat, 2 + bat_get_desclength(bat) + bath_get_tslength(bat_tsloop));
    psi_set_crc(bat);

    output_psi_section(bat, BAT_PID, &cc);

    free(bat);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
callq 0x4f30
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rdi
callq 0x8640
movq -0x8(%rbp), %rdi
xorl %esi, %esi
callq 0x4ff0
movq -0x8(%rbp), %rdi
callq 0x5020
movq -0x8(%rbp), %rdi
movzwl 0x1f095(%rip), %esi     # 0x2108e
callq 0x4fb0
movq -0x8(%rbp), %rdi
movl $0x2, %esi
callq 0x5eb0
movq -0x8(%rbp), %rdi
xorl %esi, %esi
callq 0x5ee0
movq -0x8(%rbp), %rdi
callq 0x5f30
movq %rax, -0x10(%rbp)
movq -0x10(%rbp), %rdi
callq 0x5f70
movq -0x10(%rbp), %rdi
xorl %esi, %esi
callq 0x5f90
movq -0x8(%rbp), %rdi
callq 0x5080
movq -0x8(%rbp), %rdi
movl $0x11, %esi
leaq 0x1f068(%rip), %rdx     # 0x210b9
callq 0x5170
movq -0x8(%rbp), %rdi
callq 0x8640
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x4ff0
movq -0x8(%rbp), %rdi
callq 0x5020
movq -0x8(%rbp), %rdi
movzwl 0x1f00d(%rip), %esi     # 0x2108e
callq 0x4fb0
movq -0x8(%rbp), %rdi
movl $0x3fd, %esi            # imm = 0x3FD
callq 0x5eb0
movq -0x8(%rbp), %rdi
xorl %esi, %esi
callq 0x5ee0
movq -0x8(%rbp), %rdi
movl $0xfff, %esi            # imm = 0xFFF
callq 0x5ee0
movb $0x0, -0x21(%rbp)
movq -0x8(%rbp), %rdi
callq 0x5fe0
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rdi
movb -0x21(%rbp), %al
movb %al, %cl
addb $0x1, %cl
movb %cl, -0x21(%rbp)
leaq 0x395c(%rip), %rdx      # 0x5a30
movzbl %al, %esi
callq 0x59c0
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rdi
callq 0x8680
movq -0x18(%rbp), %rdi
movb -0x21(%rbp), %al
movb %al, %cl
addb $0x1, %cl
movb %cl, -0x21(%rbp)
leaq 0x3931(%rip), %rdx      # 0x5a30
movzbl %al, %esi
callq 0x59c0
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rdi
callq 0x86d0
movq -0x18(%rbp), %rdi
leaq 0x3911(%rip), %rdx      # 0x5a30
movzbl -0x21(%rbp), %esi
callq 0x59c0
movq %rax, -0x20(%rbp)
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rax
movq -0x18(%rbp), %rcx
subq %rcx, %rax
subq $0x2, %rax
movzwl %ax, %esi
callq 0x5ee0
movq -0x8(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x8(%rbp), %rdi
callq 0x6b90
movq -0x48(%rbp), %rdi
movzwl %ax, %eax
addl $0x2, %eax
movzwl %ax, %esi
callq 0x5eb0
movq -0x8(%rbp), %rdi
callq 0x5f30
movq %rax, -0x10(%rbp)
movq -0x10(%rbp), %rdi
callq 0x5f70
movq -0x8(%rbp), %rdi
movl $0x3fd, %esi            # imm = 0x3FD
callq 0x5eb0
movb $0x0, -0x31(%rbp)
movq -0x8(%rbp), %rdi
movb -0x31(%rbp), %al
movb %al, %cl
addb $0x1, %cl
movb %cl, -0x31(%rbp)
movzbl %al, %esi
callq 0x6bc0
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rdi
callq 0x6cc0
movq -0x30(%rbp), %rdi
movzwl 0x1eec7(%rip), %esi     # 0x21088
callq 0x6ce0
movq -0x30(%rbp), %rdi
movzwl 0x1eebd(%rip), %esi     # 0x2108e
callq 0x6d20
movq -0x30(%rbp), %rdi
xorl %esi, %esi
callq 0x6d60
movb $0x0, -0x21(%rbp)
movq -0x30(%rbp), %rdi
callq 0x6db0
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rdi
movl $0xfff, %esi            # imm = 0xFFF
callq 0x5970
movq -0x18(%rbp), %rdi
movb -0x21(%rbp), %al
movb %al, %cl
addb $0x1, %cl
movb %cl, -0x21(%rbp)
leaq 0x381a(%rip), %rdx      # 0x5a30
movzbl %al, %esi
callq 0x59c0
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rdi
callq 0x6dd0
movq -0x18(%rbp), %rdi
leaq 0x37fa(%rip), %rdx      # 0x5a30
movzbl -0x21(%rbp), %esi
callq 0x59c0
movq %rax, -0x20(%rbp)
movq -0x18(%rbp), %rdi
movq -0x20(%rbp), %rax
movq -0x18(%rbp), %rcx
subq %rcx, %rax
subq $0x2, %rax
movzwl %ax, %esi
callq 0x5970
movq -0x8(%rbp), %rdi
movb -0x31(%rbp), %al
movb %al, %cl
addb $0x1, %cl
movb %cl, -0x31(%rbp)
movzbl %al, %esi
callq 0x6bc0
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rdi
callq 0x6cc0
movq -0x30(%rbp), %rdi
movzwl 0x1edfb(%rip), %eax     # 0x21088
addl $0x64, %eax
movzwl %ax, %esi
callq 0x6ce0
movq -0x30(%rbp), %rdi
movzwl 0x1edeb(%rip), %eax     # 0x2108e
addl $0x64, %eax
movzwl %ax, %esi
callq 0x6d20
movq -0x30(%rbp), %rdi
xorl %esi, %esi
callq 0x6d60
movq -0x8(%rbp), %rdi
movb -0x31(%rbp), %al
movb %al, %cl
addb $0x1, %cl
movb %cl, -0x31(%rbp)
movzbl %al, %esi
callq 0x6bc0
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rdi
callq 0x6cc0
movq -0x30(%rbp), %rdi
movzwl 0x1eda0(%rip), %eax     # 0x21088
addl $0xc8, %eax
movzwl %ax, %esi
callq 0x6ce0
movq -0x30(%rbp), %rdi
movzwl 0x1ed8e(%rip), %eax     # 0x2108e
addl $0xc8, %eax
movzwl %ax, %esi
callq 0x6d20
movq -0x30(%rbp), %rdi
xorl %esi, %esi
callq 0x6d60
movb $0x0, -0x21(%rbp)
movq -0x30(%rbp), %rdi
callq 0x6db0
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rdi
movl $0xfff, %esi            # imm = 0xFFF
callq 0x5970
movq -0x18(%rbp), %rdi
movb -0x21(%rbp), %al
movb %al, %cl
addb $0x1, %cl
movb %cl, -0x21(%rbp)
leaq 0x36e3(%rip), %rdx      # 0x5a30
movzbl %al, %esi
callq 0x59c0
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rdi
callq 0x6dd0
movq -0x18(%rbp), %rdi
leaq 0x36c3(%rip), %rdx      # 0x5a30
movzbl -0x21(%rbp), %esi
callq 0x59c0
movq %rax, -0x20(%rbp)
movq -0x18(%rbp), %rdi
movq -0x20(%rbp), %rax
movq -0x18(%rbp), %rcx
subq %rcx, %rax
subq $0x2, %rax
movzwl %ax, %esi
callq 0x5970
movq -0x8(%rbp), %rdi
movb -0x31(%rbp), %al
movb %al, %cl
addb $0x1, %cl
movb %cl, -0x31(%rbp)
movzbl %al, %esi
callq 0x6bc0
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rdi
callq 0x6cc0
movq -0x30(%rbp), %rdi
movzwl 0x1ecc4(%rip), %eax     # 0x21088
addl $0x12c, %eax            # imm = 0x12C
movzwl %ax, %esi
callq 0x6ce0
movq -0x30(%rbp), %rdi
movzwl 0x1ecb2(%rip), %eax     # 0x2108e
addl $0x12c, %eax            # imm = 0x12C
movzwl %ax, %esi
callq 0x6d20
movq -0x30(%rbp), %rdi
xorl %esi, %esi
callq 0x6d60
movq -0x8(%rbp), %rdi
movzbl -0x31(%rbp), %esi
callq 0x6bc0
movq %rax, -0x30(%rbp)
movq -0x10(%rbp), %rdi
movq -0x30(%rbp), %rax
movq -0x10(%rbp), %rcx
subq %rcx, %rax
subq $0x2, %rax
movzwl %ax, %esi
callq 0x5f90
movq -0x8(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x8(%rbp), %rdi
callq 0x6b90
movzwl %ax, %eax
addl $0x2, %eax
movl %eax, -0x38(%rbp)
movq -0x10(%rbp), %rdi
callq 0x7090
movq -0x40(%rbp), %rdi
movw %ax, %cx
movl -0x38(%rbp), %eax
movzwl %cx, %ecx
addl %ecx, %eax
movzwl %ax, %esi
callq 0x5eb0
movq -0x8(%rbp), %rdi
callq 0x5080
movq -0x8(%rbp), %rdi
movl $0x11, %esi
leaq 0x1ec46(%rip), %rdx     # 0x210b9
callq 0x5170
movq -0x8(%rbp), %rdi
callq 0x1030
addq $0x50, %rsp
popq %rbp
retq
nopw (%rax,%rax)