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

/* Variables and functions */
int /*<<< orphan*/ le_to_i16(int /*<<< orphan*/ const *);
int /*<<< orphan*/ le_to_i32(int /*<<< orphan*/ const *);
int /*<<< orphan*/ le_to_i64(int /*<<< orphan*/ const *);
int /*<<< orphan*/ le_to_i8(int /*<<< orphan*/ const *);
int64_t bcf_dec_int1(const uint8_t *p, int type, uint8_t **q) {
  if (type == 1) {
    *q = (uint8_t *)p + 1;
    return le_to_i8(p);
  } else if (type == 2) {
    *q = (uint8_t *)p + 2;
    return le_to_i16(p);
  } else if (type == 3) {
    *q = (uint8_t *)p + 4;
    return le_to_i32(p);
  } else if (type == 4) {
    *q = (uint8_t *)p + 8;
    return le_to_i64(p);
  } else {
    return 0;
  }
}


x86 assembly (clang, -O0):
<bcf_dec_int1>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
cmpl   $0x1,-0x14(%rbp)
jne    117d <bcf_dec_int1+0x3d>
mov    -0x10(%rbp),%rcx
add    $0x4,%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rdi
call   1050 <le_to_i8@plt>
mov    %eax,-0x4(%rbp)
jmp    1202 <bcf_dec_int1+0xc2>
cmpl   $0x2,-0x14(%rbp)
jne    11a7 <bcf_dec_int1+0x67>
mov    -0x10(%rbp),%rcx
add    $0x8,%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rdi
call   1060 <le_to_i16@plt>
mov    %eax,-0x4(%rbp)
jmp    1202 <bcf_dec_int1+0xc2>
cmpl   $0x3,-0x14(%rbp)
jne    11d1 <bcf_dec_int1+0x91>
mov    -0x10(%rbp),%rcx
add    $0x10,%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rdi
call   1040 <le_to_i32@plt>
mov    %eax,-0x4(%rbp)
jmp    1202 <bcf_dec_int1+0xc2>
cmpl   $0x4,-0x14(%rbp)
jne    11fb <bcf_dec_int1+0xbb>
mov    -0x10(%rbp),%rcx
add    $0x20,%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rdi
call   1030 <le_to_i64@plt>
mov    %eax,-0x4(%rbp)
jmp    1202 <bcf_dec_int1+0xc2>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bcf_dec_int1>:
add    $0xffffffff,%esi
cmp    $0x3,%esi
ja     1164 <bcf_dec_int1+0x24>
lea    0xeb1(%rip),%rax
movslq (%rax,%rsi,4),%rcx
add    %rax,%rcx
jmp    *%rcx
lea    0x4(%rdi),%rax
mov    %rax,(%rdx)
jmp    1050 <le_to_i8@plt>
xor    %eax,%eax
ret
lea    0x8(%rdi),%rax
mov    %rax,(%rdx)
jmp    1060 <le_to_i16@plt>
lea    0x10(%rdi),%rax
mov    %rax,(%rdx)
jmp    1040 <le_to_i32@plt>
lea    0x20(%rdi),%rax
mov    %rax,(%rdx)
jmp    1030 <le_to_i64@plt>

LLVM IR (-O0):
define i32 @bcf_dec_int1(i32* %0, i32 %1, i32** %2) {
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32**
store i32* %0, i32** %5
store i32 %1, i32* %6
store i32** %2, i32*** %7
%8 = load i32, i32* %6
%9 = icmp eq i32 %8, 1
br i1 %9, label %10, label %16
10: ; preds = %3
%11 = load i32*, i32** %5
%12 = getelementptr inbounds i32, i32* %11, i64 1
%13 = load i32**, i32*** %7
store i32* %12, i32** %13
%14 = load i32*, i32** %5
%15 = call i32 @le_to_i8(i32* %14)
store i32 %15, i32* %4
br label %44
16: ; preds = %3
%17 = load i32, i32* %6
%18 = icmp eq i32 %17, 2
br i1 %18, label %19, label %25
19: ; preds = %16
%20 = load i32*, i32** %5
%21 = getelementptr inbounds i32, i32* %20, i64 2
%22 = load i32**, i32*** %7
store i32* %21, i32** %22
%23 = load i32*, i32** %5
%24 = call i32 @le_to_i16(i32* %23)
store i32 %24, i32* %4
br label %44
25: ; preds = %16
%26 = load i32, i32* %6
%27 = icmp eq i32 %26, 3
br i1 %27, label %28, label %34
28: ; preds = %25
%29 = load i32*, i32** %5
%30 = getelementptr inbounds i32, i32* %29, i64 4
%31 = load i32**, i32*** %7
store i32* %30, i32** %31
%32 = load i32*, i32** %5
%33 = call i32 @le_to_i32(i32* %32)
store i32 %33, i32* %4
br label %44
34: ; preds = %25
%35 = load i32, i32* %6
%36 = icmp eq i32 %35, 4
br i1 %36, label %37, label %43
37: ; preds = %34
%38 = load i32*, i32** %5
%39 = getelementptr inbounds i32, i32* %38, i64 8
%40 = load i32**, i32*** %7
store i32* %39, i32** %40
%41 = load i32*, i32** %5
%42 = call i32 @le_to_i64(i32* %41)
store i32 %42, i32* %4
br label %44
43: ; preds = %34
store i32 0, i32* %4
br label %44
44: ; preds = %43, %37, %28, %19, %10
%45 = load i32, i32* %4
ret i32 %45
}

LLVM IR (-O2):
define i32 @bcf_dec_int1(i32* %0, i32 %1, i32** nocapture writeonly %2) {
switch i32 %1, label %16 [
i32 1, label %4
i32 2, label %7
i32 3, label %10
i32 4, label %13
]
4: ; preds = %3
%5 = getelementptr inbounds i32, i32* %0, i64 1
store i32* %5, i32** %2
%6 = tail call i32 @le_to_i8(i32* %0)
br label %16
7: ; preds = %3
%8 = getelementptr inbounds i32, i32* %0, i64 2
store i32* %8, i32** %2
%9 = tail call i32 @le_to_i16(i32* %0)
br label %16
10: ; preds = %3
%11 = getelementptr inbounds i32, i32* %0, i64 4
store i32* %11, i32** %2
%12 = tail call i32 @le_to_i32(i32* %0)
br label %16
13: ; preds = %3
%14 = getelementptr inbounds i32, i32* %0, i64 8
store i32* %14, i32** %2
%15 = tail call i32 @le_to_i64(i32* %0)
br label %16
16: ; preds = %3, %13, %10, %7, %4
%17 = phi i32 [ %6, %4 ], [ %9, %7 ], [ %12, %10 ], [ %15, %13 ], [ 0, %3 ]
ret i32 %17
}