#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*/ print_binary(unsigned char, int);
int /*<<< orphan*/ printf(char *);
void print_flags(unsigned char *str) {
  int i;
  printf("FLAGS : ");
  for (i = 1; i < 7; i++) {
    print_binary(str[i], (i == 1) ? 4 : 8);
  }
  printf("\n");
}


x86 assembly (clang, -O0):
<print_flags>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
lea    0xecd(%rip),%rdi
call   1030 <printf@plt>
movl   $0x1,-0xc(%rbp)
cmpl   $0x7,-0xc(%rbp)
jge    117d <print_flags+0x5d>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    -0xc(%rbp),%edx
mov    $0x8,%esi
mov    $0x4,%ecx
cmp    $0x1,%edx
cmove  %ecx,%esi
movzbl %al,%edi
call   1040 <print_binary@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    113f <print_flags+0x1f>
lea    0xe85(%rip),%rdi
call   1030 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_flags>:
push   %rbx
mov    %rdi,%rbx
lea    0xec5(%rip),%rdi
call   1040 <printf@plt>
movzbl 0x1(%rbx),%edi
mov    $0x4,%esi
call   1050 <print_binary@plt>
movzbl 0x2(%rbx),%edi
mov    $0x8,%esi
call   1050 <print_binary@plt>
movzbl 0x3(%rbx),%edi
mov    $0x8,%esi
call   1050 <print_binary@plt>
movzbl 0x4(%rbx),%edi
mov    $0x8,%esi
call   1050 <print_binary@plt>
movzbl 0x5(%rbx),%edi
mov    $0x8,%esi
call   1050 <print_binary@plt>
movzbl 0x6(%rbx),%edi
mov    $0x8,%esi
call   1050 <print_binary@plt>
mov    $0xa,%edi
pop    %rbx
jmp    1030 <putchar@plt>

LLVM IR (-O0):
@.str = [9 x i8] c"FLAGS : \00"
@.str.1 = [2 x i8] c"\0A\00"
define void @print_flags(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
store i8* %0, i8** %2
%4 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %5
5: ; preds = %19, %1
%6 = load i32, i32* %3
%7 = icmp slt i32 %6, 7
br i1 %7, label %8, label %22
8: ; preds = %5
%9 = load i8*, i8** %2
%10 = load i32, i32* %3
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds i8, i8* %9, i64 %11
%13 = load i8, i8* %12
%14 = load i32, i32* %3
%15 = icmp eq i32 %14, 1
%16 = zext i1 %15 to i64
%17 = select i1 %15, i32 4, i32 8
%18 = call i32 @print_binary(i8 zeroext %13, i32 %17)
br label %19
19: ; preds = %8
%20 = load i32, i32* %3
%21 = add nsw i32 %20, 1
store i32 %21, i32* %3
br label %5
22: ; preds = %5
%23 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [9 x i8] c"FLAGS : \00"
define void @print_flags(i8* nocapture %0) {
%2 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%3 = getelementptr inbounds i8, i8* %0, i64 1
%4 = load i8, i8* %3
%5 = tail call i32 @print_binary(i8 zeroext %4, i32 4)
%6 = getelementptr inbounds i8, i8* %0, i64 2
%7 = load i8, i8* %6
%8 = tail call i32 @print_binary(i8 zeroext %7, i32 8)
%9 = getelementptr inbounds i8, i8* %0, i64 3
%10 = load i8, i8* %9
%11 = tail call i32 @print_binary(i8 zeroext %10, i32 8)
%12 = getelementptr inbounds i8, i8* %0, i64 4
%13 = load i8, i8* %12
%14 = tail call i32 @print_binary(i8 zeroext %13, i32 8)
%15 = getelementptr inbounds i8, i8* %0, i64 5
%16 = load i8, i8* %15
%17 = tail call i32 @print_binary(i8 zeroext %16, i32 8)
%18 = getelementptr inbounds i8, i8* %0, i64 6
%19 = load i8, i8* %18
%20 = tail call i32 @print_binary(i8 zeroext %19, i32 8)
%21 = tail call i32 @putchar(i32 10)
ret void
}