// File: /workspace/github_c_makefile_star2_O0/phoboslab[P]pl_mpeg/./pl_mpeg.h
// Function: plm_audio_read_samples
void plm_audio_read_samples(plm_audio_t *self, int ch, int sb, int part) {
	const plm_quantizer_spec_t *q = self->allocation[ch][sb];
	int sf = self->scale_factor[ch][sb][part];
	int *sample = self->sample[ch][sb];
	int val = 0;

	if (!q) {
		// No bits allocated for this subband
		sample[0] = sample[1] = sample[2] = 0;
		return;
	}

	// Resolve scalefactor
	if (sf == 63) {
		sf = 0;
	}
	else {
		int shift = (sf / 3) | 0;
		sf = (PLM_AUDIO_SCALEFACTOR_BASE[sf % 3] + ((1 << shift) >> 1)) >> shift;
	}

	// Decode samples
	int adj = q->levels;
	if (q->group) {
		// Decode grouped samples
		val = plm_buffer_read(self->buffer, q->bits);
		sample[0] = val % adj;
		val /= adj;
		sample[1] = val % adj;
		sample[2] = val / adj;
	}
	else {
		// Decode direct samples
		sample[0] = plm_buffer_read(self->buffer, q->bits);
		sample[1] = plm_buffer_read(self->buffer, q->bits);
		sample[2] = plm_buffer_read(self->buffer, q->bits);
	}

	// Postmultiply samples
	int scale = 65536 / (adj + 1);
	adj = ((adj + 1) >> 1) - 1;

	val = (adj - sample[0]) * scale;
	sample[0] = (val * (sf >> 12) + ((val * (sf & 4095) + 2048) >> 12)) >> 12;

	val = (adj - sample[1]) * scale;
	sample[1] = (val * (sf >> 12) + ((val * (sf & 4095) + 2048) >> 12)) >> 12;

	val = (adj - sample[2]) * scale;
	sample[2] = (val * (sf >> 12) + ((val * (sf & 4095) + 2048) >> 12)) >> 12;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl %edx, -0x10(%rbp)
movl %ecx, -0x14(%rbp)
movq -0x8(%rbp), %rax
addq $0x40, %rax
movslq -0xc(%rbp), %rcx
shlq $0x8, %rcx
addq %rcx, %rax
movslq -0x10(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x20(%rbp)
movq -0x8(%rbp), %rax
addq $0x280, %rax            # imm = 0x280
movslq -0xc(%rbp), %rcx
imulq $0x180, %rcx, %rcx      # imm = 0x180
addq %rcx, %rax
movslq -0x10(%rbp), %rcx
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
movslq -0x14(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x24(%rbp)
movq -0x8(%rbp), %rax
addq $0x580, %rax            # imm = 0x580
movslq -0xc(%rbp), %rcx
imulq $0x180, %rcx, %rcx      # imm = 0x180
addq %rcx, %rax
movslq -0x10(%rbp), %rcx
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x30(%rbp)
movl $0x0, -0x34(%rbp)
cmpq $0x0, -0x20(%rbp)
jne 0xa2eb
movq -0x30(%rbp), %rax
movl $0x0, 0x8(%rax)
movq -0x30(%rbp), %rax
movl $0x0, 0x4(%rax)
movq -0x30(%rbp), %rax
movl $0x0, (%rax)
jmp 0xa4d6
cmpl $0x3f, -0x24(%rbp)
jne 0xa2fa
movl $0x0, -0x24(%rbp)
jmp 0xa33b
movl -0x24(%rbp), %eax
movl $0x3, %ecx
cltd
idivl %ecx
orl $0x0, %eax
movl %eax, -0x38(%rbp)
movl -0x24(%rbp), %eax
movl $0x3, %ecx
cltd
idivl %ecx
movslq %edx, %rcx
leaq 0x3fa4(%rip), %rax      # 0xe2c4
movl (%rax,%rcx,4), %eax
movl -0x38(%rbp), %ecx
movl $0x1, %edx
shll %cl, %edx
movl %edx, %ecx
sarl %ecx
addl %ecx, %eax
movl -0x38(%rbp), %ecx
sarl %cl, %eax
movl %eax, -0x24(%rbp)
movq -0x20(%rbp), %rax
movzwl (%rax), %eax
movl %eax, -0x3c(%rbp)
movq -0x20(%rbp), %rax
cmpb $0x0, 0x2(%rax)
je 0xa3a0
movq -0x8(%rbp), %rax
movq 0x30(%rax), %rdi
movq -0x20(%rbp), %rax
movzbl 0x3(%rax), %esi
callq 0x5320
movl %eax, -0x34(%rbp)
movl -0x34(%rbp), %eax
cltd
idivl -0x3c(%rbp)
movq -0x30(%rbp), %rax
movl %edx, (%rax)
movl -0x3c(%rbp), %ecx
movl -0x34(%rbp), %eax
cltd
idivl %ecx
movl %eax, -0x34(%rbp)
movl -0x34(%rbp), %eax
cltd
idivl -0x3c(%rbp)
movq -0x30(%rbp), %rax
movl %edx, 0x4(%rax)
movl -0x34(%rbp), %eax
cltd
idivl -0x3c(%rbp)
movl %eax, %ecx
movq -0x30(%rbp), %rax
movl %ecx, 0x8(%rax)
jmp 0xa3f9
movq -0x8(%rbp), %rax
movq 0x30(%rax), %rdi
movq -0x20(%rbp), %rax
movzbl 0x3(%rax), %esi
callq 0x5320
movl %eax, %ecx
movq -0x30(%rbp), %rax
movl %ecx, (%rax)
movq -0x8(%rbp), %rax
movq 0x30(%rax), %rdi
movq -0x20(%rbp), %rax
movzbl 0x3(%rax), %esi
callq 0x5320
movl %eax, %ecx
movq -0x30(%rbp), %rax
movl %ecx, 0x4(%rax)
movq -0x8(%rbp), %rax
movq 0x30(%rax), %rdi
movq -0x20(%rbp), %rax
movzbl 0x3(%rax), %esi
callq 0x5320
movl %eax, %ecx
movq -0x30(%rbp), %rax
movl %ecx, 0x8(%rax)
movl -0x3c(%rbp), %ecx
addl $0x1, %ecx
movl $0x10000, %eax          # imm = 0x10000
cltd
idivl %ecx
movl %eax, -0x40(%rbp)
movl -0x3c(%rbp), %eax
addl $0x1, %eax
sarl %eax
subl $0x1, %eax
movl %eax, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
movq -0x30(%rbp), %rcx
subl (%rcx), %eax
imull -0x40(%rbp), %eax
movl %eax, -0x34(%rbp)
movl -0x34(%rbp), %ecx
movl -0x24(%rbp), %eax
sarl $0xc, %eax
imull %eax, %ecx
movl -0x34(%rbp), %eax
movl -0x24(%rbp), %edx
andl $0xfff, %edx            # imm = 0xFFF
imull %edx, %eax
addl $0x800, %eax            # imm = 0x800
sarl $0xc, %eax
addl %eax, %ecx
sarl $0xc, %ecx
movq -0x30(%rbp), %rax
movl %ecx, (%rax)
movl -0x3c(%rbp), %eax
movq -0x30(%rbp), %rcx
subl 0x4(%rcx), %eax
imull -0x40(%rbp), %eax
movl %eax, -0x34(%rbp)
movl -0x34(%rbp), %ecx
movl -0x24(%rbp), %eax
sarl $0xc, %eax
imull %eax, %ecx
movl -0x34(%rbp), %eax
movl -0x24(%rbp), %edx
andl $0xfff, %edx            # imm = 0xFFF
imull %edx, %eax
addl $0x800, %eax            # imm = 0x800
sarl $0xc, %eax
addl %eax, %ecx
sarl $0xc, %ecx
movq -0x30(%rbp), %rax
movl %ecx, 0x4(%rax)
movl -0x3c(%rbp), %eax
movq -0x30(%rbp), %rcx
subl 0x8(%rcx), %eax
imull -0x40(%rbp), %eax
movl %eax, -0x34(%rbp)
movl -0x34(%rbp), %ecx
movl -0x24(%rbp), %eax
sarl $0xc, %eax
imull %eax, %ecx
movl -0x34(%rbp), %eax
movl -0x24(%rbp), %edx
andl $0xfff, %edx            # imm = 0xFFF
imull %edx, %eax
addl $0x800, %eax            # imm = 0x800
sarl $0xc, %eax
addl %eax, %ecx
sarl $0xc, %ecx
movq -0x30(%rbp), %rax
movl %ecx, 0x8(%rax)
addq $0x40, %rsp
popq %rbp
retq
nopl (%rax)