// File: /workspace/github_c_makefile_star2_O0/dwbuiten[P]obuparse/obuparse.c
// Function: obp_parse_tile_group
int obp_parse_tile_group(uint8_t *buf, size_t buf_size, OBPFrameHeader *frame_header, OBPTileGroup *tile_group,
                         int *SeenFrameHeader, OBPError *err)
{
    _OBPBitReader b   = _obp_new_br(buf, buf_size);
    _OBPBitReader *br = &b;

    tile_group->NumTiles                        = frame_header->tile_info.TileCols * frame_header->tile_info.TileRows;
    size_t startBitPos                          = 0;
    tile_group->tile_start_and_end_present_flag = 0;

    if (tile_group->NumTiles > 1) {
        _obp_br(tile_group->tile_start_and_end_present_flag, br, 1);
    }
    if (tile_group->NumTiles == 1 || !tile_group->tile_start_and_end_present_flag) {
        tile_group->tg_start = 0;
        tile_group->tg_end   = tile_group->NumTiles - 1;
    } else {
        uint8_t tileBits = _obp_tile_log2(1, frame_header->tile_info.TileCols) + _obp_tile_log2(1, frame_header->tile_info.TileRows);
        _obp_br(tile_group->tg_start, br, tileBits);
        _obp_br(tile_group->tg_end, br, tileBits);
    }
    _obp_br_byte_alignment(br);
    size_t endBitPos   = _obp_br_get_pos(br);
    size_t headerBytes = (endBitPos - startBitPos) / 8;
    size_t sz          = buf_size - headerBytes;
    size_t pos         = headerBytes;

    for (uint16_t TileNum = tile_group->tg_start; TileNum <= tile_group->tg_end; TileNum++) {
        /* tileRow = TileNum / TileCols */
        /* tileCol = TileNum % TileCols */
        int lastTile     = (TileNum == tile_group->tg_end);
        if (lastTile) {
            tile_group->TileSize[TileNum] = sz;
        } else {
            uint16_t TileSizeBytes = frame_header->tile_info.tile_size_bytes_minus_1 + 1;
            uint64_t tile_size_minus_1;
            if (sz < TileSizeBytes) {
                snprintf(err->error, err->size, "Not enough bytes left to read tile size for tile %"PRIu16".", TileNum);
                return -1;
            }
            tile_size_minus_1             = _obp_le(buf + pos, TileSizeBytes);
            tile_group->TileSize[TileNum] = tile_size_minus_1 + 1;
            if (sz < tile_group->TileSize[TileNum]) {
                snprintf(err->error, err->size, "Not enough bytes to contain TileSize for tile %"PRIu16".", TileNum);
                return -1;
            }
            sz  -= tile_group->TileSize[TileNum] + TileSizeBytes;
            pos += tile_group->TileSize[TileNum] + TileSizeBytes;
        }
        /* MiRowStart = MiRowStarts[ tileRow ] */
        /* MiRowEnd = MiRowStarts[ tileRow + 1 ] */
        /* MiColStart = MiColStarts[ tileCol ] */
        /* MiColEnd = MiColStarts[ tileCol + 1 ] */
        /* CurrentQIndex = base_q_idx */
        /* init_symbol( tileSize ) */
        /* decode_tile( ) */
        /* exit_symbol( ) */
    }
    if (tile_group->tg_end == tile_group->NumTiles - 1) {
        /* if ( !disable_frame_end_update_cdf ) {
               frame_end_update_cdf( )
           }
         */
        /* decode_frame_wrapup() is handled in obp_parse_frame_header. */
        *SeenFrameHeader = 0;
    }

    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xd0, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq %r8, -0x30(%rbp)
movq %r9, -0x38(%rbp)
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
leaq -0x60(%rbp), %rdi
callq 0x3be0
leaq -0x60(%rbp), %rax
movq %rax, -0x68(%rbp)
movq -0x20(%rbp), %rax
movzwl 0x122(%rax), %eax
movq -0x20(%rbp), %rcx
movzwl 0x120(%rcx), %ecx
imull %ecx, %eax
movw %ax, %cx
movq -0x28(%rbp), %rax
movw %cx, (%rax)
movq $0x0, -0x70(%rbp)
movq -0x28(%rbp), %rax
movl $0x0, 0x4(%rax)
movq -0x28(%rbp), %rax
movzwl (%rax), %eax
cmpl $0x1, %eax
jle 0x4259
jmp 0x41e0
movq -0x68(%rbp), %rax
movzbl 0x20(%rax), %ecx
movl $0x1, %eax
subl %ecx, %eax
addl $0x8, %eax
subl $0x1, %eax
sarl $0x3, %eax
cltq
movq %rax, -0x78(%rbp)
movq -0x78(%rbp), %rax
movq -0x68(%rbp), %rcx
movq 0x8(%rcx), %rcx
movq -0x68(%rbp), %rdx
subq 0x10(%rdx), %rcx
cmpq %rcx, %rax
jbe 0x4240
movq -0x38(%rbp), %rax
movq (%rax), %rdi
movq -0x38(%rbp), %rax
movq 0x8(%rax), %rsi
leaq 0xaf2c(%rip), %rdx      # 0xf159
movb $0x0, %al
callq 0x1030
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x45f7
movq -0x68(%rbp), %rdi
movl $0x1, %esi
callq 0x3c20
movl %eax, %ecx
movq -0x28(%rbp), %rax
movl %ecx, 0x4(%rax)
jmp 0x4259
movq -0x28(%rbp), %rax
movzwl (%rax), %eax
cmpl $0x1, %eax
je 0x426f
movq -0x28(%rbp), %rax
cmpl $0x0, 0x4(%rax)
jne 0x4293
movq -0x28(%rbp), %rax
movw $0x0, 0x8(%rax)
movq -0x28(%rbp), %rax
movzwl (%rax), %eax
subl $0x1, %eax
movw %ax, %cx
movq -0x28(%rbp), %rax
movw %cx, 0xa(%rax)
jmp 0x43ce
movq -0x20(%rbp), %rax
movzwl 0x122(%rax), %esi
movl $0x1, %edi
callq 0x4610
movl %eax, -0xcc(%rbp)
movq -0x20(%rbp), %rax
movzwl 0x120(%rax), %esi
movl $0x1, %edi
callq 0x4610
movl %eax, %ecx
movl -0xcc(%rbp), %eax
addl %ecx, %eax
movb %al, -0x79(%rbp)
movzbl -0x79(%rbp), %eax
movq -0x68(%rbp), %rcx
movzbl 0x20(%rcx), %ecx
subl %ecx, %eax
addl $0x8, %eax
subl $0x1, %eax
sarl $0x3, %eax
cltq
movq %rax, -0x88(%rbp)
movq -0x88(%rbp), %rax
movq -0x68(%rbp), %rcx
movq 0x8(%rcx), %rcx
movq -0x68(%rbp), %rdx
subq 0x10(%rdx), %rcx
cmpq %rcx, %rax
jbe 0x4335
movq -0x38(%rbp), %rax
movq (%rax), %rdi
movq -0x38(%rbp), %rax
movq 0x8(%rax), %rsi
leaq 0xae37(%rip), %rdx      # 0xf159
movb $0x0, %al
callq 0x1030
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x45f7
movq -0x68(%rbp), %rdi
movzbl -0x79(%rbp), %esi
callq 0x3c20
movw %ax, %cx
movq -0x28(%rbp), %rax
movw %cx, 0x8(%rax)
jmp 0x434f
movzbl -0x79(%rbp), %eax
movq -0x68(%rbp), %rcx
movzbl 0x20(%rcx), %ecx
subl %ecx, %eax
addl $0x8, %eax
subl $0x1, %eax
sarl $0x3, %eax
cltq
movq %rax, -0x90(%rbp)
movq -0x90(%rbp), %rax
movq -0x68(%rbp), %rcx
movq 0x8(%rcx), %rcx
movq -0x68(%rbp), %rdx
subq 0x10(%rdx), %rcx
cmpq %rcx, %rax
jbe 0x43b4
movq -0x38(%rbp), %rax
movq (%rax), %rdi
movq -0x38(%rbp), %rax
movq 0x8(%rax), %rsi
leaq 0xadb8(%rip), %rdx      # 0xf159
movb $0x0, %al
callq 0x1030
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x45f7
movq -0x68(%rbp), %rdi
movzbl -0x79(%rbp), %esi
callq 0x3c20
movw %ax, %cx
movq -0x28(%rbp), %rax
movw %cx, 0xa(%rax)
jmp 0x43ce
movq -0x68(%rbp), %rdi
callq 0x4640
movq -0x68(%rbp), %rdi
callq 0x4670
movq %rax, -0x98(%rbp)
movq -0x98(%rbp), %rax
subq -0x70(%rbp), %rax
shrq $0x3, %rax
movq %rax, -0xa0(%rbp)
movq -0x18(%rbp), %rax
subq -0xa0(%rbp), %rax
movq %rax, -0xa8(%rbp)
movq -0xa0(%rbp), %rax
movq %rax, -0xb0(%rbp)
movq -0x28(%rbp), %rax
movw 0x8(%rax), %ax
movw %ax, -0xb2(%rbp)
movzwl -0xb2(%rbp), %eax
movq -0x28(%rbp), %rcx
movzwl 0xa(%rcx), %ecx
cmpl %ecx, %eax
jg 0x45d0
movzwl -0xb2(%rbp), %eax
movq -0x28(%rbp), %rcx
movzwl 0xa(%rcx), %ecx
cmpl %ecx, %eax
sete %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0xb8(%rbp)
cmpl $0x0, -0xb8(%rbp)
je 0x4487
movq -0xa8(%rbp), %rdx
movq -0x28(%rbp), %rax
movzwl -0xb2(%rbp), %ecx
movq %rdx, 0x10(%rax,%rcx,8)
jmp 0x45b7
movq -0x20(%rbp), %rax
movzbl 0x128(%rax), %eax
addl $0x1, %eax
movw %ax, -0xba(%rbp)
movq -0xa8(%rbp), %rax
movzwl -0xba(%rbp), %ecx
cmpq %rcx, %rax
jae 0x44df
movq -0x38(%rbp), %rax
movq (%rax), %rdi
movq -0x38(%rbp), %rax
movq 0x8(%rax), %rsi
movzwl -0xb2(%rbp), %ecx
leaq 0xad64(%rip), %rdx      # 0xf230
movb $0x0, %al
callq 0x1030
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x45f7
movq -0x10(%rbp), %rdi
addq -0xb0(%rbp), %rdi
movw -0xba(%rbp), %ax
movzbl %al, %esi
callq 0x46a0
movq %rax, -0xc8(%rbp)
movq -0xc8(%rbp), %rdx
addq $0x1, %rdx
movq -0x28(%rbp), %rax
movzwl -0xb2(%rbp), %ecx
movq %rdx, 0x10(%rax,%rcx,8)
movq -0xa8(%rbp), %rax
movq -0x28(%rbp), %rcx
movzwl -0xb2(%rbp), %edx
cmpq 0x10(%rcx,%rdx,8), %rax
jae 0x4564
movq -0x38(%rbp), %rax
movq (%rax), %rdi
movq -0x38(%rbp), %rax
movq 0x8(%rax), %rsi
movzwl -0xb2(%rbp), %ecx
leaq 0xad14(%rip), %rdx      # 0xf265
movb $0x0, %al
callq 0x1030
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x45f7
movq -0x28(%rbp), %rax
movzwl -0xb2(%rbp), %ecx
movq 0x10(%rax,%rcx,8), %rcx
movzwl -0xba(%rbp), %eax
addq %rax, %rcx
movq -0xa8(%rbp), %rax
subq %rcx, %rax
movq %rax, -0xa8(%rbp)
movq -0x28(%rbp), %rax
movzwl -0xb2(%rbp), %ecx
movq 0x10(%rax,%rcx,8), %rax
movzwl -0xba(%rbp), %ecx
addq %rcx, %rax
addq -0xb0(%rbp), %rax
movq %rax, -0xb0(%rbp)
jmp 0x45b9
movw -0xb2(%rbp), %ax
addw $0x1, %ax
movw %ax, -0xb2(%rbp)
jmp 0x442c
movq -0x28(%rbp), %rax
movzwl 0xa(%rax), %eax
movq -0x28(%rbp), %rcx
movzwl (%rcx), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jne 0x45f0
movq -0x30(%rbp), %rax
movl $0x0, (%rax)
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0xd0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)