#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 pow(int, int);
int dectobin(int dec) {
  int j, i, bin = 0;
  for (i = 1; dec != 0; i++) {
    j = dec % 2;
    bin = bin + (j * pow(10, i - 1));
    dec = dec / 2;
  }
  return bin;
}


x86 assembly (clang, -O0):
<dectobin>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x1,-0xc(%rbp)
cmpl   $0x0,-0x4(%rbp)
je     1189 <dectobin+0x79>
mov    -0x4(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %edx,-0x8(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0xc(%rbp),%esi
sub    $0x1,%esi
mov    $0xa,%edi
call   1030 <pow@plt>
mov    -0x18(%rbp),%ecx
mov    %eax,%edx
mov    -0x14(%rbp),%eax
imul   %edx,%ecx
add    %ecx,%eax
mov    %eax,-0x10(%rbp)
mov    -0x4(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x4(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1129 <dectobin+0x19>
mov    -0x10(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dectobin>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
test   %edi,%edi
je     1163 <dectobin+0x53>
mov    %edi,%ebx
xor    %r15d,%r15d
xor    %r14d,%r14d
mov    %edi,%ebp
cs nopw 0x0(%rax,%rax,1)
nop
mov    $0xa,%edi
mov    %r15d,%esi
call   1030 <pow@plt>
shr    $0x1f,%ebp
add    %ebx,%ebp
mov    %ebp,%ecx
and    $0xfffffffe,%ecx
mov    %ebx,%edx
sub    %ecx,%edx
imul   %eax,%edx
add    %edx,%r14d
sar    %ebp
add    $0x1,%ebx
add    $0x1,%r15d
cmp    $0x2,%ebx
mov    %ebp,%ebx
ja     1130 <dectobin+0x20>
jmp    1166 <dectobin+0x56>
xor    %r14d,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @dectobin(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %2
store i32 0, i32* %5
store i32 1, i32* %4
br label %6
6: ; preds = %21, %1
%7 = load i32, i32* %2
%8 = icmp ne i32 %7, 0
br i1 %8, label %9, label %24
9: ; preds = %6
%10 = load i32, i32* %2
%11 = srem i32 %10, 2
store i32 %11, i32* %3
%12 = load i32, i32* %5
%13 = load i32, i32* %3
%14 = load i32, i32* %4
%15 = sub nsw i32 %14, 1
%16 = call i32 @pow(i32 10, i32 %15)
%17 = mul nsw i32 %13, %16
%18 = add nsw i32 %12, %17
store i32 %18, i32* %5
%19 = load i32, i32* %2
%20 = sdiv i32 %19, 2
store i32 %20, i32* %2
br label %21
21: ; preds = %9
%22 = load i32, i32* %4
%23 = add nsw i32 %22, 1
store i32 %23, i32* %4
br label %6
24: ; preds = %6
%25 = load i32, i32* %5
ret i32 %25
}

LLVM IR (-O2):
define i32 @dectobin(i32 %0) {
%2 = icmp eq i32 %0, 0
br i1 %2, label %16, label %3
3: ; preds = %1, %3
%4 = phi i32 [ %11, %3 ], [ 0, %1 ]
%5 = phi i32 [ %13, %3 ], [ 1, %1 ]
%6 = phi i32 [ %12, %3 ], [ %0, %1 ]
%7 = srem i32 %6, 2
%8 = add nsw i32 %5, -1
%9 = tail call i32 @pow(i32 10, i32 %8)
%10 = mul nsw i32 %9, %7
%11 = add nsw i32 %10, %4
%12 = sdiv i32 %6, 2
%13 = add nuw nsw i32 %5, 1
%14 = add i32 %6, 1
%15 = icmp ult i32 %14, 3
br i1 %15, label %16, label %3
16: ; preds = %3, %1
%17 = phi i32 [ 0, %1 ], [ %11, %3 ]
ret i32 %17
}