#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() {
  long int bin_num, oct_num = 0, j = 1, remainder;
  printf("Enter the value for binary number: ");
  scanf("%ld", &bin_num);
  while (bin_num != 0) {
    remainder = bin_num % 10;
    oct_num = oct_num + remainder * j;
    j = j * 2;
    bin_num = bin_num / 10;
  }
  printf("Equivalent octal value: %lo", oct_num);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x1,-0x20(%rbp)
lea    0xeba(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xed0(%rip),%rdi
lea    -0x10(%rbp),%rsi
call   1040 <scanf@plt>
cmpq   $0x0,-0x10(%rbp)
je     11b1 <main+0x91>
mov    -0x10(%rbp),%rax
mov    $0xa,%ecx
cqto
idiv   %rcx
mov    %rdx,-0x28(%rbp)
mov    -0x18(%rbp),%rax
mov    -0x28(%rbp),%rcx
imul   -0x20(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x18(%rbp)
mov    -0x20(%rbp),%rax
shl    $0x1,%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    $0xa,%ecx
cqto
idiv   %rcx
mov    %rax,-0x10(%rbp)
jmp    115d <main+0x3d>
mov    -0x18(%rbp),%rsi
lea    0xe6c(%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    0xee8(%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    0xe73(%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 = [36 x i8] c"Enter the value for binary number: \00"
@.str.1 = [4 x i8] c"%ld\00"
@.str.2 = [28 x i8] c"Equivalent octal value: %lo\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca i64
%4 = alloca i64
%5 = alloca i64
store i32 0, i32* %1
store i64 0, i64* %3
store i64 1, i64* %4
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
%7 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i64* %2)
br label %8
8: ; preds = %11, %0
%9 = load i64, i64* %2
%10 = icmp ne i64 %9, 0
br i1 %10, label %11, label %23
11: ; preds = %8
%12 = load i64, i64* %2
%13 = srem i64 %12, 10
store i64 %13, i64* %5
%14 = load i64, i64* %3
%15 = load i64, i64* %5
%16 = load i64, i64* %4
%17 = mul nsw i64 %15, %16
%18 = add nsw i64 %14, %17
store i64 %18, i64* %3
%19 = load i64, i64* %4
%20 = mul nsw i64 %19, 2
store i64 %20, i64* %4
%21 = load i64, i64* %2
%22 = sdiv i64 %21, 10
store i64 %22, i64* %2
br label %8
23: ; preds = %8
%24 = load i64, i64* %3
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i64 %24)
ret i32 0
}

LLVM IR (-O2):
@.str = [36 x i8] c"Enter the value for binary number: \00"
@.str.1 = [4 x i8] c"%ld\00"
@.str.2 = [28 x i8] c"Equivalent octal value: %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 ([36 x i8], [36 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 ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i64 %20)
ret i32 0
}