#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 /*<<< orphan*/ lprintf(int, char *, ...);
int decode_gpsquality(unsigned char *element, int element_len) {
  int fixtype, validity, sats;
  const char *fixstr[] = {"Unknown Fix", "No Fix", "2D Fix", "3D Fix"};
  const char *validstr[] = {"Invalid", "Valid SPS", "Valid DGPS", "Valid PPS"};
  fixtype = (element[0] & 0xc0) >> 6;
  validity = (element[0] & 0x30) >> 4;
  sats = (element[0] & 0x0f);
  lprintf(14, "GPS: %s %s, %d sats", fixstr[fixtype], validstr[validity], sats);
  if (element_len > 1)
    lprintf(14, " HDOP=%.1f", (float)element[1] / 10);
  if (element_len > 2)
    lprintf(14, " PDOP=%.1f", (float)element[2] / 10);
  if (element_len > 3)
    lprintf(14, " VDOP=%.1f", (float)element[3] / 10);
  lprintf(14, "\r\n");
  return 0;
}


x86 assembly (clang, -O0):
<decode_gpsquality>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    0x2cba(%rip),%rax
mov    %rax,-0x40(%rbp)
mov    0x2cb7(%rip),%rax
mov    %rax,-0x38(%rbp)
mov    0x2cb4(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0x2cb1(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    0x2cae(%rip),%rax
mov    %rax,-0x60(%rbp)
mov    0x2cab(%rip),%rax
mov    %rax,-0x58(%rbp)
mov    0x2ca8(%rip),%rax
mov    %rax,-0x50(%rbp)
mov    0x2ca5(%rip),%rax
mov    %rax,-0x48(%rbp)
mov    -0x8(%rbp),%rax
movzbl (%rax),%eax
and    $0xc0,%eax
sar    $0x6,%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
movzbl (%rax),%eax
and    $0x30,%eax
sar    $0x4,%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rax
movzbl (%rax),%eax
and    $0xf,%eax
mov    %eax,-0x18(%rbp)
movslq -0x10(%rbp),%rax
mov    -0x40(%rbp,%rax,8),%rdx
movslq -0x14(%rbp),%rax
mov    -0x60(%rbp,%rax,8),%rcx
mov    -0x18(%rbp),%r8d
mov    $0xe,%edi
lea    0xe84(%rip),%rsi
mov    $0x0,%al
call   1030 <lprintf@plt>
cmpl   $0x1,-0xc(%rbp)
jle    1208 <decode_gpsquality+0xf8>
mov    -0x8(%rbp),%rax
movzbl 0x1(%rax),%eax
cvtsi2ss %eax,%xmm0
movss  0xe13(%rip),%xmm1
divss  %xmm1,%xmm0
cvtss2sd %xmm0,%xmm0
mov    $0xe,%edi
lea    0xe5f(%rip),%rsi
mov    $0x1,%al
call   1030 <lprintf@plt>
cmpl   $0x2,-0xc(%rbp)
jle    1241 <decode_gpsquality+0x131>
mov    -0x8(%rbp),%rax
movzbl 0x2(%rax),%eax
cvtsi2ss %eax,%xmm0
movss  0xdda(%rip),%xmm1
divss  %xmm1,%xmm0
cvtss2sd %xmm0,%xmm0
mov    $0xe,%edi
lea    0xe31(%rip),%rsi
mov    $0x1,%al
call   1030 <lprintf@plt>
cmpl   $0x3,-0xc(%rbp)
jle    127a <decode_gpsquality+0x16a>
mov    -0x8(%rbp),%rax
movzbl 0x3(%rax),%eax
cvtsi2ss %eax,%xmm0
movss  0xda1(%rip),%xmm1
divss  %xmm1,%xmm0
cvtss2sd %xmm0,%xmm0
mov    $0xe,%edi
lea    0xe03(%rip),%rsi
mov    $0x1,%al
call   1030 <lprintf@plt>
mov    $0xe,%edi
lea    0xdfb(%rip),%rsi
mov    $0x0,%al
call   1030 <lprintf@plt>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<decode_gpsquality>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%rbx
movzbl (%rdi),%eax
mov    %rax,%rcx
shr    $0x6,%rcx
mov    %eax,%r8d
and    $0xf,%r8d
lea    0xf54(%rip),%rsi
movslq (%rsi,%rcx,4),%rdx
add    %rsi,%rdx
shr    $0x2,%rax
and    $0xc,%eax
lea    0xf4f(%rip),%rsi
movslq (%rax,%rsi,1),%rcx
add    %rsi,%rcx
lea    0xef9(%rip),%rsi
mov    $0xe,%edi
xor    %eax,%eax
call   1030 <lprintf@plt>
cmp    $0x2,%ebp
jl     11ed <decode_gpsquality+0xdd>
movzbl 0x1(%rbx),%eax
cvtsi2ss %eax,%xmm0
divss  0xe88(%rip),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xedd(%rip),%rsi
mov    $0xe,%edi
mov    $0x1,%al
call   1030 <lprintf@plt>
cmp    $0x2,%ebp
je     11ed <decode_gpsquality+0xdd>
movzbl 0x2(%rbx),%eax
xorps  %xmm0,%xmm0
cvtsi2ss %eax,%xmm0
divss  0xe59(%rip),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xeb9(%rip),%rsi
mov    $0xe,%edi
mov    $0x1,%al
call   1030 <lprintf@plt>
cmp    $0x4,%ebp
jb     11ed <decode_gpsquality+0xdd>
movzbl 0x3(%rbx),%eax
xorps  %xmm0,%xmm0
cvtsi2ss %eax,%xmm0
divss  0xe2a(%rip),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xe95(%rip),%rsi
mov    $0xe,%edi
mov    $0x1,%al
call   1030 <lprintf@plt>
lea    0xe8d(%rip),%rsi
mov    $0xe,%edi
xor    %eax,%eax
call   1030 <lprintf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [12 x i8] c"Unknown Fix\00"
@.str.1 = [7 x i8] c"No Fix\00"
@.str.2 = [7 x i8] c"2D Fix\00"
@.str.3 = [7 x i8] c"3D Fix\00"
@__const.decode_gpsquality.fixstr = [4 x i8*] [i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i32 0, i32 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i32 0, i32 0)]
@.str.4 = [8 x i8] c"Invalid\00"
@.str.5 = [10 x i8] c"Valid SPS\00"
@.str.6 = [11 x i8] c"Valid DGPS\00"
@.str.7 = [10 x i8] c"Valid PPS\00"
@__const.decode_gpsquality.validstr = [4 x i8*] [i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i32 0, i32 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i32 0, i32 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i32 0, i32 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.7, i32 0, i32 0)]
@.str.8 = [20 x i8] c"GPS: %s %s, %d sats\00"
@.str.9 = [11 x i8] c" HDOP=%.1f\00"
@.str.10 = [11 x i8] c" PDOP=%.1f\00"
@.str.11 = [11 x i8] c" VDOP=%.1f\00"
@.str.12 = [3 x i8] c"\0D\0A\00"
define i32 @decode_gpsquality(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca [4 x i8*]
%9 = alloca [4 x i8*]
store i8* %0, i8** %3
store i32 %1, i32* %4
%10 = bitcast [4 x i8*]* %8 to i8*
%11 = bitcast [4 x i8*]* %9 to i8*
%12 = load i8*, i8** %3
%13 = getelementptr inbounds i8, i8* %12, i64 0
%14 = load i8, i8* %13
%15 = zext i8 %14 to i32
%16 = and i32 %15, 192
%17 = ashr i32 %16, 6
store i32 %17, i32* %5
%18 = load i8*, i8** %3
%19 = getelementptr inbounds i8, i8* %18, i64 0
%20 = load i8, i8* %19
%21 = zext i8 %20 to i32
%22 = and i32 %21, 48
%23 = ashr i32 %22, 4
store i32 %23, i32* %6
%24 = load i8*, i8** %3
%25 = getelementptr inbounds i8, i8* %24, i64 0
%26 = load i8, i8* %25
%27 = zext i8 %26 to i32
%28 = and i32 %27, 15
store i32 %28, i32* %7
%29 = load i32, i32* %5
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds [4 x i8*], [4 x i8*]* %8, i64 0, i64 %30
%32 = load i8*, i8** %31
%33 = load i32, i32* %6
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds [4 x i8*], [4 x i8*]* %9, i64 0, i64 %34
%36 = load i8*, i8** %35
%37 = load i32, i32* %7
%38 = call i32 (i32, i8*, ...) @lprintf(i32 14, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.8, i64 0, i64 0), i8* %32, i8* %36, i32 %37)
%39 = load i32, i32* %4
%40 = icmp sgt i32 %39, 1
br i1 %40, label %41, label %49
41: ; preds = %2
%42 = load i8*, i8** %3
%43 = getelementptr inbounds i8, i8* %42, i64 1
%44 = load i8, i8* %43
%45 = uitofp i8 %44 to float
%46 = fdiv float %45, 1.000000e+01
%47 = fpext float %46 to double
%48 = call i32 (i32, i8*, ...) @lprintf(i32 14, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.9, i64 0, i64 0), double %47)
br label %49
49: ; preds = %41, %2
%50 = load i32, i32* %4
%51 = icmp sgt i32 %50, 2
br i1 %51, label %52, label %60
52: ; preds = %49
%53 = load i8*, i8** %3
%54 = getelementptr inbounds i8, i8* %53, i64 2
%55 = load i8, i8* %54
%56 = uitofp i8 %55 to float
%57 = fdiv float %56, 1.000000e+01
%58 = fpext float %57 to double
%59 = call i32 (i32, i8*, ...) @lprintf(i32 14, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.10, i64 0, i64 0), double %58)
br label %60
60: ; preds = %52, %49
%61 = load i32, i32* %4
%62 = icmp sgt i32 %61, 3
br i1 %62, label %63, label %71
63: ; preds = %60
%64 = load i8*, i8** %3
%65 = getelementptr inbounds i8, i8* %64, i64 3
%66 = load i8, i8* %65
%67 = uitofp i8 %66 to float
%68 = fdiv float %67, 1.000000e+01
%69 = fpext float %68 to double
%70 = call i32 (i32, i8*, ...) @lprintf(i32 14, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.11, i64 0, i64 0), double %69)
br label %71
71: ; preds = %63, %60
%72 = call i32 (i32, i8*, ...) @lprintf(i32 14, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.12, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str = [12 x i8] c"Unknown Fix\00"
@.str.1 = [7 x i8] c"No Fix\00"
@.str.2 = [7 x i8] c"2D Fix\00"
@.str.3 = [7 x i8] c"3D Fix\00"
@reltable.decode_gpsquality = [4 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([12 x i8]* @.str to i64), i64 ptrtoint ([4 x i32]* @reltable.decode_gpsquality to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([7 x i8]* @.str.1 to i64), i64 ptrtoint ([4 x i32]* @reltable.decode_gpsquality to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([7 x i8]* @.str.2 to i64), i64 ptrtoint ([4 x i32]* @reltable.decode_gpsquality to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([7 x i8]* @.str.3 to i64), i64 ptrtoint ([4 x i32]* @reltable.decode_gpsquality to i64)) to i32)]
@.str.4 = [8 x i8] c"Invalid\00"
@.str.5 = [10 x i8] c"Valid SPS\00"
@.str.6 = [11 x i8] c"Valid DGPS\00"
@.str.7 = [10 x i8] c"Valid PPS\00"
@reltable.decode_gpsquality.13 = [4 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([8 x i8]* @.str.4 to i64), i64 ptrtoint ([4 x i32]* @reltable.decode_gpsquality.13 to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([10 x i8]* @.str.5 to i64), i64 ptrtoint ([4 x i32]* @reltable.decode_gpsquality.13 to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([11 x i8]* @.str.6 to i64), i64 ptrtoint ([4 x i32]* @reltable.decode_gpsquality.13 to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([10 x i8]* @.str.7 to i64), i64 ptrtoint ([4 x i32]* @reltable.decode_gpsquality.13 to i64)) to i32)]
@.str.8 = [20 x i8] c"GPS: %s %s, %d sats\00"
@.str.9 = [11 x i8] c" HDOP=%.1f\00"
@.str.10 = [11 x i8] c" PDOP=%.1f\00"
@.str.11 = [11 x i8] c" VDOP=%.1f\00"
@.str.12 = [3 x i8] c"\0D\0A\00"
define i32 @decode_gpsquality(i8* nocapture %0, i32 %1) {
%3 = load i8, i8* %0
%4 = zext i8 %3 to i32
%5 = lshr i32 %4, 6
%6 = lshr i32 %4, 4
%7 = and i32 %6, 3
%8 = and i32 %4, 15
%9 = zext i32 %5 to i64
%10 = shl i64 %9, 2
%11 = call i8* @llvm.load.relative.i64(i8* bitcast ([4 x i32]* @reltable.decode_gpsquality to i8*), i64 %10)
%12 = zext i32 %7 to i64
%13 = shl i64 %12, 2
%14 = call i8* @llvm.load.relative.i64(i8* bitcast ([4 x i32]* @reltable.decode_gpsquality.13 to i8*), i64 %13)
%15 = tail call i32 (i32, i8*, ...) @lprintf(i32 14, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.8, i64 0, i64 0), i8* %11, i8* %14, i32 %8)
%16 = icmp sgt i32 %1, 1
br i1 %16, label %17, label %40
17: ; preds = %2
%18 = getelementptr inbounds i8, i8* %0, i64 1
%19 = load i8, i8* %18
%20 = uitofp i8 %19 to float
%21 = fdiv float %20, 1.000000e+01
%22 = fpext float %21 to double
%23 = tail call i32 (i32, i8*, ...) @lprintf(i32 14, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.9, i64 0, i64 0), double %22)
%24 = icmp eq i32 %1, 2
br i1 %24, label %40, label %25
25: ; preds = %17
%26 = getelementptr inbounds i8, i8* %0, i64 2
%27 = load i8, i8* %26
%28 = uitofp i8 %27 to float
%29 = fdiv float %28, 1.000000e+01
%30 = fpext float %29 to double
%31 = tail call i32 (i32, i8*, ...) @lprintf(i32 14, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.10, i64 0, i64 0), double %30)
%32 = icmp ugt i32 %1, 3
br i1 %32, label %33, label %40
33: ; preds = %25
%34 = getelementptr inbounds i8, i8* %0, i64 3
%35 = load i8, i8* %34
%36 = uitofp i8 %35 to float
%37 = fdiv float %36, 1.000000e+01
%38 = fpext float %37 to double
%39 = tail call i32 (i32, i8*, ...) @lprintf(i32 14, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.11, i64 0, i64 0), double %38)
br label %40
40: ; preds = %2, %17, %33, %25
%41 = tail call i32 (i32, i8*, ...) @lprintf(i32 14, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.12, i64 0, i64 0))
ret i32 0
}