#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 *malloc(int);
scalar_t__ pow(int, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, char *);
int strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
int main() {
  int n = 0, i = 0, tam = 0;
  char t[100], *s = malloc(sizeof *s);
  double soma = 0;
  do {
    scanf("%s", t);
    tam = strlen(t);
    if (0)
      printf("T:%s, TAM: %d\n", t, tam);
    strncpy(s, t, tam);
    if (s[0] == '-')
      return 0;
    i = 0;
    soma = 0;
    do {
      if ((s[i] != '0') && (s[i] != '1')) {
        printf("Não é binário!\n");
        return 0;
      } else {
        if (s[i] == '1') {
          soma += pow(2, tam - i - 1);
        }
      }
      i++;
    } while (i < tam);
    printf("Decimal: %.0lf\n", soma);
  } while (!n);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    $0x1,%edi
call   1060 <malloc@plt>
mov    %rax,-0x88(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x90(%rbp)
ff
lea    -0x80(%rbp),%rsi
lea    0xe52(%rip),%rdi
call   1070 <scanf@plt>
lea    -0x80(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x10(%rbp)
mov    -0x88(%rbp),%rdi
lea    -0x80(%rbp),%rsi
mov    -0x10(%rbp),%edx
call   1030 <strncpy@plt>
mov    -0x88(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2d,%eax
jne    11f1 <main+0x91>
movl   $0x0,-0x4(%rbp)
jmp    12d5 <main+0x175>
movl   $0x0,-0xc(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x90(%rbp)
ff
mov    -0x88(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x30,%eax
je     124d <main+0xed>
mov    -0x88(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x31,%eax
je     124d <main+0xed>
lea    0xdc9(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    12d5 <main+0x175>
mov    -0x88(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x31,%eax
jne    128d <main+0x12d>
mov    -0x10(%rbp),%esi
sub    -0xc(%rbp),%esi
sub    $0x1,%esi
mov    $0x2,%edi
call   1080 <pow@plt>
cvtsi2sd %rax,%xmm0
addsd  -0x90(%rbp),%xmm0
ff
movsd  %xmm0,-0x90(%rbp)
ff
jmp    1292 <main+0x132>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x10(%rbp),%eax
jl     1203 <main+0xa3>
movsd  -0x90(%rbp),%xmm0
ff
lea    0xd60(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
cmpl   $0x0,-0x8(%rbp)
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11a3 <main+0x43>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x78,%rsp
mov    $0x1,%edi
call   1070 <malloc@plt>
mov    %rax,%r13
lea    0xe6e(%rip),%rdi
lea    0x10(%rsp),%r14
mov    %r14,%rsi
call   1080 <scanf@plt>
mov    %r14,%rdi
call   1050 <strlen@plt>
mov    %eax,%ebp
mov    %r13,%rdi
mov    %r14,%rsi
mov    %eax,%edx
call   1030 <strncpy@plt>
mov    0x0(%r13),%al
cmp    $0x2d,%al
je     12aa <main+0x13a>
lea    0xe37(%rip),%r15
lea    0x10(%rsp),%r12
cmp    $0x2,%ebp
mov    $0x1,%ebx
cmovge %ebp,%ebx
mov    %eax,%ecx
and    $0xfe,%cl
cmp    $0x30,%cl
jne    129e <main+0x12e>
add    $0xffffffff,%ebp
xorps  %xmm0,%xmm0
mov    $0x1,%r14d
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
cmp    $0x31,%al
jne    1234 <main+0xc4>
mov    $0x2,%edi
mov    %ebp,%esi
movsd  %xmm0,0x8(%rsp)
call   1090 <pow@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
movsd  0x8(%rsp),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,0x8(%rsp)
movsd  0x8(%rsp),%xmm0
cmp    %r14,%rbx
je     1260 <main+0xf0>
movzbl 0x0(%r13,%r14,1),%eax
mov    %eax,%ecx
and    $0xfe,%cl
add    $0xffffffff,%ebp
add    $0x1,%r14
cmp    $0x30,%cl
je     1200 <main+0x90>
jmp    129e <main+0x12e>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
lea    0xd9c(%rip),%rdi
mov    $0x1,%al
call   1060 <printf@plt>
mov    %r15,%rdi
mov    %r12,%rsi
call   1080 <scanf@plt>
mov    %r12,%rdi
call   1050 <strlen@plt>
mov    %eax,%ebp
mov    %r13,%rdi
mov    %r12,%rsi
mov    %eax,%edx
call   1030 <strncpy@plt>
mov    0x0(%r13),%al
cmp    $0x2d,%al
jne    11ce <main+0x5e>
jmp    12aa <main+0x13a>
lea    0xd6e(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
add    $0x78,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%s\00"
@.str.1 = [19 x i8] c"N\C3\A3o \C3\A9 bin\C3\A1rio!\0A\00"
@.str.2 = [16 x i8] c"Decimal: %.0lf\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca [100 x i8]
%6 = alloca i8*
%7 = alloca double
store i32 0, i32* %1
store i32 0, i32* %2
store i32 0, i32* %3
store i32 0, i32* %4
%8 = call i8* @malloc(i32 1)
store i8* %8, i8** %6
store double 0.000000e+00, double* %7
br label %9
9: ; preds = %71, %0
%10 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%11 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %10)
%12 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%13 = call i32 @strlen(i8* %12)
store i32 %13, i32* %4
%14 = load i8*, i8** %6
%15 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%16 = load i32, i32* %4
%17 = call i32 @strncpy(i8* %14, i8* %15, i32 %16)
%18 = load i8*, i8** %6
%19 = getelementptr inbounds i8, i8* %18, i64 0
%20 = load i8, i8* %19
%21 = sext i8 %20 to i32
%22 = icmp eq i32 %21, 45
br i1 %22, label %23, label %24
23: ; preds = %9
store i32 0, i32* %1
br label %76
24: ; preds = %9
store i32 0, i32* %3
store double 0.000000e+00, double* %7
br label %25
25: ; preds = %64, %24
%26 = load i8*, i8** %6
%27 = load i32, i32* %3
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8, i8* %26, i64 %28
%30 = load i8, i8* %29
%31 = sext i8 %30 to i32
%32 = icmp ne i32 %31, 48
br i1 %32, label %33, label %43
33: ; preds = %25
%34 = load i8*, i8** %6
%35 = load i32, i32* %3
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i8, i8* %34, i64 %36
%38 = load i8, i8* %37
%39 = sext i8 %38 to i32
%40 = icmp ne i32 %39, 49
br i1 %40, label %41, label %43
41: ; preds = %33
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %1
br label %76
43: ; preds = %33, %25
%44 = load i8*, i8** %6
%45 = load i32, i32* %3
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds i8, i8* %44, i64 %46
%48 = load i8, i8* %47
%49 = sext i8 %48 to i32
%50 = icmp eq i32 %49, 49
br i1 %50, label %51, label %60
51: ; preds = %43
%52 = load i32, i32* %4
%53 = load i32, i32* %3
%54 = sub nsw i32 %52, %53
%55 = sub nsw i32 %54, 1
%56 = call i64 @pow(i32 2, i32 %55)
%57 = sitofp i64 %56 to double
%58 = load double, double* %7
%59 = fadd double %58, %57
store double %59, double* %7
br label %60
60: ; preds = %51, %43
br label %61
61: ; preds = %60
%62 = load i32, i32* %3
%63 = add nsw i32 %62, 1
store i32 %63, i32* %3
br label %64
64: ; preds = %61
%65 = load i32, i32* %3
%66 = load i32, i32* %4
%67 = icmp slt i32 %65, %66
br i1 %67, label %25, label %68
68: ; preds = %64
%69 = load double, double* %7
%70 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), double %69)
br label %71
71: ; preds = %68
%72 = load i32, i32* %2
%73 = icmp ne i32 %72, 0
%74 = xor i1 %73, true
br i1 %74, label %9, label %75
75: ; preds = %71
store i32 0, i32* %1
br label %76
76: ; preds = %75, %41, %23
%77 = load i32, i32* %1
ret i32 %77
}

LLVM IR (-O2):
@.str = [3 x i8] c"%s\00"
@.str.2 = [16 x i8] c"Decimal: %.0lf\0A\00"
@str = [18 x i8] c"N\C3\A3o \C3\A9 bin\C3\A1rio!\00"
define i32 @main() {
%1 = alloca [100 x i8]
%2 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%3 = tail call dereferenceable_or_null(1) i8* @malloc(i32 1)
%4 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %2)
%5 = call i32 @strlen(i8* %2)
%6 = call i32 @strncpy(i8* %3, i8* %2, i32 %5)
%7 = load i8, i8* %3
%8 = icmp eq i8 %7, 45
br i1 %8, label %47, label %9
9: ; preds = %0, %40
%10 = phi i8 [ %45, %40 ], [ %7, %0 ]
%11 = phi i32 [ %43, %40 ], [ %5, %0 ]
%12 = call i32 @llvm.smax.i32(i32 %11, i32 1)
%13 = zext i32 %12 to i64
%14 = and i8 %10, -2
%15 = icmp eq i8 %14, 48
br i1 %15, label %18, label %16
16: ; preds = %9, %34
%17 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str, i64 0, i64 0))
br label %47
18: ; preds = %9, %34
%19 = phi i32 [ %37, %34 ], [ 0, %9 ]
%20 = phi double [ %31, %34 ], [ 0.000000e+00, %9 ]
%21 = phi i64 [ %32, %34 ], [ 0, %9 ]
%22 = phi i8 [ %36, %34 ], [ %10, %9 ]
%23 = icmp eq i8 %22, 49
br i1 %23, label %24, label %30
24: ; preds = %18
%25 = xor i32 %19, -1
%26 = add i32 %11, %25
%27 = call i64 @pow(i32 2, i32 %26)
%28 = sitofp i64 %27 to double
%29 = fadd double %20, %28
br label %30
30: ; preds = %18, %24
%31 = phi double [ %29, %24 ], [ %20, %18 ]
%32 = add nuw nsw i64 %21, 1
%33 = icmp eq i64 %32, %13
br i1 %33, label %40, label %34
34: ; preds = %30
%35 = getelementptr inbounds i8, i8* %3, i64 %32
%36 = load i8, i8* %35
%37 = trunc i64 %32 to i32
%38 = and i8 %36, -2
%39 = icmp eq i8 %38, 48
br i1 %39, label %18, label %16
40: ; preds = %30
%41 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), double %31)
%42 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %2)
%43 = call i32 @strlen(i8* %2)
%44 = call i32 @strncpy(i8* %3, i8* %2, i32 %43)
%45 = load i8, i8* %3
%46 = icmp eq i8 %45, 45
br i1 %46, label %47, label %9
47: ; preds = %40, %0, %16
ret i32 0
}