#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 putb(size_t const size, void const *const ptr, char esc) {
  unsigned char *b = (unsigned char *)ptr;
  register unsigned char byte;
  register int i, j;
  for (i = size - 1; i >= 0; i--) {
    for (j = 7; j >= 0; j--) {
      byte = b[i] & (1 << j);
      byte >>= j;
      printf("%u", byte);
    }
  }
  printf("%c", esc);
}


x86 assembly (clang, -O0):
<putb>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %dl,%al
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %al,-0x11(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rax
sub    $0x1,%rax
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
jl     11ad <putb+0x9d>
movl   $0x7,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jl     119a <putb+0x8a>
mov    -0x20(%rbp),%rax
movslq -0x28(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
mov    -0x2c(%rbp),%ecx
mov    $0x1,%edx
shl    %cl,%edx
mov    %edx,%ecx
and    %ecx,%eax
mov    %al,-0x21(%rbp)
mov    -0x2c(%rbp),%ecx
movzbl -0x21(%rbp),%eax
sar    %cl,%eax
mov    %al,-0x21(%rbp)
lea    0xe7d(%rip),%rdi
movsbl -0x21(%rbp),%esi
call   1030 <printf@plt>
mov    -0x2c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x2c(%rbp)
jmp    1149 <putb+0x39>
jmp    119f <putb+0x8f>
mov    -0x28(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x28(%rbp)
jmp    1138 <putb+0x28>
lea    0xe4f(%rip),%rdi
movsbl -0x11(%rbp),%esi
call   1030 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<putb>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edx,%r14d
add    $0xffffffff,%edi
js     11e7 <putb+0xd7>
mov    %rsi,%rbx
mov    %edi,%ebp
add    $0xffffffffffffffff,%rbp
lea    0xecc(%rip),%r15
mov    %rbp,%r12
nopw   0x0(%rax,%rax,1)
movzbl 0x1(%rbx,%rbp,1),%eax
shr    $0x7,%al
movzbl %al,%esi
mov    %r15,%rdi
call   1030 <printf@plt>
movzbl 0x1(%rbx,%rbp,1),%esi
shr    $0x6,%esi
and    $0x1,%esi
mov    %r15,%rdi
call   1030 <printf@plt>
movzbl 0x1(%rbx,%rbp,1),%esi
shr    $0x5,%esi
and    $0x1,%esi
mov    %r15,%rdi
call   1030 <printf@plt>
movzbl 0x1(%rbx,%rbp,1),%esi
shr    $0x4,%esi
and    $0x1,%esi
mov    %r15,%rdi
call   1030 <printf@plt>
movzbl 0x1(%rbx,%rbp,1),%esi
shr    $0x3,%esi
and    $0x1,%esi
mov    %r15,%rdi
call   1030 <printf@plt>
movzbl 0x1(%rbx,%rbp,1),%esi
shr    $0x2,%esi
and    $0x1,%esi
mov    %r15,%rdi
call   1030 <printf@plt>
movzbl 0x1(%rbx,%rbp,1),%esi
shr    %esi
and    $0x1,%esi
mov    %r15,%rdi
call   1030 <printf@plt>
movzbl 0x1(%rbx,%rbp,1),%esi
and    $0x1,%esi
mov    %r15,%rdi
call   1030 <printf@plt>
add    $0xffffffffffffffff,%r12
test   $0x80000000,%ebp
mov    %r12,%rbp
je     1140 <putb+0x30>
movsbl %r14b,%esi
lea    0xe11(%rip),%rdi
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <printf@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"%u\00"
@.str.1 = [3 x i8] c"%c\00"
define void @putb(i64 %0, i8* %1, i8 signext %2) {
%4 = alloca i64
%5 = alloca i8*
%6 = alloca i8
%7 = alloca i8*
%8 = alloca i8
%9 = alloca i32
%10 = alloca i32
store i64 %0, i64* %4
store i8* %1, i8** %5
store i8 %2, i8* %6
%11 = load i8*, i8** %5
store i8* %11, i8** %7
%12 = load i64, i64* %4
%13 = sub i64 %12, 1
%14 = trunc i64 %13 to i32
store i32 %14, i32* %9
br label %15
15: ; preds = %44, %3
%16 = load i32, i32* %9
%17 = icmp sge i32 %16, 0
br i1 %17, label %18, label %47
18: ; preds = %15
store i32 7, i32* %10
br label %19
19: ; preds = %40, %18
%20 = load i32, i32* %10
%21 = icmp sge i32 %20, 0
br i1 %21, label %22, label %43
22: ; preds = %19
%23 = load i8*, i8** %7
%24 = load i32, i32* %9
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8, i8* %23, i64 %25
%27 = load i8, i8* %26
%28 = zext i8 %27 to i32
%29 = load i32, i32* %10
%30 = shl i32 1, %29
%31 = and i32 %28, %30
%32 = trunc i32 %31 to i8
store i8 %32, i8* %8
%33 = load i32, i32* %10
%34 = load i8, i8* %8
%35 = zext i8 %34 to i32
%36 = ashr i32 %35, %33
%37 = trunc i32 %36 to i8
store i8 %37, i8* %8
%38 = load i8, i8* %8
%39 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8 signext %38)
br label %40
40: ; preds = %22
%41 = load i32, i32* %10
%42 = add nsw i32 %41, -1
store i32 %42, i32* %10
br label %19
43: ; preds = %19
br label %44
44: ; preds = %43
%45 = load i32, i32* %9
%46 = add nsw i32 %45, -1
store i32 %46, i32* %9
br label %15
47: ; preds = %15
%48 = load i8, i8* %6
%49 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8 signext %48)
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"%u\00"
@.str.1 = [3 x i8] c"%c\00"
define void @putb(i64 %0, i8* nocapture %1, i8 signext %2) {
%4 = trunc i64 %0 to i32
%5 = add i32 %4, -1
%6 = icmp sgt i32 %5, -1
br i1 %6, label %7, label %45
7: ; preds = %3
%8 = zext i32 %5 to i64
br label %9
9: ; preds = %7, %9
%10 = phi i64 [ %8, %7 ], [ %42, %9 ]
%11 = getelementptr inbounds i8, i8* %1, i64 %10
%12 = load i8, i8* %11
%13 = lshr i8 %12, 7
%14 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8 signext %13)
%15 = load i8, i8* %11
%16 = lshr i8 %15, 6
%17 = and i8 %16, 1
%18 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8 signext %17)
%19 = load i8, i8* %11
%20 = lshr i8 %19, 5
%21 = and i8 %20, 1
%22 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8 signext %21)
%23 = load i8, i8* %11
%24 = lshr i8 %23, 4
%25 = and i8 %24, 1
%26 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8 signext %25)
%27 = load i8, i8* %11
%28 = lshr i8 %27, 3
%29 = and i8 %28, 1
%30 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8 signext %29)
%31 = load i8, i8* %11
%32 = lshr i8 %31, 2
%33 = and i8 %32, 1
%34 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8 signext %33)
%35 = load i8, i8* %11
%36 = lshr i8 %35, 1
%37 = and i8 %36, 1
%38 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8 signext %37)
%39 = load i8, i8* %11
%40 = and i8 %39, 1
%41 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8 signext %40)
%42 = add nsw i64 %10, -1
%43 = and i64 %42, 2147483648
%44 = icmp eq i64 %43, 0
br i1 %44, label %9, label %45
45: ; preds = %9, %3
%46 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8 signext %2)
ret void
}