#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*/ printf(char const *);
void test_bits(const char **names, unsigned int val) {
  unsigned int i;
  for (i = 0; i < 32; ++i) {
    if (names[i][0] && (val & 1)) {
      printf(names[i]);
      printf("\n");
    }
    val >>= 1;
  }
}


x86 assembly (clang, -O0):
<test_bits>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
cmpl   $0x20,-0x10(%rbp)
jae    1189 <test_bits+0x79>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%ecx
mov    (%rax,%rcx,8),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1172 <test_bits+0x62>
mov    -0xc(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     1172 <test_bits+0x62>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%ecx
mov    (%rax,%rcx,8),%rdi
call   1030 <printf@plt>
lea    0xe93(%rip),%rdi
call   1030 <printf@plt>
mov    -0xc(%rbp),%eax
shr    $0x1,%eax
mov    %eax,-0xc(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1126 <test_bits+0x16>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_bits>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%ebp
mov    %rdi,%r14
xor    %ebx,%ebx
jmp    113c <test_bits+0x1c>
nopl   (%rax)
shr    %ebp
add    $0x1,%rbx
cmp    $0x20,%rbx
je     115d <test_bits+0x3d>
mov    (%r14,%rbx,8),%rdi
cmpb   $0x0,(%rdi)
je     1130 <test_bits+0x10>
mov    %ebp,%eax
and    $0x1,%eax
je     1130 <test_bits+0x10>
call   1040 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
jmp    1130 <test_bits+0x10>
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"\0A\00"
define void @test_bits(i8** %0, i32 %1) {
%3 = alloca i8**
%4 = alloca i32
%5 = alloca i32
store i8** %0, i8*** %3
store i32 %1, i32* %4
store i32 0, i32* %5
br label %6
6: ; preds = %34, %2
%7 = load i32, i32* %5
%8 = icmp ult i32 %7, 32
br i1 %8, label %9, label %37
9: ; preds = %6
%10 = load i8**, i8*** %3
%11 = load i32, i32* %5
%12 = zext i32 %11 to i64
%13 = getelementptr inbounds i8*, i8** %10, i64 %12
%14 = load i8*, i8** %13
%15 = getelementptr inbounds i8, i8* %14, i64 0
%16 = load i8, i8* %15
%17 = sext i8 %16 to i32
%18 = icmp ne i32 %17, 0
br i1 %18, label %19, label %31
19: ; preds = %9
%20 = load i32, i32* %4
%21 = and i32 %20, 1
%22 = icmp ne i32 %21, 0
br i1 %22, label %23, label %31
23: ; preds = %19
%24 = load i8**, i8*** %3
%25 = load i32, i32* %5
%26 = zext i32 %25 to i64
%27 = getelementptr inbounds i8*, i8** %24, i64 %26
%28 = load i8*, i8** %27
%29 = call i32 @printf(i8* %28)
%30 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %31
31: ; preds = %23, %19, %9
%32 = load i32, i32* %4
%33 = lshr i32 %32, 1
store i32 %33, i32* %4
br label %34
34: ; preds = %31
%35 = load i32, i32* %5
%36 = add i32 %35, 1
store i32 %36, i32* %5
br label %6
37: ; preds = %6
ret void
}

LLVM IR (-O2):
define void @test_bits(i8** nocapture %0, i32 %1) {
br label %3
3: ; preds = %2, %16
%4 = phi i64 [ 0, %2 ], [ %18, %16 ]
%5 = phi i32 [ %1, %2 ], [ %17, %16 ]
%6 = getelementptr inbounds i8*, i8** %0, i64 %4
%7 = load i8*, i8** %6
%8 = load i8, i8* %7
%9 = icmp eq i8 %8, 0
%10 = and i32 %5, 1
%11 = icmp eq i32 %10, 0
%12 = select i1 %9, i1 true, i1 %11
br i1 %12, label %16, label %13
13: ; preds = %3
%14 = tail call i32 @printf(i8* %7)
%15 = tail call i32 @putchar(i32 10)
br label %16
16: ; preds = %13, %3
%17 = lshr i32 %5, 1
%18 = add nuw nsw i64 %4, 1
%19 = icmp eq i64 %18, 32
br i1 %19, label %20, label %3
20: ; preds = %16
ret void
}