#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 code_table_3_1(unsigned char **);
int /*<<< orphan*/ free(double *);
int gauss2ll(unsigned char **, double **, double **);
int irr_grid2ll(unsigned char **, double **, double **);
int lambert2ll(unsigned char **, double **, double **);
int mercator2ll(unsigned char **, double **, double **);
int polar2ll(unsigned char **, double **, double **);
int regular2ll(unsigned char **, double **, double **);
int rot_regular2ll(unsigned char **, double **, double **);
int space_view2ll(unsigned char **, double **, double **);
int get_latlon(unsigned char **sec, double **lon, double **lat) {
  int grid_template, err;
  if (*lat != NULL) {
    free(*lat);
    free(*lon);
    *lat = *lon = NULL;
  }
  grid_template = code_table_3_1(sec);
  if (grid_template == 0) {
    err = regular2ll(sec, lat, lon);
  } else if (grid_template == 1) {
    err = rot_regular2ll(sec, lat, lon);
  } else if (grid_template == 10) {
    err = mercator2ll(sec, lat, lon);
  } else if (grid_template == 20) {
    err = polar2ll(sec, lat, lon);
  } else if (grid_template == 30) {
    err = lambert2ll(sec, lat, lon);
  } else if (grid_template == 40) {
    err = gauss2ll(sec, lat, lon);
  } else if (grid_template == 90) {
    err = space_view2ll(sec, lat, lon);
  } else if (grid_template == 130) {
    err = irr_grid2ll(sec, lat, lon);
  } else {
    err = 1;
  }
  return err;
}


x86 assembly (clang, -O0):
<get_latlon>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmpq   $0x0,(%rax)
je     11f0 <get_latlon+0x50>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
call   1030 <free@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1030 <free@plt>
mov    -0x10(%rbp),%rax
movq   $0x0,(%rax)
mov    -0x18(%rbp),%rax
movq   $0x0,(%rax)
mov    -0x8(%rbp),%rdi
call   1040 <code_table_3_1@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jne    121f <get_latlon+0x7f>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x10(%rbp),%rdx
call   1060 <regular2ll@plt>
mov    %eax,-0x20(%rbp)
jmp    1341 <get_latlon+0x1a1>
cmpl   $0x1,-0x1c(%rbp)
jne    1242 <get_latlon+0xa2>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x10(%rbp),%rdx
call   1070 <rot_regular2ll@plt>
mov    %eax,-0x20(%rbp)
jmp    133c <get_latlon+0x19c>
cmpl   $0xa,-0x1c(%rbp)
jne    1265 <get_latlon+0xc5>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x10(%rbp),%rdx
call   10c0 <mercator2ll@plt>
mov    %eax,-0x20(%rbp)
jmp    1337 <get_latlon+0x197>
cmpl   $0x14,-0x1c(%rbp)
jne    1288 <get_latlon+0xe8>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x10(%rbp),%rdx
call   10a0 <polar2ll@plt>
mov    %eax,-0x20(%rbp)
jmp    1332 <get_latlon+0x192>
cmpl   $0x1e,-0x1c(%rbp)
jne    12ab <get_latlon+0x10b>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x10(%rbp),%rdx
call   1050 <lambert2ll@plt>
mov    %eax,-0x20(%rbp)
jmp    132d <get_latlon+0x18d>
cmpl   $0x28,-0x1c(%rbp)
jne    12ce <get_latlon+0x12e>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x10(%rbp),%rdx
call   1080 <gauss2ll@plt>
mov    %eax,-0x20(%rbp)
jmp    1328 <get_latlon+0x188>
cmpl   $0x5a,-0x1c(%rbp)
jne    12f1 <get_latlon+0x151>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x10(%rbp),%rdx
call   10b0 <space_view2ll@plt>
mov    %eax,-0x20(%rbp)
jmp    1323 <get_latlon+0x183>
cmpl   $0x82,-0x1c(%rbp)
jne    1317 <get_latlon+0x177>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x10(%rbp),%rdx
call   1090 <irr_grid2ll@plt>
mov    %eax,-0x20(%rbp)
jmp    131e <get_latlon+0x17e>
movl   $0x1,-0x20(%rbp)
jmp    1323 <get_latlon+0x183>
jmp    1328 <get_latlon+0x188>
jmp    132d <get_latlon+0x18d>
jmp    1332 <get_latlon+0x192>
jmp    1337 <get_latlon+0x197>
jmp    133c <get_latlon+0x19c>
jmp    1341 <get_latlon+0x1a1>
mov    -0x20(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_latlon>:
push   %r15
push   %r14
push   %rbx
mov    %rdx,%rbx
mov    %rsi,%r14
mov    %rdi,%r15
mov    (%rdx),%rdi
test   %rdi,%rdi
je     11d1 <get_latlon+0x31>
call   1030 <free@plt>
mov    (%r14),%rdi
call   1030 <free@plt>
movq   $0x0,(%r14)
movq   $0x0,(%rbx)
mov    %r15,%rdi
call   1040 <code_table_3_1@plt>
cmp    $0x28,%eax
ja     1203 <get_latlon+0x63>
mov    %eax,%eax
lea    0xe19(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %r14,%rdx
pop    %rbx
pop    %r14
pop    %r15
jmp    1060 <regular2ll@plt>
cmp    $0x5a,%eax
je     1290 <get_latlon+0xf0>
cmp    $0x82,%eax
jne    1226 <get_latlon+0x86>
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %r14,%rdx
pop    %rbx
pop    %r14
pop    %r15
jmp    1090 <irr_grid2ll@plt>
mov    $0x1,%eax
pop    %rbx
pop    %r14
pop    %r15
ret
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %r14,%rdx
pop    %rbx
pop    %r14
pop    %r15
jmp    1070 <rot_regular2ll@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %r14,%rdx
pop    %rbx
pop    %r14
pop    %r15
jmp    10c0 <mercator2ll@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %r14,%rdx
pop    %rbx
pop    %r14
pop    %r15
jmp    10a0 <polar2ll@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %r14,%rdx
pop    %rbx
pop    %r14
pop    %r15
jmp    1050 <lambert2ll@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %r14,%rdx
pop    %rbx
pop    %r14
pop    %r15
jmp    1080 <gauss2ll@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %r14,%rdx
pop    %rbx
pop    %r14
pop    %r15
jmp    10b0 <space_view2ll@plt>

LLVM IR (-O0):
define i32 @get_latlon(i8** %0, double** %1, double** %2) {
%4 = alloca i8**
%5 = alloca double**
%6 = alloca double**
%7 = alloca i32
%8 = alloca i32
store i8** %0, i8*** %4
store double** %1, double*** %5
store double** %2, double*** %6
%9 = load double**, double*** %6
%10 = load double*, double** %9
%11 = icmp ne double* %10, null
br i1 %11, label %12, label %21
12: ; preds = %3
%13 = load double**, double*** %6
%14 = load double*, double** %13
%15 = call i32 @free(double* %14)
%16 = load double**, double*** %5
%17 = load double*, double** %16
%18 = call i32 @free(double* %17)
%19 = load double**, double*** %5
store double* null, double** %19
%20 = load double**, double*** %6
store double* null, double** %20
br label %21
21: ; preds = %12, %3
%22 = load i8**, i8*** %4
%23 = call i32 @code_table_3_1(i8** %22)
store i32 %23, i32* %7
%24 = load i32, i32* %7
%25 = icmp eq i32 %24, 0
br i1 %25, label %26, label %31
26: ; preds = %21
%27 = load i8**, i8*** %4
%28 = load double**, double*** %6
%29 = load double**, double*** %5
%30 = call i32 @regular2ll(i8** %27, double** %28, double** %29)
store i32 %30, i32* %8
br label %95
31: ; preds = %21
%32 = load i32, i32* %7
%33 = icmp eq i32 %32, 1
br i1 %33, label %34, label %39
34: ; preds = %31
%35 = load i8**, i8*** %4
%36 = load double**, double*** %6
%37 = load double**, double*** %5
%38 = call i32 @rot_regular2ll(i8** %35, double** %36, double** %37)
store i32 %38, i32* %8
br label %94
39: ; preds = %31
%40 = load i32, i32* %7
%41 = icmp eq i32 %40, 10
br i1 %41, label %42, label %47
42: ; preds = %39
%43 = load i8**, i8*** %4
%44 = load double**, double*** %6
%45 = load double**, double*** %5
%46 = call i32 @mercator2ll(i8** %43, double** %44, double** %45)
store i32 %46, i32* %8
br label %93
47: ; preds = %39
%48 = load i32, i32* %7
%49 = icmp eq i32 %48, 20
br i1 %49, label %50, label %55
50: ; preds = %47
%51 = load i8**, i8*** %4
%52 = load double**, double*** %6
%53 = load double**, double*** %5
%54 = call i32 @polar2ll(i8** %51, double** %52, double** %53)
store i32 %54, i32* %8
br label %92
55: ; preds = %47
%56 = load i32, i32* %7
%57 = icmp eq i32 %56, 30
br i1 %57, label %58, label %63
58: ; preds = %55
%59 = load i8**, i8*** %4
%60 = load double**, double*** %6
%61 = load double**, double*** %5
%62 = call i32 @lambert2ll(i8** %59, double** %60, double** %61)
store i32 %62, i32* %8
br label %91
63: ; preds = %55
%64 = load i32, i32* %7
%65 = icmp eq i32 %64, 40
br i1 %65, label %66, label %71
66: ; preds = %63
%67 = load i8**, i8*** %4
%68 = load double**, double*** %6
%69 = load double**, double*** %5
%70 = call i32 @gauss2ll(i8** %67, double** %68, double** %69)
store i32 %70, i32* %8
br label %90
71: ; preds = %63
%72 = load i32, i32* %7
%73 = icmp eq i32 %72, 90
br i1 %73, label %74, label %79
74: ; preds = %71
%75 = load i8**, i8*** %4
%76 = load double**, double*** %6
%77 = load double**, double*** %5
%78 = call i32 @space_view2ll(i8** %75, double** %76, double** %77)
store i32 %78, i32* %8
br label %89
79: ; preds = %71
%80 = load i32, i32* %7
%81 = icmp eq i32 %80, 130
br i1 %81, label %82, label %87
82: ; preds = %79
%83 = load i8**, i8*** %4
%84 = load double**, double*** %6
%85 = load double**, double*** %5
%86 = call i32 @irr_grid2ll(i8** %83, double** %84, double** %85)
store i32 %86, i32* %8
br label %88
87: ; preds = %79
store i32 1, i32* %8
br label %88
88: ; preds = %87, %82
br label %89
89: ; preds = %88, %74
br label %90
90: ; preds = %89, %66
br label %91
91: ; preds = %90, %58
br label %92
92: ; preds = %91, %50
br label %93
93: ; preds = %92, %42
br label %94
94: ; preds = %93, %34
br label %95
95: ; preds = %94, %26
%96 = load i32, i32* %8
ret i32 %96
}

LLVM IR (-O2):
define i32 @get_latlon(i8** %0, double** %1, double** %2) {
%4 = load double*, double** %2
%5 = icmp eq double* %4, null
br i1 %5, label %10, label %6
6: ; preds = %3
%7 = tail call i32 @free(double* %4)
%8 = load double*, double** %1
%9 = tail call i32 @free(double* %8)
store double* null, double** %1
store double* null, double** %2
br label %10
10: ; preds = %6, %3
%11 = tail call i32 @code_table_3_1(i8** %0)
switch i32 %11, label %28 [
i32 0, label %12
i32 1, label %14
i32 10, label %16
i32 20, label %18
i32 30, label %20
i32 40, label %22
i32 90, label %24
i32 130, label %26
]
12: ; preds = %10
%13 = tail call i32 @regular2ll(i8** %0, double** %2, double** %1)
br label %28
14: ; preds = %10
%15 = tail call i32 @rot_regular2ll(i8** %0, double** %2, double** %1)
br label %28
16: ; preds = %10
%17 = tail call i32 @mercator2ll(i8** %0, double** %2, double** %1)
br label %28
18: ; preds = %10
%19 = tail call i32 @polar2ll(i8** %0, double** %2, double** %1)
br label %28
20: ; preds = %10
%21 = tail call i32 @lambert2ll(i8** %0, double** %2, double** %1)
br label %28
22: ; preds = %10
%23 = tail call i32 @gauss2ll(i8** %0, double** %2, double** %1)
br label %28
24: ; preds = %10
%25 = tail call i32 @space_view2ll(i8** %0, double** %2, double** %1)
br label %28
26: ; preds = %10
%27 = tail call i32 @irr_grid2ll(i8** %0, double** %2, double** %1)
br label %28
28: ; preds = %10, %14, %18, %22, %26, %24, %20, %16, %12
%29 = phi i32 [ %13, %12 ], [ %15, %14 ], [ %17, %16 ], [ %19, %18 ], [ %21, %20 ], [ %23, %22 ], [ %25, %24 ], [ %27, %26 ], [ 1, %10 ]
ret i32 %29
}