#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 *, ...);
void dec_to_bin(int num, int base) {
  int converted[20], i = 0;
  while (num != 0) {
    converted[i] = num % base;
    i++;
    num /= base;
  }
  for (int j = i - 1; j >= 0; j--) {
    printf("%d", converted[j]);
  }
  printf(" ");
}


x86 assembly (clang, -O0):
<dec_to_bin>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
movl   $0x0,-0x64(%rbp)
cmpl   $0x0,-0x4(%rbp)
je     1158 <dec_to_bin+0x48>
mov    -0x4(%rbp),%eax
cltd
idivl  -0x8(%rbp)
movslq -0x64(%rbp),%rax
mov    %edx,-0x60(%rbp,%rax,4)
mov    -0x64(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x64(%rbp)
mov    -0x8(%rbp),%ecx
mov    -0x4(%rbp),%eax
cltd
idiv   %ecx
mov    %eax,-0x4(%rbp)
jmp    1125 <dec_to_bin+0x15>
mov    -0x64(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x68(%rbp)
cmpl   $0x0,-0x68(%rbp)
jl     118f <dec_to_bin+0x7f>
movslq -0x68(%rbp),%rax
mov    -0x60(%rbp,%rax,4),%esi
lea    0xe86(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x68(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x68(%rbp)
jmp    1161 <dec_to_bin+0x51>
lea    0xe6d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dec_to_bin>:
push   %r14
push   %rbx
sub    $0x58,%rsp
test   %edi,%edi
je     116a <dec_to_bin+0x4a>
mov    %edi,%eax
xor    %ecx,%ecx
nop
cltd
idiv   %esi
mov    %edx,(%rsp,%rcx,4)
add    $0x1,%rcx
test   %eax,%eax
jne    1130 <dec_to_bin+0x10>
test   %ecx,%ecx
jle    116a <dec_to_bin+0x4a>
mov    %ecx,%ebx
add    $0x1,%rbx
lea    0xeb1(%rip),%r14
nop
lea    -0x2(%rbx),%eax
mov    (%rsp,%rax,4),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0xffffffffffffffff,%rbx
cmp    $0x1,%rbx
ja     1150 <dec_to_bin+0x30>
mov    $0x20,%edi
add    $0x58,%rsp
pop    %rbx
pop    %r14
jmp    1030 <putchar@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
@.str.1 = [2 x i8] c" \00"
define void @dec_to_bin(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca [20 x i32]
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
store i32 0, i32* %6
br label %8
8: ; preds = %11, %2
%9 = load i32, i32* %3
%10 = icmp ne i32 %9, 0
br i1 %10, label %11, label %23
11: ; preds = %8
%12 = load i32, i32* %3
%13 = load i32, i32* %4
%14 = srem i32 %12, %13
%15 = load i32, i32* %6
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds [20 x i32], [20 x i32]* %5, i64 0, i64 %16
store i32 %14, i32* %17
%18 = load i32, i32* %6
%19 = add nsw i32 %18, 1
store i32 %19, i32* %6
%20 = load i32, i32* %4
%21 = load i32, i32* %3
%22 = sdiv i32 %21, %20
store i32 %22, i32* %3
br label %8
23: ; preds = %8
%24 = load i32, i32* %6
%25 = sub nsw i32 %24, 1
store i32 %25, i32* %7
br label %26
26: ; preds = %35, %23
%27 = load i32, i32* %7
%28 = icmp sge i32 %27, 0
br i1 %28, label %29, label %38
29: ; preds = %26
%30 = load i32, i32* %7
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds [20 x i32], [20 x i32]* %5, i64 0, i64 %31
%33 = load i32, i32* %32
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %33)
br label %35
35: ; preds = %29
%36 = load i32, i32* %7
%37 = add nsw i32 %36, -1
store i32 %37, i32* %7
br label %26
38: ; preds = %26
%39 = 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 @dec_to_bin(i32 %0, i32 %1) {
%3 = alloca [20 x i32]
%4 = bitcast [20 x i32]* %3 to i8*
%5 = icmp eq i32 %0, 0
br i1 %5, label %19, label %11
6: ; preds = %11
%7 = trunc i64 %16 to i32
%8 = icmp sgt i32 %7, 0
br i1 %8, label %9, label %19
9: ; preds = %6
%10 = and i64 %16, 4294967295
br label %21
11: ; preds = %2, %11
%12 = phi i64 [ %16, %11 ], [ 0, %2 ]
%13 = phi i32 [ %17, %11 ], [ %0, %2 ]
%14 = srem i32 %13, %1
%15 = getelementptr inbounds [20 x i32], [20 x i32]* %3, i64 0, i64 %12
store i32 %14, i32* %15
%16 = add nuw i64 %12, 1
%17 = sdiv i32 %13, %1
%18 = icmp eq i32 %17, 0
br i1 %18, label %6, label %11
19: ; preds = %21, %2, %6
%20 = tail call i32 @putchar(i32 32)
ret void
21: ; preds = %9, %21
%22 = phi i64 [ %10, %9 ], [ %23, %21 ]
%23 = add nsw i64 %22, -1
%24 = and i64 %23, 4294967295
%25 = getelementptr inbounds [20 x i32], [20 x i32]* %3, i64 0, i64 %24
%26 = load i32, i32* %25
%27 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %26)
%28 = icmp ugt i64 %22, 1
br i1 %28, label %21, label %19
}