#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
int atan2(int /*<<< orphan*/, int /*<<< orphan*/);
double cos(double);
int /*<<< orphan*/ gridsquare_to_latlon(char *, double *, double *);
double pow(int /*<<< orphan*/, int);
int /*<<< orphan*/ sin(double);
int /*<<< orphan*/ sqrt(int);
int cwirc_great_circle_path(char *gs1, char *gs2) {
  double lat1, lon1;
  double lat2, lon2;
  double a, d;
  gridsquare_to_latlon(gs1, &lat1, &lon1);
  gridsquare_to_latlon(gs2, &lat2, &lon2);
  a = pow(sin((lat2 - lat1) / 2), 2) +
      cos(lat1) * cos(lat2) * pow(sin((lon2 - lon1) / 2), 2);
  d = 6367 * 2 * atan2(sqrt(a), sqrt(1 - a));
  return (d);
}


x86 assembly (clang, -O0):
<cwirc_great_circle_path>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x18(%rbp),%rsi
lea    -0x20(%rbp),%rdx
call   1080 <gridsquare_to_latlon@plt>
mov    -0x10(%rbp),%rdi
lea    -0x28(%rbp),%rsi
lea    -0x30(%rbp),%rdx
call   1080 <gridsquare_to_latlon@plt>
movsd  -0x28(%rbp),%xmm0
subsd  -0x18(%rbp),%xmm0
movsd  0xe64(%rip),%xmm1
divsd  %xmm1,%xmm0
call   1040 <sin@plt>
mov    %eax,%edi
mov    $0x2,%esi
call   1060 <pow@plt>
movsd  %xmm0,-0x58(%rbp)
movsd  -0x18(%rbp),%xmm0
call   1050 <cos@plt>
movsd  %xmm0,-0x60(%rbp)
movsd  -0x28(%rbp),%xmm0
call   1050 <cos@plt>
movaps %xmm0,%xmm1
movsd  -0x60(%rbp),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x30(%rbp),%xmm0
subsd  -0x20(%rbp),%xmm0
movsd  0xe0e(%rip),%xmm1
divsd  %xmm1,%xmm0
call   1040 <sin@plt>
mov    %eax,%edi
mov    $0x2,%esi
call   1060 <pow@plt>
movsd  -0x58(%rbp),%xmm1
movaps %xmm0,%xmm2
movsd  -0x50(%rbp),%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
cvttsd2si -0x38(%rbp),%edi
call   1070 <sqrt@plt>
mov    %eax,-0x44(%rbp)
movsd  0xdc2(%rip),%xmm0
subsd  -0x38(%rbp),%xmm0
cvttsd2si %xmm0,%edi
call   1070 <sqrt@plt>
mov    -0x44(%rbp),%edi
mov    %eax,%esi
call   1030 <atan2@plt>
imul   $0x31be,%eax,%eax
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x40(%rbp)
cvttsd2si -0x40(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cwirc_great_circle_path>:
push   %rbx
sub    $0x30,%rsp
mov    %rsi,%rbx
lea    0x18(%rsp),%rsi
lea    0x28(%rsp),%rdx
call   1080 <gridsquare_to_latlon@plt>
lea    0x10(%rsp),%rsi
lea    0x20(%rsp),%rdx
mov    %rbx,%rdi
call   1080 <gridsquare_to_latlon@plt>
movsd  0x10(%rsp),%xmm0
subsd  0x18(%rsp),%xmm0
mulsd  0xe63(%rip),%xmm0
call   1040 <sin@plt>
mov    %eax,%edi
mov    $0x2,%esi
call   1060 <pow@plt>
movsd  %xmm0,0x8(%rsp)
movsd  0x18(%rsp),%xmm0
call   1050 <cos@plt>
movsd  %xmm0,(%rsp)
movsd  0x10(%rsp),%xmm0
call   1050 <cos@plt>
mulsd  (%rsp),%xmm0
movsd  %xmm0,(%rsp)
movsd  0x20(%rsp),%xmm0
subsd  0x28(%rsp),%xmm0
mulsd  0xe13(%rip),%xmm0
call   1040 <sin@plt>
mov    %eax,%edi
mov    $0x2,%esi
call   1060 <pow@plt>
mulsd  (%rsp),%xmm0
addsd  0x8(%rsp),%xmm0
movsd  %xmm0,0x8(%rsp)
cvttsd2si %xmm0,%edi
call   1070 <sqrt@plt>
mov    %eax,%ebx
movsd  0xde6(%rip),%xmm0
subsd  0x8(%rsp),%xmm0
cvttsd2si %xmm0,%edi
call   1070 <sqrt@plt>
mov    %ebx,%edi
mov    %eax,%esi
call   1030 <atan2@plt>
imul   $0x31be,%eax,%eax
add    $0x30,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define i32 @cwirc_great_circle_path(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca double
%6 = alloca double
%7 = alloca double
%8 = alloca double
%9 = alloca double
%10 = alloca double
store i8* %0, i8** %3
store i8* %1, i8** %4
%11 = load i8*, i8** %3
%12 = call i32 @gridsquare_to_latlon(i8* %11, double* %5, double* %6)
%13 = load i8*, i8** %4
%14 = call i32 @gridsquare_to_latlon(i8* %13, double* %7, double* %8)
%15 = load double, double* %7
%16 = load double, double* %5
%17 = fsub double %15, %16
%18 = fdiv double %17, 2.000000e+00
%19 = call i32 @sin(double %18)
%20 = call double @pow(i32 %19, i32 2)
%21 = load double, double* %5
%22 = call double @cos(double %21)
%23 = load double, double* %7
%24 = call double @cos(double %23)
%25 = fmul double %22, %24
%26 = load double, double* %8
%27 = load double, double* %6
%28 = fsub double %26, %27
%29 = fdiv double %28, 2.000000e+00
%30 = call i32 @sin(double %29)
%31 = call double @pow(i32 %30, i32 2)
%32 = call double @llvm.fmuladd.f64(double %25, double %31, double %20)
store double %32, double* %9
%33 = load double, double* %9
%34 = fptosi double %33 to i32
%35 = call i32 @sqrt(i32 %34)
%36 = load double, double* %9
%37 = fsub double 1.000000e+00, %36
%38 = fptosi double %37 to i32
%39 = call i32 @sqrt(i32 %38)
%40 = call i32 @atan2(i32 %35, i32 %39)
%41 = mul nsw i32 12734, %40
%42 = sitofp i32 %41 to double
store double %42, double* %10
%43 = load double, double* %10
%44 = fptosi double %43 to i32
ret i32 %44
}

LLVM IR (-O2):
define i32 @cwirc_great_circle_path(i8* %0, i8* %1) {
%3 = alloca double
%4 = alloca double
%5 = alloca double
%6 = alloca double
%7 = bitcast double* %3 to i8*
%8 = bitcast double* %4 to i8*
%9 = bitcast double* %5 to i8*
%10 = bitcast double* %6 to i8*
%11 = call i32 @gridsquare_to_latlon(i8* %0, double* %3, double* %4)
%12 = call i32 @gridsquare_to_latlon(i8* %1, double* %5, double* %6)
%13 = load double, double* %5
%14 = load double, double* %3
%15 = fsub double %13, %14
%16 = fmul double %15, 5.000000e-01
%17 = call i32 @sin(double %16)
%18 = call double @pow(i32 %17, i32 2)
%19 = load double, double* %3
%20 = call double @cos(double %19)
%21 = load double, double* %5
%22 = call double @cos(double %21)
%23 = fmul double %20, %22
%24 = load double, double* %6
%25 = load double, double* %4
%26 = fsub double %24, %25
%27 = fmul double %26, 5.000000e-01
%28 = call i32 @sin(double %27)
%29 = call double @pow(i32 %28, i32 2)
%30 = call double @llvm.fmuladd.f64(double %23, double %29, double %18)
%31 = fptosi double %30 to i32
%32 = call i32 @sqrt(i32 %31)
%33 = fsub double 1.000000e+00, %30
%34 = fptosi double %33 to i32
%35 = call i32 @sqrt(i32 %34)
%36 = call i32 @atan2(i32 %32, i32 %35)
%37 = mul nsw i32 %36, 12734
ret i32 %37
}