// File: /workspace/github_c_makefile_star2_O1/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movslq %esi, %rsi
leaq (%rsi,%rsi,2), %rax
shlq $0x8, %rsi
addq %rdi, %rsi
movslq %edx, %rdx
movq 0x40(%rsi,%rdx,8), %r12
leaq (%rdx,%rdx,2), %rdx
shlq $0x7, %rax
addq %rdi, %rax
leaq (%rax,%rdx,4), %r14
addq $0x580, %r14            # imm = 0x580
testq %r12, %r12
je 0x7afe
movq %rdi, %rbx
movslq %ecx, %rcx
leaq (%rax,%rdx,4), %rax
movl 0x280(%rax,%rcx,4), %eax
xorl %ebp, %ebp
cmpl $0x3f, %eax
je 0x7acd
movslq %eax, %rcx
imulq $0x55555556, %rcx, %rcx # imm = 0x55555556
movq %rcx, %rdx
shrq $0x3f, %rdx
shrq $0x20, %rcx
addl %edx, %ecx
leal (%rcx,%rcx,2), %edx
subl %edx, %eax
cltq
movl $0x1, %ebp
shll %cl, %ebp
leaq 0x27be(%rip), %rdx      # 0xa284
sarl %ebp
addl (%rdx,%rax,4), %ebp
sarl %cl, %ebp
movzwl (%r12), %r15d
movb 0x2(%r12), %r13b
movq 0x30(%rbx), %rdi
movzbl 0x3(%r12), %esi
callq 0x43f5
testb %r13b, %r13b
je 0x7b12
cltd
idivl %r15d
movl %edx, (%r14)
cltd
idivl %r15d
movl %eax, %ecx
movl %edx, 0x4(%r14)
jmp 0x7b39
movl $0x0, 0x8(%r14)
movq $0x0, (%r14)
jmp 0x7bc1
movl %eax, (%r14)
movq 0x30(%rbx), %rdi
movzbl 0x3(%r12), %esi
callq 0x43f5
movl %eax, 0x4(%r14)
movq 0x30(%rbx), %rdi
movzbl 0x3(%r12), %esi
callq 0x43f5
movl %eax, %ecx
incl %r15d
movl $0x10000, %eax          # imm = 0x10000
xorl %edx, %edx
divl %r15d
shrl %r15d
decl %r15d
movl %r15d, %edi
subl (%r14), %edi
imull %eax, %edi
movl %ebp, %edx
sarl $0xc, %edx
movl %edi, %r8d
imull %edx, %r8d
andl $0xfff, %ebp            # imm = 0xFFF
imull %ebp, %edi
movl $0x800, %esi            # imm = 0x800
addl %esi, %edi
sarl $0xc, %edi
addl %r8d, %edi
sarl $0xc, %edi
movl %edi, (%r14)
movl %r15d, %edi
subl 0x4(%r14), %edi
imull %eax, %edi
movl %edi, %r8d
imull %edx, %r8d
imull %ebp, %edi
addl %esi, %edi
sarl $0xc, %edi
addl %r8d, %edi
sarl $0xc, %edi
movl %edi, 0x4(%r14)
subl %ecx, %r15d
imull %eax, %r15d
imull %r15d, %edx
imull %ebp, %r15d
addl %esi, %r15d
sarl $0xc, %r15d
addl %edx, %r15d
sarl $0xc, %r15d
movl %r15d, 0x8(%r14)
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq