#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 */
scalar_t__ pow(int, int);
int /*<<< orphan*/ printf(char *, long double);
scalar_t__ strlen(char *);
void bin_to_dec(char *bin) {
  int i = 0;
  int power = (int)strlen(bin) - 1;
  long double value = 0;
  for (i = 0; i < (int)strlen(bin); i++) {
    if (bin[i] == '1') {
      value += pow(2, power);
    }
    power--;
  }
  printf("%.0Lf\n", value);
}


x86 assembly (clang, -O0):
<bin_to_dec>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
add    $0xffffffff,%eax
mov    %eax,-0x10(%rbp)
fldz
fstpt  -0x20(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,%rcx
mov    -0x2c(%rbp),%eax
cmp    %ecx,%eax
jge    11c3 <bin_to_dec+0x93>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x31,%eax
jne    11ac <bin_to_dec+0x7c>
mov    -0x10(%rbp),%esi
mov    $0x2,%edi
call   1050 <pow@plt>
mov    %rax,-0x28(%rbp)
fildll -0x28(%rbp)
fldt   -0x20(%rbp)
faddp  %st,%st(1)
fstpt  -0x20(%rbp)
mov    -0x10(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    115e <bin_to_dec+0x2e>
fldt   -0x20(%rbp)
mov    %rsp,%rax
fstpt  (%rax)
lea    0xe2e(%rip),%rdi
call   1040 <printf@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bin_to_dec>:
push   %r15
push   %r14
push   %rbx
sub    $0x30,%rsp
mov    %rdi,%r14
call   1030 <strlen@plt>
mov    %rax,%r15
fldz
fstpt  0x1c(%rsp)
test   %r15d,%r15d
jle    11a0 <bin_to_dec+0x70>
add    $0xffffffff,%r15d
fldz
fstpt  0x1c(%rsp)
xor    %ebx,%ebx
jmp    1177 <bin_to_dec+0x47>
nopl   (%rax)
add    $0x1,%rbx
mov    %r14,%rdi
call   1030 <strlen@plt>
cltq
add    $0xffffffff,%r15d
cmp    %rax,%rbx
jge    11a0 <bin_to_dec+0x70>
cmpb   $0x31,(%r14,%rbx,1)
jne    1160 <bin_to_dec+0x30>
mov    $0x2,%edi
mov    %r15d,%esi
call   1050 <pow@plt>
mov    %rax,0x28(%rsp)
fildll 0x28(%rsp)
fldt   0x1c(%rsp)
faddp  %st,%st(1)
fstpt  0x1c(%rsp)
jmp    1160 <bin_to_dec+0x30>
fldt   0x1c(%rsp)
fstpt  (%rsp)
lea    0xe52(%rip),%rdi
call   1040 <printf@plt>
add    $0x30,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [7 x i8] c"%.0Lf\0A\00"
define void @bin_to_dec(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca x86_fp80
store i8* %0, i8** %2
store i32 0, i32* %3
%6 = load i8*, i8** %2
%7 = call i64 @strlen(i8* %6)
%8 = trunc i64 %7 to i32
%9 = sub nsw i32 %8, 1
store i32 %9, i32* %4
store x86_fp80 0xK00000000000000000000, x86_fp80* %5
store i32 0, i32* %3
br label %10
10: ; preds = %33, %1
%11 = load i32, i32* %3
%12 = load i8*, i8** %2
%13 = call i64 @strlen(i8* %12)
%14 = trunc i64 %13 to i32
%15 = icmp slt i32 %11, %14
br i1 %15, label %16, label %36
16: ; preds = %10
%17 = load i8*, i8** %2
%18 = load i32, i32* %3
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i8, i8* %17, i64 %19
%21 = load i8, i8* %20
%22 = sext i8 %21 to i32
%23 = icmp eq i32 %22, 49
br i1 %23, label %24, label %30
24: ; preds = %16
%25 = load i32, i32* %4
%26 = call i64 @pow(i32 2, i32 %25)
%27 = sitofp i64 %26 to x86_fp80
%28 = load x86_fp80, x86_fp80* %5
%29 = fadd x86_fp80 %28, %27
store x86_fp80 %29, x86_fp80* %5
br label %30
30: ; preds = %24, %16
%31 = load i32, i32* %4
%32 = add nsw i32 %31, -1
store i32 %32, i32* %4
br label %33
33: ; preds = %30
%34 = load i32, i32* %3
%35 = add nsw i32 %34, 1
store i32 %35, i32* %3
br label %10
36: ; preds = %10
%37 = load x86_fp80, x86_fp80* %5
%38 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), x86_fp80 %37)
ret void
}

LLVM IR (-O2):
@.str = [7 x i8] c"%.0Lf\0A\00"
define void @bin_to_dec(i8* nocapture %0) {
%2 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%3 = trunc i64 %2 to i32
%4 = icmp sgt i32 %3, 0
br i1 %4, label %5, label %24
5: ; preds = %1, %17
%6 = phi i64 [ %19, %17 ], [ 0, %1 ]
%7 = phi i32 [ %9, %17 ], [ %3, %1 ]
%8 = phi x86_fp80 [ %18, %17 ], [ 0xK00000000000000000000, %1 ]
%9 = add nsw i32 %7, -1
%10 = getelementptr inbounds i8, i8* %0, i64 %6
%11 = load i8, i8* %10
%12 = icmp eq i8 %11, 49
br i1 %12, label %13, label %17
13: ; preds = %5
%14 = tail call i64 @pow(i32 2, i32 %9)
%15 = sitofp i64 %14 to x86_fp80
%16 = fadd x86_fp80 %8, %15
br label %17
17: ; preds = %13, %5
%18 = phi x86_fp80 [ %16, %13 ], [ %8, %5 ]
%19 = add nuw nsw i64 %6, 1
%20 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%21 = shl i64 %20, 32
%22 = ashr exact i64 %21, 32
%23 = icmp slt i64 %19, %22
br i1 %23, label %5, label %24
24: ; preds = %17, %1
%25 = phi x86_fp80 [ 0xK00000000000000000000, %1 ], [ %18, %17 ]
%26 = tail call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), x86_fp80 %25)
ret void
}