#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;

/* Variables and functions */
int /*<<< orphan*/ printf(char const *);
void print_modifiers(uint32_t mask) {
  const char *MODIFIERS[] = {
      "Shift", "Lock",    "Ctrl",    "Alt",     "Mod2",    "Mod3",   "Mod4",
      "Mod5",  "Button1", "Button2", "Button3", "Button4", "Button5"};
  printf("modifier mask: ");
  for (const char **modifier = MODIFIERS; mask; mask >>= 1, ++modifier) {
    if (mask & 1) {
      printf(*modifier);
    }
  }
  printf("\n");
}


x86 assembly (clang, -O0):
<print_modifiers>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %edi,-0x4(%rbp)
lea    -0x70(%rbp),%rdi
lea    0x2c77(%rip),%rsi
mov    $0x68,%edx
call   1040 <memcpy@plt>
lea    0xf06(%rip),%rdi
call   1030 <printf@plt>
lea    -0x70(%rbp),%rax
mov    %rax,-0x78(%rbp)
cmpl   $0x0,-0x4(%rbp)
je     119b <print_modifiers+0x7b>
mov    -0x4(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     117c <print_modifiers+0x5c>
mov    -0x78(%rbp),%rax
mov    (%rax),%rdi
call   1030 <printf@plt>
jmp    1181 <print_modifiers+0x61>
mov    -0x4(%rbp),%eax
sar    $0x1,%eax
mov    %eax,-0x4(%rbp)
mov    -0x78(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x78(%rbp)
jmp    1157 <print_modifiers+0x37>
lea    0xebe(%rip),%rdi
call   1030 <printf@plt>
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_modifiers>:
push   %rbp
push   %rbx
sub    $0x68,%rsp
mov    %edi,%ebp
mov    0x2ce1(%rip),%rax
mov    %rax,0x60(%rsp)
movaps 0x2cc5(%rip),%xmm0
movaps %xmm0,0x50(%rsp)
movaps 0x2ca9(%rip),%xmm0
movaps %xmm0,0x40(%rsp)
movaps 0x2c8d(%rip),%xmm0
movaps %xmm0,0x30(%rsp)
movaps 0x2c71(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movaps 0x2c55(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movaps 0x2c39(%rip),%xmm0
movaps %xmm0,(%rsp)
lea    0xece(%rip),%rdi
call   1040 <printf@plt>
test   %ebp,%ebp
je     11af <print_modifiers+0x8f>
mov    %rsp,%rbx
jmp    119f <print_modifiers+0x7f>
mov    %ebp,%eax
sar    %eax
add    $0x8,%rbx
cmp    $0x2,%ebp
mov    %eax,%ebp
jb     11af <print_modifiers+0x8f>
test   $0x1,%bpl
je     1190 <print_modifiers+0x70>
mov    (%rbx),%rdi
call   1040 <printf@plt>
jmp    1190 <print_modifiers+0x70>
mov    $0xa,%edi
add    $0x68,%rsp
pop    %rbx
pop    %rbp
jmp    1030 <putchar@plt>

LLVM IR (-O0):
@.str = [6 x i8] c"Shift\00"
@.str.1 = [5 x i8] c"Lock\00"
@.str.2 = [5 x i8] c"Ctrl\00"
@.str.3 = [4 x i8] c"Alt\00"
@.str.4 = [5 x i8] c"Mod2\00"
@.str.5 = [5 x i8] c"Mod3\00"
@.str.6 = [5 x i8] c"Mod4\00"
@.str.7 = [5 x i8] c"Mod5\00"
@.str.8 = [8 x i8] c"Button1\00"
@.str.9 = [8 x i8] c"Button2\00"
@.str.10 = [8 x i8] c"Button3\00"
@.str.11 = [8 x i8] c"Button4\00"
@.str.12 = [8 x i8] c"Button5\00"
@__const.print_modifiers.MODIFIERS = [13 x i8*] [i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i32 0, i32 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.8, i32 0, i32 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.9, i32 0, i32 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.10, i32 0, i32 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.11, i32 0, i32 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.12, i32 0, i32 0)]
@.str.13 = [16 x i8] c"modifier mask: \00"
@.str.14 = [2 x i8] c"\0A\00"
define void @print_modifiers(i32 %0) {
%2 = alloca i32
%3 = alloca [13 x i8*]
%4 = alloca i8**
store i32 %0, i32* %2
%5 = bitcast [13 x i8*]* %3 to i8*
%6 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.13, i64 0, i64 0))
%7 = getelementptr inbounds [13 x i8*], [13 x i8*]* %3, i64 0, i64 0
store i8** %7, i8*** %4
br label %8
8: ; preds = %20, %1
%9 = load i32, i32* %2
%10 = icmp ne i32 %9, 0
br i1 %10, label %11, label %25
11: ; preds = %8
%12 = load i32, i32* %2
%13 = and i32 %12, 1
%14 = icmp ne i32 %13, 0
br i1 %14, label %15, label %19
15: ; preds = %11
%16 = load i8**, i8*** %4
%17 = load i8*, i8** %16
%18 = call i32 @printf(i8* %17)
br label %19
19: ; preds = %15, %11
br label %20
20: ; preds = %19
%21 = load i32, i32* %2
%22 = ashr i32 %21, 1
store i32 %22, i32* %2
%23 = load i8**, i8*** %4
%24 = getelementptr inbounds i8*, i8** %23, i32 1
store i8** %24, i8*** %4
br label %8
25: ; preds = %8
%26 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.14, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [6 x i8] c"Shift\00"
@.str.1 = [5 x i8] c"Lock\00"
@.str.2 = [5 x i8] c"Ctrl\00"
@.str.3 = [4 x i8] c"Alt\00"
@.str.4 = [5 x i8] c"Mod2\00"
@.str.5 = [5 x i8] c"Mod3\00"
@.str.6 = [5 x i8] c"Mod4\00"
@.str.7 = [5 x i8] c"Mod5\00"
@.str.8 = [8 x i8] c"Button1\00"
@.str.9 = [8 x i8] c"Button2\00"
@.str.10 = [8 x i8] c"Button3\00"
@.str.11 = [8 x i8] c"Button4\00"
@.str.12 = [8 x i8] c"Button5\00"
@__const.print_modifiers.MODIFIERS = [13 x i8*] [i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i32 0, i32 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.8, i32 0, i32 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.9, i32 0, i32 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.10, i32 0, i32 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.11, i32 0, i32 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.12, i32 0, i32 0)]
@.str.13 = [16 x i8] c"modifier mask: \00"
define void @print_modifiers(i32 %0) {
%2 = alloca [13 x i8*]
%3 = bitcast [13 x i8*]* %2 to i8*
%4 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.13, i64 0, i64 0))
%5 = icmp eq i32 %0, 0
br i1 %5, label %8, label %6
6: ; preds = %1
%7 = getelementptr inbounds [13 x i8*], [13 x i8*]* %2, i64 0, i64 0
br label %10
8: ; preds = %18, %1
%9 = tail call i32 @putchar(i32 10)
ret void
10: ; preds = %6, %18
%11 = phi i8** [ %20, %18 ], [ %7, %6 ]
%12 = phi i32 [ %19, %18 ], [ %0, %6 ]
%13 = and i32 %12, 1
%14 = icmp eq i32 %13, 0
br i1 %14, label %18, label %15
15: ; preds = %10
%16 = load i8*, i8** %11
%17 = tail call i32 @printf(i8* dereferenceable(1) %16)
br label %18
18: ; preds = %10, %15
%19 = ashr i32 %12, 1
%20 = getelementptr inbounds i8*, i8** %11, i64 1
%21 = icmp ult i32 %12, 2
br i1 %21, label %8, label %10
}