#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*/ int32_t;

/* Variables and functions */
int /*<<< orphan*/ le_to_i16(int /*<<< orphan*/ const *);
int /*<<< orphan*/ le_to_i32(int /*<<< orphan*/ const *);
int /*<<< orphan*/ le_to_i8(int /*<<< orphan*/ const *);
int32_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 {
    *q = (uint8_t *)p + 4;
    return le_to_i32(p);
  }
}


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    116d <bcf_dec_int1+0x3d>
mov    -0x10(%rbp),%rcx
add    $0x4,%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rdi
call   1040 <le_to_i8@plt>
mov    %eax,-0x4(%rbp)
jmp    11b2 <bcf_dec_int1+0x82>
cmpl   $0x2,-0x14(%rbp)
jne    1197 <bcf_dec_int1+0x67>
mov    -0x10(%rbp),%rcx
add    $0x8,%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rdi
call   1050 <le_to_i16@plt>
mov    %eax,-0x4(%rbp)
jmp    11b2 <bcf_dec_int1+0x82>
mov    -0x10(%rbp),%rcx
add    $0x10,%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rdi
call   1030 <le_to_i32@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bcf_dec_int1>:
cmp    $0x2,%esi
je     1146 <bcf_dec_int1+0x16>
cmp    $0x1,%esi
jne    1152 <bcf_dec_int1+0x22>
lea    0x4(%rdi),%rax
mov    %rax,(%rdx)
jmp    1040 <le_to_i8@plt>
lea    0x8(%rdi),%rax
mov    %rax,(%rdx)
jmp    1050 <le_to_i16@plt>
lea    0x10(%rdi),%rax
mov    %rax,(%rdx)
jmp    1030 <le_to_i32@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 %31
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 %31
25: ; preds = %16
%26 = load i32*, i32** %5
%27 = getelementptr inbounds i32, i32* %26, i64 4
%28 = load i32**, i32*** %7
store i32* %27, i32** %28
%29 = load i32*, i32** %5
%30 = call i32 @le_to_i32(i32* %29)
store i32 %30, i32* %4
br label %31
31: ; preds = %25, %19, %10
%32 = load i32, i32* %4
ret i32 %32
}

LLVM IR (-O2):
define i32 @bcf_dec_int1(i32* %0, i32 %1, i32** nocapture writeonly %2) {
switch i32 %1, label %10 [
i32 1, label %4
i32 2, label %7
]
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 %13
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 %13
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 %13
13: ; preds = %10, %7, %4
%14 = phi i32 [ %6, %4 ], [ %9, %7 ], [ %12, %10 ]
ret i32 %14
}