#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*/ signal(int, void (*)(int));
void bb_signals(int sigs, void (*f)(int)) {
  int sig_no = 0;
  int bit = 1;
  while (sigs) {
    if (sigs & bit) {
      sigs &= ~bit;
      signal(sig_no, f);
    }
    sig_no++;
    bit <<= 1;
  }
}


x86 assembly (clang, -O0):
<bb_signals>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x1,-0x18(%rbp)
cmpl   $0x0,-0x4(%rbp)
je     1175 <bb_signals+0x65>
mov    -0x4(%rbp),%eax
and    -0x18(%rbp),%eax
cmp    $0x0,%eax
je     115e <bb_signals+0x4e>
mov    -0x18(%rbp),%eax
xor    $0xffffffff,%eax
and    -0x4(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x14(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1030 <signal@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x18(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    112d <bb_signals+0x1d>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bb_signals>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
test   %edi,%edi
je     1152 <bb_signals+0x42>
mov    %rsi,%r14
mov    %edi,%r15d
xor    %ebx,%ebx
mov    $0x1,%ebp
jmp    113a <bb_signals+0x2a>
nopw   0x0(%rax,%rax,1)
add    $0x1,%ebx
add    %ebp,%ebp
test   %r15d,%r15d
je     1152 <bb_signals+0x42>
test   %r15d,%ebp
je     1130 <bb_signals+0x20>
mov    %ebp,%eax
not    %eax
and    %eax,%r15d
mov    %ebx,%edi
mov    %r14,%rsi
call   1030 <signal@plt>
jmp    1130 <bb_signals+0x20>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define void @bb_signals(i32 %0, void (i32)* %1) {
%3 = icmp eq i32 %0, 0
br i1 %3, label %19, label %4
4: ; preds = %2, %14
%5 = phi i32 [ %17, %14 ], [ 1, %2 ]
%6 = phi i32 [ %16, %14 ], [ 0, %2 ]
%7 = phi i32 [ %15, %14 ], [ %0, %2 ]
%8 = and i32 %5, %7
%9 = icmp eq i32 %8, 0
br i1 %9, label %14, label %10
10: ; preds = %4
%11 = xor i32 %5, -1
%12 = and i32 %7, %11
%13 = tail call i32 @signal(i32 %6, void (i32)* %1)
br label %14
14: ; preds = %10, %4
%15 = phi i32 [ %12, %10 ], [ %7, %4 ]
%16 = add nuw nsw i32 %6, 1
%17 = shl i32 %5, 1
%18 = icmp eq i32 %15, 0
br i1 %18, label %19, label %4
19: ; preds = %14, %2
ret void
}