#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 */
unsigned char get16(unsigned char *);
double const get32(unsigned char *);
int /*<<< orphan*/ lprintf(int, char *, double, double, ...);
int decode_position(unsigned char *element, int element_len) {
  const double semicircles = 11930464.71111111111;
  double lat, lon;
  float alt = 0;
  lat = get32(element) / semicircles;
  lon = get32(element + 4) / semicircles;
  if (lat >= 90 || lat <= -90 || lon >= 180 || lon <= -180)
    return -2;
  if (element_len == 11) {
    alt = ((*(element + 8)) << 16) + get16(element + 9);
    alt = (alt / 100) - 10000;
    lprintf(14, "Position: Lat %f Lon %f Alt %f meters\r\n", lat, lon, alt);
  } else {
    lprintf(14, "Position: Lat %f Lon %f\r\n", lat, lon);
  }
  return 0;
}


x86 assembly (clang, -O0):
<decode_position>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
movsd  0xec1(%rip),%xmm0
movsd  %xmm0,-0x20(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x34(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <get32@plt>
movsd  0xea3(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
add    $0x4,%rdi
call   1030 <get32@plt>
movsd  0xe85(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  0xe67(%rip),%xmm1
ucomisd %xmm1,%xmm0
jae    11e0 <decode_position+0xb0>
movsd  0xe65(%rip),%xmm0
ucomisd -0x28(%rbp),%xmm0
jae    11e0 <decode_position+0xb0>
movsd  -0x30(%rbp),%xmm0
movsd  0xe55(%rip),%xmm1
ucomisd %xmm1,%xmm0
jae    11e0 <decode_position+0xb0>
movsd  0xe4b(%rip),%xmm0
ucomisd -0x30(%rbp),%xmm0
jb     11ec <decode_position+0xbc>
movl   $0xfffffffe,-0x4(%rbp)
jmp    1295 <decode_position+0x165>
cmpl   $0xb,-0x14(%rbp)
jne    1271 <decode_position+0x141>
mov    -0x10(%rbp),%rax
movzbl 0x8(%rax),%eax
shl    $0x10,%eax
mov    %eax,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
add    $0x9,%rdi
call   1040 <get16@plt>
mov    %al,%cl
mov    -0x38(%rbp),%eax
movzbl %cl,%ecx
add    %ecx,%eax
cvtsi2ss %eax,%xmm0
movss  %xmm0,-0x34(%rbp)
movss  -0x34(%rbp),%xmm0
movss  0xdfb(%rip),%xmm1
divss  %xmm1,%xmm0
movss  0xdeb(%rip),%xmm1
subss  %xmm1,%xmm0
movss  %xmm0,-0x34(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  -0x30(%rbp),%xmm1
movss  -0x34(%rbp),%xmm2
cvtss2sd %xmm2,%xmm2
mov    $0xe,%edi
lea    0xdcb(%rip),%rsi
mov    $0x3,%al
call   1050 <lprintf@plt>
jmp    128e <decode_position+0x15e>
movsd  -0x28(%rbp),%xmm0
movsd  -0x30(%rbp),%xmm1
mov    $0xe,%edi
lea    0xdd1(%rip),%rsi
mov    $0x2,%al
call   1050 <lprintf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<decode_position>:
push   %rbp
push   %rbx
sub    $0x28,%rsp
mov    %esi,%ebp
mov    %rdi,%rbx
call   1030 <get32@plt>
movapd %xmm0,(%rsp)
lea    0x4(%rbx),%rdi
call   1030 <get32@plt>
movapd %xmm0,%xmm1
unpcklpd (%rsp),%xmm1
divpd  0xea1(%rip),%xmm1
movapd %xmm1,%xmm0
unpckhpd %xmm1,%xmm0
ucomisd 0xeb1(%rip),%xmm0
mov    $0xfffffffe,%eax
jae    1223 <decode_position+0xf3>
movapd %xmm1,%xmm2
cmplepd 0xe89(%rip),%xmm2
movmskpd %xmm2,%ecx
mov    %ecx,%edx
shr    %dl
jne    1223 <decode_position+0xf3>
ucomisd 0xe8b(%rip),%xmm1
jae    1223 <decode_position+0xf3>
test   $0x1,%cl
jne    1223 <decode_position+0xf3>
cmp    $0xb,%ebp
jne    120e <decode_position+0xde>
movzbl 0x8(%rbx),%ebp
shl    $0x10,%ebp
add    $0x9,%rbx
mov    %rbx,%rdi
movapd %xmm1,(%rsp)
movapd %xmm0,0x10(%rsp)
call   1040 <get16@plt>
movzbl %al,%eax
or     %ebp,%eax
xorps  %xmm0,%xmm0
cvtsi2ss %eax,%xmm0
divss  0xe51(%rip),%xmm0
addss  0xe4d(%rip),%xmm0
xorps  %xmm2,%xmm2
cvtss2sd %xmm0,%xmm2
lea    0xe43(%rip),%rsi
mov    $0xe,%edi
movapd 0x10(%rsp),%xmm0
movapd (%rsp),%xmm1
mov    $0x3,%al
call   1050 <lprintf@plt>
jmp    1221 <decode_position+0xf1>
lea    0xe4b(%rip),%rsi
mov    $0xe,%edi
mov    $0x2,%al
call   1050 <lprintf@plt>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [40 x i8] c"Position: Lat %f Lon %f Alt %f meters\0D\0A\00"
@.str.1 = [26 x i8] c"Position: Lat %f Lon %f\0D\0A\00"
define i32 @decode_position(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca double
%7 = alloca double
%8 = alloca double
%9 = alloca float
store i8* %0, i8** %4
store i32 %1, i32* %5
store double 0x4166C16C16C16C17, double* %6
store float 0.000000e+00, float* %9
%10 = load i8*, i8** %4
%11 = call double @get32(i8* %10)
%12 = fdiv double %11, 0x4166C16C16C16C17
store double %12, double* %7
%13 = load i8*, i8** %4
%14 = getelementptr inbounds i8, i8* %13, i64 4
%15 = call double @get32(i8* %14)
%16 = fdiv double %15, 0x4166C16C16C16C17
store double %16, double* %8
%17 = load double, double* %7
%18 = fcmp oge double %17, 9.000000e+01
br i1 %18, label %28, label %19
19: ; preds = %2
%20 = load double, double* %7
%21 = fcmp ole double %20, -9.000000e+01
br i1 %21, label %28, label %22
22: ; preds = %19
%23 = load double, double* %8
%24 = fcmp oge double %23, 1.800000e+02
br i1 %24, label %28, label %25
25: ; preds = %22
%26 = load double, double* %8
%27 = fcmp ole double %26, -1.800000e+02
br i1 %27, label %28, label %29
28: ; preds = %25, %22, %19, %2
store i32 -2, i32* %3
br label %57
29: ; preds = %25
%30 = load i32, i32* %5
%31 = icmp eq i32 %30, 11
br i1 %31, label %32, label %52
32: ; preds = %29
%33 = load i8*, i8** %4
%34 = getelementptr inbounds i8, i8* %33, i64 8
%35 = load i8, i8* %34
%36 = zext i8 %35 to i32
%37 = shl i32 %36, 16
%38 = load i8*, i8** %4
%39 = getelementptr inbounds i8, i8* %38, i64 9
%40 = call zeroext i8 @get16(i8* %39)
%41 = zext i8 %40 to i32
%42 = add nsw i32 %37, %41
%43 = sitofp i32 %42 to float
store float %43, float* %9
%44 = load float, float* %9
%45 = fdiv float %44, 1.000000e+02
%46 = fsub float %45, 1.000000e+04
store float %46, float* %9
%47 = load double, double* %7
%48 = load double, double* %8
%49 = load float, float* %9
%50 = fpext float %49 to double
%51 = call i32 (i32, i8*, double, double, ...) @lprintf(i32 14, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0), double %47, double %48, double %50)
br label %56
52: ; preds = %29
%53 = load double, double* %7
%54 = load double, double* %8
%55 = call i32 (i32, i8*, double, double, ...) @lprintf(i32 14, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), double %53, double %54)
br label %56
56: ; preds = %52, %32
store i32 0, i32* %3
br label %57
57: ; preds = %56, %28
%58 = load i32, i32* %3
ret i32 %58
}

LLVM IR (-O2):
@.str = [40 x i8] c"Position: Lat %f Lon %f Alt %f meters\0D\0A\00"
@.str.1 = [26 x i8] c"Position: Lat %f Lon %f\0D\0A\00"
define i32 @decode_position(i8* %0, i32 %1) {
%3 = tail call double @get32(i8* %0)
%4 = getelementptr inbounds i8, i8* %0, i64 4
%5 = tail call double @get32(i8* %4)
%6 = insertelement <2 x double> poison, double %5, i64 0
%7 = insertelement <2 x double> %6, double %3, i64 1
%8 = fdiv <2 x double> %7, <double 0x4166C16C16C16C17, double 0x4166C16C16C16C17>
%9 = extractelement <2 x double> %8, i64 1
%10 = fcmp oge double %9, 9.000000e+01
%11 = fcmp ole <2 x double> %8, <double -1.800000e+02, double -9.000000e+01>
%12 = extractelement <2 x i1> %11, i64 1
%13 = or i1 %10, %12
%14 = extractelement <2 x double> %8, i64 0
%15 = fcmp oge double %14, 1.800000e+02
%16 = select i1 %13, i1 true, i1 %15
%17 = extractelement <2 x i1> %11, i64 0
%18 = select i1 %16, i1 true, i1 %17
br i1 %18, label %37, label %19
19: ; preds = %2
%20 = icmp eq i32 %1, 11
br i1 %20, label %21, label %35
21: ; preds = %19
%22 = getelementptr inbounds i8, i8* %0, i64 8
%23 = load i8, i8* %22
%24 = zext i8 %23 to i32
%25 = shl nuw nsw i32 %24, 16
%26 = getelementptr inbounds i8, i8* %0, i64 9
%27 = tail call zeroext i8 @get16(i8* %26)
%28 = zext i8 %27 to i32
%29 = or i32 %25, %28
%30 = sitofp i32 %29 to float
%31 = fdiv float %30, 1.000000e+02
%32 = fadd float %31, -1.000000e+04
%33 = fpext float %32 to double
%34 = tail call i32 (i32, i8*, double, double, ...) @lprintf(i32 14, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0), double %9, double %14, double %33)
br label %37
35: ; preds = %19
%36 = tail call i32 (i32, i8*, double, double, ...) @lprintf(i32 14, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), double %9, double %14)
br label %37
37: ; preds = %21, %35, %2
%38 = phi i32 [ -2, %2 ], [ 0, %35 ], [ 0, %21 ]
ret i32 %38
}