#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 *binary_digits(int n) {
  char *result = malloc(9);
  int i;
  for (i = 7; i >= 0; --i) {
    if (n % 2 == 0) {
      result[i] = '0';
    } else {
      result[i] = '1';
    }
    n = n / 2;
  }
  result[8] = '\0';
  return result;
}


x86 assembly (clang, -O0):
<binary_digits>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    $0x9,%edi
call   1030 <malloc@plt>
mov    %rax,-0x10(%rbp)
movl   $0x7,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jl     1187 <binary_digits+0x77>
mov    -0x4(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    115f <binary_digits+0x4f>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movb   $0x30,(%rax,%rcx,1)
jmp    116b <binary_digits+0x5b>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movb   $0x31,(%rax,%rcx,1)
mov    -0x4(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x4(%rbp)
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
jmp    1130 <binary_digits+0x20>
mov    -0x10(%rbp),%rax
movb   $0x0,0x8(%rax)
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<binary_digits>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edi,%ebx
lea    0x7f(%rbx),%eax
test   %edi,%edi
cmovns %edi,%eax
mov    %eax,0x4(%rsp)
lea    0x3f(%rbx),%r15d
test   %edi,%edi
cmovns %edi,%r15d
lea    0x1f(%rbx),%r12d
test   %edi,%edi
cmovns %edi,%r12d
lea    0xf(%rbx),%r13d
test   %edi,%edi
cmovns %edi,%r13d
lea    0x7(%rbx),%ebp
test   %edi,%edi
cmovns %edi,%ebp
lea    0x3(%rbx),%r14d
test   %edi,%edi
cmovns %edi,%r14d
mov    $0x9,%edi
call   1030 <malloc@plt>
mov    %ebx,%ecx
and    $0x1,%cl
or     $0x30,%cl
mov    %cl,0x7(%rax)
mov    %ebx,%ecx
shr    $0x1f,%ecx
add    %ebx,%ecx
shr    %cl
and    $0x1,%cl
or     $0x30,%cl
mov    %cl,0x6(%rax)
shr    $0x2,%r14b
and    $0x1,%r14b
or     $0x30,%r14b
mov    %r14b,0x5(%rax)
shr    $0x3,%bpl
and    $0x1,%bpl
or     $0x30,%bpl
mov    %bpl,0x4(%rax)
shr    $0x4,%r13b
and    $0x1,%r13b
or     $0x30,%r13b
mov    %r13b,0x3(%rax)
shr    $0x5,%r12b
and    $0x1,%r12b
or     $0x30,%r12b
mov    %r12b,0x2(%rax)
shr    $0x6,%r15b
and    $0x1,%r15b
or     $0x30,%r15b
mov    %r15b,0x1(%rax)
mov    0x4(%rsp),%ecx
shr    $0x7,%cl
or     $0x30,%cl
mov    %cl,(%rax)
movb   $0x0,0x8(%rax)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i8* @binary_digits(i32 %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
store i32 %0, i32* %2
%5 = call i8* @malloc(i32 9)
store i8* %5, i8** %3
store i32 7, i32* %4
br label %6
6: ; preds = %26, %1
%7 = load i32, i32* %4
%8 = icmp sge i32 %7, 0
br i1 %8, label %9, label %29
9: ; preds = %6
%10 = load i32, i32* %2
%11 = srem i32 %10, 2
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %18
13: ; preds = %9
%14 = load i8*, i8** %3
%15 = load i32, i32* %4
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i8, i8* %14, i64 %16
store i8 48, i8* %17
br label %23
18: ; preds = %9
%19 = load i8*, i8** %3
%20 = load i32, i32* %4
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i8, i8* %19, i64 %21
store i8 49, i8* %22
br label %23
23: ; preds = %18, %13
%24 = load i32, i32* %2
%25 = sdiv i32 %24, 2
store i32 %25, i32* %2
br label %26
26: ; preds = %23
%27 = load i32, i32* %4
%28 = add nsw i32 %27, -1
store i32 %28, i32* %4
br label %6
29: ; preds = %6
%30 = load i8*, i8** %3
%31 = getelementptr inbounds i8, i8* %30, i64 8
store i8 0, i8* %31
%32 = load i8*, i8** %3
ret i8* %32
}

LLVM IR (-O2):
define noalias i8* @binary_digits(i32 %0) {
%2 = tail call dereferenceable_or_null(9) i8* @malloc(i32 9)
%3 = and i32 %0, 1
%4 = icmp eq i32 %3, 0
%5 = select i1 %4, i8 48, i8 49
%6 = getelementptr inbounds i8, i8* %2, i64 7
store i8 %5, i8* %6
%7 = sdiv i32 %0, 2
%8 = and i32 %7, 1
%9 = icmp eq i32 %8, 0
%10 = select i1 %9, i8 48, i8 49
%11 = getelementptr inbounds i8, i8* %2, i64 6
store i8 %10, i8* %11
%12 = sdiv i32 %0, 4
%13 = and i32 %12, 1
%14 = icmp eq i32 %13, 0
%15 = select i1 %14, i8 48, i8 49
%16 = getelementptr inbounds i8, i8* %2, i64 5
store i8 %15, i8* %16
%17 = sdiv i32 %0, 8
%18 = and i32 %17, 1
%19 = icmp eq i32 %18, 0
%20 = select i1 %19, i8 48, i8 49
%21 = getelementptr inbounds i8, i8* %2, i64 4
store i8 %20, i8* %21
%22 = sdiv i32 %0, 16
%23 = and i32 %22, 1
%24 = icmp eq i32 %23, 0
%25 = select i1 %24, i8 48, i8 49
%26 = getelementptr inbounds i8, i8* %2, i64 3
store i8 %25, i8* %26
%27 = sdiv i32 %0, 32
%28 = and i32 %27, 1
%29 = icmp eq i32 %28, 0
%30 = select i1 %29, i8 48, i8 49
%31 = getelementptr inbounds i8, i8* %2, i64 2
store i8 %30, i8* %31
%32 = sdiv i32 %0, 64
%33 = and i32 %32, 1
%34 = icmp eq i32 %33, 0
%35 = select i1 %34, i8 48, i8 49
%36 = getelementptr inbounds i8, i8* %2, i64 1
store i8 %35, i8* %36
%37 = sdiv i32 %0, 128
%38 = and i32 %37, 1
%39 = icmp eq i32 %38, 0
%40 = select i1 %39, i8 48, i8 49
store i8 %40, i8* %2
%41 = getelementptr inbounds i8, i8* %2, i64 8
store i8 0, i8* %41
ret i8* %2
}