#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 *, int, char);
void printByte(char byte) {
  for (int i = 0; i < 8; i++) {
    char temp = (byte >> (7 - i)) & 1;
    printf("%d: %d\n", i, temp);
  }
}


x86 assembly (clang, -O0):
<printByte>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %dil,%al
mov    %al,-0x1(%rbp)
movl   $0x0,-0x8(%rbp)
cmpl   $0x8,-0x8(%rbp)
jge    1164 <printByte+0x54>
movsbl -0x1(%rbp),%eax
mov    $0x7,%ecx
sub    -0x8(%rbp),%ecx
sar    %cl,%eax
and    $0x1,%eax
mov    %al,-0x9(%rbp)
mov    -0x8(%rbp),%esi
lea    0xeb3(%rip),%rdi
movsbl -0x9(%rbp),%edx
call   1030 <printf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1125 <printByte+0x15>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printByte>:
push   %r14
push   %rbx
push   %rax
mov    %edi,%ebx
mov    %ebx,%eax
shr    $0x7,%al
movzbl %al,%edx
lea    0xedb(%rip),%r14
mov    %r14,%rdi
xor    %esi,%esi
call   1030 <printf@plt>
mov    %ebx,%eax
shr    $0x6,%al
and    $0x1,%al
movzbl %al,%edx
mov    %r14,%rdi
mov    $0x1,%esi
call   1030 <printf@plt>
mov    %ebx,%eax
shr    $0x5,%al
and    $0x1,%al
movzbl %al,%edx
mov    %r14,%rdi
mov    $0x2,%esi
call   1030 <printf@plt>
mov    %ebx,%eax
shr    $0x4,%al
and    $0x1,%al
movzbl %al,%edx
mov    %r14,%rdi
mov    $0x3,%esi
call   1030 <printf@plt>
mov    %ebx,%eax
shr    $0x3,%al
and    $0x1,%al
movzbl %al,%edx
mov    %r14,%rdi
mov    $0x4,%esi
call   1030 <printf@plt>
mov    %ebx,%eax
shr    $0x2,%al
and    $0x1,%al
movzbl %al,%edx
mov    %r14,%rdi
mov    $0x5,%esi
call   1030 <printf@plt>
mov    %ebx,%eax
shr    %al
and    $0x1,%al
movzbl %al,%edx
mov    %r14,%rdi
mov    $0x6,%esi
call   1030 <printf@plt>
and    $0x1,%ebx
mov    %r14,%rdi
mov    $0x7,%esi
mov    %ebx,%edx
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <printf@plt>

LLVM IR (-O0):
@.str = [8 x i8] c"%d: %d\0A\00"
define void @printByte(i8 signext %0) {
%2 = alloca i8
%3 = alloca i32
%4 = alloca i8
store i8 %0, i8* %2
store i32 0, i32* %3
br label %5
5: ; preds = %19, %1
%6 = load i32, i32* %3
%7 = icmp slt i32 %6, 8
br i1 %7, label %8, label %22
8: ; preds = %5
%9 = load i8, i8* %2
%10 = sext i8 %9 to i32
%11 = load i32, i32* %3
%12 = sub nsw i32 7, %11
%13 = ashr i32 %10, %12
%14 = and i32 %13, 1
%15 = trunc i32 %14 to i8
store i8 %15, i8* %4
%16 = load i32, i32* %3
%17 = load i8, i8* %4
%18 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %16, i8 signext %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
ret void
}

LLVM IR (-O2):
@.str = [8 x i8] c"%d: %d\0A\00"
define void @printByte(i8 signext %0) {
%2 = lshr i8 %0, 7
%3 = tail call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 0, i8 signext %2)
%4 = lshr i8 %0, 6
%5 = and i8 %4, 1
%6 = tail call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 1, i8 signext %5)
%7 = lshr i8 %0, 5
%8 = and i8 %7, 1
%9 = tail call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 2, i8 signext %8)
%10 = lshr i8 %0, 4
%11 = and i8 %10, 1
%12 = tail call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 3, i8 signext %11)
%13 = lshr i8 %0, 3
%14 = and i8 %13, 1
%15 = tail call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 4, i8 signext %14)
%16 = lshr i8 %0, 2
%17 = and i8 %16, 1
%18 = tail call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 5, i8 signext %17)
%19 = lshr i8 %0, 1
%20 = and i8 %19, 1
%21 = tail call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 6, i8 signext %20)
%22 = and i8 %0, 1
%23 = tail call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 7, i8 signext %22)
ret void
}