#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 dirnl_emit(char *, unsigned int, int, int, int);
int find_next_bit(unsigned long const *, int, int);
int bitmap_scnlistprintf(char *buf, unsigned int buflen,
                         const unsigned long *maskp, int nmaskbits) {
  int len = 0;
  int cur, rbot, rtop;
  if (buflen == 0)
    return 0;
  buf[0] = 0;
  rbot = cur = find_next_bit(maskp, nmaskbits, 0);
  while (cur < nmaskbits) {
    rtop = cur;
    cur = find_next_bit(maskp, nmaskbits, cur + 1);
    if (cur >= nmaskbits || cur > rtop + 1) {
      len = dirnl_emit(buf, buflen, rbot, rtop, len);
      rbot = cur;
    }
  }
  return len;
}


x86 assembly (clang, -O0):
<bitmap_scnlistprintf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
cmpl   $0x0,-0x14(%rbp)
jne    1153 <bitmap_scnlistprintf+0x33>
movl   $0x0,-0x4(%rbp)
jmp    11dc <bitmap_scnlistprintf+0xbc>
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x20(%rbp),%rdi
mov    -0x24(%rbp),%esi
xor    %edx,%edx
call   1030 <find_next_bit@plt>
mov    %eax,-0x2c(%rbp)
mov    %eax,-0x30(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    11d6 <bitmap_scnlistprintf+0xb6>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x24(%rbp),%esi
mov    -0x2c(%rbp),%edx
add    $0x1,%edx
call   1030 <find_next_bit@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    11b2 <bitmap_scnlistprintf+0x92>
mov    -0x2c(%rbp),%eax
mov    -0x34(%rbp),%ecx
add    $0x1,%ecx
cmp    %ecx,%eax
jle    11d1 <bitmap_scnlistprintf+0xb1>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x30(%rbp),%edx
mov    -0x34(%rbp),%ecx
mov    -0x28(%rbp),%r8d
call   1040 <dirnl_emit@plt>
mov    %eax,-0x28(%rbp)
mov    -0x2c(%rbp),%eax
mov    %eax,-0x30(%rbp)
jmp    116e <bitmap_scnlistprintf+0x4e>
mov    -0x28(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bitmap_scnlistprintf>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %esi,0xc(%rsp)
test   %esi,%esi
je     11bb <bitmap_scnlistprintf+0x9b>
mov    %ecx,%ebx
mov    %rdx,%rbp
mov    %rdi,0x10(%rsp)
movb   $0x0,(%rdi)
movl   $0x0,0x8(%rsp)
mov    %rdx,%rdi
mov    %ecx,%esi
xor    %edx,%edx
call   1030 <find_next_bit@plt>
cmp    %ebx,%eax
jge    11c3 <bitmap_scnlistprintf+0xa3>
mov    %eax,%r12d
movl   $0x0,0x8(%rsp)
mov    %eax,%r15d
jmp    119a <bitmap_scnlistprintf+0x7a>
nop
mov    0x10(%rsp),%rdi
mov    0xc(%rsp),%esi
mov    %r12d,%edx
mov    %r15d,%ecx
mov    0x8(%rsp),%r8d
call   1040 <dirnl_emit@plt>
mov    %eax,0x8(%rsp)
mov    %ebp,%r12d
mov    %ebp,%r15d
cmp    %ebx,%ebp
mov    %r13,%rbp
jge    11c3 <bitmap_scnlistprintf+0xa3>
lea    0x1(%r15),%r14d
mov    %rbp,%r13
mov    %rbp,%rdi
mov    %ebx,%esi
mov    %r14d,%edx
call   1030 <find_next_bit@plt>
mov    %eax,%ebp
cmp    %ebx,%eax
jge    1170 <bitmap_scnlistprintf+0x50>
cmp    %r14d,%ebp
jle    1190 <bitmap_scnlistprintf+0x70>
jmp    1170 <bitmap_scnlistprintf+0x50>
movl   $0x0,0x8(%rsp)
mov    0x8(%rsp),%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @bitmap_scnlistprintf(i8* %0, i32 %1, i64* %2, i32 %3) {
%5 = icmp eq i32 %1, 0
br i1 %5, label %24, label %6
6: ; preds = %4
store i8 0, i8* %0
%7 = tail call i32 @find_next_bit(i64* %2, i32 %3, i32 0)
%8 = icmp slt i32 %7, %3
br i1 %8, label %9, label %24
9: ; preds = %6, %20
%10 = phi i32 [ %22, %20 ], [ %7, %6 ]
%11 = phi i32 [ %14, %20 ], [ %7, %6 ]
%12 = phi i32 [ %21, %20 ], [ 0, %6 ]
%13 = add nsw i32 %11, 1
%14 = tail call i32 @find_next_bit(i64* %2, i32 %3, i32 %13)
%15 = icmp sge i32 %14, %3
%16 = icmp sgt i32 %14, %13
%17 = or i1 %15, %16
br i1 %17, label %18, label %20
18: ; preds = %9
%19 = tail call i32 @dirnl_emit(i8* %0, i32 %1, i32 %10, i32 %11, i32 %12)
br label %20
20: ; preds = %9, %18
%21 = phi i32 [ %19, %18 ], [ %12, %9 ]
%22 = phi i32 [ %14, %18 ], [ %10, %9 ]
%23 = icmp slt i32 %14, %3
br i1 %23, label %9, label %24
24: ; preds = %20, %6, %4
%25 = phi i32 [ 0, %4 ], [ 0, %6 ], [ %21, %20 ]
ret i32 %25
}