#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 CHAR_BIT;
int /*<<< orphan*/ printf(char *, char);
void print_binary(unsigned n) {
  size_t unsigned_bits = sizeof(unsigned) * CHAR_BIT;
  unsigned i;
  for (i = 0; i < unsigned_bits; i++) {
    printf("%c", (n & (1 << (unsigned_bits - i - 1))) ? '1' : '0');
  }
}


x86 assembly (clang, -O0):
<print_binary>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    0x2ebe(%rip),%rax
movslq (%rax),%rax
shl    $0x2,%rax
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x10(%rbp),%rax
jae    118a <print_binary+0x7a>
mov    -0x4(%rbp),%edx
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
sub    %rcx,%rax
sub    $0x1,%rax
mov    %eax,%ecx
mov    $0x1,%eax
shl    %cl,%eax
and    %eax,%edx
mov    $0x30,%eax
mov    $0x31,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
lea    0xe8c(%rip),%rdi
movsbl %al,%esi
call   1030 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1134 <print_binary+0x24>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_binary>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    0x2ec2(%rip),%rax
movslq (%rax),%rbx
test   %rbx,%rbx
je     1162 <print_binary+0x52>
mov    %edi,%r15d
shl    $0x2,%rbx
xor    %ebp,%ebp
lea    0xeca(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
mov    %ebp,%eax
not    %eax
add    %ebx,%eax
bt     %eax,%r15d
mov    $0x31,%esi
adc    $0xffffffff,%esi
mov    %r14,%rdi
call   1030 <printf@plt>
add    $0x1,%ebp
cmp    %rbp,%rbx
ja     1140 <print_binary+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@CHAR_BIT = global i32 0
@.str = [3 x i8] c"%c\00"
define void @print_binary(i32 %0) {
%2 = alloca i32
%3 = alloca i64
%4 = alloca i32
store i32 %0, i32* %2
%5 = load i32, i32* @CHAR_BIT
%6 = sext i32 %5 to i64
%7 = mul i64 4, %6
store i64 %7, i64* %3
store i32 0, i32* %4
br label %8
8: ; preds = %28, %1
%9 = load i32, i32* %4
%10 = zext i32 %9 to i64
%11 = load i64, i64* %3
%12 = icmp ult i64 %10, %11
br i1 %12, label %13, label %31
13: ; preds = %8
%14 = load i32, i32* %2
%15 = load i64, i64* %3
%16 = load i32, i32* %4
%17 = zext i32 %16 to i64
%18 = sub i64 %15, %17
%19 = sub i64 %18, 1
%20 = trunc i64 %19 to i32
%21 = shl i32 1, %20
%22 = and i32 %14, %21
%23 = icmp ne i32 %22, 0
%24 = zext i1 %23 to i64
%25 = select i1 %23, i32 49, i32 48
%26 = trunc i32 %25 to i8
%27 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8 signext %26)
br label %28
28: ; preds = %13
%29 = load i32, i32* %4
%30 = add i32 %29, 1
store i32 %30, i32* %4
br label %8
31: ; preds = %8
ret void
}

LLVM IR (-O2):
@CHAR_BIT = global i32 0
@.str = [3 x i8] c"%c\00"
define void @print_binary(i32 %0) {
%2 = load i32, i32* @CHAR_BIT
%3 = sext i32 %2 to i64
%4 = shl nsw i64 %3, 2
%5 = icmp eq i32 %2, 0
br i1 %5, label %19, label %6
6: ; preds = %1, %6
%7 = phi i64 [ %17, %6 ], [ 0, %1 ]
%8 = xor i64 %7, -1
%9 = add nsw i64 %4, %8
%10 = trunc i64 %9 to i32
%11 = shl nuw i32 1, %10
%12 = and i32 %11, %0
%13 = icmp eq i32 %12, 0
%14 = select i1 %13, i8 48, i8 49
%15 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8 signext %14)
%16 = add nuw nsw i64 %7, 1
%17 = and i64 %16, 4294967295
%18 = icmp ugt i64 %4, %17
br i1 %18, label %6, label %19
19: ; preds = %6, %1
ret void
}