#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 */
typedef int uint8_t;

/* Variables and functions */
int /*<<< orphan*/ printf(char *, ...);
void processSTDepth(uint8_t *cmdBuffer, uint8_t size) {
  if (size == 5) {
    if (cmdBuffer[1] & 0x0f != 2) {
      printf("process error - wrong encoded data length\n");
    }
    if (cmdBuffer[2] & 0x80) {
      printf("Anchor alarm active\n");
    }
    if (cmdBuffer[2] & 0x40) {
      printf("Metric units for depth\n");
    }
    int depth = ((int)cmdBuffer[4] << 8) | (int)cmdBuffer[3];
    printf("depth = %f feet\n", depth / 10.0);
  } else {
    printf("process error - wrong datagram length\n");
  }
}


x86 assembly (clang, -O0):
<processSTDepth>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
cmpl   $0x5,-0xc(%rbp)
jne    11c6 <processSTDepth+0xb6>
mov    -0x8(%rbp),%rax
mov    0x4(%rax),%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     114a <processSTDepth+0x3a>
lea    0xec5(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%eax
and    $0x80,%eax
cmp    $0x0,%eax
je     116d <processSTDepth+0x5d>
lea    0xecd(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%eax
and    $0x40,%eax
cmp    $0x0,%eax
je     118e <processSTDepth+0x7e>
lea    0xec1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%rax
mov    0x10(%rax),%eax
shl    $0x8,%eax
mov    -0x8(%rbp),%rcx
or     0xc(%rcx),%eax
mov    %eax,-0x10(%rbp)
cvtsi2sdl -0x10(%rbp),%xmm0
movsd  0xe51(%rip),%xmm1
divsd  %xmm1,%xmm0
lea    0xea6(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
jmp    11d4 <processSTDepth+0xc4>
lea    0xea4(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<processSTDepth>:
cmp    $0x5,%esi
jne    1185 <processSTDepth+0x65>
push   %rbx
mov    %rdi,%rbx
testb  $0x1,0x4(%rdi)
je     113b <processSTDepth+0x1b>
lea    0xf34(%rip),%rdi
call   1030 <puts@plt>
mov    0x8(%rbx),%eax
test   $0x80,%al
je     1151 <processSTDepth+0x31>
lea    0xf0d(%rip),%rdi
call   1030 <puts@plt>
mov    0x8(%rbx),%eax
test   $0x40,%al
je     1161 <processSTDepth+0x41>
lea    0xee3(%rip),%rdi
call   1030 <puts@plt>
mov    0x10(%rbx),%eax
shl    $0x8,%eax
or     0xc(%rbx),%eax
cvtsi2sd %eax,%xmm0
divsd  0xe8a(%rip),%xmm0
lea    0xe8b(%rip),%rdi
mov    $0x1,%al
pop    %rbx
jmp    1040 <printf@plt>
lea    0xe8d(%rip),%rdi
jmp    1030 <puts@plt>

LLVM IR (-O0):
@.str = [43 x i8] c"process error - wrong encoded data length\0A\00"
@.str.1 = [21 x i8] c"Anchor alarm active\0A\00"
@.str.2 = [24 x i8] c"Metric units for depth\0A\00"
@.str.3 = [17 x i8] c"depth = %f feet\0A\00"
@.str.4 = [39 x i8] c"process error - wrong datagram length\0A\00"
define void @processSTDepth(i32* %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
store i32* %0, i32** %3
store i32 %1, i32* %4
%6 = load i32, i32* %4
%7 = icmp eq i32 %6, 5
br i1 %7, label %8, label %45
8: ; preds = %2
%9 = load i32*, i32** %3
%10 = getelementptr inbounds i32, i32* %9, i64 1
%11 = load i32, i32* %10
%12 = and i32 %11, 1
%13 = icmp ne i32 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %8
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0))
br label %16
16: ; preds = %14, %8
%17 = load i32*, i32** %3
%18 = getelementptr inbounds i32, i32* %17, i64 2
%19 = load i32, i32* %18
%20 = and i32 %19, 128
%21 = icmp ne i32 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %16
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
br label %24
24: ; preds = %22, %16
%25 = load i32*, i32** %3
%26 = getelementptr inbounds i32, i32* %25, i64 2
%27 = load i32, i32* %26
%28 = and i32 %27, 64
%29 = icmp ne i32 %28, 0
br i1 %29, label %30, label %32
30: ; preds = %24
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
br label %32
32: ; preds = %30, %24
%33 = load i32*, i32** %3
%34 = getelementptr inbounds i32, i32* %33, i64 4
%35 = load i32, i32* %34
%36 = shl i32 %35, 8
%37 = load i32*, i32** %3
%38 = getelementptr inbounds i32, i32* %37, i64 3
%39 = load i32, i32* %38
%40 = or i32 %36, %39
store i32 %40, i32* %5
%41 = load i32, i32* %5
%42 = sitofp i32 %41 to double
%43 = fdiv double %42, 1.000000e+01
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), double %43)
br label %47
45: ; preds = %2
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.4, i64 0, i64 0))
br label %47
47: ; preds = %45, %32
ret void
}

LLVM IR (-O2):
@.str.3 = [17 x i8] c"depth = %f feet\0A\00"
@str = [38 x i8] c"process error - wrong datagram length\00"
@str.5 = [23 x i8] c"Metric units for depth\00"
@str.6 = [20 x i8] c"Anchor alarm active\00"
@str.7 = [42 x i8] c"process error - wrong encoded data length\00"
define void @processSTDepth(i32* nocapture %0, i32 %1) {
%3 = icmp eq i32 %1, 5
br i1 %3, label %4, label %35
4: ; preds = %2
%5 = getelementptr inbounds i32, i32* %0, i64 1
%6 = load i32, i32* %5
%7 = and i32 %6, 1
%8 = icmp eq i32 %7, 0
br i1 %8, label %11, label %9
9: ; preds = %4
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @str.7, i64 0, i64 0))
br label %11
11: ; preds = %9, %4
%12 = getelementptr inbounds i32, i32* %0, i64 2
%13 = load i32, i32* %12
%14 = and i32 %13, 128
%15 = icmp eq i32 %14, 0
br i1 %15, label %19, label %16
16: ; preds = %11
%17 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str.6, i64 0, i64 0))
%18 = load i32, i32* %12
br label %19
19: ; preds = %16, %11
%20 = phi i32 [ %18, %16 ], [ %13, %11 ]
%21 = and i32 %20, 64
%22 = icmp eq i32 %21, 0
br i1 %22, label %25, label %23
23: ; preds = %19
%24 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str.5, i64 0, i64 0))
br label %25
25: ; preds = %23, %19
%26 = getelementptr inbounds i32, i32* %0, i64 4
%27 = load i32, i32* %26
%28 = shl i32 %27, 8
%29 = getelementptr inbounds i32, i32* %0, i64 3
%30 = load i32, i32* %29
%31 = or i32 %28, %30
%32 = sitofp i32 %31 to double
%33 = fdiv double %32, 1.000000e+01
%34 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), double %33)
br label %37
35: ; preds = %2
%36 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @str, i64 0, i64 0))
br label %37
37: ; preds = %35, %25
ret void
}