#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 */
int getbits(unsigned char const *, int, int);
int getbitu(unsigned char const *, int, int);
scalar_t__ getbitu3(unsigned char const *, int, int, int, int, int, int);
int getbits3(const unsigned char *buff, int p1, int l1, int p2, int l2, int p3,
             int l3) {
  if (getbitu(buff, p1, 1))
    return (int)((getbits(buff, p1, l1) << (l2 + l3)) +
                 (getbitu(buff, p2, l2) << l3) + getbitu(buff, p3, l3));
  else
    return (int)getbitu3(buff, p1, l1, p2, l2, p3, l3);
}


x86 assembly (clang, -O0):
<getbits3>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    0x10(%rbp),%eax
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8d,-0x20(%rbp)
mov    %r9d,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    $0x1,%edx
call   1040 <getbitu@plt>
cmp    $0x0,%eax
je     11c2 <getbits3+0x92>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
call   1030 <getbits@plt>
mov    -0x20(%rbp),%ecx
add    0x10(%rbp),%ecx
shl    %cl,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    -0x20(%rbp),%edx
call   1040 <getbitu@plt>
mov    %eax,%edx
mov    -0x2c(%rbp),%eax
mov    0x10(%rbp),%ecx
shl    %cl,%edx
mov    %edx,%ecx
add    %ecx,%eax
mov    %eax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x24(%rbp),%esi
mov    0x10(%rbp),%edx
call   1040 <getbitu@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x4(%rbp)
jmp    11e5 <getbits3+0xb5>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
mov    -0x1c(%rbp),%ecx
mov    -0x20(%rbp),%r8d
mov    -0x24(%rbp),%r9d
mov    0x10(%rbp),%eax
mov    %eax,(%rsp)
call   1050 <getbitu3@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getbits3>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r9d,0x14(%rsp)
mov    %r8d,%r13d
mov    %ecx,%r12d
mov    %edx,%ebp
mov    %esi,%r14d
mov    %rdi,%rbx
mov    0x50(%rsp),%r15d
mov    $0x1,%edx
call   1040 <getbitu@plt>
test   %eax,%eax
je     11a6 <getbits3+0x76>
mov    %rbx,%rdi
mov    %r14d,%esi
mov    %ebp,%edx
call   1030 <getbits@plt>
mov    %eax,%r14d
lea    (%r15,%r13,1),%ecx
shl    %cl,%r14d
mov    %rbx,%rdi
mov    %r12d,%esi
mov    %r13d,%edx
call   1040 <getbitu@plt>
mov    %eax,%ebp
mov    %r15d,%ecx
shl    %cl,%ebp
add    %r14d,%ebp
mov    %rbx,%rdi
mov    0x14(%rsp),%esi
mov    %r15d,%edx
call   1040 <getbitu@plt>
add    %ebp,%eax
jmp    11c2 <getbits3+0x92>
mov    %r15d,(%rsp)
mov    %rbx,%rdi
mov    %r14d,%esi
mov    %ebp,%edx
mov    %r12d,%ecx
mov    %r13d,%r8d
mov    0x14(%rsp),%r9d
call   1050 <getbitu3@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @getbits3(i8* %0, i32 %1, i32 %2, i32 %3, i32 %4, i32 %5, i32 %6) {
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
store i8* %0, i8** %9
store i32 %1, i32* %10
store i32 %2, i32* %11
store i32 %3, i32* %12
store i32 %4, i32* %13
store i32 %5, i32* %14
store i32 %6, i32* %15
%16 = load i8*, i8** %9
%17 = load i32, i32* %10
%18 = call i32 @getbitu(i8* %16, i32 %17, i32 1)
%19 = icmp ne i32 %18, 0
br i1 %19, label %20, label %41
20: ; preds = %7
%21 = load i8*, i8** %9
%22 = load i32, i32* %10
%23 = load i32, i32* %11
%24 = call i32 @getbits(i8* %21, i32 %22, i32 %23)
%25 = load i32, i32* %13
%26 = load i32, i32* %15
%27 = add nsw i32 %25, %26
%28 = shl i32 %24, %27
%29 = load i8*, i8** %9
%30 = load i32, i32* %12
%31 = load i32, i32* %13
%32 = call i32 @getbitu(i8* %29, i32 %30, i32 %31)
%33 = load i32, i32* %15
%34 = shl i32 %32, %33
%35 = add nsw i32 %28, %34
%36 = load i8*, i8** %9
%37 = load i32, i32* %14
%38 = load i32, i32* %15
%39 = call i32 @getbitu(i8* %36, i32 %37, i32 %38)
%40 = add nsw i32 %35, %39
store i32 %40, i32* %8
br label %51
41: ; preds = %7
%42 = load i8*, i8** %9
%43 = load i32, i32* %10
%44 = load i32, i32* %11
%45 = load i32, i32* %12
%46 = load i32, i32* %13
%47 = load i32, i32* %14
%48 = load i32, i32* %15
%49 = call i64 @getbitu3(i8* %42, i32 %43, i32 %44, i32 %45, i32 %46, i32 %47, i32 %48)
%50 = trunc i64 %49 to i32
store i32 %50, i32* %8
br label %51
51: ; preds = %41, %20
%52 = load i32, i32* %8
ret i32 %52
}

LLVM IR (-O2):
define i32 @getbits3(i8* %0, i32 %1, i32 %2, i32 %3, i32 %4, i32 %5, i32 %6) {
%8 = tail call i32 @getbitu(i8* %0, i32 %1, i32 1)
%9 = icmp eq i32 %8, 0
br i1 %9, label %19, label %10
10: ; preds = %7
%11 = tail call i32 @getbits(i8* %0, i32 %1, i32 %2)
%12 = add nsw i32 %6, %4
%13 = shl i32 %11, %12
%14 = tail call i32 @getbitu(i8* %0, i32 %3, i32 %4)
%15 = shl i32 %14, %6
%16 = add nsw i32 %15, %13
%17 = tail call i32 @getbitu(i8* %0, i32 %5, i32 %6)
%18 = add nsw i32 %16, %17
br label %22
19: ; preds = %7
%20 = tail call i64 @getbitu3(i8* %0, i32 %1, i32 %2, i32 %3, i32 %4, i32 %5, i32 %6)
%21 = trunc i64 %20 to i32
br label %22
22: ; preds = %19, %10
%23 = phi i32 [ %18, %10 ], [ %21, %19 ]
ret i32 %23
}