#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 *malloc(int);
int /*<<< orphan*/ printf(char *, int);
to_binary(int n) {
  int *a = malloc(sizeof(int) * 50);
  int sz = 0;
  while (n) {
    *(a + sz) = n % 2;
    n /= 2;
    sz++;
  }
  while (sz) {
    printf("%d ", *(a + sz - 1));
    sz--;
  }
}


x86 assembly (clang, -O0):
<to_binary>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    $0xc8,%edi
call   1040 <malloc@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     117c <to_binary+0x5c>
mov    -0x8(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x8(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x8(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1140 <to_binary+0x20>
jmp    1181 <to_binary+0x61>
cmpl   $0x0,-0x14(%rbp)
je     11b1 <to_binary+0x91>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    -0x4(%rax,%rcx,4),%esi
lea    0xe62(%rip),%rdi
call   1030 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
jmp    1181 <to_binary+0x61>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<to_binary>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %edi,%ebx
mov    $0xc8,%edi
call   1040 <malloc@plt>
test   %ebx,%ebx
je     119b <to_binary+0x7b>
xor    %r14d,%r14d
mov    %ebx,%ecx
nopl   (%rax)
shr    $0x1f,%ecx
add    %ebx,%ecx
mov    %ecx,%edx
and    $0xfffffffe,%edx
mov    %ebx,%esi
sub    %edx,%esi
mov    %esi,(%rax,%r14,4)
sar    %ecx
add    $0x1,%r14
add    $0x1,%ebx
cmp    $0x3,%ebx
mov    %ecx,%ebx
jae    1140 <to_binary+0x20>
test   %r14d,%r14d
je     119b <to_binary+0x7b>
movslq %r14d,%rcx
lea    (%rax,%rcx,4),%r12
add    $0xfffffffffffffffc,%r12
xor    %ebx,%ebx
lea    0xe85(%rip),%r15
nopl   0x0(%rax,%rax,1)
mov    (%r12,%rbx,4),%esi
mov    %r15,%rdi
call   1030 <printf@plt>
lea    -0x1(%rbx),%rax
add    %r14d,%ebx
cmp    $0x1,%ebx
mov    %rax,%rbx
jne    1180 <to_binary+0x60>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%d \00"
define i32 @to_binary(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32
store i32 %0, i32* %3
%6 = call i32* @malloc(i32 200)
store i32* %6, i32** %4
store i32 0, i32* %5
br label %7
7: ; preds = %10, %1
%8 = load i32, i32* %3
%9 = icmp ne i32 %8, 0
br i1 %9, label %10, label %21
10: ; preds = %7
%11 = load i32, i32* %3
%12 = srem i32 %11, 2
%13 = load i32*, i32** %4
%14 = load i32, i32* %5
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds i32, i32* %13, i64 %15
store i32 %12, i32* %16
%17 = load i32, i32* %3
%18 = sdiv i32 %17, 2
store i32 %18, i32* %3
%19 = load i32, i32* %5
%20 = add nsw i32 %19, 1
store i32 %20, i32* %5
br label %7
21: ; preds = %7
br label %22
22: ; preds = %25, %21
%23 = load i32, i32* %5
%24 = icmp ne i32 %23, 0
br i1 %24, label %25, label %35
25: ; preds = %22
%26 = load i32*, i32** %4
%27 = load i32, i32* %5
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i32, i32* %26, i64 %28
%30 = getelementptr inbounds i32, i32* %29, i64 -1
%31 = load i32, i32* %30
%32 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %31)
%33 = load i32, i32* %5
%34 = add nsw i32 %33, -1
store i32 %34, i32* %5
br label %22
35: ; preds = %22
%36 = load i32, i32* %2
ret i32 %36
}

LLVM IR (-O2):
@.str = [4 x i8] c"%d \00"
define i32 @to_binary(i32 %0) {
%2 = tail call i32* @malloc(i32 200)
%3 = icmp eq i32 %0, 0
br i1 %3, label %28, label %11
4: ; preds = %11
%5 = trunc i64 %17 to i32
%6 = icmp eq i32 %5, 0
br i1 %6, label %28, label %7
7: ; preds = %4
%8 = shl i64 %17, 32
%9 = ashr exact i64 %8, 32
%10 = getelementptr inbounds i32, i32* %2, i64 -1
br label %20
11: ; preds = %1, %11
%12 = phi i64 [ %17, %11 ], [ 0, %1 ]
%13 = phi i32 [ %16, %11 ], [ %0, %1 ]
%14 = srem i32 %13, 2
%15 = getelementptr inbounds i32, i32* %2, i64 %12
store i32 %14, i32* %15
%16 = sdiv i32 %13, 2
%17 = add nuw i64 %12, 1
%18 = add i32 %13, 1
%19 = icmp ult i32 %18, 3
br i1 %19, label %4, label %11
20: ; preds = %7, %20
%21 = phi i64 [ %9, %7 ], [ %25, %20 ]
%22 = getelementptr inbounds i32, i32* %10, i64 %21
%23 = load i32, i32* %22
%24 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %23)
%25 = add nsw i64 %21, -1
%26 = trunc i64 %25 to i32
%27 = icmp eq i32 %26, 0
br i1 %27, label %28, label %20
28: ; preds = %20, %1, %4
ret i32 undef
}