#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 print_binary(char *prefix, int n) {
  printf(prefix);
  for (int i = 7; i >= 0; i--) {
    int j = n >> i;
    if (j & 1) {
      printf("1");
    } else {
      printf("0");
    }
  }
  printf("\n");
}


x86 assembly (clang, -O0):
<print_binary>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <printf@plt>
movl   $0x7,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jl     1183 <print_binary+0x73>
mov    -0xc(%rbp),%eax
mov    -0x10(%rbp),%ecx
sar    %cl,%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     1164 <print_binary+0x54>
lea    0xea6(%rip),%rdi
call   1030 <printf@plt>
jmp    1170 <print_binary+0x60>
lea    0xe97(%rip),%rdi
call   1030 <printf@plt>
jmp    1175 <print_binary+0x65>
mov    -0x10(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x10(%rbp)
jmp    112f <print_binary+0x1f>
lea    0xe7a(%rip),%rdi
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_binary>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebx
call   1040 <printf@plt>
mov    %ebx,%eax
and    $0x80,%eax
cmp    $0x1,%eax
mov    $0x31,%ebp
mov    $0x31,%edi
sbb    $0x0,%edi
call   1030 <putchar@plt>
mov    %ebx,%eax
and    $0x40,%eax
cmp    $0x1,%eax
mov    $0x31,%edi
sbb    $0x0,%edi
call   1030 <putchar@plt>
mov    %ebx,%eax
and    $0x20,%eax
cmp    $0x1,%eax
mov    $0x31,%edi
sbb    $0x0,%edi
call   1030 <putchar@plt>
mov    %ebx,%eax
and    $0x10,%eax
cmp    $0x1,%eax
mov    $0x31,%edi
sbb    $0x0,%edi
call   1030 <putchar@plt>
mov    %ebx,%eax
and    $0x8,%eax
cmp    $0x1,%eax
mov    $0x31,%edi
sbb    $0x0,%edi
call   1030 <putchar@plt>
mov    %ebx,%eax
and    $0x4,%eax
cmp    $0x1,%eax
mov    $0x31,%edi
sbb    $0x0,%edi
call   1030 <putchar@plt>
mov    %ebx,%eax
and    $0x2,%eax
cmp    $0x1,%eax
sbb    $0x0,%ebp
mov    %ebp,%edi
call   1030 <putchar@plt>
and    $0x1,%ebx
or     $0x30,%ebx
mov    %ebx,%edi
call   1030 <putchar@plt>
mov    $0xa,%edi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1030 <putchar@plt>

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 @print_binary(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
%7 = load i8*, i8** %3
%8 = call i32 @printf(i8* %7)
store i32 7, i32* %5
br label %9
9: ; preds = %24, %2
%10 = load i32, i32* %5
%11 = icmp sge i32 %10, 0
br i1 %11, label %12, label %27
12: ; preds = %9
%13 = load i32, i32* %4
%14 = load i32, i32* %5
%15 = ashr i32 %13, %14
store i32 %15, i32* %6
%16 = load i32, i32* %6
%17 = and i32 %16, 1
%18 = icmp ne i32 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %12
%20 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %23
21: ; preds = %12
%22 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %23
23: ; preds = %21, %19
br label %24
24: ; preds = %23
%25 = load i32, i32* %5
%26 = add nsw i32 %25, -1
store i32 %26, i32* %5
br label %9
27: ; preds = %9
%28 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
define void @print_binary(i8* nocapture %0, i32 %1) {
%3 = tail call i32 @printf(i8* dereferenceable(1) %0)
%4 = and i32 %1, 128
%5 = icmp eq i32 %4, 0
%6 = select i1 %5, i32 48, i32 49
%7 = tail call i32 @putchar(i32 %6)
%8 = and i32 %1, 64
%9 = icmp eq i32 %8, 0
%10 = select i1 %9, i32 48, i32 49
%11 = tail call i32 @putchar(i32 %10)
%12 = and i32 %1, 32
%13 = icmp eq i32 %12, 0
%14 = select i1 %13, i32 48, i32 49
%15 = tail call i32 @putchar(i32 %14)
%16 = and i32 %1, 16
%17 = icmp eq i32 %16, 0
%18 = select i1 %17, i32 48, i32 49
%19 = tail call i32 @putchar(i32 %18)
%20 = and i32 %1, 8
%21 = icmp eq i32 %20, 0
%22 = select i1 %21, i32 48, i32 49
%23 = tail call i32 @putchar(i32 %22)
%24 = and i32 %1, 4
%25 = icmp eq i32 %24, 0
%26 = select i1 %25, i32 48, i32 49
%27 = tail call i32 @putchar(i32 %26)
%28 = and i32 %1, 2
%29 = icmp eq i32 %28, 0
%30 = select i1 %29, i32 48, i32 49
%31 = tail call i32 @putchar(i32 %30)
%32 = and i32 %1, 1
%33 = or i32 %32, 48
%34 = tail call i32 @putchar(i32 %33)
%35 = tail call i32 @putchar(i32 10)
ret void
}