#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 */
char *malloc(int);
char *binstr(unsigned long long d) {
  char *s = malloc(sizeof(char) * 65);
  int i;
  for (i = 0; i < 64; i++)
    s[i] = (((d >> (63 - i)) & 1ULL) ? '1' : '0');
  s[64] = '\0';
  return s;
}


x86 assembly (clang, -O0):
<binstr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x41,%edi
call   1030 <malloc@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x40,-0x14(%rbp)
jge    117e <binstr+0x6e>
mov    -0x8(%rbp),%rdx
mov    $0x3f,%eax
sub    -0x14(%rbp),%eax
mov    %eax,%eax
mov    %eax,%ecx
shr    %cl,%rdx
and    $0x1,%rdx
mov    $0x30,%eax
mov    $0x31,%ecx
cmp    $0x0,%rdx
cmovne %ecx,%eax
mov    %al,%dl
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1131 <binstr+0x21>
mov    -0x10(%rbp),%rax
movb   $0x0,0x40(%rax)
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<binstr>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r15
movabs $0x8000000000000000,%r14
mov    $0x41,%edi
call   1030 <malloc@plt>
xor    %edx,%edx
xchg   %ax,%ax
mov    %r14,%rsi
mov    %edx,%ecx
shr    %cl,%rsi
and    %r15,%rsi
cmp    $0x1,%rsi
mov    $0x31,%bl
sbb    $0x0,%bl
lea    0x1(%rdx),%ecx
mov    %r14,%rsi
shr    %cl,%rsi
and    %r15,%rsi
cmp    $0x1,%rsi
mov    $0x31,%cl
sbb    $0x0,%cl
mov    %bl,(%rax,%rdx,1)
mov    %cl,0x1(%rax,%rdx,1)
add    $0x2,%rdx
cmp    $0x40,%rdx
jne    1130 <binstr+0x20>
movb   $0x0,0x40(%rax)
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @binstr(i64 %0) {
%2 = alloca i64
%3 = alloca i8*
%4 = alloca i32
store i64 %0, i64* %2
%5 = call i8* @malloc(i32 65)
store i8* %5, i8** %3
store i32 0, i32* %4
br label %6
6: ; preds = %24, %1
%7 = load i32, i32* %4
%8 = icmp slt i32 %7, 64
br i1 %8, label %9, label %27
9: ; preds = %6
%10 = load i64, i64* %2
%11 = load i32, i32* %4
%12 = sub nsw i32 63, %11
%13 = zext i32 %12 to i64
%14 = lshr i64 %10, %13
%15 = and i64 %14, 1
%16 = icmp ne i64 %15, 0
%17 = zext i1 %16 to i64
%18 = select i1 %16, i32 49, i32 48
%19 = trunc i32 %18 to i8
%20 = load i8*, i8** %3
%21 = load i32, i32* %4
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8, i8* %20, i64 %22
store i8 %19, i8* %23
br label %24
24: ; preds = %9
%25 = load i32, i32* %4
%26 = add nsw i32 %25, 1
store i32 %26, i32* %4
br label %6
27: ; preds = %6
%28 = load i8*, i8** %3
%29 = getelementptr inbounds i8, i8* %28, i64 64
store i8 0, i8* %29
%30 = load i8*, i8** %3
ret i8* %30
}

LLVM IR (-O2):
define noalias i8* @binstr(i64 %0) {
%2 = tail call dereferenceable_or_null(65) i8* @malloc(i32 65)
br label %3
3: ; preds = %3, %1
%4 = phi i64 [ 0, %1 ], [ %16, %3 ]
%5 = lshr i64 -9223372036854775808, %4
%6 = and i64 %5, %0
%7 = icmp eq i64 %6, 0
%8 = select i1 %7, i8 48, i8 49
%9 = getelementptr inbounds i8, i8* %2, i64 %4
store i8 %8, i8* %9
%10 = or i64 %4, 1
%11 = lshr i64 -9223372036854775808, %10
%12 = and i64 %11, %0
%13 = icmp eq i64 %12, 0
%14 = select i1 %13, i8 48, i8 49
%15 = getelementptr inbounds i8, i8* %2, i64 %10
store i8 %14, i8* %15
%16 = add nuw nsw i64 %4, 2
%17 = icmp eq i64 %16, 64
br i1 %17, label %18, label %3
18: ; preds = %3
%19 = getelementptr inbounds i8, i8* %2, i64 64
store i8 0, i8* %19
ret i8* %2
}