// File: /workspace/github_c_makefile_star2_O1/dwbuiten[P]obuparse/obuparse.c
// Function: obp_parse_tile_list
int obp_parse_tile_list(uint8_t *buf, size_t buf_size, OBPTileList *tile_list, OBPError *err)
{
    size_t pos = 0;

    if (buf_size < 4) {
        snprintf(err->error, err->size, "Tile list OBU must be at least 4 bytes.");
        return -1;
    }

    tile_list->output_frame_width_in_tiles_minus_1  = buf[0];
    tile_list->output_frame_height_in_tiles_minus_1 = buf[1];
    tile_list->tile_count_minus_1                   = (((uint16_t) buf[2]) << 8) | buf[3];
    pos += 4;

    for (uint16_t i = 0; i < tile_list->tile_count_minus_1; i++) {
        if (pos + 5 > buf_size) {
            snprintf(err->error, err->size, "Tile list OBU malformed: Not enough bytes for next tile_list_entry().");
            return -1;
        }

        tile_list->tile_list_entry[i].anchor_frame_idx       = buf[pos];
        tile_list->tile_list_entry[i].anchor_tile_row        = buf[pos + 1];
        tile_list->tile_list_entry[i].anchor_tile_col        = buf[pos + 2];
        tile_list->tile_list_entry[i].tile_data_size_minus_1 = (((uint16_t) buf[pos + 3]) << 8) | buf[pos + 4];
        pos += 5;

        size_t N = 8 * (((size_t) tile_list->tile_list_entry[i].tile_data_size_minus_1) + 1);

        if (pos + N > buf_size) {
            snprintf(err->error, err->size, "Tile list OBU malformed: Not enough bytes for next tile_list_entry()'s data.");
            return -1;
        }

        tile_list->tile_list_entry[i].coded_tile_data      = buf + pos;
        tile_list->tile_list_entry[i].coded_tile_data_size = N;
        pos += N;
    }

    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
cmpq $0x3, %rsi
ja 0x2eff
movq (%rcx), %rdi
movq 0x8(%rcx), %rsi
leaq 0x82ab(%rip), %rdx      # 0xb199
xorl %eax, %eax
callq 0x1030
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
jmp 0x300b
movq %rdx, %r8
movq %rdi, %r12
movb (%rdi), %al
movb %al, (%rdx)
movb 0x1(%rdi), %al
movb %al, 0x1(%rdx)
movzwl 0x2(%rdi), %eax
rolw $0x8, %ax
movw %ax, 0x2(%rdx)
testw %ax, %ax
setne %r15b
je 0x3002
leaq 0x8(%r8), %r13
movl $0x4, %eax
xorl %ebx, %ebx
movq %rcx, 0x10(%rsp)
movq %rsi, 0x8(%rsp)
leaq 0x5(%rax), %r14
cmpq %rsi, %r14
ja 0x2fed
movb (%r12,%rax), %dl
movb %dl, (%r13)
movb 0x1(%r12,%rax), %dl
movb %dl, 0x1(%r13)
movb 0x2(%r12,%rax), %dl
movb %dl, 0x2(%r13)
movzwl 0x3(%r12,%rax), %eax
rolw $0x8, %ax
movw %ax, 0x4(%r13)
movzwl %ax, %eax
leaq (%r14,%rax,8), %rbp
addq $0x8, %rbp
cmpq %rsi, %rbp
jbe 0x2fb7
movq (%rcx), %rdi
movq 0x8(%rcx), %rsi
leaq 0x8276(%rip), %rdx      # 0xb207
xorl %eax, %eax
movb %r15b, 0x7(%rsp)
movq %r8, %r15
callq 0x1030
movq 0x8(%rsp), %rsi
movq %r15, %r8
movb 0x7(%rsp), %r15b
movq 0x10(%rsp), %rcx
movq %r14, %rax
jmp 0x2fcd
leaq 0x8(,%rax,8), %rax
addq %r12, %r14
movq %r14, 0x8(%r13)
movq %rax, 0x10(%r13)
movq %rbp, %rax
cmpq %rsi, %rbp
ja 0x3002
incq %rbx
movzwl 0x2(%r8), %edx
addq $0x18, %r13
cmpq %rdx, %rbx
setb %r15b
jb 0x2f3d
jmp 0x3002
movq (%rcx), %rdi
movq 0x8(%rcx), %rsi
leaq 0x81c6(%rip), %rdx      # 0xb1c1
xorl %eax, %eax
callq 0x1030
movzbl %r15b, %eax
andl $0x1, %eax
negl %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq