// File: /workspace/github_c_makefile_star2_O1/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 0x2784(%rip), %xmm0     # 0x4090
subsd 0x5dc8(%rdi), %xmm0
movsd %xmm0, 0xbb88(%rdi)
cmpl $0x1, %esi
je 0x193c
movsd 0x1f48(%rbx), %xmm1
movl $0x9c48, %eax           # imm = 0x9C48
movsd 0x2762(%rip), %xmm2     # 0x4098
ucomisd %xmm1, %xmm2
jbe 0x1946
movsd 0x8(%rbx), %xmm1
movl $0x7d08, %eax           # imm = 0x7D08
divsd %xmm1, %xmm0
movsd %xmm0, 0xfa08(%rbx)
movsd (%rbx,%rax), %xmm0
movsd %xmm0, 0x11948(%rbx)
movl $0x1, %r13d
cmpl $0x2, (%rbx)
jl 0x1b32
leaq 0xdad0(%rbx), %r12
xorl %r15d, %r15d
movsd 0x2710(%rip), %xmm1     # 0x4090
subsd -0x7d00(%r12), %xmm1
movsd %xmm1, -0x1f40(%r12)
movsd 0x2704(%rip), %xmm0     # 0x40a0
ucomisd %xmm1, %xmm0
ja 0x1b49
movsd -0x1f48(%r12), %xmm0
divsd %xmm1, %xmm0
callq 0x1070
movapd %xmm0, -0x40(%rbp)
cmpl $0x1, %r14d
jne 0x1a0d
movsd -0x1f40(%r12), %xmm1
movsd -0xdac8(%r12), %xmm0
movsd -0xdac0(%r12), %xmm2
divsd %xmm2, %xmm1
movsd %xmm1, 0x1f40(%r12)
movsd -0x5dc0(%r12), %xmm1
movsd %xmm1, 0x3e80(%r12)
divsd %xmm2, %xmm0
jmp 0x1ad9
movsd -0xbb80(%r12), %xmm1
movsd 0x2679(%rip), %xmm0     # 0x4098
ucomisd %xmm1, %xmm0
jbe 0x1a71
movsd -0x5dc0(%r12), %xmm0
movsd %xmm0, 0x3e80(%r12)
cmpl $0x1, %r15d
jne 0x1aad
movsd -0x1f40(%r12), %xmm1
movsd -0xdac8(%r12), %xmm0
movsd -0xdac0(%r12), %xmm2
divsd %xmm2, %xmm1
movsd %xmm1, 0x1f40(%r12)
divsd %xmm2, %xmm0
jmp 0x1ad3
movsd -0x1f40(%r12), %xmm0
divsd %xmm1, %xmm0
movsd %xmm0, 0x1f40(%r12)
movsd -0x3e80(%r12), %xmm0
movsd %xmm0, 0x3e80(%r12)
movsd -0xbb88(%r12), %xmm0
divsd %xmm1, %xmm0
jmp 0x1ad9
movabsq $0x40c3880000000000, %rax # imm = 0x40C3880000000000
movq %rax, 0x1f40(%r12)
movsd -0xbb88(%r12), %xmm0
divsd -0xdac0(%r12), %xmm0
movl $0x1, %r15d
callq 0x1070
movapd -0x40(%rbp), %xmm2
movapd %xmm2, %xmm1
andpd 0x2521(%rip), %xmm1     # 0x4010
divsd %xmm2, %xmm0
movsd 0x258d(%rip), %xmm3     # 0x4088
movapd %xmm3, %xmm2
subsd %xmm0, %xmm2
movapd %xmm3, %xmm0
divsd %xmm2, %xmm0
cmpltsd 0x2594(%rip), %xmm1     # 0x40a8
andnpd %xmm0, %xmm1
movlpd %xmm1, -0x8(%r12)
incq %r13
movslq (%rbx), %rax
addq $0x8, %r12
cmpq %rax, %r13
jl 0x1978
leaq (%rbx,%r13,8), %r12
addq $0xdac8, %r12           # imm = 0xDAC8
movabsq $0x3ff0000000000000, %rax # imm = 0x3FF0000000000000
jmp 0x1b7c
movabsq $0x3ee4f8b588e368f1, %rax # imm = 0x3EE4F8B588E368F1
movq %rax, 0x1f40(%r12)
movabsq $0x40f86a0000000000, %rax # imm = 0x40F86A0000000000
movq %rax, 0x3e80(%r12)
movabsq $0x3ff0000000000000, %rax # imm = 0x3FF0000000000000
movq %rax, -0x8(%r12)
movq %rax, (%r12)
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq