// File: /workspace/github_c_makefile_star2_O2/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 0x298e
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 0x2622
movapd %xmm2, %xmm0
divsd %xmm0, %xmm3
mulsd %xmm1, %xmm1
mulsd %xmm3, %xmm1
mulsd %xmm3, %xmm1
movsd 0x1a4e(%rip), %xmm5     # 0x4088
movapd %xmm5, %xmm0
subsd %xmm1, %xmm0
xorpd %xmm6, %xmm6
ucomisd %xmm6, %xmm0
movsd %xmm3, -0x28(%rbp)
jb 0x2657
sqrtsd %xmm0, %xmm4
jmp 0x2676
callq 0x1130
xorpd %xmm6, %xmm6
movsd 0x1a20(%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 0x269f
sqrtsd %xmm0, %xmm2
jmp 0x26b5
callq 0x1130
movsd 0x19dc(%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 0x26e4
sqrtsd %xmm0, %xmm13
jmp 0x26ff
callq 0x1130
xorpd %xmm1, %xmm1
movsd 0x1993(%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 0x2726
sqrtsd %xmm5, %xmm0
jmp 0x2735
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 0x188a(%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 0x1885(%rip), %rax      # 0x4150
movslq (%rax,%rbx,4), %rcx
addq %rax, %rcx
jmpq *%rcx
subsd %xmm15, %xmm10
movsd -0x20(%rbp), %xmm0
mulsd %xmm10, %xmm0
jmp 0x2930
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 0x2983
movsd -0x30(%rbp), %xmm1
mulsd 0x17b1(%rip), %xmm1     # 0x40c8
mulsd %xmm0, %xmm1
mulsd %xmm6, %xmm1
jmp 0x295b
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 0x2983
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
movq 0x3663(%rip), %rax      # 0x5ff8
movq (%rax), %rcx
leaq 0x18e5(%rip), %rdi      # 0x4284
pushq $0x14
popq %rsi
pushq $0x1
popq %rdx
callq 0x1120
pushq $-0x1
popq %rdi
callq 0x1110