#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 */
int /*<<< orphan*/ sprintf(char *, char *, int);
int strlen(char *);
char *BinaryDecimalConverter8(char BinaryChar[8]) {
  static char buffer[1 + sizeof(int) * 8] = {0};
  char *decimalChar = buffer - 1 + sizeof(int) * 8;
  *decimalChar = 0;
  int DecimalInt = 0;
  for (int i = 0; i < strlen(BinaryChar); i++) {
    if (BinaryChar[i] == '1')
      DecimalInt = DecimalInt * 2 + 1;
    else if (BinaryChar[i] == '0')
      DecimalInt *= 2;
  }
  sprintf(decimalChar, "%d", DecimalInt);
  return decimalChar;
}


x86 assembly (clang, -O0):
<BinaryDecimalConverter8>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
lea    0x2f0d(%rip),%rax
add    $0x1f,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x1c(%rbp),%eax
cmp    %ecx,%eax
jge    11c8 <BinaryDecimalConverter8+0xa8>
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x31,%eax
jne    1192 <BinaryDecimalConverter8+0x72>
mov    -0x14(%rbp),%eax
shl    $0x1,%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11b5 <BinaryDecimalConverter8+0x95>
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x30,%eax
jne    11b0 <BinaryDecimalConverter8+0x90>
mov    -0x14(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11b5 <BinaryDecimalConverter8+0x95>
jmp    11ba <BinaryDecimalConverter8+0x9a>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1150 <BinaryDecimalConverter8+0x30>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%edx
lea    0xe2a(%rip),%rsi
call   1040 <sprintf@plt>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<BinaryDecimalConverter8>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r15
movb   $0x0,0x2f30(%rip)
call   1030 <strlen@plt>
test   %eax,%eax
jle    116c <BinaryDecimalConverter8+0x4c>
xor    %ebx,%ebx
xor    %r14d,%r14d
jmp    1156 <BinaryDecimalConverter8+0x36>
nop
add    %r14d,%r14d
add    $0x1,%rbx
mov    %r15,%rdi
call   1030 <strlen@plt>
cltq
cmp    %rax,%rbx
jge    116f <BinaryDecimalConverter8+0x4f>
movzbl (%r15,%rbx,1),%eax
cmp    $0x30,%al
je     1140 <BinaryDecimalConverter8+0x20>
cmp    $0x31,%al
jne    1143 <BinaryDecimalConverter8+0x23>
add    %r14d,%r14d
add    $0x1,%r14d
jmp    1143 <BinaryDecimalConverter8+0x23>
xor    %r14d,%r14d
lea    0x2ee9(%rip),%rbx
lea    0xe83(%rip),%rsi
mov    %rbx,%rdi
mov    %r14d,%edx
call   1040 <sprintf@plt>
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@BinaryDecimalConverter8.buffer = internal global [33 x i8] zeroinitializer
@.str = [3 x i8] c"%d\00"
define i8* @BinaryDecimalConverter8(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
store i8* %0, i8** %2
store i8* getelementptr inbounds ([33 x i8], [33 x i8]* @BinaryDecimalConverter8.buffer, i64 0, i64 31), i8** %3
%6 = load i8*, i8** %3
store i8 0, i8* %6
store i32 0, i32* %4
store i32 0, i32* %5
br label %7
7: ; preds = %37, %1
%8 = load i32, i32* %5
%9 = load i8*, i8** %2
%10 = call i32 @strlen(i8* %9)
%11 = icmp slt i32 %8, %10
br i1 %11, label %12, label %40
12: ; preds = %7
%13 = load i8*, i8** %2
%14 = load i32, i32* %5
%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 %24
20: ; preds = %12
%21 = load i32, i32* %4
%22 = mul nsw i32 %21, 2
%23 = add nsw i32 %22, 1
store i32 %23, i32* %4
br label %36
24: ; preds = %12
%25 = load i8*, i8** %2
%26 = load i32, i32* %5
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i8, i8* %25, i64 %27
%29 = load i8, i8* %28
%30 = sext i8 %29 to i32
%31 = icmp eq i32 %30, 48
br i1 %31, label %32, label %35
32: ; preds = %24
%33 = load i32, i32* %4
%34 = mul nsw i32 %33, 2
store i32 %34, i32* %4
br label %35
35: ; preds = %32, %24
br label %36
36: ; preds = %35, %20
br label %37
37: ; preds = %36
%38 = load i32, i32* %5
%39 = add nsw i32 %38, 1
store i32 %39, i32* %5
br label %7
40: ; preds = %7
%41 = load i8*, i8** %3
%42 = load i32, i32* %4
%43 = call i32 @sprintf(i8* %41, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %42)
%44 = load i8*, i8** %3
ret i8* %44
}

LLVM IR (-O2):
@BinaryDecimalConverter8.buffer = internal global [33 x i8] zeroinitializer
@.str = [3 x i8] c"%d\00"
define i8* @BinaryDecimalConverter8(i8* %0) {
store i8 0, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @BinaryDecimalConverter8.buffer, i64 0, i64 31)
%2 = tail call i32 @strlen(i8* %0)
%3 = icmp sgt i32 %2, 0
br i1 %3, label %7, label %4
4: ; preds = %17, %1
%5 = phi i32 [ 0, %1 ], [ %18, %17 ]
%6 = tail call i32 @sprintf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @BinaryDecimalConverter8.buffer, i64 0, i64 31), i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %5)
ret i8* getelementptr inbounds ([33 x i8], [33 x i8]* @BinaryDecimalConverter8.buffer, i64 0, i64 31)
7: ; preds = %1, %17
%8 = phi i64 [ %19, %17 ], [ 0, %1 ]
%9 = phi i32 [ %18, %17 ], [ 0, %1 ]
%10 = getelementptr inbounds i8, i8* %0, i64 %8
%11 = load i8, i8* %10
switch i8 %11, label %17 [
i8 49, label %12
i8 48, label %15
]
12: ; preds = %7
%13 = shl nsw i32 %9, 1
%14 = or i32 %13, 1
br label %17
15: ; preds = %7
%16 = shl nsw i32 %9, 1
br label %17
17: ; preds = %7, %12, %15
%18 = phi i32 [ %14, %12 ], [ %16, %15 ], [ %9, %7 ]
%19 = add nuw nsw i64 %8, 1
%20 = tail call i32 @strlen(i8* %0)
%21 = sext i32 %20 to i64
%22 = icmp slt i64 %19, %21
br i1 %22, label %7, label %4
}