// File: /workspace/github_c_makefile_star2_O1/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 0x18da
movslq (%rdi), %rax
ucomisd 0x5dc0(%rdi,%rax,8), %xmm0
ja 0x18da
movl %eax, %ecx
testl %ecx, %ecx
jle 0x1720
xorl %eax, %eax
movsd 0x5dc8(%rdi,%rax,8), %xmm1
ucomisd %xmm0, %xmm1
ja 0x1725
incq %rax
cmpq %rax, %rcx
jne 0x1704
jmp 0x18e4
jmp 0x18e4
movapd %xmm0, %xmm3
subsd 0x5dc0(%rdi,%rax,8), %xmm3
andpd 0x28d6(%rip), %xmm3     # 0x4010
movsd 0x293e(%rip), %xmm2     # 0x4080
ucomisd %xmm3, %xmm2
jbe 0x1750
decq %rax
jmp 0x18e4
movapd %xmm0, %xmm3
subsd %xmm1, %xmm3
andpd 0x28b0(%rip), %xmm3     # 0x4010
ucomisd %xmm3, %xmm2
ja 0x18e4
leal 0x1(%rcx), %edx
movl %edx, (%rdi)
cmpl $0x3e7, %ecx            # imm = 0x3E7
jg 0x18e6
cmpl %eax, %ecx
jle 0x17f0
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)
leaq -0x1(%rcx), %rdx
movq %rdx, %rcx
cmpq %rax, %rdx
jg 0x177f
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 0x2865(%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)
jmp 0x18e4
callq 0x1266
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
popq %rbp
retq
callq 0x1237
jmp 0x18df