#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 */
unsigned int const calclen_df(int, unsigned int const);
const int calc_totalbits(const unsigned int *bit, const unsigned int stops) {
  int i, t = 0;
  for (i = 0; i < 32; i++) {
    if (bit[i])
      t += bit[i] * calclen_df(-2 << i, stops);
  }
  return t;
}


x86 assembly (clang, -O0):
<calc_totalbits>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x10(%rbp)
cmpl   $0x20,-0x10(%rbp)
jge    118a <calc_totalbits+0x7a>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
cmpl   $0x0,(%rax,%rcx,4)
je     1177 <calc_totalbits+0x67>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%ecx
mov    $0xfffffffe,%edi
shl    %cl,%edi
mov    -0xc(%rbp),%esi
call   1030 <calclen_df@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%eax
imul   %ecx,%eax
add    -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
jmp    117c <calc_totalbits+0x6c>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    112d <calc_totalbits+0x1d>
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<calc_totalbits>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %esi,%r14d
mov    %rdi,%r15
xor    %ebp,%ebp
xor    %r12d,%r12d
jmp    113a <calc_totalbits+0x2a>
cs nopw 0x0(%rax,%rax,1)
nop
add    $0x1,%rbp
cmp    $0x20,%rbp
je     115b <calc_totalbits+0x4b>
mov    (%r15,%rbp,4),%ebx
test   %ebx,%ebx
je     1130 <calc_totalbits+0x20>
mov    $0xfffffffe,%edi
mov    %ebp,%ecx
shl    %cl,%edi
mov    %r14d,%esi
call   1030 <calclen_df@plt>
imul   %ebx,%eax
add    %eax,%r12d
jmp    1130 <calc_totalbits+0x20>
mov    %r12d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @calc_totalbits(i32* nocapture %0, i32 %1) {
br label %3
3: ; preds = %2, %15
%4 = phi i64 [ 0, %2 ], [ %17, %15 ]
%5 = phi i32 [ 0, %2 ], [ %16, %15 ]
%6 = getelementptr inbounds i32, i32* %0, i64 %4
%7 = load i32, i32* %6
%8 = icmp eq i32 %7, 0
br i1 %8, label %15, label %9
9: ; preds = %3
%10 = trunc i64 %4 to i32
%11 = shl i32 -2, %10
%12 = tail call i32 @calclen_df(i32 %11, i32 %1)
%13 = mul i32 %12, %7
%14 = add i32 %13, %5
br label %15
15: ; preds = %3, %9
%16 = phi i32 [ %14, %9 ], [ %5, %3 ]
%17 = add nuw nsw i64 %4, 1
%18 = icmp eq i64 %17, 32
br i1 %18, label %19, label %3
19: ; preds = %15
ret i32 %16
}