// File: /workspace/github_c_makefile_star2_O0/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
subq $0x1f0, %rsp            # imm = 0x1F0
movl $0x0, -0x4(%rbp)
leaq 0x87a(%rip), %rdi       # 0x5173
leaq -0x10(%rbp), %rsi
movb $0x0, %al
callq 0x10f0
leaq 0x868(%rip), %rdi       # 0x5173
leaq -0x48(%rbp), %rsi
movb $0x0, %al
callq 0x10f0
leaq -0xe0(%rbp), %rsi
leaq -0xe0(%rbp), %rdx
addq $0x8, %rdx
leaq 0x841(%rip), %rdi       # 0x5170
movb $0x0, %al
callq 0x10f0
leaq -0x110(%rbp), %rsi
addq $0x18, %rsi
leaq -0x110(%rbp), %rdx
addq $0x20, %rdx
leaq -0x110(%rbp), %rcx
addq $0x28, %rcx
leaq 0x80f(%rip), %rdi       # 0x516d
movb $0x0, %al
callq 0x10f0
xorps %xmm0, %xmm0
movsd %xmm0, -0x110(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x108(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x100(%rbp)
leaq -0xd0(%rbp), %rsi
leaq 0x8eb(%rip), %rdi       # 0x527f
movb $0x0, %al
callq 0x10f0
movsd 0x73d(%rip), %xmm0      # 0x50e0
movsd %xmm0, -0x1b0(%rbp)
movsd 0x72d(%rip), %xmm0      # 0x50e0
movsd %xmm0, -0x1a8(%rbp)
movsd 0x675(%rip), %xmm0      # 0x5038
movsd %xmm0, -0x1a0(%rbp)
movsd 0x70d(%rip), %xmm0      # 0x50e0
movsd %xmm0, -0x198(%rbp)
movsd 0x6fd(%rip), %xmm0      # 0x50e0
movsd %xmm0, -0x190(%rbp)
movsd 0x645(%rip), %xmm0      # 0x5038
movsd %xmm0, -0x188(%rbp)
leaq -0xd0(%rbp), %rsi
leaq 0x879(%rip), %rdi       # 0x5282
movl $0x4, %edx
callq 0x1040
cmpl $0x0, %eax
jne 0x4a34
leaq -0xd0(%rbp), %rdi
leaq 0x859(%rip), %rsi       # 0x527f
leaq 0x85a(%rip), %rdx       # 0x5287
movb $0x0, %al
callq 0x1110
leaq -0xd0(%rbp), %rdi
leaq 0x6e1(%rip), %rsi       # 0x5123
callq 0x10d0
movq %rax, -0x1e0(%rbp)
cmpq $0x0, -0x1e0(%rbp)
jne 0x4a81
movq 0x2599(%rip), %rax      # 0x6ff8
movq (%rax), %rdi
leaq -0xd0(%rbp), %rdx
leaq 0x81c(%rip), %rsi       # 0x528c
movb $0x0, %al
callq 0x10b0
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x1120
movq -0x1e0(%rbp), %rdi
leaq 0x6b3(%rip), %rsi       # 0x5142
leaq -0x148(%rbp), %rdx
movb $0x0, %al
callq 0x1050
cmpl $0x1, %eax
je 0x4ac4
movq 0x254f(%rip), %rax      # 0x6ff8
movq (%rax), %rdi
leaq 0x7f3(%rip), %rsi       # 0x52a6
movb $0x0, %al
callq 0x10b0
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x1120
movl $0x0, -0x144(%rbp)
movl -0x144(%rbp), %eax
cmpl -0x148(%rbp), %eax
jge 0x4be7
movq -0x1e0(%rbp), %rdi
leaq 0x676(%rip), %rsi       # 0x5164
leaq -0x150(%rbp), %rdx
leaq -0x158(%rbp), %rcx
leaq -0x160(%rbp), %r8
leaq -0x168(%rbp), %r9
leaq -0x170(%rbp), %r10
leaq -0x178(%rbp), %rax
movq %r10, (%rsp)
movq %rax, 0x8(%rsp)
movb $0x0, %al
callq 0x1050
cmpl $0x6, %eax
je 0x4b4f
movq 0x24c4(%rip), %rax      # 0x6ff8
movq (%rax), %rdi
leaq 0x79c(%rip), %rsi       # 0x52da
movb $0x0, %al
callq 0x10b0
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x1120
movsd 0x4c9(%rip), %xmm0      # 0x5020
ucomisd -0x160(%rbp), %xmm0
jbe 0x4ba3
movsd -0x150(%rbp), %xmm0
movsd %xmm0, -0x180(%rbp)
movsd -0x160(%rbp), %xmm0
movsd %xmm0, -0x128(%rbp)
movsd -0x158(%rbp), %xmm0
movsd %xmm0, -0x120(%rbp)
movsd -0x168(%rbp), %xmm0
movsd %xmm0, -0x118(%rbp)
jmp 0x4be7
movsd -0x160(%rbp), %xmm0
movsd %xmm0, -0x140(%rbp)
movsd -0x158(%rbp), %xmm0
movsd %xmm0, -0x138(%rbp)
movsd -0x168(%rbp), %xmm0
movsd %xmm0, -0x130(%rbp)
movl -0x144(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x144(%rbp)
jmp 0x4ace
movl $0x1, -0xb0(%rbp)
movl $0x1, -0xac(%rbp)
movl $0x1, -0xa8(%rbp)
movl $0x0, -0xa4(%rbp)
movsd -0x48(%rbp), %xmm0
movsd %xmm0, -0x40(%rbp)
movl $0x1, -0xa0(%rbp)
movl $0x1, -0x9c(%rbp)
movl $0x1, -0x98(%rbp)
movl $0x1, -0x94(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x38(%rbp)
movl $0x1, -0x90(%rbp)
movl $0x1, -0x8c(%rbp)
movl $0x0, -0x88(%rbp)
movl $0x0, -0x84(%rbp)
movsd -0x180(%rbp), %xmm0
movsd %xmm0, -0x30(%rbp)
movl $0x0, -0x80(%rbp)
movl $0x0, -0x7c(%rbp)
movl $0x1, -0x78(%rbp)
movl $0x0, -0x74(%rbp)
movsd -0x48(%rbp), %xmm0
movsd %xmm0, -0x28(%rbp)
movl $0x0, -0x70(%rbp)
movl $0x0, -0x6c(%rbp)
movl $0x1, -0x68(%rbp)
movl $0x1, -0x64(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x20(%rbp)
movl $0x0, -0x60(%rbp)
movl $0x0, -0x5c(%rbp)
movl $0x0, -0x58(%rbp)
movl $0x0, -0x54(%rbp)
movsd -0x180(%rbp), %xmm0
movsd %xmm0, -0x18(%rbp)
movl $0x0, -0x144(%rbp)
cmpl $0x6, -0x144(%rbp)
jge 0x4e6c
leaq -0x1d0(%rbp), %rdi
movl -0x144(%rbp), %edx
addl $0x1, %edx
leaq 0x5e7(%rip), %rsi       # 0x5306
movb $0x0, %al
callq 0x1110
cmpl $0x2, -0x144(%rbp)
je 0x4dce
cmpl $0x5, -0x144(%rbp)
je 0x4dce
leaq -0xd0(%rbp), %rdi
movsd -0x10(%rbp), %xmm0
movslq -0x144(%rbp), %rax
movsd -0x40(%rbp,%rax,8), %xmm1
movsd -0x48(%rbp), %xmm2
movslq -0x144(%rbp), %rax
leaq -0xb0(%rbp), %rsi
shlq $0x4, %rax
addq %rax, %rsi
leaq -0x110(%rbp), %rdx
leaq -0xe0(%rbp), %rcx
leaq -0x1d0(%rbp), %r8
movslq -0x144(%rbp), %rax
movsd -0x1b0(%rbp,%rax,8), %xmm3
callq 0x3a00
movl %eax, -0x1d4(%rbp)
cmpl $-0x1, -0x1d4(%rbp)
jne 0x4dc9
movq 0x2245(%rip), %rax      # 0x6ff8
movq (%rax), %rdi
leaq 0x555(%rip), %rsi       # 0x5312
movb $0x0, %al
callq 0x10b0
jmp 0x4e58
jmp 0x4e56
leaq -0xd0(%rbp), %rdi
movsd -0x10(%rbp), %xmm0
movslq -0x144(%rbp), %rax
movsd -0x40(%rbp,%rax,8), %xmm1
movsd -0x48(%rbp), %xmm2
movslq -0x144(%rbp), %rax
leaq -0xb0(%rbp), %rsi
shlq $0x4, %rax
addq %rax, %rsi
leaq -0x140(%rbp), %rdx
leaq -0xe0(%rbp), %rcx
leaq -0x1d0(%rbp), %r8
movslq -0x144(%rbp), %rax
movsd -0x1b0(%rbp,%rax,8), %xmm3
callq 0x3a00
movl %eax, -0x1d4(%rbp)
cmpl $-0x1, -0x1d4(%rbp)
jne 0x4e54
movq 0x21b7(%rip), %rax      # 0x6ff8
movq (%rax), %rdi
leaq 0x4c7(%rip), %rsi       # 0x5312
movb $0x0, %al
callq 0x10b0
jmp 0x4e58
jmp 0x4e56
jmp 0x4e58
movl -0x144(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x144(%rbp)
jmp 0x4cfb
xorl %eax, %eax
addq $0x1f0, %rsp            # imm = 0x1F0
popq %rbp
retq