// File: /workspace/github_c_makefile_star2_O2/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 0xcba(%rip), %rbx       # 0x41c3
leaq -0x60(%rbp), %rsi
movq %rbx, %rdi
xorl %eax, %eax
callq 0x10e0
leaq -0x30(%rbp), %rsi
movq %rbx, %rdi
xorl %eax, %eax
callq 0x10e0
leaq -0xd8(%rbp), %rdx
leaq 0xc8d(%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 0xc60(%rip), %rdi       # 0x41bd
movq %rbx, %rcx
xorl %eax, %eax
callq 0x10e0
xorps %xmm0, %xmm0
movaps %xmm0, -0x28(%rbx)
andq $0x0, -0x18(%rbx)
leaq 0xd55(%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 0x35d9
movb $0x0, -0x7c(%rbp)
movl $0x6d657270, -0x80(%rbp) # imm = 0x6D657270
leaq 0xb93(%rip), %rsi       # 0x4173
leaq -0x80(%rbp), %rdi
callq 0x10c0
testq %rax, %rax
je 0x3879
movq %rax, %rbx
leaq 0xb96(%rip), %rsi       # 0x4192
leaq -0x34(%rbp), %rdx
movq %rax, %rdi
xorl %eax, %eax
callq 0x1040
cmpl $0x1, %eax
jne 0x3897
leaq -0x58(%rbp), %r12
leaq -0x90(%rbp), %r13
leaq -0x50(%rbp), %r14
xorl %r15d, %r15d
cmpl -0x34(%rbp), %r15d
jge 0x36a0
movsd %xmm1, -0x88(%rbp)
movq %rbx, %rdi
leaq 0xb77(%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
popq %rcx
popq %rdx
cmpl $0x6, %eax
jne 0x3855
movsd -0x90(%rbp), %xmm1
movsd 0xa17(%rip), %xmm0      # 0x4098
ucomisd %xmm1, %xmm0
ja 0x36c4
movsd -0x58(%rbp), %xmm0
movsd %xmm0, -0x40(%rbp)
movsd -0x50(%rbp), %xmm0
movsd %xmm0, -0x48(%rbp)
incl %r15d
jmp 0x3625
movsd -0x40(%rbp), %xmm0
movsd %xmm0, -0xc8(%rbp)
movsd -0x48(%rbp), %xmm0
movsd %xmm0, -0xc0(%rbp)
movsd %xmm1, -0xd0(%rbp)
jmp 0x3718
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 0x911(%rip), %xmm1      # 0x4030
leaq -0x200(%rbp), %rbx
movaps %xmm1, (%rbx)
movsd -0x30(%rbp), %xmm1
movsd %xmm1, -0x140(%rbp)
movaps 0x903(%rip), %xmm2      # 0x4040
movaps %xmm2, 0x10(%rbx)
andq $0x0, -0x138(%rbp)
movsd 0x8ff(%rip), %xmm2      # 0x4050
movaps %xmm2, 0x20(%rbx)
movsd %xmm0, -0x130(%rbp)
movaps 0x8fc(%rip), %xmm2      # 0x4060
movaps %xmm2, 0x30(%rbx)
movsd %xmm1, -0x128(%rbp)
andq $0x0, -0x120(%rbp)
movaps 0x8f1(%rip), %xmm1      # 0x4070
movaps %xmm1, 0x40(%rbx)
xorps %xmm1, %xmm1
movaps %xmm1, 0x50(%rbx)
movsd %xmm0, -0x118(%rbp)
leaq -0x1a0(%rbp), %r15
leaq -0x80(%rbp), %r12
leaq -0xe0(%rbp), %r13
xorl %r14d, %r14d
cmpq $0x6, %r14
je 0x3841
leal 0x1(%r14), %edx
movq %r15, %rdi
leaq 0xb92(%rip), %rsi       # 0x4351
xorl %eax, %eax
callq 0x1100
cmpl $0x2, %r14d
je 0x37d2
cmpl $0x5, %r14d
jne 0x37ff
movsd -0x60(%rbp), %xmm0
movsd -0x140(%rbp,%r14,8), %xmm1
movsd -0x30(%rbp), %xmm2
movsd -0x110(%rbp,%r14,8), %xmm3
movq %r12, %rdi
movq %rbx, %rsi
leaq -0xd0(%rbp), %rdx
jmp 0x382a
movsd -0x60(%rbp), %xmm0
movsd -0x140(%rbp,%r14,8), %xmm1
movsd -0x30(%rbp), %xmm2
movsd -0x110(%rbp,%r14,8), %xmm3
movq %r12, %rdi
movq %rbx, %rsi
leaq -0x180(%rbp), %rdx
movq %r13, %rcx
movq %r15, %r8
callq 0x29b2
addq $0x10, %rbx
incq %r14
jmp 0x37a7
xorl %eax, %eax
addq $0x1d8, %rsp            # imm = 0x1D8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x279c(%rip), %rax      # 0x5ff8
movq (%rax), %rcx
leaq 0xabf(%rip), %rdi       # 0x4325
pushq $0x2b
popq %rsi
pushq $0x1
popq %rdx
callq 0x1120
pushq $-0x1
popq %rdi
callq 0x1110
movq 0x2778(%rip), %rax      # 0x5ff8
movq (%rax), %rdi
leaq 0xa4d(%rip), %rsi       # 0x42d7
leaq -0x80(%rbp), %rdx
xorl %eax, %eax
callq 0x10a0
jmp 0x3871
movq 0x275a(%rip), %rax      # 0x5ff8
movq (%rax), %rcx
leaq 0xa49(%rip), %rdi       # 0x42f1
pushq $0x33
jmp 0x3868