#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*/ int8_t;
typedef int /*<<< orphan*/ int32_t;
typedef int /*<<< orphan*/ int16_t;

/* Variables and functions */
int32_t bcf_dec_int1(const uint8_t *p, int type, uint8_t **q) {
  if (type == 1) {
    *q = (uint8_t *)p + 1;
    return *(int8_t *)p;
  } else if (type == 2) {
    *q = (uint8_t *)p + 2;
    return *(int16_t *)p;
  } else {
    *q = (uint8_t *)p + 4;
    return *(int32_t *)p;
  }
}


x86 assembly (clang, -O0):
<bcf_dec_int1>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
cmpl   $0x1,-0x14(%rbp)
jne    1136 <bcf_dec_int1+0x36>
mov    -0x10(%rbp),%rcx
add    $0x4,%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1175 <bcf_dec_int1+0x75>
cmpl   $0x2,-0x14(%rbp)
jne    115d <bcf_dec_int1+0x5d>
mov    -0x10(%rbp),%rcx
add    $0x8,%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1175 <bcf_dec_int1+0x75>
mov    -0x10(%rbp),%rcx
add    $0x10,%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<bcf_dec_int1>:
xor    %eax,%eax
cmp    $0x2,%esi
setne  %al
add    %rax,%rax
add    $0x2,%rax
cmp    $0x1,%esi
mov    $0x1,%ecx
cmovne %rax,%rcx
lea    (%rdi,%rcx,4),%rax
mov    %rax,(%rdx)
mov    (%rdi),%eax
ret

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 = load i32, 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 = load i32, 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 = load 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) {
%4 = icmp eq i32 %1, 2
%5 = select i1 %4, i64 2, i64 4
%6 = icmp eq i32 %1, 1
%7 = select i1 %6, i64 1, i64 %5
%8 = getelementptr inbounds i32, i32* %0, i64 %7
store i32* %8, i32** %2
%9 = load i32, i32* %0
ret i32 %9
}