#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 ex2(int);
int binToDec(char *bin, int no) {
  static int dec = 0;
  int i;
  for (i = 0; i < no; ++i) {
    dec = dec + (ex2(i) * (bin[9 - i] - '0'));
  }
  return dec;
}


x86 assembly (clang, -O0):
<binToDec>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    117a <binToDec+0x6a>
mov    0x2ef4(%rip),%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%edi
call   1030 <ex2@plt>
mov    %al,%cl
mov    -0x14(%rbp),%eax
movsbl %cl,%ecx
mov    -0x8(%rbp),%rdx
mov    $0x9,%esi
sub    -0x10(%rbp),%esi
movslq %esi,%rsi
movsbl (%rdx,%rsi,1),%edx
sub    $0x30,%edx
imul   %edx,%ecx
add    %ecx,%eax
mov    %eax,0x2ec0(%rip)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1126 <binToDec+0x16>
mov    0x2eac(%rip),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<binToDec>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
test   %esi,%esi
jle    115b <binToDec+0x4b>
mov    %rdi,%r14
mov    %esi,%r15d
mov    0x2f05(%rip),%ebp
add    $0x9,%r14
xor    %ebx,%ebx
nopl   (%rax)
mov    %ebx,%edi
call   1030 <ex2@plt>
movsbl %al,%eax
movsbl (%r14),%ecx
add    $0xffffffd0,%ecx
imul   %eax,%ecx
add    %ecx,%ebp
mov    %ebp,0x2ee0(%rip)
add    $0x1,%rbx
add    $0xffffffffffffffff,%r14
cmp    %rbx,%r15
jne    1130 <binToDec+0x20>
jmp    1161 <binToDec+0x51>
mov    0x2ecb(%rip),%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@binToDec.dec = internal global i32 0
define i32 @binToDec(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
store i32 0, i32* %5
br label %6
6: ; preds = %25, %2
%7 = load i32, i32* %5
%8 = load i32, i32* %4
%9 = icmp slt i32 %7, %8
br i1 %9, label %10, label %28
10: ; preds = %6
%11 = load i32, i32* @binToDec.dec
%12 = load i32, i32* %5
%13 = call signext i8 @ex2(i32 %12)
%14 = sext i8 %13 to i32
%15 = load i8*, i8** %3
%16 = load i32, i32* %5
%17 = sub nsw i32 9, %16
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8, i8* %15, i64 %18
%20 = load i8, i8* %19
%21 = sext i8 %20 to i32
%22 = sub nsw i32 %21, 48
%23 = mul nsw i32 %14, %22
%24 = add nsw i32 %11, %23
store i32 %24, i32* @binToDec.dec
br label %25
25: ; preds = %10
%26 = load i32, i32* %5
%27 = add nsw i32 %26, 1
store i32 %27, i32* %5
br label %6
28: ; preds = %6
%29 = load i32, i32* @binToDec.dec
ret i32 %29
}

LLVM IR (-O2):
@binToDec.dec = internal unnamed_addr global i32 0
define i32 @binToDec(i8* nocapture %0, i32 %1) {
%3 = icmp sgt i32 %1, 0
br i1 %3, label %6, label %4
4: ; preds = %2
%5 = load i32, i32* @binToDec.dec
br label %24
6: ; preds = %2
%7 = zext i32 %1 to i64
%8 = load i32, i32* @binToDec.dec
br label %9
9: ; preds = %6, %9
%10 = phi i32 [ %8, %6 ], [ %21, %9 ]
%11 = phi i64 [ 0, %6 ], [ %22, %9 ]
%12 = trunc i64 %11 to i32
%13 = tail call signext i8 @ex2(i32 %12)
%14 = sext i8 %13 to i32
%15 = sub nsw i64 9, %11
%16 = getelementptr inbounds i8, i8* %0, i64 %15
%17 = load i8, i8* %16
%18 = sext i8 %17 to i32
%19 = add nsw i32 %18, -48
%20 = mul nsw i32 %19, %14
%21 = add nsw i32 %20, %10
store i32 %21, i32* @binToDec.dec
%22 = add nuw nsw i64 %11, 1
%23 = icmp eq i64 %22, %7
br i1 %23, label %24, label %9
24: ; preds = %9, %4
%25 = phi i32 [ %5, %4 ], [ %21, %9 ]
ret i32 %25
}