// File: /workspace/github_c_makefile_star2_O0/tvlabs[P]edge264/edge264.c
// Function: edge264_get_frame
int edge264_get_frame(Edge264Decoder *dec, Edge264Frame *out, int borrow) {
	if (dec == NULL || out == NULL)
		return EINVAL;
	if (dec->n_threads)
		pthread_mutex_lock(&dec->lock);
	int pic[2] = {-1, -1};
	unsigned used = dec->reference_flags | dec->output_flags;
	int best = (__builtin_popcount(dec->output_flags & ~dec->second_views) > dec->sps.max_num_reorder_frames ||
		(dec->second_views && __builtin_popcount(dec->output_flags & dec->second_views) > dec->ssps.max_num_reorder_frames) ||
		__builtin_popcount(used & ~dec->second_views) >= dec->sps.num_frame_buffers ||
		(dec->second_views && __builtin_popcount(used & dec->second_views) >= dec->ssps.num_frame_buffers)) ? INT_MAX : dec->dispPicOrderCnt;
	for (int o = dec->output_flags; o != 0; o &= o - 1) {
		int i = __builtin_ctz(o);
		if (dec->FieldOrderCnt[0][i] <= best) {
			int non_base = dec->second_views >> i & 1;
			if (dec->FieldOrderCnt[0][i] < best) {
				best = dec->FieldOrderCnt[0][i];
				pic[non_base ^ 1] = -1;
			}
			pic[non_base] = i;
		}
	}
	
	int res = ENOMSG;
	if (pic[0] >= 0 && dec->next_deblock_addr[pic[0]] == INT_MAX && (!dec->second_views || (pic[1] >= 0 && dec->next_deblock_addr[pic[1]] == INT_MAX))) {
		*out = dec->out;
		int top = dec->out.frame_crop_offsets[0];
		int left = dec->out.frame_crop_offsets[3];
		int offY = top * dec->out.stride_Y + (left << dec->out.pixel_depth_Y);
		int topC = dec->sps.chroma_format_idc == 3 ? top : top >> 1;
		int leftC = dec->sps.chroma_format_idc == 1 ? left >> 1 : left;
		int offC = dec->plane_size_Y + topC * dec->out.stride_C + (leftC << dec->out.pixel_depth_C);
		dec->output_flags ^= 1 << pic[0];
		const uint8_t *samples = dec->frame_buffers[pic[0]];
		out->samples[0] = samples + offY;
		out->samples[1] = samples + offC;
		out->samples[2] = samples + (dec->out.stride_C >> 1) + offC;
		out->FrameId = dec->FrameIds[pic[0]];
		out->return_arg = (void *)((size_t)1 << pic[0]);
		if (pic[1] >= 0) {
			dec->output_flags ^= 1 << pic[1];
			samples = dec->frame_buffers[pic[1]];
			out->samples_mvc[0] = samples + offY;
			out->samples_mvc[1] = samples + offC;
			out->samples_mvc[2] = samples + (dec->out.stride_C >> 1) + offC;
			out->FrameId_mvc = dec->FrameIds[pic[1]];
			out->return_arg = (void *)((size_t)1 << pic[0] | (size_t)1 << pic[1]);
		}
		res = 0;
		if (borrow)
			dec->borrow_flags |= (size_t)out->return_arg;
	}
	if (dec->n_threads)
		pthread_mutex_unlock(&dec->lock);
	return res;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
cmpq $0x0, -0x10(%rbp)
je 0x1cb24
cmpq $0x0, -0x18(%rbp)
jne 0x1cb30
movl $0x16, -0x4(%rbp)
jmp 0x1cf8b
movq -0x10(%rbp), %rax
cmpb $0x0, 0x20(%rax)
je 0x1cb4a
movq -0x10(%rbp), %rdi
addq $0x1580, %rdi           # imm = 0x1580
callq 0x7160
movq 0xb123f(%rip), %rax     # 0xcdd90
movq %rax, -0x24(%rbp)
movq -0x10(%rbp), %rax
movl 0x4c(%rax), %eax
movq -0x10(%rbp), %rcx
orl 0x54(%rcx), %eax
movl %eax, -0x28(%rbp)
movq -0x10(%rbp), %rax
movl 0x54(%rax), %eax
movq -0x10(%rbp), %rcx
movl 0x68(%rcx), %ecx
xorl $-0x1, %ecx
andl %ecx, %eax
popcntl %eax, %eax
movq -0x10(%rbp), %rcx
movsbl 0x534(%rcx), %ecx
cmpl %ecx, %eax
jg 0x1cc00
movq -0x10(%rbp), %rax
cmpl $0x0, 0x68(%rax)
je 0x1cbb7
movq -0x10(%rbp), %rax
movl 0x54(%rax), %eax
movq -0x10(%rbp), %rcx
andl 0x68(%rcx), %eax
popcntl %eax, %eax
movq -0x10(%rbp), %rcx
movsbl 0x944(%rcx), %ecx
cmpl %ecx, %eax
jg 0x1cc00
movl -0x28(%rbp), %eax
movq -0x10(%rbp), %rcx
movl 0x68(%rcx), %ecx
xorl $-0x1, %ecx
andl %ecx, %eax
popcntl %eax, %eax
movq -0x10(%rbp), %rcx
movsbl 0x533(%rcx), %ecx
cmpl %ecx, %eax
jge 0x1cc00
movq -0x10(%rbp), %rax
cmpl $0x0, 0x68(%rax)
je 0x1cc0a
movl -0x28(%rbp), %eax
movq -0x10(%rbp), %rcx
andl 0x68(%rcx), %eax
popcntl %eax, %eax
movq -0x10(%rbp), %rcx
movsbl 0x943(%rcx), %ecx
cmpl %ecx, %eax
jl 0x1cc0a
movl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, -0x64(%rbp)
jmp 0x1cc14
movq -0x10(%rbp), %rax
movl 0x48(%rax), %eax
movl %eax, -0x64(%rbp)
movl -0x64(%rbp), %eax
movl %eax, -0x2c(%rbp)
movq -0x10(%rbp), %rax
movl 0x54(%rax), %eax
movl %eax, -0x30(%rbp)
cmpl $0x0, -0x30(%rbp)
je 0x1ccb2
movl -0x30(%rbp), %eax
tzcntl %eax, %eax
movl %eax, -0x34(%rbp)
movq -0x10(%rbp), %rax
movslq -0x34(%rbp), %rcx
movl 0x3c0(%rax,%rcx,4), %eax
cmpl -0x2c(%rbp), %eax
jg 0x1cc9f
movq -0x10(%rbp), %rax
movl 0x68(%rax), %eax
movl -0x34(%rbp), %ecx
shrl %cl, %eax
andl $0x1, %eax
movl %eax, -0x38(%rbp)
movq -0x10(%rbp), %rax
movslq -0x34(%rbp), %rcx
movl 0x3c0(%rax,%rcx,4), %eax
cmpl -0x2c(%rbp), %eax
jge 0x1cc94
movq -0x10(%rbp), %rax
movslq -0x34(%rbp), %rcx
movl 0x3c0(%rax,%rcx,4), %eax
movl %eax, -0x2c(%rbp)
movl -0x38(%rbp), %eax
xorl $0x1, %eax
cltq
movl $0xffffffff, -0x24(%rbp,%rax,4) # imm = 0xFFFFFFFF
movl -0x34(%rbp), %ecx
movslq -0x38(%rbp), %rax
movl %ecx, -0x24(%rbp,%rax,4)
jmp 0x1cca1
movl -0x30(%rbp), %eax
subl $0x1, %eax
andl -0x30(%rbp), %eax
movl %eax, -0x30(%rbp)
jmp 0x1cc24
movl $0x2a, -0x3c(%rbp)
cmpl $0x0, -0x24(%rbp)
jl 0x1cf6b
movq -0x10(%rbp), %rax
movslq -0x24(%rbp), %rcx
cmpl $0x7fffffff, 0x16c0(%rax,%rcx,4) # imm = 0x7FFFFFFF
jne 0x1cf6b
movq -0x10(%rbp), %rax
cmpl $0x0, 0x68(%rax)
je 0x1cd09
cmpl $0x0, -0x20(%rbp)
jl 0x1cf6b
movq -0x10(%rbp), %rax
movslq -0x20(%rbp), %rcx
cmpl $0x7fffffff, 0x16c0(%rax,%rcx,4) # imm = 0x7FFFFFFF
jne 0x1cf6b
movq -0x18(%rbp), %rdi
movq -0x10(%rbp), %rsi
addq $0x4c0, %rsi            # imm = 0x4C0
movl $0x60, %edx
callq 0x70c0
movq -0x10(%rbp), %rax
movswl 0x510(%rax), %eax
movl %eax, -0x40(%rbp)
movq -0x10(%rbp), %rax
movswl 0x516(%rax), %eax
movl %eax, -0x44(%rbp)
movl -0x40(%rbp), %eax
movq -0x10(%rbp), %rcx
movswl 0x502(%rcx), %ecx
imull %ecx, %eax
movl -0x44(%rbp), %edx
movq -0x10(%rbp), %rcx
movsbl 0x4f8(%rcx), %ecx
shll %cl, %edx
movl %edx, %ecx
addl %ecx, %eax
movl %eax, -0x48(%rbp)
movq -0x10(%rbp), %rax
movsbl 0x520(%rax), %eax
cmpl $0x3, %eax
jne 0x1cd7e
movl -0x40(%rbp), %eax
movl %eax, -0x68(%rbp)
jmp 0x1cd86
movl -0x40(%rbp), %eax
sarl %eax
movl %eax, -0x68(%rbp)
movl -0x68(%rbp), %eax
movl %eax, -0x4c(%rbp)
movq -0x10(%rbp), %rax
movsbl 0x520(%rax), %eax
cmpl $0x1, %eax
jne 0x1cda6
movl -0x44(%rbp), %eax
sarl %eax
movl %eax, -0x6c(%rbp)
jmp 0x1cdac
movl -0x44(%rbp), %eax
movl %eax, -0x6c(%rbp)
movl -0x6c(%rbp), %eax
movl %eax, -0x50(%rbp)
movq -0x10(%rbp), %rax
movl 0x2c(%rax), %eax
movl -0x4c(%rbp), %ecx
movq -0x10(%rbp), %rdx
movswl 0x504(%rdx), %edx
imull %edx, %ecx
addl %ecx, %eax
movl -0x50(%rbp), %edx
movq -0x10(%rbp), %rcx
movsbl 0x4f9(%rcx), %ecx
shll %cl, %edx
movl %edx, %ecx
addl %ecx, %eax
movl %eax, -0x54(%rbp)
movl -0x24(%rbp), %ecx
movl $0x1, %eax
shll %cl, %eax
movl %eax, %ecx
movq -0x10(%rbp), %rax
xorl 0x54(%rax), %ecx
movl %ecx, 0x54(%rax)
movq -0x10(%rbp), %rax
movslq -0x24(%rbp), %rcx
movq 0x178(%rax,%rcx,8), %rax
movq %rax, -0x60(%rbp)
movq -0x60(%rbp), %rcx
movslq -0x48(%rbp), %rax
addq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, (%rax)
movq -0x60(%rbp), %rcx
movslq -0x54(%rbp), %rax
addq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x60(%rbp), %rcx
movq -0x10(%rbp), %rax
movswl 0x504(%rax), %eax
sarl %eax
cltq
addq %rax, %rcx
movslq -0x54(%rbp), %rax
addq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x10(%rbp), %rax
movslq -0x24(%rbp), %rcx
movl 0xec(%rax,%rcx,4), %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x48(%rax)
movl -0x24(%rbp), %eax
movl %eax, %ecx
movl $0x1, %eax
shlq %cl, %rax
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x58(%rax)
cmpl $0x0, -0x20(%rbp)
jl 0x1cf47
movl -0x20(%rbp), %ecx
movl $0x1, %eax
shll %cl, %eax
movl %eax, %ecx
movq -0x10(%rbp), %rax
xorl 0x54(%rax), %ecx
movl %ecx, 0x54(%rax)
movq -0x10(%rbp), %rax
movslq -0x20(%rbp), %rcx
movq 0x178(%rax,%rcx,8), %rax
movq %rax, -0x60(%rbp)
movq -0x60(%rbp), %rcx
movslq -0x48(%rbp), %rax
addq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x60(%rbp), %rcx
movslq -0x54(%rbp), %rax
addq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x20(%rax)
movq -0x60(%rbp), %rcx
movq -0x10(%rbp), %rax
movswl 0x504(%rax), %eax
sarl %eax
cltq
addq %rax, %rcx
movslq -0x54(%rbp), %rax
addq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x28(%rax)
movq -0x10(%rbp), %rax
movslq -0x20(%rbp), %rcx
movl 0xec(%rax,%rcx,4), %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x4c(%rax)
movl -0x24(%rbp), %eax
movl %eax, %ecx
movl $0x1, %eax
shlq %cl, %rax
movq %rax, -0x78(%rbp)
movl -0x20(%rbp), %eax
movl %eax, %ecx
movl $0x1, %eax
shlq %cl, %rax
movq -0x78(%rbp), %rcx
orq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x58(%rax)
movl $0x0, -0x3c(%rbp)
cmpl $0x0, -0x1c(%rbp)
je 0x1cf69
movq -0x18(%rbp), %rax
movq 0x58(%rax), %rdx
movq -0x10(%rbp), %rax
movl 0x58(%rax), %ecx
orq %rdx, %rcx
movl %ecx, 0x58(%rax)
jmp 0x1cf6b
movq -0x10(%rbp), %rax
cmpb $0x0, 0x20(%rax)
je 0x1cf85
movq -0x10(%rbp), %rdi
addq $0x1580, %rdi           # imm = 0x1580
callq 0x70e0
movl -0x3c(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x80, %rsp
popq %rbp
retq
nopw (%rax,%rax)