#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);
scalar_t__ strlen(char *);
double process_mantissa(char *bin) {
  int i = 0;
  int power = -1;
  double value = 0;
  for (i = 0; i < (int)strlen(bin); i++) {
    if (bin[i] == '1') {
      value += pow(2, power);
    }
    power--;
  }
  return value;
}


x86 assembly (clang, -O0):
<process_mantissa>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0xffffffff,-0x10(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x18(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,%rcx
mov    -0x1c(%rbp),%eax
cmp    %ecx,%eax
jge    11ae <process_mantissa+0x8e>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x31,%eax
jne    1197 <process_mantissa+0x77>
mov    -0x10(%rbp),%esi
mov    $0x2,%edi
call   1040 <pow@plt>
cvtsi2sd %rax,%xmm0
addsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    -0x10(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1149 <process_mantissa+0x29>
movsd  -0x18(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<process_mantissa>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%r14
call   1030 <strlen@plt>
test   %eax,%eax
jle    1193 <process_mantissa+0x73>
mov    $0xffffffff,%ebp
xorpd  %xmm0,%xmm0
movsd  %xmm0,0x8(%rsp)
xor    %ebx,%ebx
jmp    1166 <process_mantissa+0x46>
nopw   0x0(%rax,%rax,1)
add    $0xffffffff,%ebp
add    $0x1,%rbx
mov    %r14,%rdi
call   1030 <strlen@plt>
cltq
cmp    %rax,%rbx
jge    119d <process_mantissa+0x7d>
cmpb   $0x31,(%r14,%rbx,1)
jne    1150 <process_mantissa+0x30>
mov    $0x2,%edi
mov    %ebp,%esi
call   1040 <pow@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
movsd  0x8(%rsp),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,0x8(%rsp)
jmp    1150 <process_mantissa+0x30>
xorpd  %xmm0,%xmm0
movsd  %xmm0,0x8(%rsp)
movsd  0x8(%rsp),%xmm0
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define double @process_mantissa(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca double
store i8* %0, i8** %2
store i32 0, i32* %3
store i32 -1, i32* %4
store double 0.000000e+00, double* %5
store i32 0, i32* %3
br label %6
6: ; preds = %29, %1
%7 = load i32, i32* %3
%8 = load i8*, i8** %2
%9 = call i64 @strlen(i8* %8)
%10 = trunc i64 %9 to i32
%11 = icmp slt i32 %7, %10
br i1 %11, label %12, label %32
12: ; preds = %6
%13 = load i8*, i8** %2
%14 = load i32, i32* %3
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds i8, i8* %13, i64 %15
%17 = load i8, i8* %16
%18 = sext i8 %17 to i32
%19 = icmp eq i32 %18, 49
br i1 %19, label %20, label %26
20: ; preds = %12
%21 = load i32, i32* %4
%22 = call i64 @pow(i32 2, i32 %21)
%23 = sitofp i64 %22 to double
%24 = load double, double* %5
%25 = fadd double %24, %23
store double %25, double* %5
br label %26
26: ; preds = %20, %12
%27 = load i32, i32* %4
%28 = add nsw i32 %27, -1
store i32 %28, i32* %4
br label %29
29: ; preds = %26
%30 = load i32, i32* %3
%31 = add nsw i32 %30, 1
store i32 %31, i32* %3
br label %6
32: ; preds = %6
%33 = load double, double* %5
ret double %33
}

LLVM IR (-O2):
define double @process_mantissa(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, %16
%6 = phi i64 [ %19, %16 ], [ 0, %1 ]
%7 = phi double [ %17, %16 ], [ 0.000000e+00, %1 ]
%8 = phi i32 [ %18, %16 ], [ -1, %1 ]
%9 = getelementptr inbounds i8, i8* %0, i64 %6
%10 = load i8, i8* %9
%11 = icmp eq i8 %10, 49
br i1 %11, label %12, label %16
12: ; preds = %5
%13 = tail call i64 @pow(i32 2, i32 %8)
%14 = sitofp i64 %13 to double
%15 = fadd double %7, %14
br label %16
16: ; preds = %12, %5
%17 = phi double [ %15, %12 ], [ %7, %5 ]
%18 = add nsw i32 %8, -1
%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 = %16, %1
%25 = phi double [ 0.000000e+00, %1 ], [ %17, %16 ]
ret double %25
}