// File: /workspace/github_c_makefile_star2_O3/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 0x7aad
movq %rdi, %rbx
movslq %ecx, %rcx
leaq (%rax,%rdx,4), %rax
movl 0x280(%rax,%rcx,4), %eax
xorl %ebp, %ebp
cmpl $0x3f, %eax
je 0x7a7f
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 0x2a0c(%rip), %rdx      # 0xa484
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 0x4215
testb %r13b, %r13b
je 0x7ac1
cltd
idivl %r15d
movl %edx, %edi
cltd
idivl %r15d
movl %edx, %esi
movl %eax, %ecx
jmp 0x7aef
movl $0x0, 0x8(%r14)
movq $0x0, (%r14)
jmp 0x7b7f
movl %eax, (%r14)
movq 0x30(%rbx), %rdi
movzbl 0x3(%r12), %esi
callq 0x4215
movl %eax, 0x4(%r14)
movq 0x30(%rbx), %rdi
movzbl 0x3(%r12), %esi
callq 0x4215
movl %eax, %ecx
movl (%r14), %edi
movl 0x4(%r14), %esi
incl %r15d
movl $0x10000, %eax          # imm = 0x10000
xorl %edx, %edx
divl %r15d
shrl %r15d
decl %r15d
movl %r15d, %r8d
subl %edi, %r8d
imull %eax, %r8d
movl %ebp, %edx
sarl $0xc, %edx
movl %r8d, %r9d
imull %edx, %r9d
andl $0xfff, %ebp            # imm = 0xFFF
imull %ebp, %r8d
movl $0x800, %edi            # imm = 0x800
addl %edi, %r8d
sarl $0xc, %r8d
addl %r9d, %r8d
sarl $0xc, %r8d
movl %r8d, (%r14)
movl %r15d, %r8d
subl %esi, %r8d
imull %eax, %r8d
movl %r8d, %esi
imull %edx, %esi
imull %ebp, %r8d
addl %edi, %r8d
sarl $0xc, %r8d
addl %esi, %r8d
sarl $0xc, %r8d
movl %r8d, 0x4(%r14)
subl %ecx, %r15d
imull %eax, %r15d
imull %r15d, %edx
imull %ebp, %r15d
addl %edi, %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