#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*/ fprintf(int /*<<< orphan*/, char *, char, char *);
int /*<<< orphan*/ stderr;
float MagCalc(char *s, int len) {
  float fmag = 0;
  int i;
  for (i = 0; i < len; i++) {
    switch (s[i]) {
    default:
      fprintf(stderr, "Strange character (%c) in MagCalc() (in pattern %s).\n",
              s[i], s);
      break;
    case 'a':
    case 'c':
    case 'g':
    case 't':
      fmag += 1;
      break;
    case 'y':
    case 'r':
    case 'm':
    case 'k':
    case 'w':
    case 's':
      fmag += 0.5;
      break;
    case 'b':
    case 'd':
    case 'h':
    case 'v':
      fmag += 0.25;
      break;
    case 'n':
      break;
    }
  }
  return fmag;
}


x86 assembly (clang, -O0):
<MagCalc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    120d <MagCalc+0xfd>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
add    $0xffffff9f,%eax
mov    %eax,%ecx
mov    %rcx,-0x20(%rbp)
sub    $0x18,%eax
ja     116c <MagCalc+0x5c>
mov    -0x20(%rbp),%rax
lea    0xeb1(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    0x2e6d(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    -0x8(%rbp),%rcx
lea    0xeed(%rip),%rsi
movsbl %al,%edx
call   1030 <fprintf@plt>
jmp    11fa <MagCalc+0xea>
movss  0xe70(%rip),%xmm0
addss  -0x10(%rbp),%xmm0
movss  %xmm0,-0x10(%rbp)
jmp    11fa <MagCalc+0xea>
movss  -0x10(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xe48(%rip),%xmm1
addsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x10(%rbp)
jmp    11fa <MagCalc+0xea>
movss  -0x10(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xe1d(%rip),%xmm1
addsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x10(%rbp)
jmp    11fa <MagCalc+0xea>
jmp    11fa <MagCalc+0xea>
jmp    11ff <MagCalc+0xef>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    112e <MagCalc+0x1e>
movss  -0x10(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<MagCalc>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %esi,%esi
jle    11ce <MagCalc+0xbe>
mov    %rdi,%r12
mov    %esi,%r15d
xorps  %xmm0,%xmm0
xor    %ebx,%ebx
mov    0x2eab(%rip),%r13
lea    0xf34(%rip),%r14
lea    0xec9(%rip),%rbp
movss  0xebd(%rip),%xmm1
movss  0xead(%rip),%xmm2
movss  0xea9(%rip),%xmm3
jmp    116d <MagCalc+0x5d>
nopl   (%rax)
addss  %xmm3,%xmm0
add    $0x1,%rbx
cmp    %rbx,%r15
je     11d1 <MagCalc+0xc1>
movsbl (%r12,%rbx,1),%eax
lea    -0x61(%rax),%ecx
cmp    $0x18,%ecx
ja     1196 <MagCalc+0x86>
movslq 0x0(%rbp,%rcx,4),%rcx
add    %rbp,%rcx
jmp    *%rcx
addss  %xmm1,%xmm0
jmp    1164 <MagCalc+0x54>
nopw   0x0(%rax,%rax,1)
addss  %xmm2,%xmm0
jmp    1164 <MagCalc+0x54>
mov    0x0(%r13),%edi
movsbl %al,%edx
mov    %r14,%rsi
mov    %r12,%rcx
movss  %xmm0,0x4(%rsp)
call   1030 <fprintf@plt>
movss  0xe4e(%rip),%xmm3
movss  0xe42(%rip),%xmm2
movss  0xe42(%rip),%xmm1
movss  0x4(%rsp),%xmm0
jmp    1164 <MagCalc+0x54>
xorps  %xmm0,%xmm0
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [54 x i8] c"Strange character (%c) in MagCalc() (in pattern %s).\0A\00"
define float @MagCalc(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca float
%6 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
store float 0.000000e+00, float* %5
store i32 0, i32* %6
br label %7
7: ; preds = %42, %2
%8 = load i32, i32* %6
%9 = load i32, i32* %4
%10 = icmp slt i32 %8, %9
br i1 %10, label %11, label %45
11: ; preds = %7
%12 = load i8*, i8** %3
%13 = load i32, i32* %6
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds i8, i8* %12, i64 %14
%16 = load i8, i8* %15
%17 = sext i8 %16 to i32
switch i32 %17, label %18 [
i32 97, label %27
i32 99, label %27
i32 103, label %27
i32 116, label %27
i32 121, label %30
i32 114, label %30
i32 109, label %30
i32 107, label %30
i32 119, label %30
i32 115, label %30
i32 98, label %35
i32 100, label %35
i32 104, label %35
i32 118, label %35
i32 110, label %40
]
18: ; preds = %11
%19 = load i32, i32* @stderr
%20 = load i8*, i8** %3
%21 = load i32, i32* %6
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8, i8* %20, i64 %22
%24 = load i8, i8* %23
%25 = load i8*, i8** %3
%26 = call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str, i64 0, i64 0), i8 signext %24, i8* %25)
br label %41
27: ; preds = %11, %11, %11, %11
%28 = load float, float* %5
%29 = fadd float %28, 1.000000e+00
store float %29, float* %5
br label %41
30: ; preds = %11, %11, %11, %11, %11, %11
%31 = load float, float* %5
%32 = fpext float %31 to double
%33 = fadd double %32, 5.000000e-01
%34 = fptrunc double %33 to float
store float %34, float* %5
br label %41
35: ; preds = %11, %11, %11, %11
%36 = load float, float* %5
%37 = fpext float %36 to double
%38 = fadd double %37, 2.500000e-01
%39 = fptrunc double %38 to float
store float %39, float* %5
br label %41
40: ; preds = %11
br label %41
41: ; preds = %40, %35, %30, %27, %18
br label %42
42: ; preds = %41
%43 = load i32, i32* %6
%44 = add nsw i32 %43, 1
store i32 %44, i32* %6
br label %7
45: ; preds = %7
%46 = load float, float* %5
ret float %46
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [54 x i8] c"Strange character (%c) in MagCalc() (in pattern %s).\0A\00"
define float @MagCalc(i8* %0, i32 %1) {
%3 = icmp sgt i32 %1, 0
br i1 %3, label %4, label %25
4: ; preds = %2
%5 = zext i32 %1 to i64
br label %6
6: ; preds = %4, %21
%7 = phi i64 [ 0, %4 ], [ %23, %21 ]
%8 = phi float [ 0.000000e+00, %4 ], [ %22, %21 ]
%9 = getelementptr inbounds i8, i8* %0, i64 %7
%10 = load i8, i8* %9
%11 = sext i8 %10 to i32
switch i32 %11, label %12 [
i32 97, label %15
i32 99, label %15
i32 103, label %15
i32 116, label %15
i32 121, label %17
i32 114, label %17
i32 109, label %17
i32 107, label %17
i32 119, label %17
i32 115, label %17
i32 98, label %19
i32 100, label %19
i32 104, label %19
i32 118, label %19
i32 110, label %21
]
12: ; preds = %6
%13 = load i32, i32* @stderr
%14 = tail call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str, i64 0, i64 0), i8 signext %10, i8* %0)
br label %21
15: ; preds = %6, %6, %6, %6
%16 = fadd float %8, 1.000000e+00
br label %21
17: ; preds = %6, %6, %6, %6, %6, %6
%18 = fadd float %8, 5.000000e-01
br label %21
19: ; preds = %6, %6, %6, %6
%20 = fadd float %8, 2.500000e-01
br label %21
21: ; preds = %12, %15, %17, %19, %6
%22 = phi float [ %8, %12 ], [ %8, %6 ], [ %20, %19 ], [ %18, %17 ], [ %16, %15 ]
%23 = add nuw nsw i64 %7, 1
%24 = icmp eq i64 %23, %5
br i1 %24, label %25, label %6
25: ; preds = %21, %2
%26 = phi float [ 0.000000e+00, %2 ], [ %22, %21 ]
ret float %26
}