#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 */
typedef int /*<<< orphan*/ buffer;

/* Variables and functions */
int /*<<< orphan*/ snprintf(char *, int, char *, char, char *);
char *strchr(char *, char);
int /*<<< orphan*/ strcpy(char *, char *);
int /*<<< orphan*/ strlen(char *);
const char *help_bitfield(char **bit_names) {
  static char buffer[1024];
  char *pos, sepa = ':';
  unsigned int bit;
  strcpy(buffer, "bitfield");
  pos = strchr(buffer, '\0');
  for (bit = 0; bit < 32; ++bit) {
    if (bit_names[bit] == NULL)
      continue;
    snprintf(pos, sizeof(buffer) - (pos - buffer), "%c %s", sepa,
             bit_names[bit]);
    pos += strlen(pos);
    sepa = ',';
  }
  return buffer;
}


x86 assembly (clang, -O0):
<help_bitfield>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movb   $0x3a,-0x11(%rbp)
lea    0x2ef9(%rip),%rdi
lea    0xea2(%rip),%rsi
call   1030 <strcpy@plt>
lea    0x2ee6(%rip),%rdi
xor    %esi,%esi
call   1050 <strchr@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
cmpl   $0x20,-0x18(%rbp)
jae    1201 <help_bitfield+0xc1>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%ecx
cmpq   $0x0,(%rax,%rcx,8)
jne    119d <help_bitfield+0x5d>
jmp    11f3 <help_bitfield+0xb3>
mov    -0x10(%rbp),%rdi
mov    -0x10(%rbp),%rcx
lea    0x2ea4(%rip),%rax
sub    %rax,%rcx
mov    $0x400,%eax
sub    %rcx,%rax
mov    %eax,%esi
mov    -0x11(%rbp),%al
mov    -0x8(%rbp),%rcx
mov    -0x18(%rbp),%edx
mov    (%rcx,%rdx,8),%r8
lea    0xe3b(%rip),%rdx
movsbl %al,%ecx
call   1060 <snprintf@plt>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x10(%rbp)
movb   $0x2c,-0x11(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    117c <help_bitfield+0x3c>
lea    0x2e48(%rip),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<help_bitfield>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rdi,%r15
lea    0x2f0d(%rip),%r14
lea    0xeb6(%rip),%rsi
mov    %r14,%rdi
call   1030 <strcpy@plt>
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %rax,%r13
add    %r14,%r13
mov    $0x3a,%al
xor    %ebx,%ebx
lea    0xe9e(%rip),%r12
jmp    117a <help_bitfield+0x4a>
nopl   (%rax)
add    $0x1,%rbx
cmp    $0x20,%rbx
je     11ae <help_bitfield+0x7e>
mov    (%r15,%rbx,8),%r8
test   %r8,%r8
je     1170 <help_bitfield+0x40>
mov    %r14d,%esi
sub    %r13d,%esi
add    $0x400,%esi
movsbl %al,%ecx
mov    %r13,%rdi
mov    %r12,%rdx
call   1050 <snprintf@plt>
mov    %r13,%rdi
call   1040 <strlen@plt>
cltq
add    %rax,%r13
mov    $0x2c,%al
jmp    1170 <help_bitfield+0x40>
lea    0x2e9b(%rip),%rax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@help_bitfield.buffer = internal global [1024 x i8] zeroinitializer
@.str = [9 x i8] c"bitfield\00"
@.str.1 = [6 x i8] c"%c %s\00"
define i8* @help_bitfield(i8** %0) {
%2 = alloca i8**
%3 = alloca i8*
%4 = alloca i8
%5 = alloca i32
store i8** %0, i8*** %2
store i8 58, i8* %4
%6 = call i32 @strcpy(i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @help_bitfield.buffer, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%7 = call i8* @strchr(i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @help_bitfield.buffer, i64 0, i64 0), i8 signext 0)
store i8* %7, i8** %3
store i32 0, i32* %5
br label %8
8: ; preds = %38, %1
%9 = load i32, i32* %5
%10 = icmp ult i32 %9, 32
br i1 %10, label %11, label %41
11: ; preds = %8
%12 = load i8**, i8*** %2
%13 = load i32, i32* %5
%14 = zext i32 %13 to i64
%15 = getelementptr inbounds i8*, i8** %12, i64 %14
%16 = load i8*, i8** %15
%17 = icmp eq i8* %16, null
br i1 %17, label %18, label %19
18: ; preds = %11
br label %38
19: ; preds = %11
%20 = load i8*, i8** %3
%21 = load i8*, i8** %3
%22 = ptrtoint i8* %21 to i64
%23 = sub i64 %22, ptrtoint ([1024 x i8]* @help_bitfield.buffer to i64)
%24 = sub i64 1024, %23
%25 = trunc i64 %24 to i32
%26 = load i8, i8* %4
%27 = load i8**, i8*** %2
%28 = load i32, i32* %5
%29 = zext i32 %28 to i64
%30 = getelementptr inbounds i8*, i8** %27, i64 %29
%31 = load i8*, i8** %30
%32 = call i32 @snprintf(i8* %20, i32 %25, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8 signext %26, i8* %31)
%33 = load i8*, i8** %3
%34 = call i32 @strlen(i8* %33)
%35 = load i8*, i8** %3
%36 = sext i32 %34 to i64
%37 = getelementptr inbounds i8, i8* %35, i64 %36
store i8* %37, i8** %3
store i8 44, i8* %4
br label %38
38: ; preds = %19, %18
%39 = load i32, i32* %5
%40 = add i32 %39, 1
store i32 %40, i32* %5
br label %8
41: ; preds = %8
ret i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @help_bitfield.buffer, i64 0, i64 0)
}

LLVM IR (-O2):
@help_bitfield.buffer = internal global [1024 x i8] zeroinitializer
@.str = [9 x i8] c"bitfield\00"
@.str.1 = [6 x i8] c"%c %s\00"
define i8* @help_bitfield(i8** nocapture %0) {
%2 = tail call i32 @strcpy(i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @help_bitfield.buffer, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%3 = tail call i64 bitcast (i32 (i8*)* @strlen to i64 (i8*)*)(i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @help_bitfield.buffer, i64 0, i64 0))
%4 = getelementptr [1024 x i8], [1024 x i8]* @help_bitfield.buffer, i64 0, i64 %3
br label %5
5: ; preds = %1, %20
%6 = phi i64 [ 0, %1 ], [ %23, %20 ]
%7 = phi i8 [ 58, %1 ], [ %22, %20 ]
%8 = phi i8* [ %4, %1 ], [ %21, %20 ]
%9 = getelementptr inbounds i8*, i8** %0, i64 %6
%10 = load i8*, i8** %9
%11 = icmp eq i8* %10, null
br i1 %11, label %20, label %12
12: ; preds = %5
%13 = ptrtoint i8* %8 to i64
%14 = trunc i64 %13 to i32
%15 = sub i32 trunc (i64 add (i64 ptrtoint ([1024 x i8]* @help_bitfield.buffer to i64), i64 1024) to i32), %14
%16 = tail call i32 @snprintf(i8* %8, i32 %15, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8 signext %7, i8* %10)
%17 = tail call i32 @strlen(i8* %8)
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8, i8* %8, i64 %18
br label %20
20: ; preds = %5, %12
%21 = phi i8* [ %8, %5 ], [ %19, %12 ]
%22 = phi i8 [ %7, %5 ], [ 44, %12 ]
%23 = add nuw nsw i64 %6, 1
%24 = icmp eq i64 %23, 32
br i1 %24, label %25, label %5
25: ; preds = %20
ret i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @help_bitfield.buffer, i64 0, i64 0)
}