#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_bits(unsigned char);
int /*<<< orphan*/ printf(char *, ...);
unsigned char set_bits(unsigned char);
int main(void) {
  unsigned char register_val[] = {0x00, 0xff};
  for (int i = 0; i < 2; i++) {
    unsigned char result = set_bits(register_val[i]);
    printf("When register is 0x%02x, the result is ", register_val[i]);
    print_bits(result);
    printf("%s", "\n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xeba(%rip),%ax
mov    %ax,-0x6(%rbp)
movl   $0x0,-0xc(%rbp)
cmpl   $0x2,-0xc(%rbp)
jge    11af <main+0x7f>
movslq -0xc(%rbp),%rax
movzbl -0x6(%rbp,%rax,1),%edi
call   1040 <set_bits@plt>
mov    %al,-0xd(%rbp)
movslq -0xc(%rbp),%rax
movzbl -0x6(%rbp,%rax,1),%esi
lea    0xe86(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movzbl -0xd(%rbp),%edi
call   1050 <print_bits@plt>
lea    0xe97(%rip),%rdi
lea    0xe93(%rip),%rsi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1151 <main+0x21>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
xor    %edi,%edi
call   1050 <set_bits@plt>
mov    %eax,%ebx
lea    0xeac(%rip),%r14
mov    %r14,%rdi
xor    %esi,%esi
xor    %eax,%eax
call   1040 <printf@plt>
movzbl %bl,%edi
call   1060 <print_bits@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    $0xff,%edi
call   1050 <set_bits@plt>
mov    %eax,%ebx
mov    %r14,%rdi
mov    $0xff,%esi
xor    %eax,%eax
call   1040 <printf@plt>
movzbl %bl,%edi
call   1060 <print_bits@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@__const.main.register_val = [2 x i8] c"\00\FF"
@.str = [40 x i8] c"When register is 0x%02x, the result is \00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [2 x i8] c"\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [2 x i8]
%3 = alloca i32
%4 = alloca i8
store i32 0, i32* %1
%5 = bitcast [2 x i8]* %2 to i8*
store i32 0, i32* %3
br label %6
6: ; preds = %24, %0
%7 = load i32, i32* %3
%8 = icmp slt i32 %7, 2
br i1 %8, label %9, label %27
9: ; preds = %6
%10 = load i32, i32* %3
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds [2 x i8], [2 x i8]* %2, i64 0, i64 %11
%13 = load i8, i8* %12
%14 = call zeroext i8 @set_bits(i8 zeroext %13)
store i8 %14, i8* %4
%15 = load i32, i32* %3
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds [2 x i8], [2 x i8]* %2, i64 0, i64 %16
%18 = load i8, i8* %17
%19 = zext i8 %18 to i32
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0), i32 %19)
%21 = load i8, i8* %4
%22 = call i32 @print_bits(i8 zeroext %21)
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %24
24: ; preds = %9
%25 = load i32, i32* %3
%26 = add nsw i32 %25, 1
store i32 %26, i32* %3
br label %6
27: ; preds = %6
ret i32 0
}

LLVM IR (-O2):
@.str = [40 x i8] c"When register is 0x%02x, the result is \00"
define i32 @main() {
%1 = tail call zeroext i8 @set_bits(i8 zeroext 0)
%2 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0), i32 0)
%3 = tail call i32 @print_bits(i8 zeroext %1)
%4 = tail call i32 @putchar(i32 10)
%5 = tail call zeroext i8 @set_bits(i8 zeroext -1)
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0), i32 255)
%7 = tail call i32 @print_bits(i8 zeroext %5)
%8 = tail call i32 @putchar(i32 10)
ret i32 0
}