// File: /workspace/github_c_makefile_star2_O1/YunyiQian[P]multitel3/./Reflection_Coefficient.c
// Function: Reflection_Coefficient
double Reflection_Coefficient(
	double c1_p,	//Vp of media 1(incident side)
	double c1_s,	//Vs of media 1
	double c2_p,	//Vp of media 2
	double c2_s,	//Vs of media 2
	double rho1,	//density of media 1
	double rho2,	//density of media 2
	double i1,	//incidence of plane wave
	int type	//indication of reflection mode
	){

	double p;
        double Coefficient;
	double D;
	double P1,P2,P3,P4;
	double q,X,Y,Z;

	if (type > 5 || type < 1){
		fprintf(stderr,"Error type is given\n");
		exit(-1);
	}

	if (type == 1 || type == 2){
		p = sin(i1)/c1_p;
	}else{
		p = sin(i1)/c1_s;
	}

	P1 = sqrt(1 - c1_p*c1_p*p*p);
	P2 = sqrt(1 - c1_s*c1_s*p*p);

	P3 = sqrt(1 - c2_p*c2_p*p*p);
	P4 = sqrt(1 - c2_s*c2_s*p*p);

	q = 2.*(rho2*c2_s*c2_s - rho1*c1_s*c1_s);

	X = rho2 - q*p*p;
	Y = rho1 + q*p*p;
	Z = rho2 - rho1 - q*p*p;

	D =  q*q*p*p*P1*P2*P3*P4 
	   + rho1*rho2*(c1_s*c2_p*P1*P4 + c1_p*c2_s*P2*P3)
	   + c1_p*c1_s*P3*P4*Y*Y
	   + c2_p*c2_s*P1*P2*X*X
	   + c1_p*c2_p*c1_s*c2_s*p*p*Z*Z;

	switch (type){
	case 1:
		Coefficient =  (q*q*p*p*P1*P2*P3*P4 
			     + rho1*rho2*(c1_s*c2_p*P1*P4 - c1_p*c2_s*P2*P3)
			     - c1_p*c1_s*P3*P4*Y*Y
			     + c2_p*c2_s*P1*P2*X*X
			     - c1_p*c2_p*c1_s*c2_s*p*p*Z*Z)/D;
		break;
	case 2:
		Coefficient = 2.*c1_p*p*P1*(q*P3*P4*Y + c2_p*c2_s*X*Z)/D;
		break;
	case 3:
		Coefficient = -2.*c1_s*p*P2*(q*P3*P4*Y + c2_p*c2_s*X*Z)/D;
		break;
	case 4:
		Coefficient =  (q*q*p*p*P1*P2*P3*P4
			     + rho1*rho2*(c1_p*c2_s*P2*P3 - c1_s*c2_p*P1*P4)
			     - c1_p*c1_s*P3*P4*Y*Y
			     + c2_p*c2_s*P1*P2*X*X
			     - c1_p*c2_p*c1_s*c2_s*p*p*Z*Z)/D;
		break;
	case 5:
		Coefficient = (rho1*c1_s*P2 - rho2*c2_s*P4)/(rho1*c1_s*P2 + rho2*c2_s*P4);
		break;
	}

	return Coefficient;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %rbx
subq $0x68, %rsp
movl %edi, %ebx
movsd %xmm5, -0x68(%rbp)
movsd %xmm4, -0x20(%rbp)
movsd %xmm3, -0x48(%rbp)
movsd %xmm2, -0x10(%rbp)
movsd %xmm1, -0x30(%rbp)
movsd %xmm0, -0x40(%rbp)
leal -0x6(%rbx), %eax
cmpl $-0x6, %eax
jbe 0x2cd7
decl %ebx
movapd %xmm6, %xmm0
callq 0x10d0
movapd %xmm0, %xmm3
movsd -0x40(%rbp), %xmm1
movapd %xmm1, %xmm0
cmpl $0x2, %ebx
movsd -0x30(%rbp), %xmm2
jb 0x2962
movapd %xmm2, %xmm0
divsd %xmm0, %xmm3
mulsd %xmm1, %xmm1
mulsd %xmm3, %xmm1
mulsd %xmm3, %xmm1
movsd 0x170e(%rip), %xmm5     # 0x4088
movapd %xmm5, %xmm0
subsd %xmm1, %xmm0
xorpd %xmm6, %xmm6
ucomisd %xmm6, %xmm0
movsd %xmm3, -0x28(%rbp)
jb 0x299a
xorps %xmm4, %xmm4
sqrtsd %xmm0, %xmm4
jmp 0x29b9
callq 0x1130
xorpd %xmm6, %xmm6
movsd 0x16dd(%rip), %xmm5     # 0x4088
movsd -0x28(%rbp), %xmm3
movsd -0x30(%rbp), %xmm2
movapd %xmm0, %xmm4
movapd %xmm2, %xmm1
mulsd %xmm2, %xmm1
mulsd %xmm3, %xmm1
mulsd %xmm3, %xmm1
movapd %xmm5, %xmm0
subsd %xmm1, %xmm0
ucomisd %xmm6, %xmm0
movsd %xmm4, -0x58(%rbp)
jb 0x29e5
xorps %xmm2, %xmm2
sqrtsd %xmm0, %xmm2
jmp 0x29fb
callq 0x1130
movsd 0x1696(%rip), %xmm5     # 0x4088
movsd -0x28(%rbp), %xmm3
movapd %xmm0, %xmm2
movsd -0x10(%rbp), %xmm1
mulsd %xmm1, %xmm1
mulsd %xmm3, %xmm1
mulsd %xmm3, %xmm1
movapd %xmm5, %xmm0
subsd %xmm1, %xmm0
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
movsd %xmm2, -0x50(%rbp)
jb 0x2a2a
sqrtsd %xmm0, %xmm13
jmp 0x2a45
callq 0x1130
xorpd %xmm1, %xmm1
movsd 0x164d(%rip), %xmm5     # 0x4088
movsd -0x28(%rbp), %xmm3
movapd %xmm0, %xmm13
movsd -0x48(%rbp), %xmm0
mulsd %xmm0, %xmm0
mulsd %xmm3, %xmm0
mulsd %xmm3, %xmm0
subsd %xmm0, %xmm5
ucomisd %xmm1, %xmm5
movsd %xmm13, -0x38(%rbp)
jb 0x2a6f
xorps %xmm0, %xmm0
sqrtsd %xmm5, %xmm0
jmp 0x2a7e
movapd %xmm5, %xmm0
callq 0x1130
movsd -0x38(%rbp), %xmm13
movsd %xmm0, -0x18(%rbp)
movsd -0x10(%rbp), %xmm11
movsd -0x20(%rbp), %xmm12
movsd -0x48(%rbp), %xmm0
movapd %xmm0, %xmm2
movsd -0x68(%rbp), %xmm4
mulsd %xmm4, %xmm2
movsd -0x30(%rbp), %xmm6
movapd %xmm6, %xmm1
mulsd %xmm12, %xmm1
movsd %xmm1, -0x60(%rbp)
mulsd %xmm6, %xmm1
movsd %xmm2, -0x10(%rbp)
mulsd %xmm0, %xmm2
subsd %xmm1, %xmm2
addsd %xmm2, %xmm2
movapd %xmm2, %xmm3
movsd -0x28(%rbp), %xmm0
mulsd %xmm0, %xmm3
movapd 0x1541(%rip), %xmm14    # 0x4020
xorpd %xmm3, %xmm14
mulsd %xmm0, %xmm14
movapd %xmm4, %xmm7
subsd %xmm12, %xmm7
addsd %xmm14, %xmm7
addsd %xmm4, %xmm14
mulsd %xmm0, %xmm3
addsd %xmm12, %xmm3
movapd %xmm2, %xmm9
mulsd %xmm2, %xmm9
mulsd %xmm0, %xmm9
mulsd %xmm0, %xmm9
movsd -0x58(%rbp), %xmm1
mulsd %xmm1, %xmm9
movsd -0x50(%rbp), %xmm5
mulsd %xmm5, %xmm9
movapd %xmm5, %xmm8
mulsd %xmm13, %xmm9
mulsd %xmm4, %xmm12
movsd %xmm12, -0x20(%rbp)
movapd %xmm6, %xmm10
mulsd %xmm11, %xmm10
mulsd %xmm1, %xmm10
movapd %xmm11, %xmm1
movsd -0x40(%rbp), %xmm11
movapd %xmm11, %xmm15
movsd -0x48(%rbp), %xmm5
mulsd %xmm5, %xmm15
mulsd %xmm8, %xmm15
mulsd %xmm13, %xmm15
movsd -0x18(%rbp), %xmm8
mulsd %xmm8, %xmm10
movapd %xmm10, %xmm4
addsd %xmm15, %xmm4
mulsd %xmm12, %xmm4
mulsd %xmm8, %xmm9
addsd %xmm9, %xmm4
movapd %xmm11, %xmm12
mulsd %xmm6, %xmm12
mulsd %xmm13, %xmm12
mulsd %xmm8, %xmm12
mulsd %xmm3, %xmm12
mulsd %xmm3, %xmm12
addsd %xmm12, %xmm4
mulsd %xmm1, %xmm11
mulsd %xmm5, %xmm1
mulsd %xmm6, %xmm11
movsd -0x50(%rbp), %xmm6
mulsd %xmm5, %xmm11
movsd -0x58(%rbp), %xmm5
movapd %xmm1, %xmm8
mulsd %xmm5, %xmm1
mulsd %xmm6, %xmm1
mulsd %xmm14, %xmm1
mulsd %xmm14, %xmm1
addsd %xmm1, %xmm4
mulsd %xmm0, %xmm11
mulsd %xmm0, %xmm11
mulsd %xmm7, %xmm11
mulsd %xmm7, %xmm11
addsd %xmm11, %xmm4
leaq 0x153c(%rip), %rax      # 0x4150
movslq (%rax,%rbx,4), %rcx
addq %rax, %rcx
jmpq *%rcx
subsd %xmm15, %xmm10
movsd -0x20(%rbp), %xmm0
mulsd %xmm10, %xmm0
jmp 0x2c79
movsd -0x10(%rbp), %xmm0
mulsd -0x18(%rbp), %xmm0
movsd -0x60(%rbp), %xmm2
mulsd %xmm6, %xmm2
movapd %xmm2, %xmm1
subsd %xmm0, %xmm1
addsd %xmm0, %xmm2
divsd %xmm2, %xmm1
jmp 0x2ccc
movsd -0x30(%rbp), %xmm1
mulsd 0x1468(%rip), %xmm1     # 0x40c8
mulsd %xmm0, %xmm1
mulsd %xmm6, %xmm1
jmp 0x2ca4
subsd %xmm10, %xmm15
movsd -0x20(%rbp), %xmm0
mulsd %xmm15, %xmm0
addsd %xmm0, %xmm9
subsd %xmm12, %xmm9
addsd %xmm9, %xmm1
subsd %xmm11, %xmm1
divsd %xmm4, %xmm1
jmp 0x2ccc
movsd -0x40(%rbp), %xmm1
addsd %xmm1, %xmm1
mulsd %xmm0, %xmm1
mulsd %xmm5, %xmm1
mulsd -0x38(%rbp), %xmm2
mulsd -0x18(%rbp), %xmm2
mulsd %xmm14, %xmm8
mulsd %xmm8, %xmm7
mulsd %xmm3, %xmm2
addsd %xmm7, %xmm2
mulsd %xmm1, %xmm2
divsd %xmm4, %xmm2
movapd %xmm2, %xmm1
movapd %xmm1, %xmm0
addq $0x68, %rsp
popq %rbx
popq %rbp
retq
callq 0x1351