// File: /workspace/github_c_makefile_star2_O2/YunyiQian[P]multitel3/./raytrace.c
// Function: inslay
int inslay(double depth,MODEL *m){
	int i,inslay;
	int k;
	double slope;

	if (depth < 0. || depth > m->depth[m->nlay-1]){
		fprintf(stderr,"Input depth is out of range\n");
		return -1;
	}

	for (i=0;i<m->nlay;i++){
		if (m->depth[i] > depth){
			if ( fabs(depth-m->depth[i-1]) < 0.005 ){
				inslay = i-1;
				return inslay;
			}else if( fabs(depth-m->depth[i]) < 0.005 ){
				inslay = i;
				return inslay;
			}else{
				inslay = i;
				m->nlay ++;
				if (m->nlay > MAXLAY){
					fprintf(stderr,"Too many layers in inslay()\n");
					return -1;
				}
				for (k=(m->nlay-1);k>i;k--){
					m->depth[k] = m->depth[k-1];
					m->vp[k]    = m->vp[k-1];
					m->vs[k]    = m->vs[k-1];
					m->rou[k]   = m->rou[k-1];
					m->qp[k]    = m->qp[k-1];
					m->qs[k]    = m->qs[k-1];
				}

				slope = (depth-m->depth[i-1])/(m->depth[i+1] - m->depth[i-1]);
				m->depth[i] = depth;
				m->vp[i]  = slope*m->vp[i+1]  + (1.-slope)*m->vp[i-1];
				m->vs[i]  = slope*m->vs[i+1]  + (1.-slope)*m->vs[i-1];
				m->rou[i] = slope*m->rou[i+1] + (1.-slope)*m->rou[i-1];
				m->qp[i]  = slope*m->qp[i+1]  + (1.-slope)*m->qp[i-1];
				m->qs[i]  = slope*m->qs[i+1]  + (1.-slope)*m->qs[i-1];

				return inslay;
			}	// end of if
		}// end of if
	}// end of i loop 

}

// Assembly:
pushq %rbp
movq %rsp, %rbp
xorpd %xmm1, %xmm1
ucomisd %xmm0, %xmm1
ja 0x15ae
movslq (%rdi), %rcx
ucomisd 0x5dc0(%rdi,%rcx,8), %xmm0
ja 0x15ae
xorl %eax, %eax
testl %ecx, %ecx
movl $0x0, %edx
cmovgl %ecx, %edx
cmpq %rax, %rdx
je 0x16ba
movsd 0x5dc8(%rdi,%rax,8), %xmm1
ucomisd %xmm0, %xmm1
ja 0x14e5
incq %rax
jmp 0x14c8
movapd %xmm0, %xmm3
subsd 0x5dc0(%rdi,%rax,8), %xmm3
andpd 0x2b16(%rip), %xmm3     # 0x4010
movsd 0x2b7e(%rip), %xmm2     # 0x4080
ucomisd %xmm3, %xmm2
jbe 0x1510
decq %rax
jmp 0x16ba
movapd %xmm0, %xmm3
subsd %xmm1, %xmm3
andpd 0x2af0(%rip), %xmm3     # 0x4010
ucomisd %xmm3, %xmm2
ja 0x16ba
leal 0x1(%rcx), %edx
movl %edx, (%rdi)
cmpl $0x3e7, %ecx            # imm = 0x3E7
jg 0x16bc
cmpq %rax, %rcx
jle 0x15d2
movsd 0x5dc0(%rdi,%rcx,8), %xmm1
movsd %xmm1, 0x5dc8(%rdi,%rcx,8)
movsd (%rdi,%rcx,8), %xmm1
movsd %xmm1, 0x8(%rdi,%rcx,8)
movsd 0x1f40(%rdi,%rcx,8), %xmm1
movsd %xmm1, 0x1f48(%rdi,%rcx,8)
movsd 0x3e80(%rdi,%rcx,8), %xmm1
movsd %xmm1, 0x3e88(%rdi,%rcx,8)
movsd 0x7d00(%rdi,%rcx,8), %xmm1
movsd %xmm1, 0x7d08(%rdi,%rcx,8)
movsd 0x9c40(%rdi,%rcx,8), %xmm1
movsd %xmm1, 0x9c48(%rdi,%rcx,8)
decq %rcx
jmp 0x153b
movq 0x4a43(%rip), %rax      # 0x5ff8
movq (%rax), %rcx
leaq 0x2c54(%rip), %rdi      # 0x4213
pushq $0x1c
popq %rsi
pushq $0x1
popq %rdx
callq 0x1120
pushq $-0x1
popq %rax
jmp 0x16ba
movsd 0x5dc0(%rdi,%rax,8), %xmm2
movsd 0x5dd0(%rdi,%rax,8), %xmm3
movapd %xmm0, %xmm1
subsd %xmm2, %xmm1
subsd %xmm2, %xmm3
divsd %xmm3, %xmm1
movsd %xmm0, 0x5dc8(%rdi,%rax,8)
movsd 0x2a83(%rip), %xmm0     # 0x4088
subsd %xmm1, %xmm0
movsd (%rdi,%rax,8), %xmm2
mulsd %xmm0, %xmm2
movsd 0x10(%rdi,%rax,8), %xmm3
mulsd %xmm1, %xmm3
addsd %xmm2, %xmm3
movsd %xmm3, 0x8(%rdi,%rax,8)
movsd 0x1f40(%rdi,%rax,8), %xmm2
mulsd %xmm0, %xmm2
movsd 0x1f50(%rdi,%rax,8), %xmm3
mulsd %xmm1, %xmm3
addsd %xmm2, %xmm3
movsd %xmm3, 0x1f48(%rdi,%rax,8)
movsd 0x3e80(%rdi,%rax,8), %xmm2
mulsd %xmm0, %xmm2
movsd 0x3e90(%rdi,%rax,8), %xmm3
mulsd %xmm1, %xmm3
addsd %xmm2, %xmm3
movsd %xmm3, 0x3e88(%rdi,%rax,8)
movsd 0x7d00(%rdi,%rax,8), %xmm2
mulsd %xmm0, %xmm2
movsd 0x7d10(%rdi,%rax,8), %xmm3
mulsd %xmm1, %xmm3
addsd %xmm2, %xmm3
movsd %xmm3, 0x7d08(%rdi,%rax,8)
mulsd 0x9c40(%rdi,%rax,8), %xmm0
mulsd 0x9c50(%rdi,%rax,8), %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, 0x9c48(%rdi,%rax,8)
popq %rbp
retq
movq 0x4935(%rip), %rax      # 0x5ff8
movq (%rax), %rcx
leaq 0x2b63(%rip), %rdi      # 0x4230
jmp 0x15bf