#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 */
long pow(int, long);
long int bin_dec(long int num) {
  long int rem, sum = 0, power = 0;
  while (num > 0) {
    rem = num % 10;
    num = num / 10;
    sum = sum + rem * pow(2, power);
    power++;
  }
  return sum;
}


x86 assembly (clang, -O0):
<bin_dec>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
cmpq   $0x0,-0x8(%rbp)
jle    11a0 <bin_dec+0x90>
mov    -0x8(%rbp),%rax
mov    $0xa,%ecx
cqto
idiv   %rcx
mov    %rdx,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    $0xa,%ecx
cqto
idiv   %rcx
mov    %rax,-0x8(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%rsi
mov    $0x2,%edi
call   1030 <pow@plt>
mov    -0x30(%rbp),%rcx
mov    %rax,%rdx
mov    -0x28(%rbp),%rax
imul   %rdx,%rcx
add    %rcx,%rax
mov    %rax,-0x18(%rbp)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    112c <bin_dec+0x1c>
mov    -0x18(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bin_dec>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %rdi,%rdi
jle    117e <bin_dec+0x6e>
mov    %rdi,%r14
xor    %ebx,%ebx
movabs $0xcccccccccccccccd,%r13
cc cc cc
xor    %r15d,%r15d
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r14,%rax
mul    %r13
mov    %rdx,%r12
shr    $0x3,%r12
lea    (%r12,%r12,1),%rax
lea    (%rax,%rax,4),%rax
mov    %r14,%rbp
sub    %rax,%rbp
mov    $0x2,%edi
mov    %rbx,%rsi
call   1030 <pow@plt>
imul   %rbp,%rax
add    %rax,%r15
add    $0x1,%rbx
cmp    $0x9,%r14
mov    %r12,%r14
ja     1140 <bin_dec+0x30>
jmp    1181 <bin_dec+0x71>
xor    %r15d,%r15d
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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