#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(const int w, char *cd) {
  unsigned int z, c;
  for (z = 0; z < w; z++) {
    for (c = 0x80; c > 0; c >>= 1)
      (c & cd[z]) ? printf("1") : printf("0");
    printf("\n");
  }
}


x86 assembly (clang, -O0):
<printBin>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x4(%rbp),%eax
jae    11a1 <printBin+0x91>
movl   $0x80,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jbe    1187 <printBin+0x77>
mov    -0x18(%rbp),%eax
mov    -0x10(%rbp),%rcx
mov    -0x14(%rbp),%edx
movsbl (%rcx,%rdx,1),%ecx
and    %ecx,%eax
cmp    $0x0,%eax
je     116d <printBin+0x5d>
lea    0xe9d(%rip),%rdi
call   1030 <printf@plt>
jmp    1179 <printBin+0x69>
lea    0xe8e(%rip),%rdi
call   1030 <printf@plt>
mov    -0x18(%rbp),%eax
shr    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1139 <printBin+0x29>
lea    0xe76(%rip),%rdi
call   1030 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1126 <printBin+0x16>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printBin>:
push   %r15
push   %r14
push   %rbx
test   %edi,%edi
je     11ee <printBin+0xde>
mov    %rsi,%r15
mov    %edi,%r14d
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nop
xor    %edi,%edi
cmpb   $0x0,(%r15,%rbx,1)
setns  %dil
xor    $0x31,%edi
call   1030 <putchar@plt>
movzbl (%r15,%rbx,1),%eax
and    $0x40,%al
cmp    $0x1,%al
mov    $0x31,%edi
sbb    $0x0,%edi
call   1030 <putchar@plt>
movzbl (%r15,%rbx,1),%eax
and    $0x20,%al
cmp    $0x1,%al
mov    $0x31,%edi
sbb    $0x0,%edi
call   1030 <putchar@plt>
movzbl (%r15,%rbx,1),%eax
and    $0x10,%al
cmp    $0x1,%al
mov    $0x31,%edi
sbb    $0x0,%edi
call   1030 <putchar@plt>
movzbl (%r15,%rbx,1),%eax
and    $0x8,%al
cmp    $0x1,%al
mov    $0x31,%edi
sbb    $0x0,%edi
call   1030 <putchar@plt>
movzbl (%r15,%rbx,1),%eax
and    $0x4,%al
cmp    $0x1,%al
mov    $0x31,%edi
sbb    $0x0,%edi
call   1030 <putchar@plt>
movzbl (%r15,%rbx,1),%eax
and    $0x2,%al
cmp    $0x1,%al
mov    $0x31,%edi
sbb    $0x0,%edi
call   1030 <putchar@plt>
movzbl (%r15,%rbx,1),%edi
and    $0x1,%edi
or     $0x30,%edi
call   1030 <putchar@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
add    $0x1,%rbx
cmp    %rbx,%r14
jne    1130 <printBin+0x20>
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define void @printBin(i32 %0, i8* nocapture %1) {
%3 = icmp eq i32 %0, 0
br i1 %3, label %51, label %4
4: ; preds = %2
%5 = zext i32 %0 to i64
br label %6
6: ; preds = %4, %6
%7 = phi i64 [ 0, %4 ], [ %49, %6 ]
%8 = getelementptr inbounds i8, i8* %1, i64 %7
%9 = load i8, i8* %8
%10 = icmp sgt i8 %9, -1
%11 = select i1 %10, i32 48, i32 49
%12 = tail call i32 @putchar(i32 %11)
%13 = load i8, i8* %8
%14 = and i8 %13, 64
%15 = icmp eq i8 %14, 0
%16 = select i1 %15, i32 48, i32 49
%17 = tail call i32 @putchar(i32 %16)
%18 = load i8, i8* %8
%19 = and i8 %18, 32
%20 = icmp eq i8 %19, 0
%21 = select i1 %20, i32 48, i32 49
%22 = tail call i32 @putchar(i32 %21)
%23 = load i8, i8* %8
%24 = and i8 %23, 16
%25 = icmp eq i8 %24, 0
%26 = select i1 %25, i32 48, i32 49
%27 = tail call i32 @putchar(i32 %26)
%28 = load i8, i8* %8
%29 = and i8 %28, 8
%30 = icmp eq i8 %29, 0
%31 = select i1 %30, i32 48, i32 49
%32 = tail call i32 @putchar(i32 %31)
%33 = load i8, i8* %8
%34 = and i8 %33, 4
%35 = icmp eq i8 %34, 0
%36 = select i1 %35, i32 48, i32 49
%37 = tail call i32 @putchar(i32 %36)
%38 = load i8, i8* %8
%39 = and i8 %38, 2
%40 = icmp eq i8 %39, 0
%41 = select i1 %40, i32 48, i32 49
%42 = tail call i32 @putchar(i32 %41)
%43 = load i8, i8* %8
%44 = and i8 %43, 1
%45 = icmp eq i8 %44, 0
%46 = select i1 %45, i32 48, i32 49
%47 = tail call i32 @putchar(i32 %46)
%48 = tail call i32 @putchar(i32 10)
%49 = add nuw nsw i64 %7, 1
%50 = icmp eq i64 %49, %5
br i1 %50, label %51, label %6
51: ; preds = %6, %2
ret void
}