#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 *, ...);
void printbin(unsigned char *c) {
  int i, j;
  unsigned char x;
  if (!c) {
    printf("printbin: invalid params\n");
    return;
  }
  for (i = 0; i < 6; i++) {
    x = c[i];
    for (j = 0; j < 8; j++) {
      printf("%d", (x & 0x80) >> 7);
      x = x << 1;
    }
  }
  printf("\n");
}


x86 assembly (clang, -O0):
<printbin>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    113a <printbin+0x2a>
lea    0xed2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11be <printbin+0xae>
movl   $0x0,-0xc(%rbp)
cmpl   $0x6,-0xc(%rbp)
jge    11b0 <printbin+0xa0>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x11(%rbp)
movl   $0x0,-0x10(%rbp)
cmpl   $0x8,-0x10(%rbp)
jge    119d <printbin+0x8d>
movzbl -0x11(%rbp),%esi
and    $0x80,%esi
sar    $0x7,%esi
lea    0xe9c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movzbl -0x11(%rbp),%eax
shl    $0x1,%eax
mov    %al,-0x11(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1160 <printbin+0x50>
jmp    11a2 <printbin+0x92>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1141 <printbin+0x31>
lea    0xe61(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printbin>:
test   %rdi,%rdi
je     1200 <printbin+0xd0>
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
lea    0xeb6(%rip),%r15
xor    %ebx,%ebx
nopl   0x0(%rax)
movzbl (%r14,%rbx,1),%ebp
mov    %ebp,%esi
shr    $0x7,%esi
mov    %r15,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %ebp,%esi
shr    $0x6,%esi
and    $0x1,%esi
mov    %r15,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %ebp,%esi
shr    $0x5,%esi
and    $0x1,%esi
mov    %r15,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %ebp,%esi
shr    $0x4,%esi
and    $0x1,%esi
mov    %r15,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %ebp,%esi
shr    $0x3,%esi
and    $0x1,%esi
mov    %r15,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %ebp,%esi
shr    $0x2,%esi
and    $0x1,%esi
mov    %r15,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %ebp,%esi
shr    %esi
and    $0x1,%esi
mov    %r15,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
and    $0x1,%ebp
mov    %r15,%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1050 <printf@plt>
add    $0x1,%rbx
cmp    $0x6,%rbx
jne    1150 <printbin+0x20>
mov    $0xa,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <putchar@plt>
lea    0xdfc(%rip),%rdi
jmp    1040 <puts@plt>

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

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