// File: /workspace/github_c_makefile_star2_O2/YunyiQian[P]multitel3/./raytrace.c
// Function: raytrace
int raytrace(MODEL *m,double p,int ks,int ke,int TURN,double xc[],double yc[],double ti[]){

	int i,nturn,npt;
	int l0,il;
	int l;
	int k0;
	double w;
	double pdiv0,pdiv1;
	double psq0,psq1;
	double xsum;
	double tsum;
	double xtmp;
	double ttmp;
	double p2;

	if (ks < 0 || ke < 0 || p < 0.){
		fprintf(stderr,"Input is illegal\n");
		return -1;
	}

	for (i=0;i<m->nlay;i++){
		if (m->p[i] <= p){
			nturn = i;
			break;
		}
	}

	if (ks > nturn || nturn == 0 || ke > nturn){
		fprintf(stderr,"The wave cannot arrive the ke layer\n");
		return -1;
	}

	l0 = ks < ke ? ks : ke;
	p2 = p*p;

	xsum  = 0.;
	tsum  = 0.;
	xc[0] = 0.;
	ti[0] = 0.;
	yc[0] = m->depth[l0];

	pdiv0 = acos(p/m->p[l0]);
	psq0  = sqrt(m->p[l0]*m->p[l0]-p2);

	for (l=l0+1,i=1;l < nturn;l++,i++){
		w = m->B[l-1];
		pdiv1 = acos(p/m->p[l]);
		psq1  = sqrt(m->p[l]*m->p[l] - p2);
		xsum += w*(pdiv0 - pdiv1);
		tsum += w*(psq0 - psq1);
		yc[i] = m->depth[l];
		xc[i] = xsum*R2D;
		ti[i] = tsum;

		pdiv0 = pdiv1;
		psq0  = psq1;
	}

	w = m->B[l-1];
	xsum += w*pdiv0;
	tsum += w*psq0;
	xsum  = xc[i] = xsum*R2D;
	yc[i] = Rearth - m->radius[l-1]*pow(p/m->p[l-1],w);
	ti[i] = tsum;
	
	for (l=i-1;l>=0;l--,i++){
		xc[i] = 2.*xsum - xc[l];
		ti[i] = 2.*tsum - ti[l];
		yc[i] = yc[l];
	}

	if (TURN == 1){
		npt = 2*nturn + 1 - ks - ke;
	}else{
		if ( ks <= ke ){
			npt = ke - ks + 1;
		}else{
			npt = ks - ke + 1;
		}
	}

	if ( ks <= ke ){
		return npt;
	}else{
		if (TURN == 1){
			k0 = ks - ke;
		}else{
			k0 = 2*nturn - ks - ke;
		}

		xtmp = xc[k0];
		ttmp = ti[k0];
		for (i=0,il=k0;i < npt;i++,il++){
			xc[i] = xc[il] - xtmp;
			ti[i] = ti[il] - ttmp;
			yc[i] = yc[il];
		}

		return npt;
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
xorpd %xmm1, %xmm1
movapd %xmm0, -0x60(%rbp)
ucomisd %xmm0, %xmm1
ja 0x1d48
movl %edx, %eax
orl %esi, %eax
js 0x1d48
movq %r9, %rbx
movq %r8, %r14
movq %rdi, %r15
movq 0x10(%rbp), %r13
movl (%rdi), %edi
xorl %eax, %eax
testl %edi, %edi
cmovlel %eax, %edi
movapd -0x60(%rbp), %xmm0
cmpq %rax, %rdi
je 0x1a0f
ucomisd 0xfa08(%r15,%rax,8), %xmm0
jae 0x1a0d
incq %rax
jmp 0x19f7
movl %eax, %edi
cmpl %edx, %edi
jl 0x1d5d
cmpl %esi, %edi
jl 0x1d5d
testl %edi, %edi
je 0x1d5d
movq %rdi, -0x38(%rbp)
movl %ecx, -0x4c(%rbp)
cmpl %edx, %esi
movq %rdx, -0x80(%rbp)
movl %edx, %r12d
movq %rsi, -0x78(%rbp)
cmovll %esi, %r12d
andq $0x0, (%r14)
andq $0x0, (%r13)
movsd 0x5dc8(%r15,%r12,8), %xmm0
movsd %xmm0, (%rbx)
movapd -0x60(%rbp), %xmm0
divsd 0xfa08(%r15,%r12,8), %xmm0
callq 0x1090
movapd %xmm0, %xmm2
movq %r12, -0x68(%rbp)
movsd 0xfa08(%r15,%r12,8), %xmm0
movapd 0x259c(%rip), %xmm1     # 0x4020
movapd -0x60(%rbp), %xmm3
xorpd %xmm3, %xmm1
mulsd %xmm3, %xmm1
mulsd %xmm0, %xmm0
movapd %xmm1, -0xb0(%rbp)
addsd %xmm1, %xmm0
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jb 0x1ab1
sqrtsd %xmm0, %xmm0
jmp 0x1ac0
movsd %xmm2, -0x30(%rbp)
callq 0x1130
movsd -0x30(%rbp), %xmm2
movq %r15, -0x70(%rbp)
movq -0x68(%rbp), %rax
leaq (%r15,%rax,8), %r12
addq $0xfa10, %r12           # imm = 0xFA10
incl %eax
movq %rax, -0x90(%rbp)
xorl %r15d, %r15d
xorpd %xmm4, %xmm4
xorpd %xmm3, %xmm3
movq -0x38(%rbp), %rcx
movq -0x90(%rbp), %rax
addl %r15d, %eax
cmpl %eax, %ecx
jle 0x1bdb
movsd %xmm4, -0xa0(%rbp)
movsd %xmm3, -0x40(%rbp)
movsd %xmm0, -0x48(%rbp)
movsd %xmm2, -0x30(%rbp)
movsd -0x1f48(%r12,%r15,8), %xmm0
movsd %xmm0, -0x98(%rbp)
movapd -0x60(%rbp), %xmm0
divsd (%r12,%r15,8), %xmm0
callq 0x1090
movapd %xmm0, %xmm2
movsd (%r12,%r15,8), %xmm0
mulsd %xmm0, %xmm0
addsd -0xb0(%rbp), %xmm0
ucomisd 0x2564(%rip), %xmm0     # 0x40b8
jb 0x1b5c
sqrtsd %xmm0, %xmm0
jmp 0x1b71
movsd %xmm2, -0x88(%rbp)
callq 0x1130
movsd -0x88(%rbp), %xmm2
movsd -0x30(%rbp), %xmm1
subsd %xmm2, %xmm1
movsd -0x98(%rbp), %xmm3
mulsd %xmm3, %xmm1
movsd -0xa0(%rbp), %xmm4
addsd %xmm1, %xmm4
movsd -0x48(%rbp), %xmm1
subsd %xmm0, %xmm1
mulsd %xmm3, %xmm1
movsd -0x40(%rbp), %xmm3
addsd %xmm1, %xmm3
movsd -0x9c40(%r12,%r15,8), %xmm1
movsd %xmm1, 0x8(%rbx,%r15,8)
movapd %xmm4, %xmm1
mulsd 0x24eb(%rip), %xmm1     # 0x40b0
movsd %xmm1, 0x8(%r14,%r15,8)
movsd %xmm3, 0x8(%r13,%r15,8)
incq %r15
jmp 0x1ae7
movq -0x68(%rbp), %rcx
addl %r15d, %ecx
movq -0x70(%rbp), %rax
movsd 0xdac8(%rax,%rcx,8), %xmm1
mulsd %xmm1, %xmm2
addsd %xmm4, %xmm2
mulsd %xmm1, %xmm0
addsd %xmm3, %xmm0
movsd %xmm0, -0x48(%rbp)
mulsd 0x24a4(%rip), %xmm2     # 0x40b0
movsd %xmm2, -0x30(%rbp)
incq %r15
movl %r15d, %r12d
movsd %xmm2, (%r14,%r12,8)
movsd 0xbb88(%rax,%rcx,8), %xmm0
movsd %xmm0, -0x40(%rbp)
movapd -0x60(%rbp), %xmm0
divsd 0xfa08(%rax,%rcx,8), %xmm0
callq 0x1050
movsd -0x48(%rbp), %xmm3
movsd -0x30(%rbp), %xmm2
mulsd -0x40(%rbp), %xmm0
movsd 0x243b(%rip), %xmm1     # 0x4090
subsd %xmm0, %xmm1
movsd %xmm1, (%rbx,%r12,8)
movsd %xmm3, (%r13,%r12,8)
addsd %xmm2, %xmm2
addsd %xmm3, %xmm3
movq %r15, %rax
movl -0x4c(%rbp), %edx
movq -0x80(%rbp), %rsi
movq -0x78(%rbp), %rdi
testq %rax, %rax
jle 0x1cb8
movapd %xmm2, %xmm0
subsd -0x8(%r14,%rax,8), %xmm0
movsd %xmm0, (%r14,%r15,8)
movapd %xmm3, %xmm0
subsd -0x8(%r13,%rax,8), %xmm0
movsd %xmm0, (%r13,%r15,8)
movsd -0x8(%rbx,%rax,8), %xmm0
decq %rax
movsd %xmm0, (%rbx,%r15,8)
incq %r15
jmp 0x1c7c
cmpl $0x1, %edx
jne 0x1ccb
movq -0x38(%rbp), %r8
leal (%r8,%r8), %eax
subl %edi, %eax
subl %esi, %eax
jmp 0x1cd9
movl %edi, %eax
subl %esi, %eax
movq -0x38(%rbp), %r8
jg 0x1cd9
movl %esi, %eax
subl %edi, %eax
incl %eax
movl %edi, %ecx
subl %esi, %ecx
jle 0x1d7c
addl %r8d, %r8d
addl %edi, %esi
subl %esi, %r8d
cmpl $0x1, %edx
cmovel %ecx, %r8d
movslq %r8d, %rcx
movsd (%r14,%rcx,8), %xmm0
movsd (%r13,%rcx,8), %xmm1
xorl %edx, %edx
testl %eax, %eax
cmovgl %eax, %edx
subq $0x1, %rdx
jb 0x1d7c
movsd (%r14,%rcx,8), %xmm2
subsd %xmm0, %xmm2
movsd %xmm2, (%r14)
movsd (%r13,%rcx,8), %xmm2
subsd %xmm1, %xmm2
movsd %xmm2, (%r13)
movsd (%rbx,%rcx,8), %xmm2
movsd %xmm2, (%rbx)
addq $0x8, %rbx
addq $0x8, %r13
addq $0x8, %r14
jmp 0x1d0b
movq 0x42a9(%rip), %rax      # 0x5ff8
movq (%rax), %rcx
leaq 0x24f4(%rip), %rdi      # 0x424d
pushq $0x11
jmp 0x1d70
movq 0x4294(%rip), %rax      # 0x5ff8
movq (%rax), %rcx
leaq 0x24f1(%rip), %rdi      # 0x425f
pushq $0x24
popq %rsi
pushq $0x1
popq %rdx
callq 0x1120
pushq $-0x1
popq %rax
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq