#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 *, int *);
int main() {
  int b, a, wt, p, r;
  printf("Enter the binary number");
  scanf("%d", &b);
  p = 0;
  wt = 1;
  while (b > 0) {
    r = b % 10;
    a = wt * r;
    wt = wt * 2;
    p = p + a;
  }
  printf("The converted binary digits in dicimal is %d", p);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeca(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xefe(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1040 <scanf@plt>
movl   $0x0,-0x14(%rbp)
movl   $0x1,-0x10(%rbp)
cmpl   $0x0,-0x8(%rbp)
jle    1194 <main+0x74>
mov    -0x8(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %edx,-0x18(%rbp)
mov    -0x10(%rbp),%eax
imul   -0x18(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x10(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x10(%rbp)
mov    -0x14(%rbp),%eax
add    -0xc(%rbp),%eax
mov    %eax,-0x14(%rbp)
jmp    115b <main+0x3b>
mov    -0x14(%rbp),%esi
lea    0xe7a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
lea    0xed8(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xf0c(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1040 <scanf@plt>
lea    0xed1(%rip),%rdi
xor    %esi,%esi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [24 x i8] c"Enter the binary number\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [45 x i8] c"The converted binary digits in dicimal is %d\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 0, i32* %1
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
%8 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
store i32 0, i32* %5
store i32 1, i32* %4
br label %9
9: ; preds = %12, %0
%10 = load i32, i32* %2
%11 = icmp sgt i32 %10, 0
br i1 %11, label %12, label %23
12: ; preds = %9
%13 = load i32, i32* %2
%14 = srem i32 %13, 10
store i32 %14, i32* %6
%15 = load i32, i32* %4
%16 = load i32, i32* %6
%17 = mul nsw i32 %15, %16
store i32 %17, i32* %3
%18 = load i32, i32* %4
%19 = mul nsw i32 %18, 2
store i32 %19, i32* %4
%20 = load i32, i32* %5
%21 = load i32, i32* %3
%22 = add nsw i32 %20, %21
store i32 %22, i32* %5
br label %9
23: ; preds = %9
%24 = load i32, i32* %5
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.2, i64 0, i64 0), i32 %24)
ret i32 0
}

LLVM IR (-O2):
@.str = [24 x i8] c"Enter the binary number\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [45 x i8] c"The converted binary digits in dicimal is %d\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
%4 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%5 = load i32, i32* %1
%6 = icmp slt i32 %5, 1
%7 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @.str.2, i64 0, i64 0), i32 0)
ret i32 0
}