#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 /*<<< orphan*/ number_bits(int);
int calculate_stat_modifier(int bonus) {
  int mod;
  mod = 1;
  while (!number_bits(3))
    mod++;
  if (!number_bits(3))
    mod *= -1;
  mod += bonus;
  if (mod == 0)
    mod = 1;
  return mod;
}


x86 assembly (clang, -O0):
<calculate_stat_modifier>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x1,-0x8(%rbp)
mov    $0x3,%edi
call   1030 <number_bits@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1141 <calculate_stat_modifier+0x31>
jmp    114f <calculate_stat_modifier+0x3f>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1122 <calculate_stat_modifier+0x12>
mov    $0x3,%edi
call   1030 <number_bits@plt>
cmp    $0x0,%eax
jne    1169 <calculate_stat_modifier+0x59>
imul   $0xffffffff,-0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0x4(%rbp),%eax
add    -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jne    1183 <calculate_stat_modifier+0x73>
movl   $0x1,-0x8(%rbp)
mov    -0x8(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<calculate_stat_modifier>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebx
xor    %ebp,%ebp
nopw   0x0(%rax,%rax,1)
mov    $0x3,%edi
call   1030 <number_bits@plt>
add    $0x1,%ebp
test   %eax,%eax
je     1120 <calculate_stat_modifier+0x10>
mov    $0x3,%edi
call   1030 <number_bits@plt>
mov    %ebp,%ecx
neg    %ecx
test   %eax,%eax
cmovne %ebp,%ecx
add    %ebx,%ecx
mov    $0x1,%eax
cmovne %ecx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i32 @calculate_stat_modifier(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %2
store i32 1, i32* %3
br label %4
4: ; preds = %8, %1
%5 = call i32 @number_bits(i32 3)
%6 = icmp ne i32 %5, 0
%7 = xor i1 %6, true
br i1 %7, label %8, label %11
8: ; preds = %4
%9 = load i32, i32* %3
%10 = add nsw i32 %9, 1
store i32 %10, i32* %3
br label %4
11: ; preds = %4
%12 = call i32 @number_bits(i32 3)
%13 = icmp ne i32 %12, 0
br i1 %13, label %17, label %14
14: ; preds = %11
%15 = load i32, i32* %3
%16 = mul nsw i32 %15, -1
store i32 %16, i32* %3
br label %17
17: ; preds = %14, %11
%18 = load i32, i32* %2
%19 = load i32, i32* %3
%20 = add nsw i32 %19, %18
store i32 %20, i32* %3
%21 = load i32, i32* %3
%22 = icmp eq i32 %21, 0
br i1 %22, label %23, label %24
23: ; preds = %17
store i32 1, i32* %3
br label %24
24: ; preds = %23, %17
%25 = load i32, i32* %3
ret i32 %25
}

LLVM IR (-O2):
define i32 @calculate_stat_modifier(i32 %0) {
br label %2
2: ; preds = %2, %1
%3 = phi i32 [ 1, %1 ], [ %6, %2 ]
%4 = tail call i32 @number_bits(i32 3)
%5 = icmp eq i32 %4, 0
%6 = add nuw nsw i32 %3, 1
br i1 %5, label %2, label %7
7: ; preds = %2
%8 = tail call i32 @number_bits(i32 3)
%9 = icmp eq i32 %8, 0
%10 = sub nsw i32 0, %3
%11 = select i1 %9, i32 %10, i32 %3
%12 = add nsw i32 %11, %0
%13 = icmp eq i32 %12, 0
%14 = select i1 %13, i32 1, i32 %12
ret i32 %14
}