#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 rt_modbus_total_bytes(uint8_t *buf, int n) {
  switch (buf[1]) {
  case (0x01):
  case (0x02):
  case (0x03):
  case (0x04):
  case (0x05):
  case (0x06):
  case (0x08):
  case (67):
    if (n != 8)
      return -1;
    return 8;
  case (0x07):
  case (0x11):
    if (n != 4)
      return -1;
    return 4;
  case (0x0F):
  case (0x10):
    if (n != 7)
      return -1;
    return buf[6] + 9;
  default:
    return -1;
  }
}


x86 assembly (clang, -O0):
<rt_modbus_total_bytes>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%eax
add    $0xffffffff,%eax
mov    %eax,%ecx
mov    %rcx,-0x20(%rbp)
sub    $0x42,%eax
ja     11a4 <rt_modbus_total_bytes+0xa4>
mov    -0x20(%rbp),%rax
lea    0xed1(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
cmpl   $0x8,-0x14(%rbp)
je     114e <rt_modbus_total_bytes+0x4e>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ab <rt_modbus_total_bytes+0xab>
movl   $0x8,-0x4(%rbp)
jmp    11ab <rt_modbus_total_bytes+0xab>
cmpl   $0x4,-0x14(%rbp)
je     1170 <rt_modbus_total_bytes+0x70>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ab <rt_modbus_total_bytes+0xab>
movl   $0x4,-0x4(%rbp)
jmp    11ab <rt_modbus_total_bytes+0xab>
cmpl   $0x7,-0x14(%rbp)
je     1192 <rt_modbus_total_bytes+0x92>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ab <rt_modbus_total_bytes+0xab>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%eax
add    $0x9,%eax
mov    %eax,-0x4(%rbp)
jmp    11ab <rt_modbus_total_bytes+0xab>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<rt_modbus_total_bytes>:
mov    0x4(%rdi),%ecx
mov    $0xffffffff,%eax
add    $0xffffffff,%ecx
cmp    $0x42,%ecx
ja     1149 <rt_modbus_total_bytes+0x49>
lea    0xee9(%rip),%rdx
movslq (%rdx,%rcx,4),%rcx
add    %rdx,%rcx
jmp    *%rcx
xor    %eax,%eax
cmp    $0x8,%esi
sete   %al
lea    (%rax,%rax,8),%eax
add    $0xffffffff,%eax
ret
xor    %eax,%eax
cmp    $0x4,%esi
sete   %al
lea    (%rax,%rax,4),%eax
add    $0xffffffff,%eax
ret
cmp    $0x7,%esi
jne    1149 <rt_modbus_total_bytes+0x49>
mov    0x18(%rdi),%eax
add    $0x9,%eax
ret

LLVM IR (-O0):
define i32 @rt_modbus_total_bytes(i32* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32
store i32* %0, i32** %4
store i32 %1, i32* %5
%6 = load i32*, i32** %4
%7 = getelementptr inbounds i32, i32* %6, i64 1
%8 = load i32, i32* %7
switch i32 %8, label %28 [
i32 1, label %9
i32 2, label %9
i32 3, label %9
i32 4, label %9
i32 5, label %9
i32 6, label %9
i32 8, label %9
i32 67, label %9
i32 7, label %14
i32 17, label %14
i32 15, label %19
i32 16, label %19
]
9: ; preds = %2, %2, %2, %2, %2, %2, %2, %2
%10 = load i32, i32* %5
%11 = icmp ne i32 %10, 8
br i1 %11, label %12, label %13
12: ; preds = %9
store i32 -1, i32* %3
br label %29
13: ; preds = %9
store i32 8, i32* %3
br label %29
14: ; preds = %2, %2
%15 = load i32, i32* %5
%16 = icmp ne i32 %15, 4
br i1 %16, label %17, label %18
17: ; preds = %14
store i32 -1, i32* %3
br label %29
18: ; preds = %14
store i32 4, i32* %3
br label %29
19: ; preds = %2, %2
%20 = load i32, i32* %5
%21 = icmp ne i32 %20, 7
br i1 %21, label %22, label %23
22: ; preds = %19
store i32 -1, i32* %3
br label %29
23: ; preds = %19
%24 = load i32*, i32** %4
%25 = getelementptr inbounds i32, i32* %24, i64 6
%26 = load i32, i32* %25
%27 = add nsw i32 %26, 9
store i32 %27, i32* %3
br label %29
28: ; preds = %2
store i32 -1, i32* %3
br label %29
29: ; preds = %28, %23, %22, %18, %17, %13, %12
%30 = load i32, i32* %3
ret i32 %30
}

LLVM IR (-O2):
define i32 @rt_modbus_total_bytes(i32* nocapture %0, i32 %1) {
%3 = getelementptr inbounds i32, i32* %0, i64 1
%4 = load i32, i32* %3
switch i32 %4, label %17 [
i32 1, label %5
i32 2, label %5
i32 3, label %5
i32 4, label %5
i32 5, label %5
i32 6, label %5
i32 8, label %5
i32 67, label %5
i32 7, label %8
i32 17, label %8
i32 15, label %11
i32 16, label %11
]
5: ; preds = %2, %2, %2, %2, %2, %2, %2, %2
%6 = icmp eq i32 %1, 8
%7 = select i1 %6, i32 8, i32 -1
br label %17
8: ; preds = %2, %2
%9 = icmp eq i32 %1, 4
%10 = select i1 %9, i32 4, i32 -1
br label %17
11: ; preds = %2, %2
%12 = icmp eq i32 %1, 7
br i1 %12, label %13, label %17
13: ; preds = %11
%14 = getelementptr inbounds i32, i32* %0, i64 6
%15 = load i32, i32* %14
%16 = add nsw i32 %15, 9
br label %17
17: ; preds = %2, %11, %8, %5, %13
%18 = phi i32 [ %16, %13 ], [ %7, %5 ], [ %10, %8 ], [ -1, %11 ], [ -1, %2 ]
ret i32 %18
}