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

/* Variables and functions */
int /*<<< orphan*/ snprintf(char *, int, char *, char const *);
char *strbits(const char **m, uint32_t val) {
  static char buf[2048];
  char *b = buf;
  *b = 0;
  for (; *m; ++m, val >>= 1)
    if (val & 1)
      b += snprintf(b, sizeof(buf) - (b - buf), "%s, ", *m);
  return buf;
}


x86 assembly (clang, -O0):
<strbits>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
lea    0x2f1a(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x8(%rbp),%rax
cmpq   $0x0,(%rax)
je     11ac <strbits+0x9c>
mov    -0xc(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     118d <strbits+0x7d>
mov    -0x18(%rbp),%rdi
mov    -0x18(%rbp),%rcx
lea    0x2ee3(%rip),%rax
sub    %rax,%rcx
mov    $0x800,%eax
sub    %rcx,%rax
mov    %eax,%esi
mov    -0x8(%rbp),%rax
mov    (%rax),%rcx
lea    0xe88(%rip),%rdx
call   1030 <snprintf@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x18(%rbp)
jmp    1192 <strbits+0x82>
mov    -0x8(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x8(%rbp)
mov    -0xc(%rbp),%eax
sar    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1131 <strbits+0x21>
lea    0x2e8d(%rip),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strbits>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
movb   $0x0,0x2f21(%rip)
mov    (%rdi),%rcx
test   %rcx,%rcx
je     1182 <strbits+0x72>
mov    %esi,%ebp
mov    %rdi,%rbx
add    $0x8,%rbx
lea    0x2f09(%rip),%r12
lea    0xec2(%rip),%r14
mov    %r12,%r15
jmp    115e <strbits+0x4e>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
sar    %ebp
mov    (%rbx),%rcx
add    $0x8,%rbx
test   %rcx,%rcx
je     1182 <strbits+0x72>
test   $0x1,%bpl
je     1150 <strbits+0x40>
mov    %r12d,%esi
sub    %r15d,%esi
add    $0x800,%esi
mov    %r15,%rdi
mov    %r14,%rdx
call   1030 <snprintf@plt>
cltq
add    %rax,%r15
jmp    1150 <strbits+0x40>
lea    0x2eb7(%rip),%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@strbits.buf = internal global [2048 x i8] zeroinitializer
@.str = [5 x i8] c"%s, \00"
define i8* @strbits(i8** %0, i32 %1) {
%3 = alloca i8**
%4 = alloca i32
%5 = alloca i8*
store i8** %0, i8*** %3
store i32 %1, i32* %4
store i8* getelementptr inbounds ([2048 x i8], [2048 x i8]* @strbits.buf, i64 0, i64 0), i8** %5
%6 = load i8*, i8** %5
store i8 0, i8* %6
br label %7
7: ; preds = %29, %2
%8 = load i8**, i8*** %3
%9 = load i8*, i8** %8
%10 = icmp ne i8* %9, null
br i1 %10, label %11, label %34
11: ; preds = %7
%12 = load i32, i32* %4
%13 = and i32 %12, 1
%14 = icmp ne i32 %13, 0
br i1 %14, label %15, label %28
15: ; preds = %11
%16 = load i8*, i8** %5
%17 = load i8*, i8** %5
%18 = ptrtoint i8* %17 to i64
%19 = sub i64 %18, ptrtoint ([2048 x i8]* @strbits.buf to i64)
%20 = sub i64 2048, %19
%21 = trunc i64 %20 to i32
%22 = load i8**, i8*** %3
%23 = load i8*, i8** %22
%24 = call i32 @snprintf(i8* %16, i32 %21, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %23)
%25 = load i8*, i8** %5
%26 = sext i32 %24 to i64
%27 = getelementptr inbounds i8, i8* %25, i64 %26
store i8* %27, i8** %5
br label %28
28: ; preds = %15, %11
br label %29
29: ; preds = %28
%30 = load i8**, i8*** %3
%31 = getelementptr inbounds i8*, i8** %30, i32 1
store i8** %31, i8*** %3
%32 = load i32, i32* %4
%33 = ashr i32 %32, 1
store i32 %33, i32* %4
br label %7
34: ; preds = %7
ret i8* getelementptr inbounds ([2048 x i8], [2048 x i8]* @strbits.buf, i64 0, i64 0)
}

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