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


x86 assembly (clang, -O0):
<getbits2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8d,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    $0x1,%edx
call   1050 <getbitu@plt>
cmp    $0x0,%rax
je     119f <getbits2+0x6f>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
call   1040 <getbits@plt>
mov    -0x20(%rbp),%ecx
shl    %cl,%eax
cltq
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    -0x20(%rbp),%edx
call   1050 <getbitu@plt>
mov    %rax,%rcx
mov    -0x28(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x4(%rbp)
jmp    11b8 <getbits2+0x88>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
mov    -0x1c(%rbp),%ecx
mov    -0x20(%rbp),%r8d
call   1030 <getbitu2@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getbits2>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %r8d,%r15d
mov    %ecx,%r14d
mov    %edx,%r12d
mov    %esi,%ebx
mov    %rdi,%rbp
mov    $0x1,%edx
call   1050 <getbitu@plt>
test   %rax,%rax
je     117c <getbits2+0x4c>
mov    %rbp,%rdi
mov    %ebx,%esi
mov    %r12d,%edx
call   1040 <getbits@plt>
mov    %eax,%ebx
mov    %r15d,%ecx
shl    %cl,%ebx
mov    %rbp,%rdi
mov    %r14d,%esi
mov    %r15d,%edx
call   1050 <getbitu@plt>
add    %rbx,%rax
jmp    118f <getbits2+0x5f>
mov    %rbp,%rdi
mov    %ebx,%esi
mov    %r12d,%edx
mov    %r14d,%ecx
mov    %r15d,%r8d
call   1030 <getbitu2@plt>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

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