double bcdeight(unsigned char *s) {
  int i, j;
  double p, num;
  p = 0.01;
  num = 0;
  for (j = 0; j < 4; j++)
    for (i = 0; i < 2; i++) {
      num += ((s[j] >> 4 * i) & 0x0f) * p;
      p *= 10;
    }
  return num;
}


x86 assembly (clang, -O0):
<bcdeight>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
movsd  0xef0(%rip),%xmm0
movsd  %xmm0,-0x18(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
movl   $0x0,-0x10(%rbp)
cmpl   $0x4,-0x10(%rbp)
jge    11a4 <bcdeight+0xa4>
movl   $0x0,-0xc(%rbp)
cmpl   $0x2,-0xc(%rbp)
jge    1191 <bcdeight+0x91>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
mov    -0xc(%rbp),%ecx
shl    $0x2,%ecx
sar    %cl,%eax
and    $0xf,%eax
cvtsi2sd %eax,%xmm0
movsd  -0x18(%rbp),%xmm2
movsd  -0x20(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  0xe8f(%rip),%xmm0
mulsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1135 <bcdeight+0x35>
jmp    1196 <bcdeight+0x96>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1124 <bcdeight+0x24>
movsd  -0x20(%rbp),%xmm0
pop    %rbp
ret

x86 assembly (clang, -O2):
<bcdeight>:
movzbl (%rdi),%eax
mov    %eax,%ecx
and    $0xf,%ecx
cvtsi2sd %ecx,%xmm0
mulsd  0xeec(%rip),%xmm0
xorpd  %xmm1,%xmm1
addsd  %xmm0,%xmm1
shr    $0x4,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
mulsd  0xeda(%rip),%xmm0
addsd  %xmm1,%xmm0
movzbl 0x1(%rdi),%eax
mov    %eax,%ecx
and    $0xf,%ecx
xorps  %xmm1,%xmm1
cvtsi2sd %ecx,%xmm1
shr    $0x4,%eax
cvtsi2sd %eax,%xmm2
mulsd  0xebf(%rip),%xmm2
addsd  %xmm0,%xmm1
addsd  %xmm1,%xmm2
movzbl 0x2(%rdi),%eax
mov    %eax,%ecx
and    $0xf,%ecx
xorps  %xmm0,%xmm0
cvtsi2sd %ecx,%xmm0
mulsd  0xea7(%rip),%xmm0
addsd  %xmm2,%xmm0
shr    $0x4,%eax
xorps  %xmm1,%xmm1
cvtsi2sd %eax,%xmm1
mulsd  0xe99(%rip),%xmm1
movzbl 0x3(%rdi),%eax
mov    %eax,%ecx
and    $0xf,%ecx
xorps  %xmm2,%xmm2
cvtsi2sd %ecx,%xmm2
mulsd  0xe89(%rip),%xmm2
addsd  %xmm0,%xmm1
shr    $0x4,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
addsd  %xmm1,%xmm2
mulsd  0xe77(%rip),%xmm0
addsd  %xmm2,%xmm0
ret

LLVM IR (-O0):
define double @bcdeight(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca double
%6 = alloca double
store i8* %0, i8** %2
store double 1.000000e-02, double* %5
store double 0.000000e+00, double* %6
store i32 0, i32* %4
br label %7
7: ; preds = %35, %1
%8 = load i32, i32* %4
%9 = icmp slt i32 %8, 4
br i1 %9, label %10, label %38
10: ; preds = %7
store i32 0, i32* %3
br label %11
11: ; preds = %31, %10
%12 = load i32, i32* %3
%13 = icmp slt i32 %12, 2
br i1 %13, label %14, label %34
14: ; preds = %11
%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 = zext i8 %19 to i32
%21 = load i32, i32* %3
%22 = mul nsw i32 4, %21
%23 = ashr i32 %20, %22
%24 = and i32 %23, 15
%25 = sitofp i32 %24 to double
%26 = load double, double* %5
%27 = load double, double* %6
%28 = call double @llvm.fmuladd.f64(double %25, double %26, double %27)
store double %28, double* %6
%29 = load double, double* %5
%30 = fmul double %29, 1.000000e+01
store double %30, double* %5
br label %31
31: ; preds = %14
%32 = load i32, i32* %3
%33 = add nsw i32 %32, 1
store i32 %33, i32* %3
br label %11
34: ; preds = %11
br label %35
35: ; preds = %34
%36 = load i32, i32* %4
%37 = add nsw i32 %36, 1
store i32 %37, i32* %4
br label %7
38: ; preds = %7
%39 = load double, double* %6
ret double %39
}

LLVM IR (-O2):
define double @bcdeight(i8* nocapture %0) {
%2 = load i8, i8* %0
%3 = zext i8 %2 to i32
%4 = and i32 %3, 15
%5 = sitofp i32 %4 to double
%6 = tail call double @llvm.fmuladd.f64(double %5, double 1.000000e-02, double 0.000000e+00)
%7 = lshr i32 %3, 4
%8 = sitofp i32 %7 to double
%9 = tail call double @llvm.fmuladd.f64(double %8, double 1.000000e-01, double %6)
%10 = getelementptr inbounds i8, i8* %0, i64 1
%11 = load i8, i8* %10
%12 = zext i8 %11 to i32
%13 = and i32 %12, 15
%14 = sitofp i32 %13 to double
%15 = fadd double %9, %14
%16 = lshr i32 %12, 4
%17 = sitofp i32 %16 to double
%18 = tail call double @llvm.fmuladd.f64(double %17, double 1.000000e+01, double %15)
%19 = getelementptr inbounds i8, i8* %0, i64 2
%20 = load i8, i8* %19
%21 = zext i8 %20 to i32
%22 = and i32 %21, 15
%23 = sitofp i32 %22 to double
%24 = tail call double @llvm.fmuladd.f64(double %23, double 1.000000e+02, double %18)
%25 = lshr i32 %21, 4
%26 = sitofp i32 %25 to double
%27 = tail call double @llvm.fmuladd.f64(double %26, double 1.000000e+03, double %24)
%28 = getelementptr inbounds i8, i8* %0, i64 3
%29 = load i8, i8* %28
%30 = zext i8 %29 to i32
%31 = and i32 %30, 15
%32 = sitofp i32 %31 to double
%33 = tail call double @llvm.fmuladd.f64(double %32, double 1.000000e+04, double %27)
%34 = lshr i32 %30, 4
%35 = sitofp i32 %34 to double
%36 = tail call double @llvm.fmuladd.f64(double %35, double 1.000000e+05, double %33)
ret double %36
}