#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 get_freqmap_idx(unsigned char);
void freqmap_pcalc_xor(unsigned char *data, size_t datalen, unsigned char k,
                       size_t interval, double *out) {
  size_t i;
  double fact = interval * 1.0 / datalen;
  for (i = 0; i < 27; ++i)
    out[i] = 0.0;
  for (i = 0; i < datalen; i += interval) {
    unsigned char v;
    char idx;
    v = data[i] ^ k;
    idx = get_freqmap_idx(v);
    if (idx != -1)
      out[(size_t)idx] += 1;
  }
  for (i = 0; i < 27; ++i)
    out[i] *= fact;
}


x86 assembly (clang, -O0):
<freqmap_pcalc_xor>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %dl,%al
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %al,-0x11(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
movaps 0xecc(%rip),%xmm3
movq   -0x20(%rbp),%xmm0
punpckldq %xmm3,%xmm0
movapd 0xecb(%rip),%xmm2
subpd  %xmm2,%xmm0
movaps %xmm0,%xmm1
unpckhpd %xmm0,%xmm0
addsd  %xmm1,%xmm0
movq   -0x10(%rbp),%xmm1
punpckldq %xmm3,%xmm1
subpd  %xmm2,%xmm1
movaps %xmm1,%xmm2
unpckhpd %xmm1,%xmm1
addsd  %xmm2,%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
movq   $0x0,-0x30(%rbp)
cmpq   $0x1b,-0x30(%rbp)
jae    11a9 <freqmap_pcalc_xor+0x99>
mov    -0x28(%rbp),%rax
mov    -0x30(%rbp),%rcx
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    117d <freqmap_pcalc_xor+0x6d>
movq   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    121e <freqmap_pcalc_xor+0x10e>
mov    -0x8(%rbp),%rax
mov    -0x30(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
movzbl -0x11(%rbp),%ecx
xor    %ecx,%eax
mov    %al,-0x39(%rbp)
movzbl -0x39(%rbp),%edi
call   1030 <get_freqmap_idx@plt>
mov    %al,-0x3a(%rbp)
movsbl -0x3a(%rbp),%eax
cmp    $0xffffffff,%eax
je     1208 <freqmap_pcalc_xor+0xf8>
mov    -0x28(%rbp),%rax
movsbq -0x3a(%rbp),%rcx
movsd  0xe22(%rip),%xmm0
addsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,(%rax,%rcx,8)
jmp    120d <freqmap_pcalc_xor+0xfd>
mov    -0x20(%rbp),%rax
add    -0x30(%rbp),%rax
mov    %rax,-0x30(%rbp)
jmp    11b1 <freqmap_pcalc_xor+0xa1>
movq   $0x0,-0x30(%rbp)
cmpq   $0x1b,-0x30(%rbp)
jae    1259 <freqmap_pcalc_xor+0x149>
movsd  -0x38(%rbp),%xmm0
mov    -0x28(%rbp),%rax
mov    -0x30(%rbp),%rcx
mulsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    1226 <freqmap_pcalc_xor+0x116>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<freqmap_pcalc_xor>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r8,%rbx
movq   %rsi,%xmm0
movdqa 0xed2(%rip),%xmm1
punpckldq %xmm1,%xmm0
movapd 0xed6(%rip),%xmm2
subpd  %xmm2,%xmm0
movapd %xmm0,%xmm3
unpckhpd %xmm0,%xmm3
addsd  %xmm0,%xmm3
xorpd  %xmm0,%xmm0
movupd %xmm0,0xc0(%r8)
movupd %xmm0,0xb0(%r8)
movupd %xmm0,0xa0(%r8)
movupd %xmm0,0x90(%r8)
movupd %xmm0,0x80(%r8)
movupd %xmm0,0x70(%r8)
movupd %xmm0,0x60(%r8)
movupd %xmm0,0x50(%r8)
movupd %xmm0,0x40(%r8)
movupd %xmm0,0x30(%r8)
movupd %xmm0,0x20(%r8)
movupd %xmm0,0x10(%r8)
movupd %xmm0,(%r8)
movq   $0x0,0xd0(%r8)
movq   %rcx,%xmm4
punpckldq %xmm1,%xmm4
subpd  %xmm2,%xmm4
movapd %xmm4,%xmm2
unpckhpd %xmm4,%xmm2
addsd  %xmm4,%xmm2
divsd  %xmm3,%xmm2
test   %rsi,%rsi
je     1281 <freqmap_pcalc_xor+0x171>
mov    %rcx,%r14
mov    %edx,%r15d
mov    %rsi,%r13
mov    %rdi,%r12
movapd %xmm2,(%rsp)
xor    %ebp,%ebp
jmp    11f8 <freqmap_pcalc_xor+0xe8>
add    %r14,%rbp
cmp    %r13,%rbp
jae    1224 <freqmap_pcalc_xor+0x114>
movzbl (%r12,%rbp,1),%eax
xor    %r15b,%al
movzbl %al,%edi
call   1030 <get_freqmap_idx@plt>
cmp    $0xff,%al
je     11f0 <freqmap_pcalc_xor+0xe0>
movsbq %al,%rax
movsd  (%rbx,%rax,8),%xmm0
addsd  0xe03(%rip),%xmm0
movsd  %xmm0,(%rbx,%rax,8)
jmp    11f0 <freqmap_pcalc_xor+0xe0>
movupd (%rbx),%xmm0
movupd 0x10(%rbx),%xmm6
movupd 0x20(%rbx),%xmm5
movupd 0x30(%rbx),%xmm4
movupd 0x40(%rbx),%xmm3
movupd 0x50(%rbx),%xmm14
movupd 0x60(%rbx),%xmm13
movupd 0x70(%rbx),%xmm12
movupd 0x80(%rbx),%xmm11
movupd 0x90(%rbx),%xmm10
movupd 0xa0(%rbx),%xmm9
movupd 0xb0(%rbx),%xmm8
movq   0xc0(%rbx),%xmm1
movapd (%rsp),%xmm2
jmp    12b8 <freqmap_pcalc_xor+0x1a8>
pxor   %xmm1,%xmm1
xorpd  %xmm6,%xmm6
xorpd  %xmm5,%xmm5
xorpd  %xmm4,%xmm4
xorpd  %xmm3,%xmm3
xorpd  %xmm14,%xmm14
xorpd  %xmm13,%xmm13
xorpd  %xmm12,%xmm12
xorpd  %xmm11,%xmm11
xorpd  %xmm10,%xmm10
xorpd  %xmm9,%xmm9
xorpd  %xmm8,%xmm8
movapd %xmm2,%xmm7
unpcklpd %xmm2,%xmm7
mulpd  %xmm7,%xmm0
movupd %xmm0,(%rbx)
mulpd  %xmm7,%xmm6
movupd %xmm6,0x10(%rbx)
mulpd  %xmm7,%xmm5
movupd %xmm5,0x20(%rbx)
mulpd  %xmm7,%xmm4
movupd %xmm4,0x30(%rbx)
mulpd  %xmm7,%xmm3
movupd %xmm3,0x40(%rbx)
mulpd  %xmm7,%xmm14
movupd %xmm14,0x50(%rbx)
mulpd  %xmm7,%xmm13
movupd %xmm13,0x60(%rbx)
mulpd  %xmm7,%xmm12
movupd %xmm12,0x70(%rbx)
mulpd  %xmm7,%xmm11
movupd %xmm11,0x80(%rbx)
mulpd  %xmm7,%xmm10
movupd %xmm10,0x90(%rbx)
mulpd  %xmm7,%xmm9
movupd %xmm9,0xa0(%rbx)
mulpd  %xmm7,%xmm8
movupd %xmm8,0xb0(%rbx)
movhpd 0xc8(%rbx),%xmm1
mulpd  %xmm7,%xmm1
movupd %xmm1,0xc0(%rbx)
mulsd  0xd0(%rbx),%xmm2
movsd  %xmm2,0xd0(%rbx)
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @freqmap_pcalc_xor(i8* %0, i64 %1, i8 zeroext %2, i64 %3, double* %4) {
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i8
%9 = alloca i64
%10 = alloca double*
%11 = alloca i64
%12 = alloca double
%13 = alloca i8
%14 = alloca i8
store i8* %0, i8** %6
store i64 %1, i64* %7
store i8 %2, i8* %8
store i64 %3, i64* %9
store double* %4, double** %10
%15 = load i64, i64* %9
%16 = uitofp i64 %15 to double
%17 = fmul double %16, 1.000000e+00
%18 = load i64, i64* %7
%19 = uitofp i64 %18 to double
%20 = fdiv double %17, %19
store double %20, double* %12
store i64 0, i64* %11
br label %21
21: ; preds = %28, %5
%22 = load i64, i64* %11
%23 = icmp ult i64 %22, 27
br i1 %23, label %24, label %31
24: ; preds = %21
%25 = load double*, double** %10
%26 = load i64, i64* %11
%27 = getelementptr inbounds double, double* %25, i64 %26
store double 0.000000e+00, double* %27
br label %28
28: ; preds = %24
%29 = load i64, i64* %11
%30 = add i64 %29, 1
store i64 %30, i64* %11
br label %21
31: ; preds = %21
store i64 0, i64* %11
br label %32
32: ; preds = %59, %31
%33 = load i64, i64* %11
%34 = load i64, i64* %7
%35 = icmp ult i64 %33, %34
br i1 %35, label %36, label %63
36: ; preds = %32
%37 = load i8*, i8** %6
%38 = load i64, i64* %11
%39 = getelementptr inbounds i8, i8* %37, i64 %38
%40 = load i8, i8* %39
%41 = zext i8 %40 to i32
%42 = load i8, i8* %8
%43 = zext i8 %42 to i32
%44 = xor i32 %41, %43
%45 = trunc i32 %44 to i8
store i8 %45, i8* %13
%46 = load i8, i8* %13
%47 = call signext i8 @get_freqmap_idx(i8 zeroext %46)
store i8 %47, i8* %14
%48 = load i8, i8* %14
%49 = sext i8 %48 to i32
%50 = icmp ne i32 %49, -1
br i1 %50, label %51, label %58
51: ; preds = %36
%52 = load double*, double** %10
%53 = load i8, i8* %14
%54 = sext i8 %53 to i64
%55 = getelementptr inbounds double, double* %52, i64 %54
%56 = load double, double* %55
%57 = fadd double %56, 1.000000e+00
store double %57, double* %55
br label %58
58: ; preds = %51, %36
br label %59
59: ; preds = %58
%60 = load i64, i64* %9
%61 = load i64, i64* %11
%62 = add i64 %61, %60
store i64 %62, i64* %11
br label %32
63: ; preds = %32
store i64 0, i64* %11
br label %64
64: ; preds = %74, %63
%65 = load i64, i64* %11
%66 = icmp ult i64 %65, 27
br i1 %66, label %67, label %77
67: ; preds = %64
%68 = load double, double* %12
%69 = load double*, double** %10
%70 = load i64, i64* %11
%71 = getelementptr inbounds double, double* %69, i64 %70
%72 = load double, double* %71
%73 = fmul double %72, %68
store double %73, double* %71
br label %74
74: ; preds = %67
%75 = load i64, i64* %11
%76 = add i64 %75, 1
store i64 %76, i64* %11
br label %64
77: ; preds = %64
ret void
}

LLVM IR (-O2):
define void @freqmap_pcalc_xor(i8* nocapture %0, i64 %1, i8 zeroext %2, i64 %3, double* nocapture %4) {
%6 = bitcast double* %4 to i8*
%7 = uitofp i64 %1 to double
%8 = uitofp i64 %3 to double
%9 = fdiv double %8, %7
%10 = icmp eq i64 %1, 0
br i1 %10, label %49, label %110
11: ; preds = %122
%12 = bitcast double* %4 to <2 x double>*
%13 = load <2 x double>, <2 x double>* %12
%14 = getelementptr inbounds double, double* %4, i64 2
%15 = bitcast double* %14 to <2 x double>*
%16 = load <2 x double>, <2 x double>* %15
%17 = getelementptr inbounds double, double* %4, i64 4
%18 = bitcast double* %17 to <2 x double>*
%19 = load <2 x double>, <2 x double>* %18
%20 = getelementptr inbounds double, double* %4, i64 6
%21 = bitcast double* %20 to <2 x double>*
%22 = load <2 x double>, <2 x double>* %21
%23 = getelementptr inbounds double, double* %4, i64 8
%24 = bitcast double* %23 to <2 x double>*
%25 = load <2 x double>, <2 x double>* %24
%26 = getelementptr inbounds double, double* %4, i64 10
%27 = bitcast double* %26 to <2 x double>*
%28 = load <2 x double>, <2 x double>* %27
%29 = getelementptr inbounds double, double* %4, i64 12
%30 = bitcast double* %29 to <2 x double>*
%31 = load <2 x double>, <2 x double>* %30
%32 = getelementptr inbounds double, double* %4, i64 14
%33 = bitcast double* %32 to <2 x double>*
%34 = load <2 x double>, <2 x double>* %33
%35 = getelementptr inbounds double, double* %4, i64 16
%36 = bitcast double* %35 to <2 x double>*
%37 = load <2 x double>, <2 x double>* %36
%38 = getelementptr inbounds double, double* %4, i64 18
%39 = bitcast double* %38 to <2 x double>*
%40 = load <2 x double>, <2 x double>* %39
%41 = getelementptr inbounds double, double* %4, i64 20
%42 = bitcast double* %41 to <2 x double>*
%43 = load <2 x double>, <2 x double>* %42
%44 = getelementptr inbounds double, double* %4, i64 22
%45 = bitcast double* %44 to <2 x double>*
%46 = load <2 x double>, <2 x double>* %45
%47 = getelementptr inbounds double, double* %4, i64 24
%48 = load double, double* %47
br label %49
49: ; preds = %11, %5
%50 = phi double [ %48, %11 ], [ 0.000000e+00, %5 ]
%51 = phi <2 x double> [ %13, %11 ], [ zeroinitializer, %5 ]
%52 = phi <2 x double> [ %16, %11 ], [ zeroinitializer, %5 ]
%53 = phi <2 x double> [ %19, %11 ], [ zeroinitializer, %5 ]
%54 = phi <2 x double> [ %22, %11 ], [ zeroinitializer, %5 ]
%55 = phi <2 x double> [ %25, %11 ], [ zeroinitializer, %5 ]
%56 = phi <2 x double> [ %28, %11 ], [ zeroinitializer, %5 ]
%57 = phi <2 x double> [ %31, %11 ], [ zeroinitializer, %5 ]
%58 = phi <2 x double> [ %34, %11 ], [ zeroinitializer, %5 ]
%59 = phi <2 x double> [ %37, %11 ], [ zeroinitializer, %5 ]
%60 = phi <2 x double> [ %40, %11 ], [ zeroinitializer, %5 ]
%61 = phi <2 x double> [ %43, %11 ], [ zeroinitializer, %5 ]
%62 = phi <2 x double> [ %46, %11 ], [ zeroinitializer, %5 ]
%63 = insertelement <2 x double> poison, double %9, i64 0
%64 = shufflevector <2 x double> %63, <2 x double> poison, <2 x i32> zeroinitializer
%65 = fmul <2 x double> %64, %51
%66 = bitcast double* %4 to <2 x double>*
store <2 x double> %65, <2 x double>* %66
%67 = getelementptr inbounds double, double* %4, i64 2
%68 = fmul <2 x double> %64, %52
%69 = bitcast double* %67 to <2 x double>*
store <2 x double> %68, <2 x double>* %69
%70 = getelementptr inbounds double, double* %4, i64 4
%71 = fmul <2 x double> %64, %53
%72 = bitcast double* %70 to <2 x double>*
store <2 x double> %71, <2 x double>* %72
%73 = getelementptr inbounds double, double* %4, i64 6
%74 = fmul <2 x double> %64, %54
%75 = bitcast double* %73 to <2 x double>*
store <2 x double> %74, <2 x double>* %75
%76 = getelementptr inbounds double, double* %4, i64 8
%77 = fmul <2 x double> %64, %55
%78 = bitcast double* %76 to <2 x double>*
store <2 x double> %77, <2 x double>* %78
%79 = getelementptr inbounds double, double* %4, i64 10
%80 = fmul <2 x double> %64, %56
%81 = bitcast double* %79 to <2 x double>*
store <2 x double> %80, <2 x double>* %81
%82 = getelementptr inbounds double, double* %4, i64 12
%83 = fmul <2 x double> %64, %57
%84 = bitcast double* %82 to <2 x double>*
store <2 x double> %83, <2 x double>* %84
%85 = getelementptr inbounds double, double* %4, i64 14
%86 = fmul <2 x double> %64, %58
%87 = bitcast double* %85 to <2 x double>*
store <2 x double> %86, <2 x double>* %87
%88 = getelementptr inbounds double, double* %4, i64 16
%89 = fmul <2 x double> %64, %59
%90 = bitcast double* %88 to <2 x double>*
store <2 x double> %89, <2 x double>* %90
%91 = getelementptr inbounds double, double* %4, i64 18
%92 = fmul <2 x double> %64, %60
%93 = bitcast double* %91 to <2 x double>*
store <2 x double> %92, <2 x double>* %93
%94 = getelementptr inbounds double, double* %4, i64 20
%95 = fmul <2 x double> %64, %61
%96 = bitcast double* %94 to <2 x double>*
store <2 x double> %95, <2 x double>* %96
%97 = getelementptr inbounds double, double* %4, i64 22
%98 = fmul <2 x double> %64, %62
%99 = bitcast double* %97 to <2 x double>*
store <2 x double> %98, <2 x double>* %99
%100 = getelementptr inbounds double, double* %4, i64 24
%101 = getelementptr inbounds double, double* %4, i64 25
%102 = load double, double* %101
%103 = insertelement <2 x double> poison, double %50, i64 0
%104 = insertelement <2 x double> %103, double %102, i64 1
%105 = fmul <2 x double> %64, %104
%106 = bitcast double* %100 to <2 x double>*
store <2 x double> %105, <2 x double>* %106
%107 = getelementptr inbounds double, double* %4, i64 26
%108 = load double, double* %107
%109 = fmul double %9, %108
store double %109, double* %107
ret void
110: ; preds = %5, %122
%111 = phi i64 [ %123, %122 ], [ 0, %5 ]
%112 = getelementptr inbounds i8, i8* %0, i64 %111
%113 = load i8, i8* %112
%114 = xor i8 %113, %2
%115 = tail call signext i8 @get_freqmap_idx(i8 zeroext %114)
%116 = icmp eq i8 %115, -1
br i1 %116, label %122, label %117
117: ; preds = %110
%118 = sext i8 %115 to i64
%119 = getelementptr inbounds double, double* %4, i64 %118
%120 = load double, double* %119
%121 = fadd double %120, 1.000000e+00
store double %121, double* %119
br label %122
122: ; preds = %117, %110
%123 = add i64 %111, %3
%124 = icmp ult i64 %123, %1
br i1 %124, label %110, label %11
}