#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 */
char EOF;
char fgetc(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int scanf(char *, double *, double *);
int /*<<< orphan*/ sphdpa(int, double, double, double *, double *, double *,
                          double *);
int /*<<< orphan*/ sphpad(int, double, double, double *, double *, double *,
                          double *);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ ungetc(char, int /*<<< orphan*/);
int main() {
  char c;
  double dist, lat, lat0, lng, lng0, pa;
  while (1) {
    printf("\nEnter reference (lng,lat): ");
    if (scanf("%lf%*[ ,	]%lf", &lng0, &lat0) != 2) {
      printf("Input error, please try again.\n");
      continue;
    }
    break;
  }
  while (fgetc(stdin) != '\n')
    ;
  while (1) {
    printf("\nEnter field (lng,lat): ");
    c = fgetc(stdin);
    if (c == EOF || c == '\n') {
      if (c == EOF)
        printf("\n");
      break;
    }
    ungetc(c, stdin);
    if (scanf("%lf%*[ ,	]%lf", &lng, &lat) != 2) {
      ;
      printf("Input error, please try again.\n");
      while (fgetc(stdin) != '\n')
        ;
      continue;
    }
    while (fgetc(stdin) != '\n')
      ;
    sphdpa(1, lng0, lat0, &lng, &lat, &dist, &pa);
    printf("(%.4f,%.4f) - (%.4f,%.4f) -> (%.4f,%.4f) (dist,pa)\n", lng0, lat0,
           lng, lat, dist, pa);
    sphpad(1, lng0, lat0, &dist, &pa, &lng, &lat);
    printf("(%.4f,%.4f) + (%.4f,%.4f) -> (%.4f,%.4f) (lng,lat)\n", lng0, lat0,
           dist, pa, lng, lat);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe8a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe99(%rip),%rdi
lea    -0x30(%rbp),%rsi
lea    -0x20(%rbp),%rdx
call   1070 <scanf@plt>
cmp    $0x2,%eax
je     11ad <main+0x4d>
lea    0xe8a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    116f <main+0xf>
jmp    11b2 <main+0x52>
jmp    11b7 <main+0x57>
mov    0x2e2a(%rip),%rax
mov    (%rax),%edi
call   1040 <fgetc@plt>
movsbl %al,%eax
cmp    $0xa,%eax
je     11d6 <main+0x76>
jmp    11b7 <main+0x57>
jmp    11db <main+0x7b>
lea    0xe69(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2df8(%rip),%rax
mov    (%rax),%edi
call   1040 <fgetc@plt>
mov    %al,-0x5(%rbp)
movsbl -0x5(%rbp),%eax
mov    0x2ddb(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     121d <main+0xbd>
movsbl -0x5(%rbp),%eax
cmp    $0xa,%eax
jne    1246 <main+0xe6>
movsbl -0x5(%rbp),%eax
mov    0x2db8(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
jne    1241 <main+0xe1>
lea    0xe5c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1372 <main+0x212>
mov    -0x5(%rbp),%al
mov    0x2d98(%rip),%rcx
mov    (%rcx),%esi
movsbl %al,%edi
call   1060 <ungetc@plt>
lea    0xdbc(%rip),%rdi
lea    -0x28(%rbp),%rsi
lea    -0x18(%rbp),%rdx
call   1070 <scanf@plt>
cmp    $0x2,%eax
je     12a9 <main+0x149>
lea    0xdad(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2d5c(%rip),%rax
mov    (%rax),%edi
call   1040 <fgetc@plt>
movsbl %al,%eax
cmp    $0xa,%eax
je     12a4 <main+0x144>
jmp    1285 <main+0x125>
jmp    11db <main+0x7b>
jmp    12ae <main+0x14e>
mov    0x2d33(%rip),%rax
mov    (%rax),%edi
call   1040 <fgetc@plt>
movsbl %al,%eax
cmp    $0xa,%eax
je     12cd <main+0x16d>
jmp    12ae <main+0x14e>
movsd  -0x30(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm1
mov    $0x1,%edi
lea    -0x28(%rbp),%rsi
lea    -0x18(%rbp),%rdx
lea    -0x10(%rbp),%rcx
lea    -0x38(%rbp),%r8
call   1080 <sphdpa@plt>
movsd  -0x30(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm1
movsd  -0x28(%rbp),%xmm2
movsd  -0x18(%rbp),%xmm3
movsd  -0x10(%rbp),%xmm4
movsd  -0x38(%rbp),%xmm5
lea    0xd4e(%rip),%rdi
mov    $0x6,%al
call   1030 <printf@plt>
movsd  -0x30(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm1
mov    $0x1,%edi
lea    -0x10(%rbp),%rsi
lea    -0x38(%rbp),%rdx
lea    -0x28(%rbp),%rcx
lea    -0x18(%rbp),%r8
call   1050 <sphpad@plt>
movsd  -0x30(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm1
movsd  -0x10(%rbp),%xmm2
movsd  -0x38(%rbp),%xmm3
movsd  -0x28(%rbp),%xmm4
movsd  -0x18(%rbp),%xmm5
lea    0xd32(%rip),%rdi
mov    $0x6,%al
call   1030 <printf@plt>
jmp    11db <main+0x7b>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
lea    0xe6b(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe7a(%rip),%rdi
lea    0x8(%rsp),%rsi
lea    0x10(%rsp),%rdx
call   1090 <scanf@plt>
cmp    $0x2,%eax
je     1205 <main+0x85>
lea    0xeee(%rip),%r14
lea    0xe3b(%rip),%r15
lea    0xe51(%rip),%r12
lea    0x8(%rsp),%rbp
lea    0x10(%rsp),%rbx
cs nopw 0x0(%rax,%rax,1)
mov    %r14,%rdi
call   1040 <puts@plt>
mov    %r15,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r12,%rdi
mov    %rbp,%rsi
mov    %rbx,%rdx
call   1090 <scanf@plt>
cmp    $0x2,%eax
jne    11e0 <main+0x60>
mov    0x2ddc(%rip),%r14
nopl   0x0(%rax)
mov    (%r14),%edi
call   1060 <fgetc@plt>
cmp    $0xa,%al
jne    1210 <main+0x90>
lea    0xe08(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    (%r14),%edi
call   1060 <fgetc@plt>
mov    0x2da7(%rip),%rcx
mov    (%rcx),%dl
cmp    %dl,%al
sete   %cl
cmp    $0xa,%al
je     13a8 <main+0x228>
cmp    %dl,%al
je     13a8 <main+0x228>
lea    0x20(%rsp),%r15
lea    0x28(%rsp),%rbx
lea    0x30(%rsp),%r12
lea    0x18(%rsp),%r13
lea    0xdc0(%rip),%rbp
nopl   0x0(%rax,%rax,1)
mov    (%r14),%esi
movsbl %al,%edi
call   1080 <ungetc@plt>
lea    0xd9b(%rip),%rdi
mov    %r15,%rsi
mov    %rbx,%rdx
call   1090 <scanf@plt>
cmp    $0x2,%eax
jne    1360 <main+0x1e0>
cs nopw 0x0(%rax,%rax,1)
mov    (%r14),%edi
call   1060 <fgetc@plt>
cmp    $0xa,%al
jne    12a0 <main+0x120>
movsd  0x8(%rsp),%xmm0
movsd  0x10(%rsp),%xmm1
mov    $0x1,%edi
mov    %r15,%rsi
mov    %rbx,%rdx
mov    %r12,%rcx
mov    %r13,%r8
call   10a0 <sphdpa@plt>
movsd  0x8(%rsp),%xmm0
movsd  0x10(%rsp),%xmm1
movsd  0x20(%rsp),%xmm2
movsd  0x28(%rsp),%xmm3
movsd  0x30(%rsp),%xmm4
movsd  0x18(%rsp),%xmm5
lea    0xd4b(%rip),%rdi
mov    $0x6,%al
call   1050 <printf@plt>
movsd  0x8(%rsp),%xmm0
movsd  0x10(%rsp),%xmm1
mov    $0x1,%edi
mov    %r12,%rsi
mov    %r13,%rdx
mov    %r15,%rcx
mov    %rbx,%r8
call   1070 <sphpad@plt>
movsd  0x8(%rsp),%xmm0
movsd  0x10(%rsp),%xmm1
movsd  0x30(%rsp),%xmm2
movsd  0x18(%rsp),%xmm3
movsd  0x20(%rsp),%xmm4
movsd  0x28(%rsp),%xmm5
lea    0xd2b(%rip),%rdi
mov    $0x6,%al
call   1050 <printf@plt>
jmp    137c <main+0x1fc>
cs nopw 0x0(%rax,%rax,1)
lea    0xd45(%rip),%rdi
call   1040 <puts@plt>
nopl   0x0(%rax)
mov    (%r14),%edi
call   1060 <fgetc@plt>
cmp    $0xa,%al
jne    1370 <main+0x1f0>
mov    %rbp,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    (%r14),%edi
call   1060 <fgetc@plt>
mov    0x2c4b(%rip),%rcx
mov    (%rcx),%dl
cmp    %dl,%al
sete   %cl
cmp    $0xa,%al
je     13a8 <main+0x228>
cmp    %dl,%al
jne    1270 <main+0xf0>
test   %cl,%cl
je     13b6 <main+0x236>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [29 x i8] c"\0AEnter reference (lng,lat): \00"
@.str.1 = [14 x i8] c"%lf%*[ ,\09]%lf\00"
@.str.2 = [32 x i8] c"Input error, please try again.\0A\00"
@stdin = global i32 0
@.str.3 = [25 x i8] c"\0AEnter field (lng,lat): \00"
@EOF = global i8 0
@.str.4 = [2 x i8] c"\0A\00"
@.str.5 = [52 x i8] c"(%.4f,%.4f) - (%.4f,%.4f) -> (%.4f,%.4f) (dist,pa)\0A\00"
@.str.6 = [52 x i8] c"(%.4f,%.4f) + (%.4f,%.4f) -> (%.4f,%.4f) (lng,lat)\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8
%3 = alloca double
%4 = alloca double
%5 = alloca double
%6 = alloca double
%7 = alloca double
%8 = alloca double
store i32 0, i32* %1
br label %9
9: ; preds = %0, %13
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
%11 = call i32 @scanf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), double* %7, double* %5)
%12 = icmp ne i32 %11, 2
br i1 %12, label %13, label %15
13: ; preds = %9
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0))
br label %9
15: ; preds = %9
br label %16
16: ; preds = %15
br label %17
17: ; preds = %22, %16
%18 = load i32, i32* @stdin
%19 = call signext i8 @fgetc(i32 %18)
%20 = sext i8 %19 to i32
%21 = icmp ne i32 %20, 10
br i1 %21, label %22, label %23
22: ; preds = %17
br label %17
23: ; preds = %17
br label %24
24: ; preds = %23, %60, %68
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0))
%26 = load i32, i32* @stdin
%27 = call signext i8 @fgetc(i32 %26)
store i8 %27, i8* %2
%28 = load i8, i8* %2
%29 = sext i8 %28 to i32
%30 = load i8, i8* @EOF
%31 = sext i8 %30 to i32
%32 = icmp eq i32 %29, %31
br i1 %32, label %37, label %33
33: ; preds = %24
%34 = load i8, i8* %2
%35 = sext i8 %34 to i32
%36 = icmp eq i32 %35, 10
br i1 %36, label %37, label %46
37: ; preds = %33, %24
%38 = load i8, i8* %2
%39 = sext i8 %38 to i32
%40 = load i8, i8* @EOF
%41 = sext i8 %40 to i32
%42 = icmp eq i32 %39, %41
br i1 %42, label %43, label %45
43: ; preds = %37
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
br label %45
45: ; preds = %43, %37
br label %89
46: ; preds = %33
%47 = load i8, i8* %2
%48 = load i32, i32* @stdin
%49 = call i32 @ungetc(i8 signext %47, i32 %48)
%50 = call i32 @scanf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), double* %6, double* %4)
%51 = icmp ne i32 %50, 2
br i1 %51, label %52, label %61
52: ; preds = %46
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0))
br label %54
54: ; preds = %59, %52
%55 = load i32, i32* @stdin
%56 = call signext i8 @fgetc(i32 %55)
%57 = sext i8 %56 to i32
%58 = icmp ne i32 %57, 10
br i1 %58, label %59, label %60
59: ; preds = %54
br label %54
60: ; preds = %54
br label %24
61: ; preds = %46
br label %62
62: ; preds = %67, %61
%63 = load i32, i32* @stdin
%64 = call signext i8 @fgetc(i32 %63)
%65 = sext i8 %64 to i32
%66 = icmp ne i32 %65, 10
br i1 %66, label %67, label %68
67: ; preds = %62
br label %62
68: ; preds = %62
%69 = load double, double* %7
%70 = load double, double* %5
%71 = call i32 @sphdpa(i32 1, double %69, double %70, double* %6, double* %4, double* %3, double* %8)
%72 = load double, double* %7
%73 = load double, double* %5
%74 = load double, double* %6
%75 = load double, double* %4
%76 = load double, double* %3
%77 = load double, double* %8
%78 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.5, i64 0, i64 0), double %72, double %73, double %74, double %75, double %76, double %77)
%79 = load double, double* %7
%80 = load double, double* %5
%81 = call i32 @sphpad(i32 1, double %79, double %80, double* %3, double* %8, double* %6, double* %4)
%82 = load double, double* %7
%83 = load double, double* %5
%84 = load double, double* %3
%85 = load double, double* %8
%86 = load double, double* %6
%87 = load double, double* %4
%88 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.6, i64 0, i64 0), double %82, double %83, double %84, double %85, double %86, double %87)
br label %24
89: ; preds = %45
ret i32 0
}

LLVM IR (-O2):
@.str = [29 x i8] c"\0AEnter reference (lng,lat): \00"
@.str.1 = [14 x i8] c"%lf%*[ ,\09]%lf\00"
@stdin = global i32 0
@.str.3 = [25 x i8] c"\0AEnter field (lng,lat): \00"
@EOF = global i8 0
@.str.5 = [52 x i8] c"(%.4f,%.4f) - (%.4f,%.4f) -> (%.4f,%.4f) (dist,pa)\0A\00"
@.str.6 = [52 x i8] c"(%.4f,%.4f) + (%.4f,%.4f) -> (%.4f,%.4f) (lng,lat)\0A\00"
@str.7 = [31 x i8] c"Input error, please try again.\00"
define i32 @main() {
%1 = alloca double
%2 = alloca double
%3 = alloca double
%4 = alloca double
%5 = alloca double
%6 = alloca double
%7 = bitcast double* %1 to i8*
%8 = bitcast double* %2 to i8*
%9 = bitcast double* %3 to i8*
%10 = bitcast double* %4 to i8*
%11 = bitcast double* %5 to i8*
%12 = bitcast double* %6 to i8*
%13 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
%14 = call i32 @scanf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), double* %5, double* %3)
%15 = icmp eq i32 %14, 2
br i1 %15, label %21, label %16
16: ; preds = %0, %16
%17 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str.7, i64 0, i64 0))
%18 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
%19 = call i32 @scanf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), double* %5, double* %3)
%20 = icmp eq i32 %19, 2
br i1 %20, label %21, label %16
21: ; preds = %16, %0
br label %22
22: ; preds = %21, %22
%23 = load i32, i32* @stdin
%24 = call signext i8 @fgetc(i32 %23)
%25 = icmp eq i8 %24, 10
br i1 %25, label %26, label %22
26: ; preds = %22
%27 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0))
%28 = load i32, i32* @stdin
%29 = call signext i8 @fgetc(i32 %28)
%30 = load i8, i8* @EOF
%31 = icmp eq i8 %29, %30
%32 = icmp eq i8 %29, 10
%33 = or i1 %32, %31
br i1 %33, label %34, label %38
34: ; preds = %75, %26
%35 = phi i1 [ %31, %26 ], [ %80, %75 ]
br i1 %35, label %36, label %83
36: ; preds = %34
%37 = call i32 @putchar(i32 10)
br label %83
38: ; preds = %26, %75
%39 = phi i8 [ %78, %75 ], [ %29, %26 ]
%40 = load i32, i32* @stdin
%41 = call i32 @ungetc(i8 signext %39, i32 %40)
%42 = call i32 @scanf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), double* %4, double* %2)
%43 = icmp eq i32 %42, 2
br i1 %43, label %50, label %44
44: ; preds = %38
%45 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str.7, i64 0, i64 0))
br label %46
46: ; preds = %46, %44
%47 = load i32, i32* @stdin
%48 = call signext i8 @fgetc(i32 %47)
%49 = icmp eq i8 %48, 10
br i1 %49, label %75, label %46
50: ; preds = %38, %50
%51 = load i32, i32* @stdin
%52 = call signext i8 @fgetc(i32 %51)
%53 = icmp eq i8 %52, 10
br i1 %53, label %54, label %50
54: ; preds = %50
%55 = load double, double* %5
%56 = load double, double* %3
%57 = call i32 @sphdpa(i32 1, double %55, double %56, double* %4, double* %2, double* %1, double* %6)
%58 = load double, double* %5
%59 = load double, double* %3
%60 = load double, double* %4
%61 = load double, double* %2
%62 = load double, double* %1
%63 = load double, double* %6
%64 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([52 x i8], [52 x i8]* @.str.5, i64 0, i64 0), double %58, double %59, double %60, double %61, double %62, double %63)
%65 = load double, double* %5
%66 = load double, double* %3
%67 = call i32 @sphpad(i32 1, double %65, double %66, double* %1, double* %6, double* %4, double* %2)
%68 = load double, double* %5
%69 = load double, double* %3
%70 = load double, double* %1
%71 = load double, double* %6
%72 = load double, double* %4
%73 = load double, double* %2
%74 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([52 x i8], [52 x i8]* @.str.6, i64 0, i64 0), double %68, double %69, double %70, double %71, double %72, double %73)
br label %75
75: ; preds = %46, %54
%76 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0))
%77 = load i32, i32* @stdin
%78 = call signext i8 @fgetc(i32 %77)
%79 = load i8, i8* @EOF
%80 = icmp eq i8 %78, %79
%81 = icmp eq i8 %78, 10
%82 = or i1 %81, %80
br i1 %82, label %34, label %38
83: ; preds = %34, %36
ret i32 0
}