#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 */
double RAND_MAX;
scalar_t__ rand();
int fp_uniform_fault_injection(double *in, unsigned int len, double p_e) {
  unsigned int i, b;
  double r;
  for (i = 0; i < len; i++) {
    for (b = 0; b < 64; b++) {
      r = ((double)rand()) / RAND_MAX;
      if (r > p_e) {
      } else {
        *(unsigned long *)&in[i] ^= ((unsigned long)1 << b);
      }
    }
  }
  return 1;
}


x86 assembly (clang, -O0):
<fp_uniform_fault_injection>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movsd  %xmm0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jae    11bb <fp_uniform_fault_injection+0xab>
movl   $0x0,-0x20(%rbp)
cmpl   $0x40,-0x20(%rbp)
jae    11a8 <fp_uniform_fault_injection+0x98>
mov    $0x0,%al
call   1030 <rand@plt>
cvtsi2sd %rax,%xmm0
mov    0x2e8d(%rip),%rax
divsd  (%rax),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
ucomisd -0x18(%rbp),%xmm0
jbe    1179 <fp_uniform_fault_injection+0x69>
jmp    1195 <fp_uniform_fault_injection+0x85>
mov    -0x20(%rbp),%eax
mov    %eax,%ecx
mov    $0x1,%edx
shl    %cl,%rdx
mov    -0x8(%rbp),%rax
mov    -0x1c(%rbp),%ecx
xor    (%rax,%rcx,8),%rdx
mov    %rdx,(%rax,%rcx,8)
jmp    119a <fp_uniform_fault_injection+0x8a>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    113e <fp_uniform_fault_injection+0x2e>
jmp    11ad <fp_uniform_fault_injection+0x9d>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    112b <fp_uniform_fault_injection+0x1b>
mov    $0x1,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fp_uniform_fault_injection>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
movsd  %xmm0,0x8(%rsp)
test   %esi,%esi
je     1187 <fp_uniform_fault_injection+0x77>
mov    %rdi,%r14
mov    %esi,%r15d
mov    0x2eb4(%rip),%r12
xor    %r13d,%r13d
jmp    1149 <fp_uniform_fault_injection+0x39>
nopl   0x0(%rax)
add    $0x1,%r13
cmp    %r15,%r13
je     1187 <fp_uniform_fault_injection+0x77>
xor    %ebx,%ebx
jmp    115a <fp_uniform_fault_injection+0x4a>
nopl   (%rax)
add    $0x1,%rbx
cmp    $0x40,%rbx
je     1140 <fp_uniform_fault_injection+0x30>
xor    %eax,%eax
call   1030 <rand@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
divsd  (%r12),%xmm0
ucomisd 0x8(%rsp),%xmm0
ja     1150 <fp_uniform_fault_injection+0x40>
mov    $0x1,%eax
mov    %ebx,%ecx
shl    %cl,%rax
xor    %rax,(%r14,%r13,8)
jmp    1150 <fp_uniform_fault_injection+0x40>
mov    $0x1,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@RAND_MAX = global double 0.000000e+00
define i32 @fp_uniform_fault_injection(double* %0, i32 %1, double %2) {
%4 = alloca double*
%5 = alloca i32
%6 = alloca double
%7 = alloca i32
%8 = alloca i32
%9 = alloca double
store double* %0, double** %4
store i32 %1, i32* %5
store double %2, double* %6
store i32 0, i32* %7
br label %10
10: ; preds = %43, %3
%11 = load i32, i32* %7
%12 = load i32, i32* %5
%13 = icmp ult i32 %11, %12
br i1 %13, label %14, label %46
14: ; preds = %10
store i32 0, i32* %8
br label %15
15: ; preds = %39, %14
%16 = load i32, i32* %8
%17 = icmp ult i32 %16, 64
br i1 %17, label %18, label %42
18: ; preds = %15
%19 = call i64 (...) @rand()
%20 = sitofp i64 %19 to double
%21 = load double, double* @RAND_MAX
%22 = fdiv double %20, %21
store double %22, double* %9
%23 = load double, double* %9
%24 = load double, double* %6
%25 = fcmp ogt double %23, %24
br i1 %25, label %26, label %27
26: ; preds = %18
br label %38
27: ; preds = %18
%28 = load i32, i32* %8
%29 = zext i32 %28 to i64
%30 = shl i64 1, %29
%31 = load double*, double** %4
%32 = load i32, i32* %7
%33 = zext i32 %32 to i64
%34 = getelementptr inbounds double, double* %31, i64 %33
%35 = bitcast double* %34 to i64*
%36 = load i64, i64* %35
%37 = xor i64 %36, %30
store i64 %37, i64* %35
br label %38
38: ; preds = %27, %26
br label %39
39: ; preds = %38
%40 = load i32, i32* %8
%41 = add i32 %40, 1
store i32 %41, i32* %8
br label %15
42: ; preds = %15
br label %43
43: ; preds = %42
%44 = load i32, i32* %7
%45 = add i32 %44, 1
store i32 %45, i32* %7
br label %10
46: ; preds = %10
ret i32 1
}

LLVM IR (-O2):
@RAND_MAX = global double 0.000000e+00
define i32 @fp_uniform_fault_injection(double* nocapture %0, i32 %1, double %2) {
%4 = icmp eq i32 %1, 0
br i1 %4, label %28, label %5
5: ; preds = %3
%6 = zext i32 %1 to i64
br label %7
7: ; preds = %5, %25
%8 = phi i64 [ 0, %5 ], [ %26, %25 ]
%9 = getelementptr inbounds double, double* %0, i64 %8
%10 = bitcast double* %9 to i64*
br label %11
11: ; preds = %7, %22
%12 = phi i64 [ 0, %7 ], [ %23, %22 ]
%13 = tail call i64 (...) @rand()
%14 = sitofp i64 %13 to double
%15 = load double, double* @RAND_MAX
%16 = fdiv double %14, %15
%17 = fcmp ogt double %16, %2
br i1 %17, label %22, label %18
18: ; preds = %11
%19 = shl nuw i64 1, %12
%20 = load i64, i64* %10
%21 = xor i64 %20, %19
store i64 %21, i64* %10
br label %22
22: ; preds = %18, %11
%23 = add nuw nsw i64 %12, 1
%24 = icmp eq i64 %23, 64
br i1 %24, label %25, label %11
25: ; preds = %22
%26 = add nuw nsw i64 %8, 1
%27 = icmp eq i64 %26, %6
br i1 %27, label %28, label %7
28: ; preds = %25, %3
ret i32 1
}