#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 pow(int, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, char *);
int main() {
  int bin[50];
  int binSize = 0;
  char binChar;
  int dec = 0;
  printf("Entre com um binario: ");
  while (1) {
    scanf("%c", &binChar);
    if (binChar == '1')
      bin[binSize] = 1;
    else if (binChar == '0')
      bin[binSize] = 0;
    else
      break;
    binSize++;
  }
  int i;
  for (i = binSize - 1; i >= 0; i--) {
    dec += ((int)bin[i] * pow(2, i + 1));
  }
  printf("O decimal eh: %d\n", dec);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xf0,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0xd4(%rbp)
movl   $0x0,-0xdc(%rbp)
lea    0xea3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xeac(%rip),%rdi
lea    -0xd5(%rbp),%rsi
call   1040 <scanf@plt>
movsbl -0xd5(%rbp),%eax
cmp    $0x31,%eax
jne    119e <main+0x6e>
movslq -0xd4(%rbp),%rax
movl   $0x1,-0xd0(%rbp,%rax,4)
jmp    11cf <main+0x9f>
movsbl -0xd5(%rbp),%eax
cmp    $0x30,%eax
jne    11c5 <main+0x95>
movslq -0xd4(%rbp),%rax
movl   $0x0,-0xd0(%rbp,%rax,4)
jmp    11ca <main+0x9a>
jmp    11e3 <main+0xb3>
jmp    11cf <main+0x9f>
mov    -0xd4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xd4(%rbp)
jmp    1164 <main+0x34>
mov    -0xd4(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0xe0(%rbp)
cmpl   $0x0,-0xe0(%rbp)
jl     1251 <main+0x121>
movslq -0xe0(%rbp),%rax
mov    -0xd0(%rbp,%rax,4),%eax
mov    %eax,-0xe4(%rbp)
mov    -0xe0(%rbp),%esi
add    $0x1,%esi
mov    $0x2,%edi
call   1050 <pow@plt>
mov    %eax,%ecx
mov    -0xe4(%rbp),%eax
imul   %ecx,%eax
add    -0xdc(%rbp),%eax
mov    %eax,-0xdc(%rbp)
mov    -0xe0(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xe0(%rbp)
jmp    11f2 <main+0xc2>
mov    -0xdc(%rbp),%esi
lea    0xdbc(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0xf0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0xd8,%rsp
lea    0xebc(%rip),%rdi
xor    %ebx,%ebx
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xec3(%rip),%r14
lea    0xf(%rsp),%r15
jmp    116a <main+0x3a>
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
mov    %eax,0x10(%rsp,%rbx,4)
add    $0x1,%rbx
mov    %r14,%rdi
mov    %r15,%rsi
call   1040 <scanf@plt>
movzbl 0xf(%rsp),%ecx
cmp    $0x30,%cl
je     1160 <main+0x30>
mov    $0x1,%eax
cmp    $0x31,%cl
je     1162 <main+0x32>
test   %ebx,%ebx
je     11c8 <main+0x98>
mov    %ebx,%esi
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
lea    -0x1(%rsi),%r14
mov    %r14d,%eax
mov    0x10(%rsp,%rax,4),%ebp
mov    $0x2,%edi
call   1050 <pow@plt>
imul   %ebp,%eax
add    %eax,%ebx
lea    0x1(%r14),%eax
mov    %r14,%rsi
cmp    $0x1,%eax
jg     11a0 <main+0x70>
jmp    11ca <main+0x9a>
xor    %ebx,%ebx
lea    0xe49(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
add    $0xd8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [23 x i8] c"Entre com um binario: \00"
@.str.1 = [3 x i8] c"%c\00"
@.str.2 = [18 x i8] c"O decimal eh: %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [50 x i32]
%3 = alloca i32
%4 = alloca i8
%5 = alloca i32
%6 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %3
store i32 0, i32* %5
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
br label %8
8: ; preds = %0, %27
%9 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %4)
%10 = load i8, i8* %4
%11 = sext i8 %10 to i32
%12 = icmp eq i32 %11, 49
br i1 %12, label %13, label %17
13: ; preds = %8
%14 = load i32, i32* %3
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds [50 x i32], [50 x i32]* %2, i64 0, i64 %15
store i32 1, i32* %16
br label %27
17: ; preds = %8
%18 = load i8, i8* %4
%19 = sext i8 %18 to i32
%20 = icmp eq i32 %19, 48
br i1 %20, label %21, label %25
21: ; preds = %17
%22 = load i32, i32* %3
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds [50 x i32], [50 x i32]* %2, i64 0, i64 %23
store i32 0, i32* %24
br label %26
25: ; preds = %17
br label %30
26: ; preds = %21
br label %27
27: ; preds = %26, %13
%28 = load i32, i32* %3
%29 = add nsw i32 %28, 1
store i32 %29, i32* %3
br label %8
30: ; preds = %25
%31 = load i32, i32* %3
%32 = sub nsw i32 %31, 1
store i32 %32, i32* %6
br label %33
33: ; preds = %47, %30
%34 = load i32, i32* %6
%35 = icmp sge i32 %34, 0
br i1 %35, label %36, label %50
36: ; preds = %33
%37 = load i32, i32* %6
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds [50 x i32], [50 x i32]* %2, i64 0, i64 %38
%40 = load i32, i32* %39
%41 = load i32, i32* %6
%42 = add nsw i32 %41, 1
%43 = call i32 @pow(i32 2, i32 %42)
%44 = mul nsw i32 %40, %43
%45 = load i32, i32* %5
%46 = add nsw i32 %45, %44
store i32 %46, i32* %5
br label %47
47: ; preds = %36
%48 = load i32, i32* %6
%49 = add nsw i32 %48, -1
store i32 %49, i32* %6
br label %33
50: ; preds = %33
%51 = load i32, i32* %5
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i32 %51)
ret i32 0
}

LLVM IR (-O2):
@.str = [23 x i8] c"Entre com um binario: \00"
@.str.1 = [3 x i8] c"%c\00"
@.str.2 = [18 x i8] c"O decimal eh: %d\0A\00"
define i32 @main() {
%1 = alloca [50 x i32]
%2 = alloca i8
%3 = bitcast [50 x i32]* %1 to i8*
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
br label %5
5: ; preds = %15, %0
%6 = phi i64 [ %18, %15 ], [ 0, %0 ]
%7 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %2)
%8 = load i8, i8* %2
switch i8 %8, label %9 [
i8 49, label %15
i8 48, label %14
]
9: ; preds = %5
%10 = trunc i64 %6 to i32
%11 = icmp eq i32 %10, 0
br i1 %11, label %31, label %12
12: ; preds = %9
%13 = and i64 %6, 4294967295
br label %19
14: ; preds = %5
br label %15
15: ; preds = %5, %14
%16 = phi i32 [ 0, %14 ], [ 1, %5 ]
%17 = getelementptr inbounds [50 x i32], [50 x i32]* %1, i64 0, i64 %6
store i32 %16, i32* %17
%18 = add nuw i64 %6, 1
br label %5
19: ; preds = %12, %19
%20 = phi i64 [ %13, %12 ], [ %22, %19 ]
%21 = phi i32 [ 0, %12 ], [ %29, %19 ]
%22 = add nsw i64 %20, -1
%23 = and i64 %22, 4294967295
%24 = getelementptr inbounds [50 x i32], [50 x i32]* %1, i64 0, i64 %23
%25 = load i32, i32* %24
%26 = trunc i64 %20 to i32
%27 = call i32 @pow(i32 2, i32 %26)
%28 = mul nsw i32 %27, %25
%29 = add nsw i32 %28, %21
%30 = icmp sgt i32 %26, 1
br i1 %30, label %19, label %31
31: ; preds = %19, %9
%32 = phi i32 [ 0, %9 ], [ %29, %19 ]
%33 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i32 %32)
ret i32 0
}