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

	int i,nturn,npt;
	int l0,il;
	int l;
	int k0;
	double w;
	double pdiv0,pdiv1;
	double psq0,psq1;
	double xsum;
	double tsum;
	double xtmp;
	double ttmp;
	double p2;

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

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

	if (ks > nturn || nturn == 0 || ke > nturn){
		fprintf(stderr,"The wave cannot arrive the ke layer\n");
		return -1;
	}

	l0 = ks < ke ? ks : ke;
	p2 = p*p;

	xsum  = 0.;
	tsum  = 0.;
	xc[0] = 0.;
	ti[0] = 0.;
	yc[0] = m->depth[l0];

	pdiv0 = acos(p/m->p[l0]);
	psq0  = sqrt(m->p[l0]*m->p[l0]-p2);

	for (l=l0+1,i=1;l < nturn;l++,i++){
		w = m->B[l-1];
		pdiv1 = acos(p/m->p[l]);
		psq1  = sqrt(m->p[l]*m->p[l] - p2);
		xsum += w*(pdiv0 - pdiv1);
		tsum += w*(psq0 - psq1);
		yc[i] = m->depth[l];
		xc[i] = xsum*R2D;
		ti[i] = tsum;

		pdiv0 = pdiv1;
		psq0  = psq1;
	}

	w = m->B[l-1];
	xsum += w*pdiv0;
	tsum += w*psq0;
	xsum  = xc[i] = xsum*R2D;
	yc[i] = Rearth - m->radius[l-1]*pow(p/m->p[l-1],w);
	ti[i] = tsum;
	
	for (l=i-1;l>=0;l--,i++){
		xc[i] = 2.*xsum - xc[l];
		ti[i] = 2.*tsum - ti[l];
		yc[i] = yc[l];
	}

	if (TURN == 1){
		npt = 2*nturn + 1 - ks - ke;
	}else{
		if ( ks <= ke ){
			npt = ke - ks + 1;
		}else{
			npt = ks - ke + 1;
		}
	}

	if ( ks <= ke ){
		return npt;
	}else{
		if (TURN == 1){
			k0 = ks - ke;
		}else{
			k0 = 2*nturn - ks - ke;
		}

		xtmp = xc[k0];
		ttmp = ti[k0];
		for (i=0,il=k0;i < npt;i++,il++){
			xc[i] = xc[il] - xtmp;
			ti[i] = ti[il] - ttmp;
			yc[i] = yc[il];
		}

		return npt;
	}
}

// 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 0x1f8f
cmpl $0x0, -0x20(%rbp)
jl 0x1f8f
xorps %xmm0, %xmm0
ucomisd -0x18(%rbp), %xmm0
jbe 0x1fb3
movq 0x5062(%rip), %rax      # 0x6ff8
movq (%rax), %rdi
leaq 0x325d(%rip), %rsi      # 0x51fd
movb $0x0, %al
callq 0x10b0
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x2599
movl $0x0, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl (%rcx), %eax
jge 0x1ff6
movq -0x10(%rbp), %rax
movslq -0x3c(%rbp), %rcx
movsd 0xfa08(%rax,%rcx,8), %xmm1
movsd -0x18(%rbp), %xmm0
ucomisd %xmm1, %xmm0
jb 0x1fe9
movl -0x3c(%rbp), %eax
movl %eax, -0x40(%rbp)
jmp 0x1ff6
jmp 0x1feb
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x1fba
movl -0x1c(%rbp), %eax
cmpl -0x40(%rbp), %eax
jg 0x200c
cmpl $0x0, -0x40(%rbp)
je 0x200c
movl -0x20(%rbp), %eax
cmpl -0x40(%rbp), %eax
jle 0x2030
movq 0x4fe5(%rip), %rax      # 0x6ff8
movq (%rax), %rdi
leaq 0x31f2(%rip), %rsi      # 0x520f
movb $0x0, %al
callq 0x10b0
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x2599
movl -0x1c(%rbp), %eax
cmpl -0x20(%rbp), %eax
jge 0x2043
movl -0x1c(%rbp), %eax
movl %eax, -0xac(%rbp)
jmp 0x204c
movl -0x20(%rbp), %eax
movl %eax, -0xac(%rbp)
movl -0xac(%rbp), %eax
movl %eax, -0x48(%rbp)
movsd -0x18(%rbp), %xmm0
mulsd -0x18(%rbp), %xmm0
movsd %xmm0, -0xa8(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x88(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x90(%rbp)
movq -0x30(%rbp), %rax
xorps %xmm0, %xmm0
movsd %xmm0, (%rax)
movq 0x10(%rbp), %rax
xorps %xmm0, %xmm0
movsd %xmm0, (%rax)
movq -0x10(%rbp), %rax
movslq -0x48(%rbp), %rcx
movsd 0x5dc8(%rax,%rcx,8), %xmm0
movq -0x38(%rbp), %rax
movsd %xmm0, (%rax)
movsd -0x18(%rbp), %xmm0
movq -0x10(%rbp), %rax
movslq -0x48(%rbp), %rcx
divsd 0xfa08(%rax,%rcx,8), %xmm0
callq 0x10a0
movsd %xmm0, -0x68(%rbp)
movq -0x10(%rbp), %rax
movslq -0x48(%rbp), %rcx
movsd 0xfa08(%rax,%rcx,8), %xmm0
movq -0x10(%rbp), %rax
movslq -0x48(%rbp), %rcx
movsd 0xfa08(%rax,%rcx,8), %xmm2
movsd -0xa8(%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)
movl -0x48(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x50(%rbp)
movl $0x1, -0x3c(%rbp)
movl -0x50(%rbp), %eax
cmpl -0x40(%rbp), %eax
jge 0x2292
movq -0x10(%rbp), %rax
movl -0x50(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movsd 0xdac8(%rax,%rcx,8), %xmm0
movsd %xmm0, -0x60(%rbp)
movsd -0x18(%rbp), %xmm0
movq -0x10(%rbp), %rax
movslq -0x50(%rbp), %rcx
divsd 0xfa08(%rax,%rcx,8), %xmm0
callq 0x10a0
movsd %xmm0, -0x70(%rbp)
movq -0x10(%rbp), %rax
movslq -0x50(%rbp), %rcx
movsd 0xfa08(%rax,%rcx,8), %xmm0
movq -0x10(%rbp), %rax
movslq -0x50(%rbp), %rcx
movsd 0xfa08(%rax,%rcx,8), %xmm2
movsd -0xa8(%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, -0x80(%rbp)
movsd -0x60(%rbp), %xmm0
movsd -0x68(%rbp), %xmm2
subsd -0x70(%rbp), %xmm2
movsd -0x88(%rbp), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x88(%rbp)
movsd -0x60(%rbp), %xmm0
movsd -0x78(%rbp), %xmm2
subsd -0x80(%rbp), %xmm2
movsd -0x90(%rbp), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x90(%rbp)
movq -0x10(%rbp), %rax
movslq -0x50(%rbp), %rcx
movsd 0x5dc8(%rax,%rcx,8), %xmm0
movq -0x38(%rbp), %rax
movslq -0x3c(%rbp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movsd 0x2e13(%rip), %xmm0     # 0x5050
mulsd -0x88(%rbp), %xmm0
movq -0x30(%rbp), %rax
movslq -0x3c(%rbp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movsd -0x90(%rbp), %xmm0
movq 0x10(%rbp), %rax
movslq -0x3c(%rbp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movsd -0x70(%rbp), %xmm0
movsd %xmm0, -0x68(%rbp)
movsd -0x80(%rbp), %xmm0
movsd %xmm0, -0x78(%rbp)
movl -0x50(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x50(%rbp)
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x212f
movq -0x10(%rbp), %rax
movl -0x50(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movsd 0xdac8(%rax,%rcx,8), %xmm0
movsd %xmm0, -0x60(%rbp)
movsd -0x60(%rbp), %xmm0
movsd -0x68(%rbp), %xmm2
movsd -0x88(%rbp), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x88(%rbp)
movsd -0x60(%rbp), %xmm0
movsd -0x78(%rbp), %xmm2
movsd -0x90(%rbp), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x90(%rbp)
movsd 0x2d57(%rip), %xmm0     # 0x5050
mulsd -0x88(%rbp), %xmm0
movq -0x30(%rbp), %rax
movslq -0x3c(%rbp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movsd %xmm0, -0x88(%rbp)
movq -0x10(%rbp), %rax
movl -0x50(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movsd 0xbb88(%rax,%rcx,8), %xmm0
movsd %xmm0, -0xb8(%rbp)
movsd -0x18(%rbp), %xmm0
movq -0x10(%rbp), %rax
movl -0x50(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
divsd 0xfa08(%rax,%rcx,8), %xmm0
movsd -0x60(%rbp), %xmm1
callq 0x1060
movaps %xmm0, %xmm1
movsd -0xb8(%rbp), %xmm0
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
mulsd %xmm1, %xmm0
movsd 0x2c91(%rip), %xmm1     # 0x5018
addsd %xmm1, %xmm0
movq -0x38(%rbp), %rax
movslq -0x3c(%rbp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movsd -0x90(%rbp), %xmm0
movq 0x10(%rbp), %rax
movslq -0x3c(%rbp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movl -0x3c(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x50(%rbp)
cmpl $0x0, -0x50(%rbp)
jl 0x2473
movsd -0x88(%rbp), %xmm0
movq -0x30(%rbp), %rax
movslq -0x50(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm1
movq %xmm1, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm1
addsd %xmm0, %xmm0
addsd %xmm1, %xmm0
movq -0x30(%rbp), %rax
movslq -0x3c(%rbp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movsd -0x90(%rbp), %xmm0
movq 0x10(%rbp), %rax
movslq -0x50(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm1
movq %xmm1, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm1
addsd %xmm0, %xmm0
addsd %xmm1, %xmm0
movq 0x10(%rbp), %rax
movslq -0x3c(%rbp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movq -0x38(%rbp), %rax
movslq -0x50(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
movq -0x38(%rbp), %rax
movslq -0x3c(%rbp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movl -0x50(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x50(%rbp)
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x23b6
cmpl $0x1, -0x24(%rbp)
jne 0x248c
movl -0x40(%rbp), %eax
shll %eax
addl $0x1, %eax
subl -0x1c(%rbp), %eax
subl -0x20(%rbp), %eax
movl %eax, -0x44(%rbp)
jmp 0x24b0
movl -0x1c(%rbp), %eax
cmpl -0x20(%rbp), %eax
jg 0x24a2
movl -0x20(%rbp), %eax
subl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
jmp 0x24ae
movl -0x1c(%rbp), %eax
subl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
jmp 0x24b0
movl -0x1c(%rbp), %eax
cmpl -0x20(%rbp), %eax
jg 0x24c3
movl -0x44(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x2599
cmpl $0x1, -0x24(%rbp)
jne 0x24d4
movl -0x1c(%rbp), %eax
subl -0x20(%rbp), %eax
movl %eax, -0x54(%rbp)
jmp 0x24e2
movl -0x40(%rbp), %eax
shll %eax
subl -0x1c(%rbp), %eax
subl -0x20(%rbp), %eax
movl %eax, -0x54(%rbp)
movq -0x30(%rbp), %rax
movslq -0x54(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
movsd %xmm0, -0x98(%rbp)
movq 0x10(%rbp), %rax
movslq -0x54(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
movsd %xmm0, -0xa0(%rbp)
movl $0x0, -0x3c(%rbp)
movl -0x54(%rbp), %eax
movl %eax, -0x4c(%rbp)
movl -0x3c(%rbp), %eax
cmpl -0x44(%rbp), %eax
jge 0x2593
movq -0x30(%rbp), %rax
movslq -0x4c(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
subsd -0x98(%rbp), %xmm0
movq -0x30(%rbp), %rax
movslq -0x3c(%rbp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movq 0x10(%rbp), %rax
movslq -0x4c(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
subsd -0xa0(%rbp), %xmm0
movq 0x10(%rbp), %rax
movslq -0x3c(%rbp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movq -0x38(%rbp), %rax
movslq -0x4c(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
movq -0x38(%rbp), %rax
movslq -0x3c(%rbp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4c(%rbp)
jmp 0x2519
movl -0x44(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0xc0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)