#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 print_flags(const char **attributes, int p, int r, int pr) {
  int i;
  printf("Selected flags:\n");
  i = 0;
  while (attributes[i]) {
    if (p & (1 << i)) {
      printf("\tPERMITS   : %s\n", attributes[i]);
    } else if (r & (1 << i)) {
      printf("\tREQUIRES  : %s\n", attributes[i]);
    } else if (pr & (1 << i)) {
      printf("\tPROHIBITS : %s\n", attributes[i]);
    }
    ++i;
  }
  printf("\n");
}


x86 assembly (clang, -O0):
<print_flags>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
lea    0xed4(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
je     120b <print_flags+0xfb>
mov    -0xc(%rbp),%eax
mov    -0x18(%rbp),%ecx
mov    $0x1,%edx
shl    %cl,%edx
mov    %edx,%ecx
and    %ecx,%eax
cmp    $0x0,%eax
je     1186 <print_flags+0x76>
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
lea    0xe97(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11fd <print_flags+0xed>
mov    -0x10(%rbp),%eax
mov    -0x18(%rbp),%ecx
mov    $0x1,%edx
shl    %cl,%edx
mov    %edx,%ecx
and    %ecx,%eax
cmp    $0x0,%eax
je     11bf <print_flags+0xaf>
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
lea    0xe6f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11f8 <print_flags+0xe8>
mov    -0x14(%rbp),%eax
mov    -0x18(%rbp),%ecx
mov    $0x1,%edx
shl    %cl,%edx
mov    %edx,%ecx
and    %ecx,%eax
cmp    $0x0,%eax
je     11f3 <print_flags+0xe3>
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
lea    0xe47(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11f8 <print_flags+0xe8>
jmp    11fd <print_flags+0xed>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    113a <print_flags+0x2a>
lea    0xdfd(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_flags>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %ecx,0x4(%rsp)
mov    %edx,%r15d
mov    %esi,%r12d
mov    %rdi,%rbp
lea    0xee4(%rip),%rdi
call   1040 <puts@plt>
mov    0x0(%rbp),%rsi
test   %rsi,%rsi
je     11b5 <print_flags+0x85>
lea    0xe9c(%rip),%r13
lea    0xea6(%rip),%r14
xor    %ebx,%ebx
nopl   (%rax)
mov    $0x1,%eax
mov    %ebx,%ecx
shl    %cl,%eax
bt     %ebx,%r12d
mov    %r13,%rdi
jb     11a0 <print_flags+0x70>
mov    %r14,%rdi
test   %r15d,%eax
jne    11a0 <print_flags+0x70>
lea    0xe91(%rip),%rdi
test   %eax,0x4(%rsp)
je     11a7 <print_flags+0x77>
nopw   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x8(%rbp,%rbx,8),%rsi
add    $0x1,%rbx
test   %rsi,%rsi
jne    1170 <print_flags+0x40>
mov    $0xa,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <putchar@plt>

LLVM IR (-O0):
@.str = [17 x i8] c"Selected flags:\0A\00"
@.str.1 = [17 x i8] c"\09PERMITS : %s\0A\00"
@.str.2 = [17 x i8] c"\09REQUIRES : %s\0A\00"
@.str.3 = [17 x i8] c"\09PROHIBITS : %s\0A\00"
@.str.4 = [2 x i8] c"\0A\00"
define void @print_flags(i8** %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i8** %0, i8*** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %9
br label %11
11: ; preds = %59, %4
%12 = load i8**, i8*** %5
%13 = load i32, i32* %9
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds i8*, i8** %12, i64 %14
%16 = load i8*, i8** %15
%17 = icmp ne i8* %16, null
br i1 %17, label %18, label %62
18: ; preds = %11
%19 = load i32, i32* %6
%20 = load i32, i32* %9
%21 = shl i32 1, %20
%22 = and i32 %19, %21
%23 = icmp ne i32 %22, 0
br i1 %23, label %24, label %31
24: ; preds = %18
%25 = load i8**, i8*** %5
%26 = load i32, i32* %9
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i8*, i8** %25, i64 %27
%29 = load i8*, i8** %28
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* %29)
br label %59
31: ; preds = %18
%32 = load i32, i32* %7
%33 = load i32, i32* %9
%34 = shl i32 1, %33
%35 = and i32 %32, %34
%36 = icmp ne i32 %35, 0
br i1 %36, label %37, label %44
37: ; preds = %31
%38 = load i8**, i8*** %5
%39 = load i32, i32* %9
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i8*, i8** %38, i64 %40
%42 = load i8*, i8** %41
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8* %42)
br label %58
44: ; preds = %31
%45 = load i32, i32* %8
%46 = load i32, i32* %9
%47 = shl i32 1, %46
%48 = and i32 %45, %47
%49 = icmp ne i32 %48, 0
br i1 %49, label %50, label %57
50: ; preds = %44
%51 = load i8**, i8*** %5
%52 = load i32, i32* %9
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds i8*, i8** %51, i64 %53
%55 = load i8*, i8** %54
%56 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), i8* %55)
br label %57
57: ; preds = %50, %44
br label %58
58: ; preds = %57, %37
br label %59
59: ; preds = %58, %24
%60 = load i32, i32* %9
%61 = add nsw i32 %60, 1
store i32 %61, i32* %9
br label %11
62: ; preds = %11
%63 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str.1 = [17 x i8] c"\09PERMITS : %s\0A\00"
@.str.2 = [17 x i8] c"\09REQUIRES : %s\0A\00"
@.str.3 = [17 x i8] c"\09PROHIBITS : %s\0A\00"
@str = [16 x i8] c"Selected flags:\00"
define void @print_flags(i8** nocapture %0, i32 %1, i32 %2, i32 %3) {
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str, i64 0, i64 0))
%6 = load i8*, i8** %0
%7 = icmp eq i8* %6, null
br i1 %7, label %29, label %8
8: ; preds = %4, %24
%9 = phi i64 [ %25, %24 ], [ 0, %4 ]
%10 = phi i8* [ %27, %24 ], [ %6, %4 ]
%11 = trunc i64 %9 to i32
%12 = shl nuw i32 1, %11
%13 = and i32 %12, %1
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %21
15: ; preds = %8
%16 = and i32 %12, %2
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %15
%19 = and i32 %12, %3
%20 = icmp eq i32 %19, 0
br i1 %20, label %24, label %21
21: ; preds = %18, %15, %8
%22 = phi i8* [ getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), %8 ], [ getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), %15 ], [ getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), %18 ]
%23 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) %22, i8* %10)
br label %24
24: ; preds = %21, %18
%25 = add nuw i64 %9, 1
%26 = getelementptr inbounds i8*, i8** %0, i64 %25
%27 = load i8*, i8** %26
%28 = icmp eq i8* %27, null
br i1 %28, label %29, label %8
29: ; preds = %24, %4
%30 = tail call i32 @putchar(i32 10)
ret void
}