#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*/ printf(char *, int);
int strlen(char *);
int binaryToDecimal(char *binary) {
  int length;
  int i;
  int res = 0;
  length = strlen(binary);
  for (i = 0; i < length; i++) {
    printf("i = %d : ", i);
    if (binary[i] == '1') {
      res = (res << 1) | 1;
      printf("res = %d \n", res);
    } else {
      res = res << 1;
      printf("res = %d \n", res);
    }
  }
  printf("Taille de la chaine à convertir : %d \n", length);
  printf("Conversion en décimal de la chaine : %d \n", res);
  return res;
}


x86 assembly (clang, -O0):
<binaryToDecimal>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11c1 <binaryToDecimal+0xa1>
mov    -0x10(%rbp),%esi
lea    0xea4(%rip),%rdi
call   1040 <printf@plt>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x31,%eax
jne    1196 <binaryToDecimal+0x76>
mov    -0x14(%rbp),%eax
shl    $0x1,%eax
or     $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%esi
lea    0xe7e(%rip),%rdi
call   1040 <printf@plt>
jmp    11ae <binaryToDecimal+0x8e>
mov    -0x14(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%esi
lea    0xe61(%rip),%rdi
call   1040 <printf@plt>
jmp    11b3 <binaryToDecimal+0x93>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1146 <binaryToDecimal+0x26>
mov    -0xc(%rbp),%esi
lea    0xe4a(%rip),%rdi
call   1040 <printf@plt>
mov    -0x14(%rbp),%esi
lea    0xe63(%rip),%rdi
call   1040 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<binaryToDecimal>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r15
call   1030 <strlen@plt>
test   %eax,%eax
mov    %eax,0x4(%rsp)
jle    117c <binaryToDecimal+0x5c>
mov    %eax,%r14d
xor    %ebx,%ebx
lea    0xeb9(%rip),%r12
lea    0xebc(%rip),%r13
xor    %ebp,%ebp
mov    %r12,%rdi
mov    %ebx,%esi
call   1040 <printf@plt>
xor    %eax,%eax
cmpb   $0x31,(%r15,%rbx,1)
sete   %al
lea    (%rax,%rbp,2),%ebp
mov    %r13,%rdi
mov    %ebp,%esi
call   1040 <printf@plt>
add    $0x1,%rbx
cmp    %rbx,%r14
jne    1150 <binaryToDecimal+0x30>
jmp    117e <binaryToDecimal+0x5e>
xor    %ebp,%ebp
lea    0xe90(%rip),%rdi
mov    0x4(%rsp),%esi
call   1040 <printf@plt>
lea    0xea8(%rip),%rdi
mov    %ebp,%esi
call   1040 <printf@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [10 x i8] c"i = %d : \00"
@.str.1 = [11 x i8] c"res = %d \0A\00"
@.str.2 = [40 x i8] c"Taille de la chaine \C3\A0 convertir : %d \0A\00"
@.str.3 = [43 x i8] c"Conversion en d\C3\A9cimal de la chaine : %d \0A\00"
define i32 @binaryToDecimal(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 = %34, %1
%9 = load i32, i32* %4
%10 = load i32, i32* %3
%11 = icmp slt i32 %9, %10
br i1 %11, label %12, label %37
12: ; preds = %8
%13 = load i32, i32* %4
%14 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %13)
%15 = load i8*, i8** %2
%16 = load i32, i32* %4
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i8, i8* %15, i64 %17
%19 = load i8, i8* %18
%20 = sext i8 %19 to i32
%21 = icmp eq i32 %20, 49
br i1 %21, label %22, label %28
22: ; preds = %12
%23 = load i32, i32* %5
%24 = shl i32 %23, 1
%25 = or i32 %24, 1
store i32 %25, i32* %5
%26 = load i32, i32* %5
%27 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 %26)
br label %33
28: ; preds = %12
%29 = load i32, i32* %5
%30 = shl i32 %29, 1
store i32 %30, i32* %5
%31 = load i32, i32* %5
%32 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 %31)
br label %33
33: ; preds = %28, %22
br label %34
34: ; preds = %33
%35 = load i32, i32* %4
%36 = add nsw i32 %35, 1
store i32 %36, i32* %4
br label %8
37: ; preds = %8
%38 = load i32, i32* %3
%39 = call i32 @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0), i32 %38)
%40 = load i32, i32* %5
%41 = call i32 @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.3, i64 0, i64 0), i32 %40)
%42 = load i32, i32* %5
ret i32 %42
}

LLVM IR (-O2):
@.str = [10 x i8] c"i = %d : \00"
@.str.1 = [11 x i8] c"res = %d \0A\00"
@.str.2 = [40 x i8] c"Taille de la chaine \C3\A0 convertir : %d \0A\00"
@.str.3 = [43 x i8] c"Conversion en d\C3\A9cimal de la chaine : %d \0A\00"
define i32 @binaryToDecimal(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = icmp sgt i32 %2, 0
br i1 %3, label %4, label %20
4: ; preds = %1
%5 = zext i32 %2 to i64
br label %6
6: ; preds = %4, %6
%7 = phi i64 [ 0, %4 ], [ %18, %6 ]
%8 = phi i32 [ 0, %4 ], [ %16, %6 ]
%9 = trunc i64 %7 to i32
%10 = tail call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %9)
%11 = getelementptr inbounds i8, i8* %0, i64 %7
%12 = load i8, i8* %11
%13 = icmp eq i8 %12, 49
%14 = shl i32 %8, 1
%15 = zext i1 %13 to i32
%16 = or i32 %14, %15
%17 = tail call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 %16)
%18 = add nuw nsw i64 %7, 1
%19 = icmp eq i64 %18, %5
br i1 %19, label %20, label %6
20: ; preds = %6, %1
%21 = phi i32 [ 0, %1 ], [ %16, %6 ]
%22 = tail call i32 @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0), i32 %2)
%23 = tail call i32 @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.3, i64 0, i64 0), i32 %21)
ret i32 %21
}