#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 */
typedef int /*<<< orphan*/ x;
typedef int ssize_t;

/* Variables and functions */
int CHAR_BIT;
int /*<<< orphan*/ putchar(char);
int printbin(unsigned long long x) {
  char str[CHAR_BIT * sizeof(x)];
  ssize_t i = 0;
  while (x > 0) {
    str[i++] = x & 1;
    x >>= 1;
  }
  for (i = i - 1; i >= 0; --i)
    putchar(str[i] + '0');
  putchar('\n');
  return 0;
}


x86 assembly (clang, -O0):
<printbin>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    0x2ebd(%rip),%rax
movslq (%rax),%rcx
mov    %rcx,%rax
shl    $0x3,%rax
mov    %rsp,%rdx
mov    %rdx,-0x10(%rbp)
lea    0xf(,%rcx,8),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x28(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpq   $0x0,-0x8(%rbp)
jbe    1193 <printbin+0x83>
mov    -0x28(%rbp),%rax
mov    -0x8(%rbp),%rcx
and    $0x1,%rcx
mov    %cl,%dl
mov    -0x1c(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x1c(%rbp)
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x8(%rbp),%rax
shr    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    1158 <printbin+0x48>
mov    -0x1c(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jl     11cb <printbin+0xbb>
mov    -0x28(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
add    $0x30,%eax
movsbl %al,%edi
call   1030 <putchar@plt>
mov    -0x1c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x1c(%rbp)
jmp    119c <printbin+0x8c>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    -0x10(%rbp),%rax
mov    %rax,%rsp
xor    %eax,%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printbin>:
push   %rbp
mov    %rsp,%rbp
push   %r14
push   %rbx
mov    0x2ec2(%rip),%rax
movslq (%rax),%rax
mov    %rsp,%r14
lea    0xf(,%rax,8),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r14
mov    %r14,%rsp
test   %rdi,%rdi
je     118a <printbin+0x7a>
xor    %ebx,%ebx
mov    %rdi,%rax
mov    %edi,%ecx
and    $0x1,%cl
mov    %cl,(%r14,%rbx,1)
add    $0x1,%rbx
shr    %rax
cmp    $0x2,%rdi
mov    %rax,%rdi
jae    1140 <printbin+0x30>
test   %ebx,%ebx
jle    118a <printbin+0x7a>
add    $0x1,%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movzbl -0x2(%r14,%rbx,1),%eax
add    $0x30,%al
movsbl %al,%edi
call   1030 <putchar@plt>
add    $0xffffffffffffffff,%rbx
cmp    $0x1,%rbx
ja     1170 <printbin+0x60>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
lea    -0x10(%rbp),%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@CHAR_BIT = global i32 0
define i32 @printbin(i64 %0) {
%2 = alloca i64
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i32
store i64 %0, i64* %2
%6 = load i32, i32* @CHAR_BIT
%7 = sext i32 %6 to i64
%8 = mul i64 %7, 8
%9 = call i8* @llvm.stacksave()
store i8* %9, i8** %3
%10 = alloca i8, i64 %8
store i64 %8, i64* %4
store i32 0, i32* %5
br label %11
11: ; preds = %14, %1
%12 = load i64, i64* %2
%13 = icmp ugt i64 %12, 0
br i1 %13, label %14, label %24
14: ; preds = %11
%15 = load i64, i64* %2
%16 = and i64 %15, 1
%17 = trunc i64 %16 to i8
%18 = load i32, i32* %5
%19 = add nsw i32 %18, 1
store i32 %19, i32* %5
%20 = sext i32 %18 to i64
%21 = getelementptr inbounds i8, i8* %10, i64 %20
store i8 %17, i8* %21
%22 = load i64, i64* %2
%23 = lshr i64 %22, 1
store i64 %23, i64* %2
br label %11
24: ; preds = %11
%25 = load i32, i32* %5
%26 = sub nsw i32 %25, 1
store i32 %26, i32* %5
br label %27
27: ; preds = %39, %24
%28 = load i32, i32* %5
%29 = icmp sge i32 %28, 0
br i1 %29, label %30, label %42
30: ; preds = %27
%31 = load i32, i32* %5
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8, i8* %10, i64 %32
%34 = load i8, i8* %33
%35 = sext i8 %34 to i32
%36 = add nsw i32 %35, 48
%37 = trunc i32 %36 to i8
%38 = call i32 @putchar(i8 signext %37)
br label %39
39: ; preds = %30
%40 = load i32, i32* %5
%41 = add nsw i32 %40, -1
store i32 %41, i32* %5
br label %27
42: ; preds = %27
%43 = call i32 @putchar(i8 signext 10)
%44 = load i8*, i8** %3
ret i32 0
}

LLVM IR (-O2):
@CHAR_BIT = global i32 0
define i32 @printbin(i64 %0) {
%2 = load i32, i32* @CHAR_BIT
%3 = sext i32 %2 to i64
%4 = shl nsw i64 %3, 3
%5 = alloca i8, i64 %4
%6 = icmp eq i64 %0, 0
br i1 %6, label %29, label %12
7: ; preds = %12
%8 = trunc i64 %17 to i32
%9 = icmp sgt i32 %8, 0
br i1 %9, label %10, label %29
10: ; preds = %7
%11 = and i64 %17, 4294967295
br label %21
12: ; preds = %1, %12
%13 = phi i64 [ %17, %12 ], [ 0, %1 ]
%14 = phi i64 [ %19, %12 ], [ %0, %1 ]
%15 = trunc i64 %14 to i8
%16 = and i8 %15, 1
%17 = add nuw nsw i64 %13, 1
%18 = getelementptr inbounds i8, i8* %5, i64 %13
store i8 %16, i8* %18
%19 = lshr i64 %14, 1
%20 = icmp ult i64 %14, 2
br i1 %20, label %7, label %12
21: ; preds = %10, %21
%22 = phi i64 [ %11, %10 ], [ %23, %21 ]
%23 = add nsw i64 %22, -1
%24 = getelementptr inbounds i8, i8* %5, i64 %23
%25 = load i8, i8* %24
%26 = add i8 %25, 48
%27 = tail call i32 @putchar(i8 signext %26)
%28 = icmp ugt i64 %22, 1
br i1 %28, label %21, label %29
29: ; preds = %21, %1, %7
%30 = tail call i32 @putchar(i8 signext 10)
ret i32 0
}