#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 *, char *);
void print_flag(unsigned int flag) {
  int i, bit = 1;
  char *str[] = {"open", "read", "write", "lseek", "close"};
  for (i = 0; i < 5; i++, bit <<= 1)
    if (flag & bit)
      printf("%s option is set\n", str[i]);
  return;
}


x86 assembly (clang, -O0):
<print_flag>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x1,-0xc(%rbp)
lea    -0x40(%rbp),%rdi
xor    %esi,%esi
mov    $0x28,%edx
call   1040 <memset@plt>
lea    0xeb7(%rip),%rax
mov    %rax,-0x40(%rbp)
lea    0xeb1(%rip),%rax
mov    %rax,-0x38(%rbp)
lea    0xeab(%rip),%rax
mov    %rax,-0x30(%rbp)
lea    0xea6(%rip),%rax
mov    %rax,-0x28(%rbp)
lea    0xea1(%rip),%rax
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x8(%rbp)
cmpl   $0x5,-0x8(%rbp)
jge    11ca <print_flag+0xaa>
mov    -0x4(%rbp),%eax
and    -0xc(%rbp),%eax
cmp    $0x0,%eax
je     11ae <print_flag+0x8e>
movslq -0x8(%rbp),%rax
mov    -0x40(%rbp,%rax,8),%rsi
lea    0xe73(%rip),%rdi
call   1030 <printf@plt>
jmp    11b3 <print_flag+0x93>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
mov    -0xc(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1180 <print_flag+0x60>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_flag>:
push   %rbx
mov    %edi,%ebx
test   $0x1,%bl
jne    112e <print_flag+0x1e>
test   $0x2,%bl
jne    1146 <print_flag+0x36>
test   $0x4,%bl
jne    115e <print_flag+0x4e>
test   $0x8,%bl
jne    1176 <print_flag+0x66>
test   $0x10,%bl
jne    118e <print_flag+0x7e>
pop    %rbx
ret
lea    0xee7(%rip),%rdi
lea    0xec4(%rip),%rsi
call   1030 <printf@plt>
test   $0x2,%bl
je     111d <print_flag+0xd>
lea    0xecf(%rip),%rdi
lea    0xeb1(%rip),%rsi
call   1030 <printf@plt>
test   $0x4,%bl
je     1122 <print_flag+0x12>
lea    0xeb7(%rip),%rdi
lea    0xe9e(%rip),%rsi
call   1030 <printf@plt>
test   $0x8,%bl
je     1127 <print_flag+0x17>
lea    0xe9f(%rip),%rdi
lea    0xe8c(%rip),%rsi
call   1030 <printf@plt>
test   $0x10,%bl
je     112c <print_flag+0x1c>
lea    0xe87(%rip),%rdi
lea    0xe7a(%rip),%rsi
pop    %rbx
jmp    1030 <printf@plt>

LLVM IR (-O0):
@.str = [5 x i8] c"open\00"
@.str.1 = [5 x i8] c"read\00"
@.str.2 = [6 x i8] c"write\00"
@.str.3 = [6 x i8] c"lseek\00"
@.str.4 = [6 x i8] c"close\00"
@.str.5 = [18 x i8] c"%s option is set\0A\00"
define void @print_flag(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca [5 x i8*]
store i32 %0, i32* %2
store i32 1, i32* %4
%6 = bitcast [5 x i8*]* %5 to i8*
%7 = bitcast i8* %6 to [5 x i8*]*
%8 = getelementptr inbounds [5 x i8*], [5 x i8*]* %7, i32 0, i32 0
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i32 0, i32 0), i8** %8
%9 = getelementptr inbounds [5 x i8*], [5 x i8*]* %7, i32 0, i32 1
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i32 0, i32 0), i8** %9
%10 = getelementptr inbounds [5 x i8*], [5 x i8*]* %7, i32 0, i32 2
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i32 0, i32 0), i8** %10
%11 = getelementptr inbounds [5 x i8*], [5 x i8*]* %7, i32 0, i32 3
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i32 0, i32 0), i8** %11
%12 = getelementptr inbounds [5 x i8*], [5 x i8*]* %7, i32 0, i32 4
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i32 0, i32 0), i8** %12
store i32 0, i32* %3
br label %13
13: ; preds = %28, %1
%14 = load i32, i32* %3
%15 = icmp slt i32 %14, 5
br i1 %15, label %16, label %33
16: ; preds = %13
%17 = load i32, i32* %2
%18 = load i32, i32* %4
%19 = and i32 %17, %18
%20 = icmp ne i32 %19, 0
br i1 %20, label %21, label %27
21: ; preds = %16
%22 = load i32, i32* %3
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds [5 x i8*], [5 x i8*]* %5, i64 0, i64 %23
%25 = load i8*, i8** %24
%26 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0), i8* %25)
br label %27
27: ; preds = %21, %16
br label %28
28: ; preds = %27
%29 = load i32, i32* %3
%30 = add nsw i32 %29, 1
store i32 %30, i32* %3
%31 = load i32, i32* %4
%32 = shl i32 %31, 1
store i32 %32, i32* %4
br label %13
33: ; preds = %13
ret void
}

LLVM IR (-O2):
@.str = [5 x i8] c"open\00"
@.str.1 = [5 x i8] c"read\00"
@.str.2 = [6 x i8] c"write\00"
@.str.3 = [6 x i8] c"lseek\00"
@.str.4 = [6 x i8] c"close\00"
@.str.5 = [18 x i8] c"%s option is set\0A\00"
define void @print_flag(i32 %0) {
%2 = and i32 %0, 1
%3 = icmp eq i32 %2, 0
br i1 %3, label %6, label %4
4: ; preds = %1
%5 = tail call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %6
6: ; preds = %1, %4
%7 = and i32 %0, 2
%8 = icmp eq i32 %7, 0
br i1 %8, label %11, label %9
9: ; preds = %6
%10 = tail call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %11
11: ; preds = %9, %6
%12 = and i32 %0, 4
%13 = icmp eq i32 %12, 0
br i1 %13, label %16, label %14
14: ; preds = %11
%15 = tail call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
br label %16
16: ; preds = %14, %11
%17 = and i32 %0, 8
%18 = icmp eq i32 %17, 0
br i1 %18, label %21, label %19
19: ; preds = %16
%20 = tail call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
br label %21
21: ; preds = %19, %16
%22 = and i32 %0, 16
%23 = icmp eq i32 %22, 0
br i1 %23, label %26, label %24
24: ; preds = %21
%25 = tail call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
br label %26
26: ; preds = %24, %21
ret void
}