// File: /workspace/github_c_makefile_star2_O1/YunyiQian[P]multitel3/main.c
// Function: main
int main(){
	double sdepth;		// depth of source 
	double ddepth[NUM];	// depth of discontinuities for each ray
	double rdepth;		// depth of receivers
	int indr[NUM][4];	// indicators of ray (see above and rayinformation.c)
	char modelname[20];	// name of input standary 1-D model

	double Vr[2];		// structure of near-receiver layer
	double Vm[6];		// structure of PP/SS rebound point
	double temp[6];		// structure of CMB (you can modify code below to change it to another discontinuity)
	int i,layers;
	double depth,Vp,Vs;
	double rho,Qp,Qs;
	double depth_cmb;
	double dh[6];           //differential of hh when generating ray information 
	char outfile[20];
	int error;

	FILE *fp;

	scanf ("%lf",&sdepth);			// depth of source
	scanf ("%lf",&rdepth);			// depth of receivers
	scanf ("%lf%lf",&Vr[0],&Vr[1]);			// Vs and Vp near the receiver
	scanf ("%lf%lf%lf",&Vm[3],&Vm[4],&Vm[5]);	// Vs, Vp and Rho of PP/SS rebound point
	Vm[0] = 0.0;	//Vs of the layer above surface
	Vm[1] = 0.0;	//Vp of the layer above surface
	Vm[2] = 0.0;	//rho of the layer above surface
	scanf ("%s",modelname);
	dh[0] = 0.0005;
	dh[1] = 0.0005;
	dh[2] = 0.0001;
        dh[3] = 0.0005;
	dh[4] = 0.0005;
        dh[5] = 0.0001;

	if ( strncmp("none",modelname,4) == 0 ){
		sprintf (modelname,"%s","prem");
	}

	fp = fopen (modelname,"r");
	if ( fp == NULL ){
		fprintf (stderr,"Error in opening %s file\n",modelname);
		exit (-1);
	}
	if ( fscanf (fp,"%d",&layers) != 1 ){
		fprintf (stderr,"Error in reading number of layers in stdmodel file\n");
		exit (-1);
	}

	for ( i=0;i<layers;i++ ){
		if ( fscanf (fp,"%lf%lf%lf%lf%lf%lf",&depth,&Vp,&Vs,&rho,&Qp,&Qs) != 6 ){
			fprintf (stderr,"Error in reading information from stdmodel\n");
			exit (-1);
		}
		if (Vs < 0.1){		//CMB 
			depth_cmb = depth;
			temp[3] = Vs;
			temp[4] = Vp;
			temp[5] = rho;
			break;
		}
		temp[0] = Vs;	//structure information of CMB
		temp[1] = Vp;
		temp[2] = rho;
	}

	/* P indicator */
	indr[0][0] = 1;
	indr[0][1] = 1;
	indr[0][2] = 1;
	indr[0][3] = 0;
	ddepth[0]  = rdepth;


	/* PP indicator */
	indr[1][0] = 1;
	indr[1][1] = 1;
	indr[1][2] = 1;
	indr[1][3] = 1;
	ddepth[1]  = 0.;

	/* PcP indicator */
	indr[2][0] = 1;
	indr[2][1] = 1;
	indr[2][2] = 0;
	indr[2][3] = 0;
	ddepth[2]  = depth_cmb;
	
	/* S indicator */
	indr[3][0] = 0;
	indr[3][1] = 0;
	indr[3][2] = 1;
	indr[3][3] = 0;
	ddepth[3]  = rdepth;

	/* SS indicator */
	indr[4][0] = 0;
	indr[4][1] = 0;
	indr[4][2] = 1;
	indr[4][3] = 1;
	ddepth[4]  = 0.;

	/* ScS indicator */
	indr[5][0] = 0;
	indr[5][1] = 0;
	indr[5][2] = 0;
	indr[5][3] = 0;
	ddepth[5]  = depth_cmb;

	for ( i=0;i<NUM;i++ ){
		sprintf (outfile,"ray%1d.info",i+1);
		if (i != 2 && i != 5){
			error = rayinformation(modelname,sdepth,ddepth[i],rdepth,indr[i],Vm,Vr,outfile,dh[i]);
			if (error == -1){
				fprintf (stderr,"Error in running rayinformation\n");
				continue;
			}
		}else{
			error = rayinformation(modelname,sdepth,ddepth[i],rdepth,indr[i],temp,Vr,outfile,dh[i]);
			if (error == -1){
				fprintf (stderr,"Error in running rayinformation\n");
				continue;
			}	
		}
	}

	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1c8, %rsp            # imm = 0x1C8
leaq 0x9cc(%rip), %rbx       # 0x41c3
leaq -0x68(%rbp), %rsi
movq %rbx, %rdi
xorl %eax, %eax
callq 0x10e0
leaq -0x50(%rbp), %rsi
movq %rbx, %rdi
xorl %eax, %eax
callq 0x10e0
leaq -0xc8(%rbp), %rdx
leaq 0x99f(%rip), %rdi       # 0x41c0
leaq -0xd0(%rbp), %rsi
xorl %eax, %eax
callq 0x10e0
leaq -0x158(%rbp), %rsi
leaq -0x150(%rbp), %rdx
leaq -0x148(%rbp), %rbx
leaq 0x972(%rip), %rdi       # 0x41bd
movq %rbx, %rcx
xorl %eax, %eax
callq 0x10e0
xorps %xmm0, %xmm0
movaps %xmm0, -0x28(%rbx)
movq $0x0, -0x18(%rbx)
leaq 0xa64(%rip), %rdi       # 0x42cf
leaq -0x80(%rbp), %rbx
movq %rbx, %rsi
xorl %eax, %eax
callq 0x10e0
movabsq $0x3f40624dd2f1a9fc, %rax # imm = 0x3F40624DD2F1A9FC
movq %rax, -0x100(%rbp)
movq %rax, -0xf8(%rbp)
movabsq $0x3f1a36e2eb1c432d, %rcx # imm = 0x3F1A36E2EB1C432D
movq %rcx, -0xf0(%rbp)
movq %rax, -0xe8(%rbp)
movq %rax, -0xe0(%rbp)
movq %rcx, -0xd8(%rbp)
cmpl $0x656e6f6e, (%rbx)     # imm = 0x656E6F6E
jne 0x38ca
movb $0x0, -0x7c(%rbp)
movl $0x6d657270, -0x80(%rbp) # imm = 0x6D657270
leaq 0x8a2(%rip), %rsi       # 0x4173
leaq -0x80(%rbp), %rdi
callq 0x10c0
testq %rax, %rax
je 0x3bbe
movq %rax, %rbx
leaq 0x8a5(%rip), %rsi       # 0x4192
leaq -0x2c(%rbp), %rdx
movq %rax, %rdi
xorl %eax, %eax
callq 0x1040
cmpl $0x1, %eax
jne 0x3bc7
movsd -0xb0(%rbp), %xmm1
cmpl $0x0, -0x2c(%rbp)
jle 0x39d9
movsd %xmm1, -0x48(%rbp)
movsd -0xa8(%rbp), %xmm0
movsd %xmm0, -0x38(%rbp)
movsd -0xa0(%rbp), %xmm0
movsd %xmm0, -0x40(%rbp)
leaq -0x60(%rbp), %r12
leaq -0xb8(%rbp), %r13
leaq -0x58(%rbp), %r14
xorl %r15d, %r15d
movq %rbx, %rdi
leaq 0x863(%rip), %rsi       # 0x41b4
leaq -0xc0(%rbp), %rdx
movq %r12, %rcx
movq %r13, %r8
movq %r14, %r9
xorl %eax, %eax
leaq -0x138(%rbp), %r10
pushq %r10
leaq -0x140(%rbp), %r10
pushq %r10
callq 0x1040
addq $0x10, %rsp
cmpl $0x6, %eax
jne 0x3b6d
movsd -0xb8(%rbp), %xmm1
movsd 0x701(%rip), %xmm0      # 0x4098
ucomisd %xmm1, %xmm0
ja 0x39e3
movsd -0x60(%rbp), %xmm0
movsd %xmm0, -0x38(%rbp)
movsd -0x58(%rbp), %xmm0
movsd %xmm0, -0x40(%rbp)
incl %r15d
movsd %xmm1, -0x48(%rbp)
cmpl -0x2c(%rbp), %r15d
jl 0x3947
movsd -0x38(%rbp), %xmm0
movsd %xmm0, -0xa8(%rbp)
movsd -0x40(%rbp), %xmm0
movsd %xmm0, -0xa0(%rbp)
movsd %xmm1, -0xb0(%rbp)
jmp 0x3a34
movsd -0x38(%rbp), %xmm0
movsd %xmm0, -0xa8(%rbp)
movsd -0x40(%rbp), %xmm0
movsd %xmm0, -0xa0(%rbp)
movsd -0x48(%rbp), %xmm0
movsd %xmm0, -0xb0(%rbp)
movsd -0xc0(%rbp), %xmm0
movsd %xmm1, -0x98(%rbp)
movsd -0x60(%rbp), %xmm1
movsd %xmm1, -0x90(%rbp)
movsd -0x58(%rbp), %xmm1
movsd %xmm1, -0x88(%rbp)
movaps 0x5f5(%rip), %xmm1      # 0x4030
leaq -0x1f0(%rbp), %rbx
movaps %xmm1, (%rbx)
movsd -0x50(%rbp), %xmm1
movsd %xmm1, -0x130(%rbp)
movaps 0x5e7(%rip), %xmm2      # 0x4040
movaps %xmm2, 0x10(%rbx)
xorl %eax, %eax
movq %rax, -0x128(%rbp)
movsd 0x5e2(%rip), %xmm2      # 0x4050
movaps %xmm2, 0x20(%rbx)
movsd %xmm0, -0x120(%rbp)
movaps 0x5df(%rip), %xmm2      # 0x4060
movaps %xmm2, 0x30(%rbx)
movsd %xmm1, -0x118(%rbp)
movaps 0x5dc(%rip), %xmm1      # 0x4070
movaps %xmm1, 0x40(%rbx)
movq %rax, -0x110(%rbp)
xorps %xmm1, %xmm1
movaps %xmm1, 0x50(%rbx)
movsd %xmm0, -0x108(%rbp)
leaq -0x190(%rbp), %r15
leaq -0xd0(%rbp), %r13
xorl %r14d, %r14d
leaq 0x1(%r14), %r12
movq %r15, %rdi
leaq 0x884(%rip), %rsi       # 0x4351
movl %r12d, %edx
xorl %eax, %eax
callq 0x1100
cmpl $0x2, %r14d
je 0x3ae3
cmpl $0x5, %r14d
jne 0x3b11
movsd -0x68(%rbp), %xmm0
movsd -0x130(%rbp,%r14,8), %xmm1
movsd -0x50(%rbp), %xmm2
movsd -0x100(%rbp,%r14,8), %xmm3
leaq -0x80(%rbp), %rdi
movq %rbx, %rsi
leaq -0xb0(%rbp), %rdx
jmp 0x3b3d
movsd -0x68(%rbp), %xmm0
movsd -0x130(%rbp,%r14,8), %xmm1
movsd -0x50(%rbp), %xmm2
movsd -0x100(%rbp,%r14,8), %xmm3
leaq -0x80(%rbp), %rdi
movq %rbx, %rsi
leaq -0x170(%rbp), %rdx
movq %r13, %rcx
movq %r15, %r8
callq 0x2cdc
addq $0x10, %rbx
movq %r12, %r14
cmpq $0x6, %r12
jne 0x3abf
xorl %eax, %eax
addq $0x1c8, %rsp            # imm = 0x1C8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movsd -0x38(%rbp), %xmm0
movsd %xmm0, -0xa8(%rbp)
movsd -0x40(%rbp), %xmm0
movsd %xmm0, -0xa0(%rbp)
movsd -0x48(%rbp), %xmm0
movsd %xmm0, -0xb0(%rbp)
movq 0x245d(%rip), %rax      # 0x5ff8
movq (%rax), %rcx
leaq 0x780(%rip), %rdi       # 0x4325
movl $0x2b, %esi
movl $0x1, %edx
callq 0x1120
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x1110
leaq -0x80(%rbp), %rdi
callq 0x13c9
callq 0x13a1