#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 *, ...);
void flag_decode(unsigned long reg, const char *flags[]) {
  unsigned int i;
  for (i = 0; i < 32; i++) {
    if (reg & (1 << i)) {
      if (flags[i])
        printf(" %s", flags[i]);
      else
        printf(" [%u]", i);
    }
  }
}


x86 assembly (clang, -O0):
<flag_decode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x20,-0x14(%rbp)
jae    11aa <flag_decode+0x9a>
mov    -0x8(%rbp),%rax
mov    -0x14(%rbp),%ecx
mov    $0x1,%edx
shl    %cl,%edx
mov    %edx,%ecx
movslq %ecx,%rcx
and    %rcx,%rax
cmp    $0x0,%rax
je     1197 <flag_decode+0x87>
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
cmpq   $0x0,(%rax,%rcx,8)
je     1181 <flag_decode+0x71>
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
mov    (%rax,%rcx,8),%rsi
lea    0xe8b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1192 <flag_decode+0x82>
mov    -0x14(%rbp),%esi
lea    0xe79(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1197 <flag_decode+0x87>
jmp    119c <flag_decode+0x8c>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1127 <flag_decode+0x17>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<flag_decode>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r13
lea    0xede(%rip),%r15
lea    0xed3(%rip),%r12
xor    %ebx,%ebx
jmp    1156 <flag_decode+0x46>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1030 <printf@plt>
add    $0x1,%rbx
cmp    $0x20,%rbx
je     117b <flag_decode+0x6b>
mov    $0x1,%eax
mov    %ebx,%ecx
shl    %cl,%eax
cltq
test   %r13,%rax
je     114c <flag_decode+0x3c>
mov    (%r14,%rbx,8),%rsi
test   %rsi,%rsi
je     1140 <flag_decode+0x30>
mov    %r12,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
jmp    114c <flag_decode+0x3c>
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@.str = [4 x i8] c" %s\00"
@.str.1 = [6 x i8] c" [%u]\00"
define void @flag_decode(i64 %0, i8** nocapture %1) {
br label %3
3: ; preds = %2, %18
%4 = phi i64 [ 0, %2 ], [ %19, %18 ]
%5 = trunc i64 %4 to i32
%6 = shl nuw i32 1, %5
%7 = sext i32 %6 to i64
%8 = and i64 %7, %0
%9 = icmp eq i64 %8, 0
br i1 %9, label %18, label %10
10: ; preds = %3
%11 = getelementptr inbounds i8*, i8** %1, i64 %4
%12 = load i8*, i8** %11
%13 = icmp eq i8* %12, null
br i1 %13, label %16, label %14
14: ; preds = %10
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %12)
br label %18
16: ; preds = %10
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %5)
br label %18
18: ; preds = %3, %16, %14
%19 = add nuw nsw i64 %4, 1
%20 = icmp eq i64 %19, 32
br i1 %20, label %21, label %3
21: ; preds = %18
ret void
}