// File: /workspace/github_cpp_makefile_star2_O3/OpenFodder[P]SOS_Unpacker/capsimg/CAPSImg/CapsImageStd.cpp
// Function: CCapsImageStd::GenerateNoiseDensity(DiskTrackInfo*)
int CCapsImageStd::GenerateNoiseDensity(PDISKTRACKINFO pti)
{
	// same size with track data
	if (pti->tracklen && pti->trackcnt)
		pti->timecnt=pti->tracklen/pti->trackcnt;
	else
		if (!(pti->timecnt=pti->ci.trksize))
			pti->timecnt=12500;

	pti->timebuf=new UDWORD[pti->timecnt+1];

	int pos;
	for (pos=0; pos < pti->timecnt; pos++) {
		UDWORD val=1000;

		if (pos & 512)
			val+=(pos % 99)+(pos&31);
		else
			val-=(pos % 121)-(pos&31);

		pti->timebuf[pos]=val;
	}

	pti->timebuf[pos]=0;

	return imgeOk;
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
movq %rsi, %r14
movl 0x50(%rsi), %eax
testl %eax, %eax
je 0xa7bd
movl 0x28(%r14), %ecx
testl %ecx, %ecx
je 0xa7bd
cltd
idivl %ecx
movl %eax, %ebx
movl %eax, 0xa8(%r14)
jmp 0xa7d5
movl 0x110(%r14), %eax
testl %eax, %eax
movl $0x30d4, %ebx           # imm = 0x30D4
cmovnel %eax, %ebx
movl %ebx, 0xa8(%r14)
movslq %ebx, %r15
leaq 0x4(,%r15,4), %rax
cmpl $-0x1, %r15d
movq $-0x1, %rdi
cmovgeq %rax, %rdi
callq 0x4040
movq %rax, 0xb0(%r14)
testl %r15d, %r15d
jle 0xaa82
movl %ebx, %ecx
addl $0x3, %ebx
leaq -0x1(%rcx), %rdx
movq %rdx, %xmm0
pshufd $0x44, %xmm0, %xmm0     # xmm0 = xmm0[0,1,0,1]
shrl $0x2, %ebx
shlq $0x4, %rbx
movdqa 0x7a7a(%rip), %xmm1     # 0x122a0
movdqa 0x7a82(%rip), %xmm2     # 0x122b0
movdqa 0x7a8a(%rip), %xmm3     # 0x122c0
xorl %edx, %edx
pxor 0x7a90(%rip), %xmm0     # 0x122d0
pcmpeqd %xmm5, %xmm5
movdqa 0x7ae3(%rip), %xmm12    # 0x12330
movdqa 0x7aea(%rip), %xmm13    # 0x12340
movdqa %xmm2, %xmm7
movdqa 0x7a6e(%rip), %xmm4     # 0x122d0
pxor %xmm4, %xmm7
movdqa %xmm7, %xmm6
pcmpgtd %xmm0, %xmm6
pshufd $0xa0, %xmm6, %xmm14    # xmm14 = xmm6[0,0,2,2]
pcmpeqd %xmm0, %xmm7
pshufd $0xf5, %xmm7, %xmm7     # xmm7 = xmm7[1,1,3,3]
pand %xmm7, %xmm14
pshufd $0xf5, %xmm6, %xmm8     # xmm8 = xmm6[1,1,3,3]
por %xmm8, %xmm14
pxor %xmm5, %xmm14
movdqa %xmm1, %xmm15
pxor %xmm4, %xmm15
movdqa %xmm15, %xmm4
pcmpgtd %xmm0, %xmm4
pcmpeqd %xmm0, %xmm15
pshufd $0xf5, %xmm15, %xmm9    # xmm9 = xmm15[1,1,3,3]
pand %xmm4, %xmm9
pshufd $0xf5, %xmm4, %xmm15    # xmm15 = xmm4[1,1,3,3]
por %xmm9, %xmm15
pxor %xmm5, %xmm15
movd %xmm14, %esi
movdqa %xmm14, %xmm4
shufps $0x88, %xmm15, %xmm4    # xmm4 = xmm4[0,2],xmm15[0,2]
movdqa %xmm3, %xmm14
pand 0x79fe(%rip), %xmm14    # 0x122e0
pcmpeqd 0x7a75(%rip), %xmm14    # 0x12360
pand %xmm4, %xmm14
movdqa %xmm3, %xmm4
movdqa 0x7a03(%rip), %xmm11    # 0x12300
pmuludq %xmm11, %xmm4
pshufd $0xed, %xmm4, %xmm4     # xmm4 = xmm4[1,3,2,3]
pshufd $0xf5, %xmm3, %xmm10    # xmm10 = xmm3[1,1,3,3]
movdqa %xmm10, %xmm9
pmuludq %xmm11, %xmm9
pshufd $0xed, %xmm9, %xmm9     # xmm9 = xmm9[1,3,2,3]
punpckldq %xmm9, %xmm4    # xmm4 = xmm4[0],xmm9[0],xmm4[1],xmm9[1]
psrld $0x6, %xmm4
pshufd $0xf5, %xmm4, %xmm9     # xmm9 = xmm4[1,1,3,3]
movdqa 0x79da(%rip), %xmm11    # 0x12310
pmuludq %xmm11, %xmm4
pshufd $0xe8, %xmm4, %xmm4     # xmm4 = xmm4[0,2,2,3]
pmuludq %xmm11, %xmm9
pshufd $0xe8, %xmm9, %xmm9     # xmm9 = xmm9[0,2,2,3]
punpckldq %xmm9, %xmm4    # xmm4 = xmm4[0],xmm9[0],xmm4[1],xmm9[1]
movdqa %xmm3, %xmm9
psubd %xmm4, %xmm9
movdqa %xmm3, %xmm4
movdqa 0x79b9(%rip), %xmm11    # 0x12320
pmuludq %xmm11, %xmm4
pshufd $0xed, %xmm4, %xmm4     # xmm4 = xmm4[1,3,2,3]
pmuludq %xmm11, %xmm10
pshufd $0xed, %xmm10, %xmm10   # xmm10 = xmm10[1,3,2,3]
punpckldq %xmm10, %xmm4   # xmm4 = xmm4[0],xmm10[0],xmm4[1],xmm10[1]
movdqa %xmm3, %xmm10
psubd %xmm4, %xmm10
psrld $0x1, %xmm10
paddd %xmm4, %xmm10
psrld $0x6, %xmm10
pshufd $0xf5, %xmm10, %xmm4    # xmm4 = xmm10[1,1,3,3]
pmuludq %xmm12, %xmm10
pshufd $0xe8, %xmm10, %xmm10   # xmm10 = xmm10[0,2,2,3]
pmuludq %xmm12, %xmm4
pshufd $0xe8, %xmm4, %xmm4     # xmm4 = xmm4[0,2,2,3]
punpckldq %xmm4, %xmm10   # xmm10 = xmm10[0],xmm4[0],xmm10[1],xmm4[1]
psubd %xmm3, %xmm10
pand %xmm14, %xmm10
pandn %xmm9, %xmm14
por %xmm10, %xmm14
movdqa %xmm3, %xmm4
pand 0x7914(%rip), %xmm4     # 0x122f0
paddd %xmm4, %xmm14
testb $0x1, %sil
je 0xa9f5
movd %xmm14, %esi
addl $0x3e8, %esi            # imm = 0x3E8
movl %esi, (%rax,%rdx)
pand %xmm6, %xmm7
por %xmm8, %xmm7
pxor %xmm5, %xmm7
pextrw $0x4, %xmm7, %esi
testb $0x1, %sil
je 0xaa21
pshufd $0x55, %xmm14, %xmm4    # xmm4 = xmm14[1,1,1,1]
movd %xmm4, %esi
addl $0x3e8, %esi            # imm = 0x3E8
movl %esi, 0x4(%rax,%rdx)
pextrw $0x0, %xmm15, %esi
testb $0x1, %sil
je 0xaa41
pshufd $0xee, %xmm14, %xmm4    # xmm4 = xmm14[2,3,2,3]
movd %xmm4, %esi
addl $0x3e8, %esi            # imm = 0x3E8
movl %esi, 0x8(%rax,%rdx)
pextrw $0x4, %xmm15, %esi
testb $0x1, %sil
je 0xaa61
pshufd $0xff, %xmm14, %xmm4    # xmm4 = xmm14[3,3,3,3]
movd %xmm4, %esi
addl $0x3e8, %esi            # imm = 0x3E8
movl %esi, 0xc(%rax,%rdx)
paddq %xmm13, %xmm2
paddq %xmm13, %xmm1
paddd 0x78dd(%rip), %xmm3     # 0x12350
addq $0x10, %rdx
cmpq %rdx, %rbx
jne 0xa856
jmp 0xaa84
xorl %ecx, %ecx
movl $0x0, (%rax,%rcx,4)
xorl %eax, %eax
popq %rbx
popq %r14
popq %r15
retq
nop