#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 */
size_t ipbus_transaction_payload_size(unsigned char words, unsigned char type,
                                      unsigned char info_code) {
  size_t datasize = 0;
  if (info_code != 0xf && info_code != 0x0) {
    datasize = 0;
  } else {
    int is_response = (info_code == 0x0);
    switch (type) {
    case 0x0:
    case 0x2:
      datasize = is_response ? words : 1;
      break;
    case 0x1:
    case 0x3:
      datasize = is_response ? 0 : words + 1;
      break;
    case 0x4:
      datasize = is_response ? 1 : 3;
      break;
    case 0x5:
      datasize = is_response ? 1 : 2;
      break;
    }
  }
  return datasize;
}


x86 assembly (clang, -O0):
<ipbus_transaction_payload_size>:
push   %rbp
mov    %rsp,%rbp
mov    %dl,%al
mov    %sil,%cl
mov    %dil,%dl
mov    %dl,-0x1(%rbp)
mov    %cl,-0x2(%rbp)
mov    %al,-0x3(%rbp)
movq   $0x0,-0x10(%rbp)
movzbl -0x3(%rbp),%eax
cmp    $0xf,%eax
je     1144 <ipbus_transaction_payload_size+0x44>
movzbl -0x3(%rbp),%eax
cmp    $0x0,%eax
je     1144 <ipbus_transaction_payload_size+0x44>
movq   $0x0,-0x10(%rbp)
jmp    1211 <ipbus_transaction_payload_size+0x111>
mov    -0x3(%rbp),%al
test   %al,%al
sete   %al
movzbl %al,%eax
mov    %eax,-0x14(%rbp)
movzbl -0x2(%rbp),%eax
mov    %rax,-0x20(%rbp)
sub    $0x5,%rax
ja     120c <ipbus_transaction_payload_size+0x10c>
mov    -0x20(%rbp),%rax
lea    0xe91(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
cmpl   $0x0,-0x14(%rbp)
je     118e <ipbus_transaction_payload_size+0x8e>
movzbl -0x1(%rbp),%eax
mov    %eax,-0x24(%rbp)
jmp    119b <ipbus_transaction_payload_size+0x9b>
mov    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    119b <ipbus_transaction_payload_size+0x9b>
mov    -0x24(%rbp),%eax
cltq
mov    %rax,-0x10(%rbp)
jmp    120c <ipbus_transaction_payload_size+0x10c>
cmpl   $0x0,-0x14(%rbp)
je     11bd <ipbus_transaction_payload_size+0xbd>
xor    %eax,%eax
mov    %eax,-0x28(%rbp)
jmp    11c7 <ipbus_transaction_payload_size+0xc7>
movzbl -0x1(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cltq
mov    %rax,-0x10(%rbp)
jmp    120c <ipbus_transaction_payload_size+0x10c>
mov    -0x14(%rbp),%edx
mov    $0x3,%eax
mov    $0x1,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
cltq
mov    %rax,-0x10(%rbp)
jmp    120c <ipbus_transaction_payload_size+0x10c>
mov    -0x14(%rbp),%edx
mov    $0x2,%eax
mov    $0x1,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
cltq
mov    %rax,-0x10(%rbp)
jmp    1211 <ipbus_transaction_payload_size+0x111>
mov    -0x10(%rbp),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<ipbus_transaction_payload_size>:
cmp    $0xf,%dl
je     1109 <ipbus_transaction_payload_size+0x9>
test   %dl,%dl
jne    1135 <ipbus_transaction_payload_size+0x35>
cmp    $0x5,%sil
ja     1135 <ipbus_transaction_payload_size+0x35>
movzbl %sil,%eax
lea    0xee6(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
test   %dl,%dl
movzbl %dil,%eax
mov    $0x1,%ecx
cmove  %eax,%ecx
movzbl %cl,%eax
ret
xor    %eax,%eax
ret
movzbl %dil,%ecx
add    $0x1,%rcx
xor    %eax,%eax
test   %dl,%dl
cmovne %rcx,%rax
ret
xor    %eax,%eax
test   %dl,%dl
setne  %al
add    %rax,%rax
add    $0x1,%rax
ret
cmp    $0x1,%dl
mov    $0x2,%eax
sbb    $0x0,%rax
ret

LLVM IR (-O0):
define i64 @ipbus_transaction_payload_size(i8 zeroext %0, i8 zeroext %1, i8 zeroext %2) {
%4 = alloca i8
%5 = alloca i8
%6 = alloca i8
%7 = alloca i64
%8 = alloca i32
store i8 %0, i8* %4
store i8 %1, i8* %5
store i8 %2, i8* %6
store i64 0, i64* %7
%9 = load i8, i8* %6
%10 = zext i8 %9 to i32
%11 = icmp ne i32 %10, 15
br i1 %11, label %12, label %17
12: ; preds = %3
%13 = load i8, i8* %6
%14 = zext i8 %13 to i32
%15 = icmp ne i32 %14, 0
br i1 %15, label %16, label %17
16: ; preds = %12
store i64 0, i64* %7
br label %58
17: ; preds = %12, %3
%18 = load i8, i8* %6
%19 = zext i8 %18 to i32
%20 = icmp eq i32 %19, 0
%21 = zext i1 %20 to i32
store i32 %21, i32* %8
%22 = load i8, i8* %5
%23 = zext i8 %22 to i32
switch i32 %23, label %57 [
i32 0, label %24
i32 2, label %24
i32 1, label %34
i32 3, label %34
i32 4, label %45
i32 5, label %51
]
24: ; preds = %17, %17
%25 = load i32, i32* %8
%26 = icmp ne i32 %25, 0
br i1 %26, label %27, label %30
27: ; preds = %24
%28 = load i8, i8* %4
%29 = zext i8 %28 to i32
br label %31
30: ; preds = %24
br label %31
31: ; preds = %30, %27
%32 = phi i32 [ %29, %27 ], [ 1, %30 ]
%33 = sext i32 %32 to i64
store i64 %33, i64* %7
br label %57
34: ; preds = %17, %17
%35 = load i32, i32* %8
%36 = icmp ne i32 %35, 0
br i1 %36, label %37, label %38
37: ; preds = %34
br label %42
38: ; preds = %34
%39 = load i8, i8* %4
%40 = zext i8 %39 to i32
%41 = add nsw i32 %40, 1
br label %42
42: ; preds = %38, %37
%43 = phi i32 [ 0, %37 ], [ %41, %38 ]
%44 = sext i32 %43 to i64
store i64 %44, i64* %7
br label %57
45: ; preds = %17
%46 = load i32, i32* %8
%47 = icmp ne i32 %46, 0
%48 = zext i1 %47 to i64
%49 = select i1 %47, i32 1, i32 3
%50 = sext i32 %49 to i64
store i64 %50, i64* %7
br label %57
51: ; preds = %17
%52 = load i32, i32* %8
%53 = icmp ne i32 %52, 0
%54 = zext i1 %53 to i64
%55 = select i1 %53, i32 1, i32 2
%56 = sext i32 %55 to i64
store i64 %56, i64* %7
br label %57
57: ; preds = %17, %51, %45, %42, %31
br label %58
58: ; preds = %57, %16
%59 = load i64, i64* %7
ret i64 %59
}

LLVM IR (-O2):
define i64 @ipbus_transaction_payload_size(i8 zeroext %0, i8 zeroext %1, i8 zeroext %2) {
switch i8 %2, label %17 [
i8 15, label %4
i8 0, label %4
]
4: ; preds = %3, %3
%5 = icmp eq i8 %2, 0
switch i8 %1, label %17 [
i8 0, label %6
i8 2, label %6
i8 1, label %9
i8 3, label %9
i8 4, label %13
i8 5, label %15
]
6: ; preds = %4, %4
%7 = select i1 %5, i8 %0, i8 1
%8 = zext i8 %7 to i64
br label %17
9: ; preds = %4, %4
%10 = zext i8 %0 to i64
%11 = add nuw nsw i64 %10, 1
%12 = select i1 %5, i64 0, i64 %11
br label %17
13: ; preds = %4
%14 = select i1 %5, i64 1, i64 3
br label %17
15: ; preds = %4
%16 = select i1 %5, i64 1, i64 2
br label %17
17: ; preds = %6, %9, %13, %15, %4, %3
%18 = phi i64 [ 0, %3 ], [ 0, %4 ], [ %16, %15 ], [ %14, %13 ], [ %12, %9 ], [ %8, %6 ]
ret i64 %18
}