// File: /workspace/github_c_makefile_star2_O3/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 $0x1d8, %rsp            # imm = 0x1D8
leaq 0x921(%rip), %rbx       # 0x41c3
leaq -0x60(%rbp), %rsi
movq %rbx, %rdi
xorl %eax, %eax
callq 0x10e0
leaq -0x38(%rbp), %rsi
movq %rbx, %rdi
xorl %eax, %eax
callq 0x10e0
leaq -0xd8(%rbp), %rdx
leaq 0x8f4(%rip), %rdi       # 0x41c0
leaq -0xe0(%rbp), %rsi
xorl %eax, %eax
callq 0x10e0
leaq -0x168(%rbp), %rsi
leaq -0x160(%rbp), %rdx
leaq -0x158(%rbp), %rbx
leaq 0x8c7(%rip), %rdi       # 0x41bd
movq %rbx, %rcx
xorl %eax, %eax
callq 0x10e0
xorps %xmm0, %xmm0
movaps %xmm0, -0x28(%rbx)
movq $0x0, -0x18(%rbx)
leaq 0x9b9(%rip), %rdi       # 0x42cf
leaq -0x80(%rbp), %rbx
movq %rbx, %rsi
xorl %eax, %eax
callq 0x10e0
movabsq $0x3f40624dd2f1a9fc, %rax # imm = 0x3F40624DD2F1A9FC
movq %rax, -0x110(%rbp)
movq %rax, -0x108(%rbp)
movabsq $0x3f1a36e2eb1c432d, %rcx # imm = 0x3F1A36E2EB1C432D
movq %rcx, -0x100(%rbp)
movq %rax, -0xf8(%rbp)
movq %rax, -0xf0(%rbp)
movq %rcx, -0xe8(%rbp)
cmpl $0x656e6f6e, (%rbx)     # imm = 0x656E6F6E
jne 0x3975
movb $0x0, -0x7c(%rbp)
movl $0x6d657270, -0x80(%rbp) # imm = 0x6D657270
leaq 0x7f7(%rip), %rsi       # 0x4173
leaq -0x80(%rbp), %rdi
callq 0x10c0
testq %rax, %rax
je 0x3bfe
movq %rax, %rbx
leaq 0x7fa(%rip), %rsi       # 0x4192
leaq -0x2c(%rbp), %rdx
movq %rax, %rdi
xorl %eax, %eax
callq 0x1040
cmpl $0x1, %eax
jne 0x3c07
cmpl $0x0, -0x2c(%rbp)
jle 0x3a62
leaq -0x58(%rbp), %r12
leaq -0x90(%rbp), %r13
leaq -0x50(%rbp), %r14
xorl %r15d, %r15d
movq %rbx, %rdi
leaq 0x7df(%rip), %rsi       # 0x41b4
leaq -0x98(%rbp), %rdx
movq %r12, %rcx
movq %r13, %r8
movq %r14, %r9
xorl %eax, %eax
leaq -0x148(%rbp), %r10
pushq %r10
leaq -0x150(%rbp), %r10
pushq %r10
callq 0x1040
addq $0x10, %rsp
cmpl $0x6, %eax
jne 0x3bf9
movsd -0x90(%rbp), %xmm1
movsd 0x67d(%rip), %xmm0      # 0x4098
ucomisd %xmm1, %xmm0
ja 0x3a6c
movsd -0x58(%rbp), %xmm0
movsd %xmm0, -0x40(%rbp)
movsd -0x50(%rbp), %xmm0
movsd %xmm0, -0x48(%rbp)
incl %r15d
movsd %xmm1, -0x88(%rbp)
cmpl -0x2c(%rbp), %r15d
jl 0x39cb
movsd -0x40(%rbp), %xmm0
movsd %xmm0, -0xc8(%rbp)
movsd -0x48(%rbp), %xmm0
movsd %xmm0, -0xc0(%rbp)
jmp 0x3a62
movsd %xmm1, -0xd0(%rbp)
jmp 0x3ac0
movsd -0x40(%rbp), %xmm0
movsd %xmm0, -0xc8(%rbp)
movsd -0x48(%rbp), %xmm0
movsd %xmm0, -0xc0(%rbp)
movsd -0x88(%rbp), %xmm0
movsd %xmm0, -0xd0(%rbp)
movsd -0x98(%rbp), %xmm0
movsd %xmm1, -0xb8(%rbp)
movsd -0x58(%rbp), %xmm1
movsd %xmm1, -0xb0(%rbp)
movsd -0x50(%rbp), %xmm1
movsd %xmm1, -0xa8(%rbp)
movaps 0x569(%rip), %xmm1      # 0x4030
leaq -0x200(%rbp), %rbx
movaps %xmm1, (%rbx)
movsd -0x38(%rbp), %xmm1
movsd %xmm1, -0x140(%rbp)
movaps 0x55b(%rip), %xmm2      # 0x4040
movaps %xmm2, 0x10(%rbx)
xorl %eax, %eax
movq %rax, -0x138(%rbp)
movsd 0x556(%rip), %xmm2      # 0x4050
movaps %xmm2, 0x20(%rbx)
movsd %xmm0, -0x130(%rbp)
movaps 0x553(%rip), %xmm2      # 0x4060
movaps %xmm2, 0x30(%rbx)
movsd %xmm1, -0x128(%rbp)
movaps 0x550(%rip), %xmm1      # 0x4070
movaps %xmm1, 0x40(%rbx)
movq %rax, -0x120(%rbp)
xorps %xmm1, %xmm1
movaps %xmm1, 0x50(%rbx)
movsd %xmm0, -0x118(%rbp)
leaq -0x1a0(%rbp), %r15
leaq -0xe0(%rbp), %r13
xorl %r14d, %r14d
leaq 0x1(%r14), %r12
movq %r15, %rdi
leaq 0x7f8(%rip), %rsi       # 0x4351
movl %r12d, %edx
xorl %eax, %eax
callq 0x1100
cmpl $0x2, %r14d
je 0x3b6f
cmpl $0x5, %r14d
jne 0x3b9d
movsd -0x60(%rbp), %xmm0
movsd -0x140(%rbp,%r14,8), %xmm1
movsd -0x38(%rbp), %xmm2
movsd -0x110(%rbp,%r14,8), %xmm3
leaq -0x80(%rbp), %rdi
movq %rbx, %rsi
leaq -0xd0(%rbp), %rdx
jmp 0x3bc9
movsd -0x60(%rbp), %xmm0
movsd -0x140(%rbp,%r14,8), %xmm1
movsd -0x38(%rbp), %xmm2
movsd -0x110(%rbp,%r14,8), %xmm3
leaq -0x80(%rbp), %rdi
movq %rbx, %rsi
leaq -0x180(%rbp), %rdx
movq %r13, %rcx
movq %r15, %r8
callq 0x2d0d
addq $0x10, %rbx
movq %r12, %r14
cmpq $0x6, %r12
jne 0x3b4b
xorl %eax, %eax
addq $0x1d8, %rsp            # imm = 0x1D8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x13c9
leaq -0x80(%rbp), %rdi
callq 0x13f1
callq 0x13a1