// File: /workspace/github_c_makefile_star2_O3/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 0x1924
movslq (%rdi), %rax
ucomisd 0x5dc0(%rdi,%rax,8), %xmm0
ja 0x1924
movl %eax, %ecx
testl %ecx, %ecx
jle 0x175e
xorl %eax, %eax
movsd 0x5dc8(%rdi,%rax,8), %xmm3
ucomisd %xmm0, %xmm3
ja 0x1763
incq %rax
cmpq %rax, %rcx
jne 0x1742
jmp 0x192e
jmp 0x192e
movsd 0x5dc0(%rdi,%rax,8), %xmm2
movapd %xmm0, %xmm1
subsd %xmm2, %xmm1
movapd 0x2894(%rip), %xmm5     # 0x4010
andpd %xmm1, %xmm5
movsd 0x28f8(%rip), %xmm4     # 0x4080
ucomisd %xmm5, %xmm4
jbe 0x1796
decq %rax
jmp 0x192e
movapd %xmm0, %xmm5
subsd %xmm3, %xmm5
andpd 0x286a(%rip), %xmm5     # 0x4010
ucomisd %xmm5, %xmm4
ja 0x192e
leal 0x1(%rcx), %edx
movl %edx, (%rdi)
cmpl $0x3e7, %ecx            # imm = 0x3E7
jg 0x1930
cmpl %eax, %ecx
jle 0x184b
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 0x17c9
movsd 0x5dc0(%rdi,%rax,8), %xmm2
movapd %xmm0, %xmm1
subsd %xmm2, %xmm1
movsd 0x5dd0(%rdi,%rax,8), %xmm3
subsd %xmm2, %xmm3
divsd %xmm3, %xmm1
movsd %xmm0, 0x5dc8(%rdi,%rax,8)
movsd 0x281b(%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 0x192e
callq 0x1266
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
popq %rbp
retq
callq 0x1237
jmp 0x1929