#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 get16(unsigned char *);
int /*<<< orphan*/ lprintf(int, char *, unsigned int, float);
int decode_courseandspeed(unsigned char *element, int element_len) {
  unsigned int course;
  unsigned int rawspeed;
  float speed;
  course = (*element << 1) | ((*(element + 1) & 0x80) >> 7);
  rawspeed = get16(element + 1) & 0x7fff;
  speed = (float)rawspeed * 0.072;
  if (course >= 360)
    return -2;
  lprintf(14, "Course: %d Speed: %f kph\r\n", course, speed);
  return 0;
}


x86 assembly (clang, -O0):
<decode_courseandspeed>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x10(%rbp),%rcx
movzbl (%rcx),%eax
movzbl 0x1(%rcx),%edx
shr    $0x7,%edx
mov    %eax,%ecx
mov    %edx,%eax
lea    (%rax,%rcx,2),%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
add    $0x1,%rdi
call   1030 <get16@plt>
and    $0x7fff,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cvtsi2ss %rax,%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xe90(%rip),%xmm1
mulsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x20(%rbp)
cmpl   $0x168,-0x18(%rbp)
jb     1196 <decode_courseandspeed+0x76>
movl   $0xfffffffe,-0x4(%rbp)
jmp    11b6 <decode_courseandspeed+0x96>
mov    -0x18(%rbp),%edx
movss  -0x20(%rbp),%xmm0
mov    $0xe,%edi
lea    0xe5e(%rip),%rsi
call   1040 <lprintf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<decode_courseandspeed>:
push   %rbx
movzbl (%rdi),%eax
movzbl 0x1(%rdi),%ecx
add    $0x1,%rdi
shr    $0x7,%ecx
lea    (%rcx,%rax,2),%ebx
call   1030 <get16@plt>
mov    $0xfffffffe,%ecx
cmp    $0x167,%ebx
ja     1172 <decode_courseandspeed+0x52>
and    $0x7fff,%eax
cvtsi2ss %eax,%xmm0
cvtss2sd %xmm0,%xmm0
mulsd  0xea7(%rip),%xmm0
cvtsd2ss %xmm0,%xmm0
lea    0xea4(%rip),%rsi
mov    $0xe,%edi
mov    %ebx,%edx
call   1040 <lprintf@plt>
xor    %ecx,%ecx
mov    %ecx,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [27 x i8] c"Course: %d Speed: %f kph\0D\0A\00"
define i32 @decode_courseandspeed(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca float
store i8* %0, i8** %4
store i32 %1, i32* %5
%9 = load i8*, i8** %4
%10 = load i8, i8* %9
%11 = zext i8 %10 to i32
%12 = shl i32 %11, 1
%13 = load i8*, i8** %4
%14 = getelementptr inbounds i8, i8* %13, i64 1
%15 = load i8, i8* %14
%16 = zext i8 %15 to i32
%17 = and i32 %16, 128
%18 = ashr i32 %17, 7
%19 = or i32 %12, %18
store i32 %19, i32* %6
%20 = load i8*, i8** %4
%21 = getelementptr inbounds i8, i8* %20, i64 1
%22 = call i32 @get16(i8* %21)
%23 = and i32 %22, 32767
store i32 %23, i32* %7
%24 = load i32, i32* %7
%25 = uitofp i32 %24 to float
%26 = fpext float %25 to double
%27 = fmul double %26, 0x3FB26E978D4FDF3B
%28 = fptrunc double %27 to float
store float %28, float* %8
%29 = load i32, i32* %6
%30 = icmp uge i32 %29, 360
br i1 %30, label %31, label %32
31: ; preds = %2
store i32 -2, i32* %3
br label %36
32: ; preds = %2
%33 = load i32, i32* %6
%34 = load float, float* %8
%35 = call i32 @lprintf(i32 14, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i32 %33, float %34)
store i32 0, i32* %3
br label %36
36: ; preds = %32, %31
%37 = load i32, i32* %3
ret i32 %37
}

LLVM IR (-O2):
@.str = [27 x i8] c"Course: %d Speed: %f kph\0D\0A\00"
define i32 @decode_courseandspeed(i8* %0, i32 %1) {
%3 = load i8, i8* %0
%4 = zext i8 %3 to i32
%5 = shl nuw nsw i32 %4, 1
%6 = getelementptr inbounds i8, i8* %0, i64 1
%7 = load i8, i8* %6
%8 = lshr i8 %7, 7
%9 = zext i8 %8 to i32
%10 = or i32 %5, %9
%11 = tail call i32 @get16(i8* %6)
%12 = icmp ugt i32 %10, 359
br i1 %12, label %20, label %13
13: ; preds = %2
%14 = and i32 %11, 32767
%15 = uitofp i32 %14 to float
%16 = fpext float %15 to double
%17 = fmul double %16, 0x3FB26E978D4FDF3B
%18 = fptrunc double %17 to float
%19 = tail call i32 @lprintf(i32 14, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i32 %10, float %18)
br label %20
20: ; preds = %2, %13
%21 = phi i32 [ 0, %13 ], [ -2, %2 ]
ret i32 %21
}