// File: /workspace/github_c_makefile_star2_O0/YunyiQian[P]multitel3/./raytrace.c
// Function: raytrace2
int raytrace2(MODEL *m,double p,int ks,int ke,int TURN,double *xc,double *tt,double *ti){

	int i,k;
	int l0,l1;
	int nturn;
	double w;
	double pdiv0,pdiv1;
	double psq0,psq1;
	double xsum,xtmp;
	double tsum,ttmp;
	double dt;
	double tstar,temp;
	double p2;

	if (ks < 0 || p < 0 || ke < 0){
		fprintf(stderr,"Input is illegal\n");
		return -1;
	}

	for (i=0,nturn=0;i < m->nlay;i++){
		if (m->p[i] <= p){
			nturn = i;
			break;
		}
	}

	if (p < 1.4 || nturn == 0){
		nturn = m->nlay;
	}

	if (ks >= nturn || nturn == 0 || ke >= nturn){
//if (nturn > 45)
//printf("ks=%d\tke=%d\tnturn=%d\n",ks,ke,nturn);
//		fprintf(stderr,"The wave cannot arrives the ke layer\n");
		return -1;
	}

	if ( ks > ke ){
		l0 = ke;
		l1 = ks;
	}else{
		l0 = ks;
		l1 = ke;
	}

	p2 = p*p;
	xsum  = 0.;
	tsum  = 0.;
	tstar = 0.;
	pdiv0 = acos(p/m->p[l0]);
	psq0  = sqrt(m->p[l0]*m->p[l0] - p2);

	for (i=l0+1;i<=l1;i++){
		w = m->B[i-1];
		pdiv1  = acos(p/m->p[i]);
		psq1   = sqrt(m->p[i]*m->p[i] - p2);
		xsum  += w*(pdiv0 - pdiv1);
		dt     = w*(psq0 - psq1);
		tsum  += dt;
		if ( m->Q[i-1] < SMALL ){
//			printf ("Bad Q value in raytrace2\n");
			return -1;
		}else{
			tstar += dt/m->Q[i-1];
		}
		pdiv0  = pdiv1;
		psq0   = psq1;
	}

	if (TURN == 1){
		xtmp = xsum;
		ttmp = tsum;
		temp = tstar;
		xsum = 0.;
		tsum = 0.;
		tstar = 0.;

		for (i=l1+1;i<nturn;i++){
			w = m->B[i-1];
			pdiv1  = acos(p/m->p[i]);
			psq1   = sqrt(m->p[i]*m->p[i] - p2);
			xsum  += w*(pdiv0 - pdiv1);
			dt     = w*(psq0 - psq1);
			tsum  += dt;
			if ( m->Q[i-1] < SMALL ){
//				printf ("Bad Q value in raytrace2\n");
				return -1;
			}else{
				tstar += dt/m->Q[i-1];
			}
			pdiv0  = pdiv1;
			psq0   = psq1;
		}
		w = m->B[nturn-1];
		xsum  += w*pdiv0;
		dt     = w*psq0;
		tsum  += dt;
		tstar += dt/m->Q[nturn-1];
		
		*xc = R2D*(2.*xsum + xtmp);
		*ti = 2.*tsum + ttmp;
//		*bot = Rearth - m->radius[nturn-1]*pow(p/m->p[nturn-1],w);
		*tt = 2.*tstar + temp;
	}else{
		*xc = xsum*R2D;
		*ti = tsum;
//		*bot = m->depth[l1];
		*tt = tstar;
	}
	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xc0, %rsp
movq 0x10(%rbp), %rax
movq %rdi, -0x10(%rbp)
movsd %xmm0, -0x18(%rbp)
movl %esi, -0x1c(%rbp)
movl %edx, -0x20(%rbp)
movl %ecx, -0x24(%rbp)
movq %r8, -0x30(%rbp)
movq %r9, -0x38(%rbp)
cmpl $0x0, -0x1c(%rbp)
jl 0x25ef
xorps %xmm0, %xmm0
ucomisd -0x18(%rbp), %xmm0
ja 0x25ef
cmpl $0x0, -0x20(%rbp)
jge 0x2613
movq 0x4a02(%rip), %rax      # 0x6ff8
movq (%rax), %rdi
leaq 0x2bfd(%rip), %rsi      # 0x51fd
movb $0x0, %al
callq 0x10b0
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x2bd3
movl $0x0, -0x3c(%rbp)
movl $0x0, -0x4c(%rbp)
movl -0x3c(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl (%rcx), %eax
jge 0x265d
movq -0x10(%rbp), %rax
movslq -0x3c(%rbp), %rcx
movsd 0xfa08(%rax,%rcx,8), %xmm1
movsd -0x18(%rbp), %xmm0
ucomisd %xmm1, %xmm0
jb 0x2650
movl -0x3c(%rbp), %eax
movl %eax, -0x4c(%rbp)
jmp 0x265d
jmp 0x2652
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x2621
movsd 0x29f3(%rip), %xmm0     # 0x5058
ucomisd -0x18(%rbp), %xmm0
ja 0x2672
cmpl $0x0, -0x4c(%rbp)
jne 0x267b
movq -0x10(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x4c(%rbp)
movl -0x1c(%rbp), %eax
cmpl -0x4c(%rbp), %eax
jge 0x2691
cmpl $0x0, -0x4c(%rbp)
je 0x2691
movl -0x20(%rbp), %eax
cmpl -0x4c(%rbp), %eax
jl 0x269d
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x2bd3
movl -0x1c(%rbp), %eax
cmpl -0x20(%rbp), %eax
jle 0x26b3
movl -0x20(%rbp), %eax
movl %eax, -0x44(%rbp)
movl -0x1c(%rbp), %eax
movl %eax, -0x48(%rbp)
jmp 0x26bf
movl -0x1c(%rbp), %eax
movl %eax, -0x44(%rbp)
movl -0x20(%rbp), %eax
movl %eax, -0x48(%rbp)
movsd -0x18(%rbp), %xmm0
mulsd -0x18(%rbp), %xmm0
movsd %xmm0, -0xb8(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x80(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x90(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0xa8(%rbp)
movsd -0x18(%rbp), %xmm0
movq -0x10(%rbp), %rax
movslq -0x44(%rbp), %rcx
divsd 0xfa08(%rax,%rcx,8), %xmm0
callq 0x10a0
movsd %xmm0, -0x60(%rbp)
movq -0x10(%rbp), %rax
movslq -0x44(%rbp), %rcx
movsd 0xfa08(%rax,%rcx,8), %xmm0
movq -0x10(%rbp), %rax
movslq -0x44(%rbp), %rcx
movsd 0xfa08(%rax,%rcx,8), %xmm2
movsd -0xb8(%rbp), %xmm1
movq %xmm1, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
callq 0x1130
movsd %xmm0, -0x70(%rbp)
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
cmpl -0x48(%rbp), %eax
jg 0x28d5
movq -0x10(%rbp), %rax
movl -0x3c(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movsd 0xdac8(%rax,%rcx,8), %xmm0
movsd %xmm0, -0x58(%rbp)
movsd -0x18(%rbp), %xmm0
movq -0x10(%rbp), %rax
movslq -0x3c(%rbp), %rcx
divsd 0xfa08(%rax,%rcx,8), %xmm0
callq 0x10a0
movsd %xmm0, -0x68(%rbp)
movq -0x10(%rbp), %rax
movslq -0x3c(%rbp), %rcx
movsd 0xfa08(%rax,%rcx,8), %xmm0
movq -0x10(%rbp), %rax
movslq -0x3c(%rbp), %rcx
movsd 0xfa08(%rax,%rcx,8), %xmm2
movsd -0xb8(%rbp), %xmm1
movq %xmm1, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
callq 0x1130
movsd %xmm0, -0x78(%rbp)
movsd -0x58(%rbp), %xmm0
movsd -0x60(%rbp), %xmm2
subsd -0x68(%rbp), %xmm2
movsd -0x80(%rbp), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x80(%rbp)
movsd -0x58(%rbp), %xmm0
movsd -0x70(%rbp), %xmm1
subsd -0x78(%rbp), %xmm1
mulsd %xmm1, %xmm0
movsd %xmm0, -0xa0(%rbp)
movsd -0xa0(%rbp), %xmm0
addsd -0x90(%rbp), %xmm0
movsd %xmm0, -0x90(%rbp)
movq -0x10(%rbp), %rax
movl -0x3c(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movsd 0x27b2(%rip), %xmm0     # 0x5020
ucomisd 0x11948(%rax,%rcx,8), %xmm0
jbe 0x2885
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x2bd3
movsd -0xa0(%rbp), %xmm0
movq -0x10(%rbp), %rax
movl -0x3c(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
divsd 0x11948(%rax,%rcx,8), %xmm0
addsd -0xa8(%rbp), %xmm0
movsd %xmm0, -0xa8(%rbp)
movsd -0x68(%rbp), %xmm0
movsd %xmm0, -0x60(%rbp)
movsd -0x78(%rbp), %xmm0
movsd %xmm0, -0x70(%rbp)
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x276b
cmpl $0x1, -0x24(%rbp)
jne 0x2b97
movsd -0x80(%rbp), %xmm0
movsd %xmm0, -0x88(%rbp)
movsd -0x90(%rbp), %xmm0
movsd %xmm0, -0x98(%rbp)
movsd -0xa8(%rbp), %xmm0
movsd %xmm0, -0xb0(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x80(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x90(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0xa8(%rbp)
movl -0x48(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
cmpl -0x4c(%rbp), %eax
jge 0x2a9d
movq -0x10(%rbp), %rax
movl -0x3c(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movsd 0xdac8(%rax,%rcx,8), %xmm0
movsd %xmm0, -0x58(%rbp)
movsd -0x18(%rbp), %xmm0
movq -0x10(%rbp), %rax
movslq -0x3c(%rbp), %rcx
divsd 0xfa08(%rax,%rcx,8), %xmm0
callq 0x10a0
movsd %xmm0, -0x68(%rbp)
movq -0x10(%rbp), %rax
movslq -0x3c(%rbp), %rcx
movsd 0xfa08(%rax,%rcx,8), %xmm0
movq -0x10(%rbp), %rax
movslq -0x3c(%rbp), %rcx
movsd 0xfa08(%rax,%rcx,8), %xmm2
movsd -0xb8(%rbp), %xmm1
movq %xmm1, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
callq 0x1130
movsd %xmm0, -0x78(%rbp)
movsd -0x58(%rbp), %xmm0
movsd -0x60(%rbp), %xmm2
subsd -0x68(%rbp), %xmm2
movsd -0x80(%rbp), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x80(%rbp)
movsd -0x58(%rbp), %xmm0
movsd -0x70(%rbp), %xmm1
subsd -0x78(%rbp), %xmm1
mulsd %xmm1, %xmm0
movsd %xmm0, -0xa0(%rbp)
movsd -0xa0(%rbp), %xmm0
addsd -0x90(%rbp), %xmm0
movsd %xmm0, -0x90(%rbp)
movq -0x10(%rbp), %rax
movl -0x3c(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movsd 0x25ea(%rip), %xmm0     # 0x5020
ucomisd 0x11948(%rax,%rcx,8), %xmm0
jbe 0x2a4d
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x2bd3
movsd -0xa0(%rbp), %xmm0
movq -0x10(%rbp), %rax
movl -0x3c(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
divsd 0x11948(%rax,%rcx,8), %xmm0
addsd -0xa8(%rbp), %xmm0
movsd %xmm0, -0xa8(%rbp)
movsd -0x68(%rbp), %xmm0
movsd %xmm0, -0x60(%rbp)
movsd -0x78(%rbp), %xmm0
movsd %xmm0, -0x70(%rbp)
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x2933
movq -0x10(%rbp), %rax
movl -0x4c(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movsd 0xdac8(%rax,%rcx,8), %xmm0
movsd %xmm0, -0x58(%rbp)
movsd -0x58(%rbp), %xmm0
movsd -0x60(%rbp), %xmm2
movsd -0x80(%rbp), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x80(%rbp)
movsd -0x58(%rbp), %xmm0
mulsd -0x70(%rbp), %xmm0
movsd %xmm0, -0xa0(%rbp)
movsd -0xa0(%rbp), %xmm0
addsd -0x90(%rbp), %xmm0
movsd %xmm0, -0x90(%rbp)
movsd -0xa0(%rbp), %xmm0
movq -0x10(%rbp), %rax
movl -0x4c(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
divsd 0x11948(%rax,%rcx,8), %xmm0
addsd -0xa8(%rbp), %xmm0
movsd %xmm0, -0xa8(%rbp)
movsd -0x80(%rbp), %xmm1
movsd -0x88(%rbp), %xmm0
addsd %xmm1, %xmm1
addsd %xmm0, %xmm1
movsd 0x2507(%rip), %xmm0     # 0x5050
mulsd %xmm1, %xmm0
movq -0x30(%rbp), %rax
movsd %xmm0, (%rax)
movsd -0x90(%rbp), %xmm0
movsd -0x98(%rbp), %xmm1
addsd %xmm0, %xmm0
addsd %xmm1, %xmm0
movq 0x10(%rbp), %rax
movsd %xmm0, (%rax)
movsd -0xa8(%rbp), %xmm0
movsd -0xb0(%rbp), %xmm1
addsd %xmm0, %xmm0
addsd %xmm1, %xmm0
movq -0x38(%rbp), %rax
movsd %xmm0, (%rax)
jmp 0x2bcc
movsd 0x24b1(%rip), %xmm0     # 0x5050
mulsd -0x80(%rbp), %xmm0
movq -0x30(%rbp), %rax
movsd %xmm0, (%rax)
movsd -0x90(%rbp), %xmm0
movq 0x10(%rbp), %rax
movsd %xmm0, (%rax)
movsd -0xa8(%rbp), %xmm0
movq -0x38(%rbp), %rax
movsd %xmm0, (%rax)
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0xc0, %rsp
popq %rbp
retq
nop