#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 */
char getchar();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ scanf(char *, char *);
int main() {
  char bin[20] = "0";
  int x;
  int dec_total = 0;
  long unsigned int dec = 1;
  printf("\tThe Amazing Binary to Decimal Conveter\n\n\a");
  printf("Enter here the bin23 number you want to be converted to decimal %c ",
         16);
  scanf("%s", bin);
  while (getchar() != '\n')
    continue;
  for (x = 0; x < 20; x++) {
    if (bin[x] == '1') {
      dec_total += dec;
      dec <<= 1;
    } else
      dec <<= 1;
  }
  printf("\n\n%s\n\tin\n\tdecimal\n\tis\n\t\t%d", bin, dec_total);
  puts("\n\n\n");
  getchar();
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xeaa(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0xea7(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    0xea5(%rip),%eax
mov    %eax,-0x10(%rbp)
movl   $0x0,-0x28(%rbp)
movq   $0x1,-0x30(%rbp)
lea    0xe90(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xead(%rip),%rdi
mov    $0x10,%esi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x20(%rbp),%rsi
lea    0xeda(%rip),%rdi
call   1060 <scanf@plt>
mov    $0x0,%al
call   1050 <getchar@plt>
movsbl %al,%eax
cmp    $0xa,%eax
je     11c6 <main+0x86>
jmp    11ae <main+0x6e>
movl   $0x0,-0x24(%rbp)
cmpl   $0x14,-0x24(%rbp)
jge    1227 <main+0xe7>
movslq -0x24(%rbp),%rax
movsbl -0x20(%rbp,%rax,1),%eax
cmp    $0x31,%eax
jne    1208 <main+0xc8>
mov    -0x30(%rbp),%rcx
movslq -0x28(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x28(%rbp)
mov    -0x30(%rbp),%rax
shl    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    1214 <main+0xd4>
mov    -0x30(%rbp),%rax
shl    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    1219 <main+0xd9>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11cd <main+0x8d>
lea    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%edx
lea    0xe51(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe5e(%rip),%rdi
call   1030 <puts@plt>
mov    $0x0,%al
call   1050 <getchar@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
sub    $0x18,%rsp
movaps 0xf15(%rip),%xmm0
movaps %xmm0,(%rsp)
movl   $0x0,0x10(%rsp)
lea    0xf16(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xf33(%rip),%rdi
mov    $0x10,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xf64(%rip),%rdi
mov    %rsp,%rsi
call   1060 <scanf@plt>
nopw   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1050 <getchar@plt>
cmp    $0xa,%al
jne    1190 <main+0x50>
xor    %eax,%eax
cmpb   $0x31,(%rsp)
sete   %al
xor    %ecx,%ecx
cmpb   $0x31,0x1(%rsp)
sete   %cl
add    %ecx,%ecx
xor    %edx,%edx
cmpb   $0x31,0x2(%rsp)
sete   %dl
shl    $0x2,%edx
or     %ecx,%edx
or     %eax,%edx
movd   0x3(%rsp),%xmm0
movdqa 0xe31(%rip),%xmm1
pcmpeqb %xmm1,%xmm0
punpcklbw %xmm0,%xmm0
punpcklwd %xmm0,%xmm0
pand   0xe2d(%rip),%xmm0
pshufd $0xee,%xmm0,%xmm2
por    %xmm0,%xmm2
pshufd $0x55,%xmm2,%xmm0
por    %xmm2,%xmm0
movd   %xmm0,%eax
or     %edx,%eax
xor    %ecx,%ecx
cmpb   $0x31,0x7(%rsp)
movq   0x8(%rsp),%xmm0
pcmpeqb %xmm1,%xmm0
punpcklbw %xmm0,%xmm0
punpcklwd %xmm0,%xmm0
psrad  $0x18,%xmm0
pand   0xdff(%rip),%xmm0
sete   %cl
movq   0xc(%rsp),%xmm1
pcmpeqb 0xdfe(%rip),%xmm1
shl    $0x7,%ecx
punpcklbw %xmm1,%xmm1
punpcklwd %xmm1,%xmm2
psrad  $0x18,%xmm2
punpckhwd %xmm1,%xmm1
psrad  $0x18,%xmm1
pand   0xded(%rip),%xmm1
pand   0xdf5(%rip),%xmm2
por    %xmm1,%xmm2
pshufd $0xee,%xmm2,%xmm1
paddd  %xmm2,%xmm1
pshufd $0x55,%xmm1,%xmm2
paddd  %xmm1,%xmm2
movd   %xmm2,%esi
pshufd $0xee,%xmm0,%xmm1
paddd  %xmm0,%xmm1
pshufd $0x55,%xmm1,%xmm0
paddd  %xmm1,%xmm0
movd   %xmm0,%edx
add    %esi,%edx
add    %ecx,%edx
add    %eax,%edx
lea    0xe4e(%rip),%rdi
mov    %rsp,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe58(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1050 <getchar@plt>
xor    %eax,%eax
add    $0x18,%rsp
ret

LLVM IR (-O0):
@__const.main.bin = [20 x i8] c"0\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
@.str = [43 x i8] c"\09The Amazing Binary to Decimal Conveter\0A\0A\07\00"
@.str.1 = [68 x i8] c"Enter here the bin23 number you want to be converted to decimal %c \00"
@.str.2 = [3 x i8] c"%s\00"
@.str.3 = [27 x i8] c"\0A\0A%s\0A\09in\0A\09decimal\0A\09is\0A\09\09%d\00"
@.str.4 = [4 x i8] c"\0A\0A\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [20 x i8]
%3 = alloca i32
%4 = alloca i32
%5 = alloca i64
store i32 0, i32* %1
%6 = bitcast [20 x i8]* %2 to i8*
store i32 0, i32* %4
store i64 1, i64* %5
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0))
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([68 x i8], [68 x i8]* @.str.1, i64 0, i64 0), i32 16)
%9 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 0
%10 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %9)
br label %11
11: ; preds = %15, %0
%12 = call signext i8 (...) @getchar()
%13 = sext i8 %12 to i32
%14 = icmp ne i32 %13, 10
br i1 %14, label %15, label %16
15: ; preds = %11
br label %11
16: ; preds = %11
store i32 0, i32* %3
br label %17
17: ; preds = %39, %16
%18 = load i32, i32* %3
%19 = icmp slt i32 %18, 20
br i1 %19, label %20, label %42
20: ; preds = %17
%21 = load i32, i32* %3
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 %22
%24 = load i8, i8* %23
%25 = sext i8 %24 to i32
%26 = icmp eq i32 %25, 49
br i1 %26, label %27, label %35
27: ; preds = %20
%28 = load i64, i64* %5
%29 = load i32, i32* %4
%30 = sext i32 %29 to i64
%31 = add i64 %30, %28
%32 = trunc i64 %31 to i32
store i32 %32, i32* %4
%33 = load i64, i64* %5
%34 = shl i64 %33, 1
store i64 %34, i64* %5
br label %38
35: ; preds = %20
%36 = load i64, i64* %5
%37 = shl i64 %36, 1
store i64 %37, i64* %5
br label %38
38: ; preds = %35, %27
br label %39
39: ; preds = %38
%40 = load i32, i32* %3
%41 = add nsw i32 %40, 1
store i32 %41, i32* %3
br label %17
42: ; preds = %17
%43 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 0
%44 = load i32, i32* %4
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0), i8* %43, i32 %44)
%46 = call i32 @puts(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0))
%47 = call signext i8 (...) @getchar()
ret i32 0
}

LLVM IR (-O2):
@__const.main.bin = [20 x i8] c"0\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
@.str = [43 x i8] c"\09The Amazing Binary to Decimal Conveter\0A\0A\07\00"
@.str.1 = [68 x i8] c"Enter here the bin23 number you want to be converted to decimal %c \00"
@.str.2 = [3 x i8] c"%s\00"
@.str.3 = [27 x i8] c"\0A\0A%s\0A\09in\0A\09decimal\0A\09is\0A\09\09%d\00"
@.str.4 = [4 x i8] c"\0A\0A\0A\00"
define i32 @main() {
%1 = alloca [20 x i8]
%2 = getelementptr inbounds [20 x i8], [20 x i8]* %1, i64 0, i64 0
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0))
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([68 x i8], [68 x i8]* @.str.1, i64 0, i64 0), i32 16)
%5 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %2)
br label %6
6: ; preds = %6, %0
%7 = call signext i8 (...) @getchar()
%8 = icmp eq i8 %7, 10
br i1 %8, label %9, label %6
9: ; preds = %6
%10 = load i8, i8* %2
%11 = icmp eq i8 %10, 49
%12 = zext i1 %11 to i32
%13 = getelementptr inbounds [20 x i8], [20 x i8]* %1, i64 0, i64 1
%14 = load i8, i8* %13
%15 = icmp eq i8 %14, 49
%16 = select i1 %15, i32 2, i32 0
%17 = getelementptr inbounds [20 x i8], [20 x i8]* %1, i64 0, i64 2
%18 = load i8, i8* %17
%19 = icmp eq i8 %18, 49
%20 = select i1 %19, i32 4, i32 0
%21 = getelementptr inbounds [20 x i8], [20 x i8]* %1, i64 0, i64 3
%22 = bitcast i8* %21 to <4 x i8>*
%23 = load <4 x i8>, <4 x i8>* %22
%24 = icmp eq <4 x i8> %23, <i8 49, i8 49, i8 49, i8 49>
%25 = select <4 x i1> %24, <4 x i32> <i32 8, i32 16, i32 32, i32 64>, <4 x i32> zeroinitializer
%26 = call i32 @llvm.vector.reduce.or.v4i32(<4 x i32> %25)
%27 = or i32 %26, %20
%28 = or i32 %27, %16
%29 = or i32 %28, %12
%30 = getelementptr inbounds [20 x i8], [20 x i8]* %1, i64 0, i64 7
%31 = load i8, i8* %30
%32 = icmp eq i8 %31, 49
%33 = select i1 %32, i32 128, i32 0
%34 = getelementptr inbounds [20 x i8], [20 x i8]* %1, i64 0, i64 8
%35 = bitcast i8* %34 to <4 x i8>*
%36 = load <4 x i8>, <4 x i8>* %35
%37 = icmp eq <4 x i8> %36, <i8 49, i8 49, i8 49, i8 49>
%38 = select <4 x i1> %37, <4 x i32> <i32 256, i32 512, i32 1024, i32 2048>, <4 x i32> zeroinitializer
%39 = getelementptr inbounds [20 x i8], [20 x i8]* %1, i64 0, i64 12
%40 = bitcast i8* %39 to <8 x i8>*
%41 = load <8 x i8>, <8 x i8>* %40
%42 = icmp eq <8 x i8> %41, <i8 49, i8 49, i8 49, i8 49, i8 49, i8 49, i8 49, i8 49>
%43 = select <8 x i1> %42, <8 x i32> <i32 4096, i32 8192, i32 16384, i32 32768, i32 65536, i32 131072, i32 262144, i32 524288>, <8 x i32> zeroinitializer
%44 = call i32 @llvm.vector.reduce.add.v8i32(<8 x i32> %43)
%45 = call i32 @llvm.vector.reduce.add.v4i32(<4 x i32> %38)
%46 = add i32 %44, %45
%47 = add i32 %46, %33
%48 = add i32 %47, %29
%49 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0), i8* %2, i32 %48)
%50 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0))
%51 = call signext i8 (...) @getchar()
ret i32 0
}