// File: /workspace/github_c_makefile_star2_O2/YunyiQian[P]multitel3/./raytrace.c
// Function: mhrv_interp
void mhrv_interp(MODEL *m,int P){
	int i;
	int k=0;
	double tmp,tmp1;
	
	m->radius[0] = Rearth - m->depth[0];
	if ( P == 1 || m->vs[0] < SMALL ){
		m->p[0] = m->radius[0]/m->vp[0];
		m->Q[0] = m->qp[0];
	}else{
		m->p[0] = m->radius[0]/m->vs[0];
		m->Q[0] = m->qs[0];
	}
/*
	if ( P == 1 ){
		m->p[0] = m->radius[0]/m->vp[0];
		m->Q[0] = m->qp[0];
	}else if ( m->vs[0] < SMALL ){
		m->p[0] = m->radius[0]/SMALL;
		m->Q[0] = SMALL;
	}else{
		m->p[0] = m->radius[0]/m->vs[0];
		m->Q[0] = m->qs[0];
	}
*/
	for (i=1;i<m->nlay;i++){
		m->radius[i] = Rearth - m->depth[i];
		if (m->radius[i] < 0.001){	// the center of earth
			m->p[i]   = 0.00001;
			m->Q[i]   = 100000;
			m->B[i-1] = 1.;
			m->B[i]   = 1.;
			return;
		}else{
			tmp = log(m->radius[i-1]/m->radius[i]);
		}

		if ( P == 1 ){
			m->p[i] = m->radius[i]/m->vp[i];
			m->Q[i] = m->qp[i];
			tmp1 = log(m->vp[i-1]/m->vp[i]);
		}else if( m->vs[i] < SMALL ){
			m->Q[i] = m->qp[i];
			if ( k == 1 ){
				m->p[i] = m->radius[i]/m->vp[i];
				tmp1 = log(m->vp[i-1]/m->vp[i]);
			}else{
//				m->p[i] = m->radius[i]/m->vp[i];
				m->p[i] = BIG;
				tmp1 = log(m->vs[i-1]/m->vp[i]);
				k = 1;
			}
		}else{
			m->p[i] = m->radius[i]/m->vs[i];
			m->Q[i] = m->qs[i];
			tmp1 = log(m->vs[i-1]/m->vs[i]);
		}

/*		if ( P == 1 ){
			m->p[i] = m->radius[i]/m->vp[i];
			m->Q[i] = m->qp[i];
			tmp1 = log(m->vp[i-1]/m->vp[i]);
		}else{
			if ( m->vs[i] < SMALL ){
				m->vs[i] = SMALL;
			}
			m->p[i] = m->radius[i]/m->vs[i];
			m->Q[i] = m->qs[i];
			tmp1 = log(m->vs[i-1]/m->vs[i]);
		}
*/
		if (fabs(tmp) < 1.0e-4){	//discontinuity
			m->B[i-1] = 0.;
		}else{
			tmp = tmp1/tmp;
			m->B[i-1] = 1./(1.-tmp);
		}
	}
	m->B[i] = 1.;

	return;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movl %esi, %r14d
movq %rdi, %rbx
movsd 0x299f(%rip), %xmm0     # 0x4090
subsd 0x5dc8(%rdi), %xmm0
movsd %xmm0, 0xbb88(%rdi)
cmpl $0x1, %esi
je 0x1721
movsd 0x1f48(%rbx), %xmm1
movl $0x9c48, %eax           # imm = 0x9C48
movsd 0x297d(%rip), %xmm2     # 0x4098
ucomisd %xmm1, %xmm2
jbe 0x172b
movsd 0x8(%rbx), %xmm1
movl $0x7d08, %eax           # imm = 0x7D08
divsd %xmm1, %xmm0
movsd %xmm0, 0xfa08(%rbx)
movsd (%rbx,%rax), %xmm0
movsd %xmm0, 0x11948(%rbx)
xorl %r12d, %r12d
pushq $0x1
popq %r15
pushq $0x1
popq %r13
movslq (%rbx), %rcx
movabsq $0x3ff0000000000000, %rax # imm = 0x3FF0000000000000
cmpq %rcx, %r15
jge 0x192f
movsd 0x2923(%rip), %xmm1     # 0x4090
subsd 0x5dc8(%rbx,%r15,8), %xmm1
movsd %xmm1, 0xbb88(%rbx,%r15,8)
movsd 0x2917(%rip), %xmm0     # 0x40a0
ucomisd %xmm1, %xmm0
ja 0x1903
movsd 0xbb80(%rbx,%r15,8), %xmm0
divsd %xmm1, %xmm0
callq 0x1070
movapd %xmm0, -0x40(%rbp)
cmpl $0x1, %r14d
jne 0x17f3
movsd 0xbb88(%rbx,%r15,8), %xmm1
movsd (%rbx,%r15,8), %xmm0
movsd 0x8(%rbx,%r15,8), %xmm2
divsd %xmm2, %xmm1
movsd %xmm1, 0xfa08(%rbx,%r15,8)
movsd 0x7d08(%rbx,%r15,8), %xmm1
movsd %xmm1, 0x11948(%rbx,%r15,8)
divsd %xmm2, %xmm0
jmp 0x18b2
movsd 0x1f48(%rbx,%r15,8), %xmm1
movsd 0x2893(%rip), %xmm0     # 0x4098
ucomisd %xmm1, %xmm0
jbe 0x1850
movsd 0x7d08(%rbx,%r15,8), %xmm0
movsd %xmm0, 0x11948(%rbx,%r15,8)
cmpl $0x1, %r12d
jne 0x188c
movsd 0xbb88(%rbx,%r15,8), %xmm1
movsd (%rbx,%r15,8), %xmm0
movsd 0x8(%rbx,%r15,8), %xmm2
divsd %xmm2, %xmm1
movsd %xmm1, 0xfa08(%rbx,%r15,8)
divsd %xmm2, %xmm0
jmp 0x18af
movsd 0xbb88(%rbx,%r15,8), %xmm0
divsd %xmm1, %xmm0
movsd %xmm0, 0xfa08(%rbx,%r15,8)
movsd 0x9c48(%rbx,%r15,8), %xmm0
movsd %xmm0, 0x11948(%rbx,%r15,8)
movsd 0x1f40(%rbx,%r15,8), %xmm0
divsd %xmm1, %xmm0
jmp 0x18b2
movabsq $0x40c3880000000000, %rax # imm = 0x40C3880000000000
movq %rax, 0xfa08(%rbx,%r15,8)
movsd 0x1f40(%rbx,%r15,8), %xmm0
divsd 0x8(%rbx,%r15,8), %xmm0
movl %r13d, %r12d
callq 0x1070
movapd -0x40(%rbp), %xmm2
movapd %xmm2, %xmm1
andpd 0x2748(%rip), %xmm1     # 0x4010
divsd %xmm2, %xmm0
movsd 0x27b4(%rip), %xmm3     # 0x4088
movapd %xmm3, %xmm2
subsd %xmm0, %xmm2
movapd %xmm3, %xmm0
divsd %xmm2, %xmm0
cmpltsd 0x27bb(%rip), %xmm1     # 0x40a8
andnpd %xmm0, %xmm1
movlpd %xmm1, 0xdac0(%rbx,%r15,8)
incq %r15
jmp 0x174f
movabsq $0x3ee4f8b588e368f1, %rcx # imm = 0x3EE4F8B588E368F1
movq %rcx, 0xfa08(%rbx,%r15,8)
movabsq $0x40f86a0000000000, %rcx # imm = 0x40F86A0000000000
movq %rcx, 0x11948(%rbx,%r15,8)
movq %rax, 0xdac0(%rbx,%r15,8)
movq %rax, 0xdac8(%rbx,%r15,8)
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq