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


x86 assembly (clang, -O0):
<fp_fault_injection_single>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jae    11bc <fp_fault_injection_single+0xac>
movl   $0x0,-0x20(%rbp)
cmpl   $0x20,-0x20(%rbp)
jae    11a9 <fp_fault_injection_single+0x99>
mov    $0x0,%al
call   1030 <rand@plt>
cvtsi2sd %rax,%xmm0
mov    0x2e8e(%rip),%rax
divsd  (%rax),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%ecx
ucomisd (%rax,%rcx,8),%xmm0
jbe    117f <fp_fault_injection_single+0x6f>
jmp    1196 <fp_fault_injection_single+0x86>
mov    -0x20(%rbp),%ecx
mov    $0x1,%edx
shl    %cl,%edx
mov    -0x8(%rbp),%rax
mov    -0x1c(%rbp),%ecx
xor    (%rax,%rcx,4),%edx
mov    %edx,(%rax,%rcx,4)
jmp    119b <fp_fault_injection_single+0x8b>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    113d <fp_fault_injection_single+0x2d>
jmp    11ae <fp_fault_injection_single+0x9e>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    112a <fp_fault_injection_single+0x1a>
mov    $0x1,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fp_fault_injection_single>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %esi,%esi
je     1186 <fp_fault_injection_single+0x76>
mov    %rdx,%r15
mov    %rdi,%r14
mov    %esi,%r12d
mov    0x2eb9(%rip),%r13
xor    %ebp,%ebp
jmp    1149 <fp_fault_injection_single+0x39>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
add    $0x1,%rbp
cmp    %r12,%rbp
je     1186 <fp_fault_injection_single+0x76>
xor    %ebx,%ebx
jmp    115a <fp_fault_injection_single+0x4a>
nopl   (%rax)
add    $0x1,%rbx
cmp    $0x20,%rbx
je     1140 <fp_fault_injection_single+0x30>
xor    %eax,%eax
call   1030 <rand@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
divsd  0x0(%r13),%xmm0
ucomisd (%r15,%rbx,8),%xmm0
ja     1150 <fp_fault_injection_single+0x40>
mov    $0x1,%eax
mov    %ebx,%ecx
shl    %cl,%eax
xor    %eax,(%r14,%rbp,4)
jmp    1150 <fp_fault_injection_single+0x40>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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