#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 pow_int(int, int);
int /*<<< orphan*/ printf(char *, int, int);
int strlen(char *);
void cal_bits(char *s) {
  int len;
  int i;
  int sum = 0;
  len = strlen(s);
  for (i = 0; i < len; ++i) {
    sum += pow_int(2, len - 1 - i) * (s[i] - '0');
  }
  printf("%d/%d\n", sum, 2 << (len - 1));
}


x86 assembly (clang, -O0):
<cal_bits>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    119e <cal_bits+0x6e>
mov    -0xc(%rbp),%esi
sub    $0x1,%esi
sub    -0x10(%rbp),%esi
mov    $0x2,%edi
call   1030 <pow_int@plt>
movsbl %al,%eax
mov    -0x8(%rbp),%rcx
movslq -0x10(%rbp),%rdx
movsbl (%rcx,%rdx,1),%ecx
sub    $0x30,%ecx
imul   %ecx,%eax
add    -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1156 <cal_bits+0x26>
mov    -0x14(%rbp),%esi
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
mov    $0x2,%edx
shl    %cl,%edx
lea    0xe4b(%rip),%rdi
call   1050 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cal_bits>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r15
call   1040 <strlen@plt>
mov    %eax,%r14d
test   %eax,%eax
jle    118b <cal_bits+0x5b>
mov    %r14d,%r12d
mov    %r14d,%ebx
add    $0xffffffff,%ebx
xor    %ebp,%ebp
xor    %r13d,%r13d
nopl   0x0(%rax,%rax,1)
mov    $0x2,%edi
mov    %ebx,%esi
call   1030 <pow_int@plt>
movsbl %al,%eax
movsbl (%r15,%rbp,1),%ecx
add    $0xffffffd0,%ecx
imul   %eax,%ecx
add    %ecx,%r13d
add    $0x1,%rbp
add    $0xffffffff,%ebx
cmp    %rbp,%r12
jne    1160 <cal_bits+0x30>
jmp    118e <cal_bits+0x5e>
xor    %r13d,%r13d
lea    -0x1(%r14),%ecx
mov    $0x2,%edx
shl    %cl,%edx
lea    0xe60(%rip),%rdi
mov    %r13d,%esi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <printf@plt>

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

LLVM IR (-O2):
@.str = [7 x i8] c"%d/%d\0A\00"
define void @cal_bits(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = icmp sgt i32 %2, 0
br i1 %3, label %4, label %22
4: ; preds = %1
%5 = zext i32 %2 to i64
br label %6
6: ; preds = %4, %6
%7 = phi i64 [ 0, %4 ], [ %20, %6 ]
%8 = phi i32 [ 0, %4 ], [ %19, %6 ]
%9 = trunc i64 %7 to i32
%10 = xor i32 %9, -1
%11 = add i32 %2, %10
%12 = tail call signext i8 @pow_int(i32 2, i32 %11)
%13 = sext i8 %12 to i32
%14 = getelementptr inbounds i8, i8* %0, i64 %7
%15 = load i8, i8* %14
%16 = sext i8 %15 to i32
%17 = add nsw i32 %16, -48
%18 = mul nsw i32 %17, %13
%19 = add nsw i32 %18, %8
%20 = add nuw nsw i64 %7, 1
%21 = icmp eq i64 %20, %5
br i1 %21, label %22, label %6
22: ; preds = %6, %1
%23 = phi i32 [ 0, %1 ], [ %19, %6 ]
%24 = add nsw i32 %2, -1
%25 = shl i32 2, %24
%26 = tail call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %23, i32 %25)
ret void
}