#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 *, ...);
int size_t_unit();
void printbinary(int n) {
  int i;
  size_t bits = sizeof(int) * size_t_unit();
  unsigned int j = 1 << (bits - 1);
  for (i = 0; i < bits; i++, j >>= 1) {
    printf("%d", (j & n ? 1 : 0));
  }
  printf("\n");
}


x86 assembly (clang, -O0):
<printbinary>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    $0x0,%al
call   1040 <size_t_unit@plt>
cltq
shl    $0x2,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
sub    $0x1,%rax
mov    %eax,%ecx
mov    $0x1,%eax
shl    %cl,%eax
mov    %eax,-0x14(%rbp)
movl   $0x0,-0x8(%rbp)
movslq -0x8(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    119d <printbinary+0x7d>
mov    -0x14(%rbp),%ecx
and    -0x4(%rbp),%ecx
xor    %esi,%esi
mov    $0x1,%eax
cmp    $0x0,%ecx
cmovne %eax,%esi
lea    0xe81(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
mov    -0x14(%rbp),%eax
shr    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1157 <printbinary+0x37>
lea    0xe5f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printbinary>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edi,%r15d
xor    %eax,%eax
call   1050 <size_t_unit@plt>
test   %eax,%eax
je     118b <printbinary+0x5b>
cltq
shl    $0x2,%rax
lea    -0x1(%rax),%ecx
mov    $0x1,%ebp
shl    %cl,%ebp
cmp    $0x2,%rax
mov    $0x1,%ebx
cmovae %rax,%rbx
lea    0xe97(%rip),%r14
nopl   0x0(%rax)
xor    %esi,%esi
test   %r15d,%ebp
setne  %sil
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
shr    %ebp
add    $0xffffffffffffffff,%rbx
jne    1170 <printbinary+0x40>
mov    $0xa,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <putchar@plt>

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

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
define void @printbinary(i32 %0) {
%2 = tail call i32 (...) @size_t_unit()
%3 = sext i32 %2 to i64
%4 = shl nsw i64 %3, 2
%5 = icmp eq i32 %2, 0
br i1 %5, label %21, label %6
6: ; preds = %1
%7 = trunc i64 %4 to i32
%8 = add i32 %7, -1
%9 = shl nuw i32 1, %8
%10 = call i64 @llvm.umax.i64(i64 %4, i64 1)
br label %11
11: ; preds = %6, %11
%12 = phi i64 [ 0, %6 ], [ %18, %11 ]
%13 = phi i32 [ %9, %6 ], [ %19, %11 ]
%14 = and i32 %13, %0
%15 = icmp ne i32 %14, 0
%16 = zext i1 %15 to i32
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %16)
%18 = add nuw i64 %12, 1
%19 = lshr i32 %13, 1
%20 = icmp eq i64 %18, %10
br i1 %20, label %21, label %11
21: ; preds = %11, %1
%22 = tail call i32 @putchar(i32 10)
ret void
}