#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 */
char *get_sensor_scale_string(int, int);
char *get_sensor_type_string(int);
int /*<<< orphan*/ printf(char *, ...);
void multilevel_dump(void *data, void *payload, int len) {
  unsigned char *pp = (unsigned char *)payload;
  int type, size, scale, precision, i;
  unsigned long val;
  unsigned long div = 1;
  if (pp[0] != 0x5) {
    printf("Impossible command %x\n", pp[0]);
    return;
  }
  type = pp[1];
  size = pp[2] & 0x7;
  scale = (pp[2] >> 3) & 0x3;
  precision = (pp[2] >> 5) & 0x7;
  printf("sensor type: 0x%02x (%s)\n", type, get_sensor_type_string(type));
  printf("precision: %d\n", precision);
  printf("scale: %d (%s)\n", scale, get_sensor_scale_string(type, scale));
  printf("size: %d\n", size);
  val = 0;
  for (i = 0; i < size; i++)
    val = val << 8 | pp[3 + i];
  for (i = 0; i < precision; i++)
    div = div * 10;
  printf("val: %lu\n", val);
  printf("%s is %lu.%lu %s\n", get_sensor_type_string(type), val / div,
         val % div, get_sensor_scale_string(type, scale));
}


x86 assembly (clang, -O0):
<multilevel_dump>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
movq   $0x1,-0x48(%rbp)
mov    -0x20(%rbp),%rax
movzbl (%rax),%eax
cmp    $0x5,%eax
je     117d <multilevel_dump+0x4d>
mov    -0x20(%rbp),%rax
movzbl (%rax),%esi
lea    0xe8f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    12fa <multilevel_dump+0x1ca>
mov    -0x20(%rbp),%rax
movzbl 0x1(%rax),%eax
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%rax
movzbl 0x2(%rax),%eax
and    $0x7,%eax
mov    %eax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
movzbl 0x2(%rax),%eax
sar    $0x3,%eax
and    $0x3,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x20(%rbp),%rax
movzbl 0x2(%rax),%eax
sar    $0x5,%eax
and    $0x7,%eax
mov    %eax,-0x30(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x50(%rbp)
mov    -0x24(%rbp),%edi
call   1050 <get_sensor_type_string@plt>
mov    -0x50(%rbp),%esi
mov    %rax,%rdx
lea    0xe44(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x30(%rbp),%esi
lea    0xe4d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4c(%rbp)
mov    -0x24(%rbp),%edi
mov    -0x2c(%rbp),%esi
call   1030 <get_sensor_scale_string@plt>
mov    -0x4c(%rbp),%esi
mov    %rax,%rdx
lea    0xe37(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x28(%rbp),%esi
lea    0xe36(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movq   $0x0,-0x40(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x28(%rbp),%eax
jge    126a <multilevel_dump+0x13a>
mov    -0x40(%rbp),%rax
shl    $0x8,%rax
mov    -0x20(%rbp),%rcx
mov    -0x34(%rbp),%edx
add    $0x3,%edx
movslq %edx,%rdx
movzbl (%rcx,%rdx,1),%ecx
or     %rcx,%rax
mov    %rax,-0x40(%rbp)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1230 <multilevel_dump+0x100>
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x30(%rbp),%eax
jge    1294 <multilevel_dump+0x164>
imul   $0xa,-0x48(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1271 <multilevel_dump+0x141>
mov    -0x40(%rbp),%rsi
lea    0xdbb(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x24(%rbp),%edi
call   1050 <get_sensor_type_string@plt>
mov    %rax,-0x68(%rbp)
mov    -0x40(%rbp),%rax
xor    %ecx,%ecx
mov    %ecx,%edx
divq   -0x48(%rbp)
mov    %rax,-0x60(%rbp)
mov    -0x40(%rbp),%rax
xor    %ecx,%ecx
mov    %ecx,%edx
divq   -0x48(%rbp)
mov    %rdx,-0x58(%rbp)
mov    -0x24(%rbp),%edi
mov    -0x2c(%rbp),%esi
call   1030 <get_sensor_scale_string@plt>
mov    -0x68(%rbp),%rsi
mov    -0x60(%rbp),%rdx
mov    -0x58(%rbp),%rcx
mov    %rax,%r8
lea    0xd71(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<multilevel_dump>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbp
movzbl (%rsi),%esi
cmp    $0x5,%esi
jne    12a7 <multilevel_dump+0x177>
movzbl 0x1(%rbp),%r14d
movzbl 0x2(%rbp),%ebx
mov    %ebx,%r12d
shr    $0x3,%r12d
and    $0x3,%r12d
mov    %ebx,%r15d
shr    $0x5,%r15d
mov    %r14d,%edi
call   1050 <get_sensor_type_string@plt>
lea    0xeb7(%rip),%rdi
xor    %r13d,%r13d
mov    %r14d,%esi
mov    %rax,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xeba(%rip),%rdi
mov    %r15d,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r14d,%edi
mov    %r12d,%esi
call   1030 <get_sensor_scale_string@plt>
lea    0xead(%rip),%rdi
mov    %r12d,%esi
mov    %rax,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xea9(%rip),%rdi
mov    %ebx,%esi
and    $0x7,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %ebx,%eax
and    $0x7,%eax
je     1247 <multilevel_dump+0x117>
movzbl 0x3(%rbp),%r13d
cmp    $0x1,%eax
je     1247 <multilevel_dump+0x117>
mov    %r13,%rcx
shl    $0x8,%rcx
movzbl 0x4(%rbp),%r13d
or     %rcx,%r13
cmp    $0x2,%eax
je     1247 <multilevel_dump+0x117>
mov    %r13,%rcx
shl    $0x8,%rcx
movzbl 0x5(%rbp),%r13d
or     %rcx,%r13
cmp    $0x3,%eax
je     1247 <multilevel_dump+0x117>
mov    %r13,%rcx
shl    $0x8,%rcx
movzbl 0x6(%rbp),%r13d
or     %rcx,%r13
cmp    $0x4,%eax
je     1247 <multilevel_dump+0x117>
mov    %r13,%rcx
shl    $0x8,%rcx
movzbl 0x7(%rbp),%r13d
or     %rcx,%r13
cmp    $0x5,%eax
je     1247 <multilevel_dump+0x117>
mov    %r13,%rcx
shl    $0x8,%rcx
movzbl 0x8(%rbp),%r13d
or     %rcx,%r13
cmp    $0x6,%eax
je     1247 <multilevel_dump+0x117>
shl    $0x8,%r13
movzbl 0x9(%rbp),%eax
or     %rax,%r13
mov    $0x1,%ebp
cmp    $0x20,%bl
jb     126c <multilevel_dump+0x13c>
cmp    $0x2,%r15d
mov    $0x1,%eax
cmovae %r15d,%eax
mov    $0xa,%ebp
cmp    $0x40,%bl
jae    1301 <multilevel_dump+0x1d1>
lea    0xdfb(%rip),%rdi
mov    %r13,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r14d,%edi
call   1050 <get_sensor_type_string@plt>
mov    %rax,%r15
movabs $0xffffff00000000,%rax
test   %rax,%r13
je     12c3 <multilevel_dump+0x193>
mov    %r13,%rax
xor    %edx,%edx
div    %rbp
mov    %rdx,%rbx
mov    %rax,%rbp
jmp    12ce <multilevel_dump+0x19e>
lea    0xd66(%rip),%rdi
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <printf@plt>
mov    %r13d,%eax
xor    %edx,%edx
div    %ebp
mov    %edx,%ebx
mov    %eax,%ebp
mov    %r14d,%edi
mov    %r12d,%esi
call   1030 <get_sensor_scale_string@plt>
lea    0xd98(%rip),%rdi
mov    %r15,%rsi
mov    %rbp,%rdx
mov    %rbx,%rcx
mov    %rax,%r8
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <printf@plt>
add    $0xfffffffe,%eax
cmp    $0x4,%eax
ja     1328 <multilevel_dump+0x1f8>
mov    $0x64,%ebp
lea    0xceb(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    $0x3e8,%ebp
jmp    126c <multilevel_dump+0x13c>
mov    $0x989680,%ebp
jmp    126c <multilevel_dump+0x13c>
mov    $0x2710,%ebp
jmp    126c <multilevel_dump+0x13c>
mov    $0x186a0,%ebp
jmp    126c <multilevel_dump+0x13c>
mov    $0xf4240,%ebp
jmp    126c <multilevel_dump+0x13c>

LLVM IR (-O0):
@.str = [23 x i8] c"Impossible command %x\0A\00"
@.str.1 = [26 x i8] c"sensor type: 0x%02x (%s)\0A\00"
@.str.2 = [15 x i8] c"precision: %d\0A\00"
@.str.3 = [16 x i8] c"scale: %d (%s)\0A\00"
@.str.4 = [10 x i8] c"size: %d\0A\00"
@.str.5 = [10 x i8] c"val: %lu\0A\00"
@.str.6 = [18 x i8] c"%s is %lu.%lu %s\0A\00"
define void @multilevel_dump(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i64
%14 = alloca i64
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%15 = load i8*, i8** %5
store i8* %15, i8** %7
store i64 1, i64* %14
%16 = load i8*, i8** %7
%17 = getelementptr inbounds i8, i8* %16, i64 0
%18 = load i8, i8* %17
%19 = zext i8 %18 to i32
%20 = icmp ne i32 %19, 5
br i1 %20, label %21, label %27
21: ; preds = %3
%22 = load i8*, i8** %7
%23 = getelementptr inbounds i8, i8* %22, i64 0
%24 = load i8, i8* %23
%25 = zext i8 %24 to i32
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 %25)
br label %106
27: ; preds = %3
%28 = load i8*, i8** %7
%29 = getelementptr inbounds i8, i8* %28, i64 1
%30 = load i8, i8* %29
%31 = zext i8 %30 to i32
store i32 %31, i32* %8
%32 = load i8*, i8** %7
%33 = getelementptr inbounds i8, i8* %32, i64 2
%34 = load i8, i8* %33
%35 = zext i8 %34 to i32
%36 = and i32 %35, 7
store i32 %36, i32* %9
%37 = load i8*, i8** %7
%38 = getelementptr inbounds i8, i8* %37, i64 2
%39 = load i8, i8* %38
%40 = zext i8 %39 to i32
%41 = ashr i32 %40, 3
%42 = and i32 %41, 3
store i32 %42, i32* %10
%43 = load i8*, i8** %7
%44 = getelementptr inbounds i8, i8* %43, i64 2
%45 = load i8, i8* %44
%46 = zext i8 %45 to i32
%47 = ashr i32 %46, 5
%48 = and i32 %47, 7
store i32 %48, i32* %11
%49 = load i32, i32* %8
%50 = load i32, i32* %8
%51 = call i8* @get_sensor_type_string(i32 %50)
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i32 %49, i8* %51)
%53 = load i32, i32* %11
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i32 %53)
%55 = load i32, i32* %10
%56 = load i32, i32* %8
%57 = load i32, i32* %10
%58 = call i8* @get_sensor_scale_string(i32 %56, i32 %57)
%59 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i32 %55, i8* %58)
%60 = load i32, i32* %9
%61 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i32 %60)
store i64 0, i64* %13
store i32 0, i32* %12
br label %62
62: ; preds = %77, %27
%63 = load i32, i32* %12
%64 = load i32, i32* %9
%65 = icmp slt i32 %63, %64
br i1 %65, label %66, label %80
66: ; preds = %62
%67 = load i64, i64* %13
%68 = shl i64 %67, 8
%69 = load i8*, i8** %7
%70 = load i32, i32* %12
%71 = add nsw i32 3, %70
%72 = sext i32 %71 to i64
%73 = getelementptr inbounds i8, i8* %69, i64 %72
%74 = load i8, i8* %73
%75 = zext i8 %74 to i64
%76 = or i64 %68, %75
store i64 %76, i64* %13
br label %77
77: ; preds = %66
%78 = load i32, i32* %12
%79 = add nsw i32 %78, 1
store i32 %79, i32* %12
br label %62
80: ; preds = %62
store i32 0, i32* %12
br label %81
81: ; preds = %88, %80
%82 = load i32, i32* %12
%83 = load i32, i32* %11
%84 = icmp slt i32 %82, %83
br i1 %84, label %85, label %91
85: ; preds = %81
%86 = load i64, i64* %14
%87 = mul i64 %86, 10
store i64 %87, i64* %14
br label %88
88: ; preds = %85
%89 = load i32, i32* %12
%90 = add nsw i32 %89, 1
store i32 %90, i32* %12
br label %81
91: ; preds = %81
%92 = load i64, i64* %13
%93 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0), i64 %92)
%94 = load i32, i32* %8
%95 = call i8* @get_sensor_type_string(i32 %94)
%96 = load i64, i64* %13
%97 = load i64, i64* %14
%98 = udiv i64 %96, %97
%99 = load i64, i64* %13
%100 = load i64, i64* %14
%101 = urem i64 %99, %100
%102 = load i32, i32* %8
%103 = load i32, i32* %10
%104 = call i8* @get_sensor_scale_string(i32 %102, i32 %103)
%105 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.6, i64 0, i64 0), i8* %95, i64 %98, i64 %101, i8* %104)
br label %106
106: ; preds = %91, %21
ret void
}

LLVM IR (-O2):
@.str = [23 x i8] c"Impossible command %x\0A\00"
@.str.1 = [26 x i8] c"sensor type: 0x%02x (%s)\0A\00"
@.str.2 = [15 x i8] c"precision: %d\0A\00"
@.str.3 = [16 x i8] c"scale: %d (%s)\0A\00"
@.str.4 = [10 x i8] c"size: %d\0A\00"
@.str.5 = [10 x i8] c"val: %lu\0A\00"
@.str.6 = [18 x i8] c"%s is %lu.%lu %s\0A\00"
define void @multilevel_dump(i8* nocapture readnone %0, i8* nocapture %1, i32 %2) {
%4 = load i8, i8* %1
%5 = icmp eq i8 %4, 5
br i1 %5, label %9, label %6
6: ; preds = %3
%7 = zext i8 %4 to i32
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 %7)
br label %93
9: ; preds = %3
%10 = getelementptr inbounds i8, i8* %1, i64 1
%11 = load i8, i8* %10
%12 = zext i8 %11 to i32
%13 = getelementptr inbounds i8, i8* %1, i64 2
%14 = load i8, i8* %13
%15 = zext i8 %14 to i32
%16 = and i32 %15, 7
%17 = lshr i32 %15, 3
%18 = and i32 %17, 3
%19 = lshr i32 %15, 5
%20 = tail call i8* @get_sensor_type_string(i32 %12)
%21 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i32 %12, i8* %20)
%22 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i32 %19)
%23 = tail call i8* @get_sensor_scale_string(i32 %12, i32 %18)
%24 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i32 %18, i8* %23)
%25 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i32 %16)
%26 = icmp eq i32 %16, 0
br i1 %26, label %27, label %33
27: ; preds = %33, %38, %45, %52, %59, %66, %73, %9
%28 = phi i64 [ 0, %9 ], [ %36, %33 ], [ %43, %38 ], [ %50, %45 ], [ %57, %52 ], [ %64, %59 ], [ %71, %66 ], [ %78, %73 ]
%29 = icmp ult i8 %14, 32
br i1 %29, label %85, label %30
30: ; preds = %27
%31 = call i32 @llvm.umax.i32(i32 %19, i32 1)
%32 = icmp ult i8 %14, 64
br i1 %32, label %85, label %79
33: ; preds = %9
%34 = getelementptr inbounds i8, i8* %1, i64 3
%35 = load i8, i8* %34
%36 = zext i8 %35 to i64
%37 = icmp eq i32 %16, 1
br i1 %37, label %27, label %38
38: ; preds = %33
%39 = shl nuw nsw i64 %36, 8
%40 = getelementptr inbounds i8, i8* %1, i64 4
%41 = load i8, i8* %40
%42 = zext i8 %41 to i64
%43 = or i64 %39, %42
%44 = icmp eq i32 %16, 2
br i1 %44, label %27, label %45
45: ; preds = %38
%46 = shl nuw nsw i64 %43, 8
%47 = getelementptr inbounds i8, i8* %1, i64 5
%48 = load i8, i8* %47
%49 = zext i8 %48 to i64
%50 = or i64 %46, %49
%51 = icmp eq i32 %16, 3
br i1 %51, label %27, label %52
52: ; preds = %45
%53 = shl nuw nsw i64 %50, 8
%54 = getelementptr inbounds i8, i8* %1, i64 6
%55 = load i8, i8* %54
%56 = zext i8 %55 to i64
%57 = or i64 %53, %56
%58 = icmp eq i32 %16, 4
br i1 %58, label %27, label %59
59: ; preds = %52
%60 = shl i64 %57, 8
%61 = getelementptr inbounds i8, i8* %1, i64 7
%62 = load i8, i8* %61
%63 = zext i8 %62 to i64
%64 = or i64 %60, %63
%65 = icmp eq i32 %16, 5
br i1 %65, label %27, label %66
66: ; preds = %59
%67 = shl i64 %64, 8
%68 = getelementptr inbounds i8, i8* %1, i64 8
%69 = load i8, i8* %68
%70 = zext i8 %69 to i64
%71 = or i64 %67, %70
%72 = icmp eq i32 %16, 6
br i1 %72, label %27, label %73
73: ; preds = %66
%74 = shl i64 %71, 8
%75 = getelementptr inbounds i8, i8* %1, i64 9
%76 = load i8, i8* %75
%77 = zext i8 %76 to i64
%78 = or i64 %74, %77
br label %27
79: ; preds = %30
switch i32 %31, label %80 [
i32 2, label %85
i32 3, label %81
i32 4, label %82
i32 5, label %83
i32 6, label %84
]
80: ; preds = %79
br label %85
81: ; preds = %79
br label %85
82: ; preds = %79
br label %85
83: ; preds = %79
br label %85
84: ; preds = %79
br label %85
85: ; preds = %30, %80, %81, %82, %83, %84, %79, %27
%86 = phi i64 [ 1, %27 ], [ 10, %30 ], [ 100, %79 ], [ 10000000, %80 ], [ 1000, %81 ], [ 10000, %82 ], [ 100000, %83 ], [ 1000000, %84 ]
%87 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0), i64 %28)
%88 = tail call i8* @get_sensor_type_string(i32 %12)
%89 = udiv i64 %28, %86
%90 = urem i64 %28, %86
%91 = tail call i8* @get_sensor_scale_string(i32 %12, i32 %18)
%92 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.6, i64 0, i64 0), i8* %88, i64 %89, i64 %90, i8* %91)
br label %93
93: ; preds = %85, %6
ret void
}