#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 *, ...);
int /*<<< orphan*/ scanf(char *, long *);
int main(void) {
  long int binum, decnum = 0, octnum = 0, j = 1, rem;
  printf("Enter binary value: ");
  scanf("%ld", &binum);
  while (binum != 0) {
    rem = binum % 10;
    decnum += rem * j;
    j *= 2;
    binum /= 10;
  }
  octnum = decnum;
  printf("Decimal: %d\n", decnum);
  printf("Octal: %lo", octnum);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x1,-0x28(%rbp)
lea    0xeb2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xeb9(%rip),%rdi
lea    -0x10(%rbp),%rsi
call   1040 <scanf@plt>
cmpq   $0x0,-0x10(%rbp)
je     11b6 <main+0x96>
mov    -0x10(%rbp),%rax
mov    $0xa,%ecx
cqto
idiv   %rcx
mov    %rdx,-0x30(%rbp)
mov    -0x30(%rbp),%rax
imul   -0x28(%rbp),%rax
add    -0x18(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x28(%rbp),%rax
shl    $0x1,%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    $0xa,%ecx
cqto
idiv   %rcx
mov    %rax,-0x10(%rbp)
jmp    1165 <main+0x45>
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rsi
lea    0xe50(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x20(%rbp),%rsi
lea    0xe4b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
lea    0xed4(%rip),%rdi
xor    %ebx,%ebx
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xed9(%rip),%rdi
lea    0x8(%rsp),%rsi
call   1040 <scanf@plt>
mov    0x8(%rsp),%rdx
test   %rdx,%rdx
je     11ae <main+0x8e>
mov    $0x1,%esi
xor    %ebx,%ebx
movabs $0x6666666666666667,%r8
66 66 66
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %rdx,%rdi
mov    %rdx,%rax
imul   %r8
mov    %rdx,%rax
shr    $0x3f,%rax
sar    $0x2,%rdx
add    %rax,%rdx
lea    (%rdx,%rdx,1),%rax
lea    (%rax,%rax,4),%rax
mov    %rdi,%rcx
sub    %rax,%rcx
imul   %rsi,%rcx
add    %rcx,%rbx
add    %rsi,%rsi
add    $0x9,%rdi
cmp    $0x12,%rdi
ja     1170 <main+0x50>
mov    %rdx,0x8(%rsp)
lea    0xe64(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xe60(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [21 x i8] c"Enter binary value: \00"
@.str.1 = [4 x i8] c"%ld\00"
@.str.2 = [13 x i8] c"Decimal: %d\0A\00"
@.str.3 = [11 x i8] c"Octal: %lo\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca i64
%4 = alloca i64
%5 = alloca i64
%6 = alloca i64
store i32 0, i32* %1
store i64 0, i64* %3
store i64 0, i64* %4
store i64 1, i64* %5
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
%8 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i64* %2)
br label %9
9: ; preds = %12, %0
%10 = load i64, i64* %2
%11 = icmp ne i64 %10, 0
br i1 %11, label %12, label %24
12: ; preds = %9
%13 = load i64, i64* %2
%14 = srem i64 %13, 10
store i64 %14, i64* %6
%15 = load i64, i64* %6
%16 = load i64, i64* %5
%17 = mul nsw i64 %15, %16
%18 = load i64, i64* %3
%19 = add nsw i64 %18, %17
store i64 %19, i64* %3
%20 = load i64, i64* %5
%21 = mul nsw i64 %20, 2
store i64 %21, i64* %5
%22 = load i64, i64* %2
%23 = sdiv i64 %22, 10
store i64 %23, i64* %2
br label %9
24: ; preds = %9
%25 = load i64, i64* %3
store i64 %25, i64* %4
%26 = load i64, i64* %3
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i64 %26)
%28 = load i64, i64* %4
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i64 %28)
ret i32 0
}

LLVM IR (-O2):
@.str = [21 x i8] c"Enter binary value: \00"
@.str.1 = [4 x i8] c"%ld\00"
@.str.2 = [13 x i8] c"Decimal: %d\0A\00"
@.str.3 = [11 x i8] c"Octal: %lo\00"
define i32 @main() {
%1 = alloca i64
%2 = bitcast i64* %1 to i8*
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
%4 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i64* %1)
%5 = load i64, i64* %1
%6 = icmp eq i64 %5, 0
br i1 %6, label %19, label %7
7: ; preds = %0, %7
%8 = phi i64 [ %13, %7 ], [ 0, %0 ]
%9 = phi i64 [ %14, %7 ], [ 1, %0 ]
%10 = phi i64 [ %15, %7 ], [ %5, %0 ]
%11 = srem i64 %10, 10
%12 = mul nsw i64 %11, %9
%13 = add nsw i64 %8, %12
%14 = shl nsw i64 %9, 1
%15 = sdiv i64 %10, 10
%16 = add i64 %10, 9
%17 = icmp ult i64 %16, 19
br i1 %17, label %18, label %7
18: ; preds = %7
store i64 %15, i64* %1
br label %19
19: ; preds = %18, %0
%20 = phi i64 [ %13, %18 ], [ 0, %0 ]
%21 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i64 %20)
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i64 %20)
ret i32 0
}