; LLVM IR from introlab/odas :: src/utils (random)

; Unoptimized IR (clang -disable-llvm-passes):
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

%struct.normal_obj = type { double }

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nounwind
declare i32 @rand() #1

; Function Attrs: nounwind uwtable
define dso_local void @normal_generate(ptr noundef %0, i32 noundef %1, ptr noundef %2) #2 {
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca double, align 8
  %9 = alloca double, align 8
  %10 = alloca double, align 8
  %11 = alloca double, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  store ptr %2, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  store i32 0, ptr %7, align 4, !tbaa !9
  br label %12

12:                                               ; preds = %66, %3
  %13 = load i32, ptr %7, align 4, !tbaa !9
  %14 = load i32, ptr %5, align 4, !tbaa !9
  %15 = icmp ult i32 %13, %14
  br i1 %15, label %16, label %69

16:                                               ; preds = %12
  br label %17

17:                                               ; preds = %24, %16
  %18 = call i32 @rand() #3
  %19 = sitofp i32 %18 to double
  %20 = fdiv double %19, 0x41DFFFFFFFC00000
  store double %20, ptr %8, align 8, !tbaa !11
  %21 = call i32 @rand() #3
  %22 = sitofp i32 %21 to double
  %23 = fdiv double %22, 0x41DFFFFFFFC00000
  store double %23, ptr %9, align 8, !tbaa !11
  br label %24

24:                                               ; preds = %17
  %25 = load double, ptr %8, align 8, !tbaa !11
  %26 = load ptr, ptr %4, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.normal_obj, ptr %26, i32 0, i32 0
  %28 = load double, ptr %27, align 8, !tbaa !13
  %29 = fcmp ole double %25, %28
  br i1 %29, label %17, label %30, !llvm.loop !15

30:                                               ; preds = %24
  %31 = load double, ptr %8, align 8, !tbaa !11
  %32 = call double @log(double noundef %31) #3
  %33 = fmul double -2.000000e+00, %32
  %34 = call double @sqrt(double noundef %33) #3
  %35 = load double, ptr %9, align 8, !tbaa !11
  %36 = fmul double 0x401921FB54442D18, %35
  %37 = call double @cos(double noundef %36) #3
  %38 = fmul double %34, %37
  store double %38, ptr %10, align 8, !tbaa !11
  %39 = load double, ptr %10, align 8, !tbaa !11
  %40 = fptrunc double %39 to float
  %41 = load ptr, ptr %6, align 8, !tbaa !5
  %42 = load i32, ptr %7, align 4, !tbaa !9
  %43 = zext i32 %42 to i64
  %44 = getelementptr inbounds float, ptr %41, i64 %43
  store float %40, ptr %44, align 4, !tbaa !17
  %45 = load i32, ptr %7, align 4, !tbaa !9
  %46 = add i32 %45, 1
  %47 = load i32, ptr %5, align 4, !tbaa !9
  %48 = icmp ult i32 %46, %47
  br i1 %48, label %49, label %65

49:                                               ; preds = %30
  %50 = load double, ptr %8, align 8, !tbaa !11
  %51 = call double @log(double noundef %50) #3
  %52 = fmul double -2.000000e+00, %51
  %53 = call double @sqrt(double noundef %52) #3
  %54 = load double, ptr %9, align 8, !tbaa !11
  %55 = fmul double 0x401921FB54442D18, %54
  %56 = call double @sin(double noundef %55) #3
  %57 = fmul double %53, %56
  store double %57, ptr %11, align 8, !tbaa !11
  %58 = load double, ptr %11, align 8, !tbaa !11
  %59 = fptrunc double %58 to float
  %60 = load ptr, ptr %6, align 8, !tbaa !5
  %61 = load i32, ptr %7, align 4, !tbaa !9
  %62 = add i32 %61, 1
  %63 = zext i32 %62 to i64
  %64 = getelementptr inbounds float, ptr %60, i64 %63
  store float %59, ptr %64, align 4, !tbaa !17
  br label %65

65:                                               ; preds = %49, %30
  br label %66

66:                                               ; preds = %65
  %67 = load i32, ptr %7, align 4, !tbaa !9
  %68 = add i32 %67, 2
  store i32 %68, ptr %7, align 4, !tbaa !9
  br label %12, !llvm.loop !19

69:                                               ; preds = %12
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  ret void
}

; Function Attrs: nounwind
declare double @sqrt(double noundef) #1

; Function Attrs: nounwind
declare double @log(double noundef) #1

; Function Attrs: nounwind
declare double @cos(double noundef) #1

; Function Attrs: nounwind
declare double @sin(double noundef) #1

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nounwind "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #2 = { nounwind uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #3 = { nounwind }

!llvm.module.flags = !{!0, !1, !2, !3}
!llvm.ident = !{!4}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"clang version 19.1.0 (git@github.com:llvm/llvm-project.git a4bf6cd7cfb1a1421ba92bca9d017b49936c55e4)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"double", !7, i64 0}
!13 = !{!14, !12, i64 0}
!14 = !{!"normal_obj", !12, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = !{!18, !18, i64 0}
!18 = !{!"float", !7, i64 0}
!19 = distinct !{!19, !16}


; Optimized IR (opt -passes='default<O3>'):
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

; Function Attrs: nounwind
declare i32 @rand() local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @normal_generate(ptr nocapture noundef readonly %0, i32 noundef %1, ptr nocapture noundef writeonly %2) local_unnamed_addr #1 {
  %.not = icmp eq i32 %1, 0
  br i1 %.not, label %._crit_edge, label %.preheader

.preheader:                                       ; preds = %3, %34
  %.019 = phi i32 [ %35, %34 ], [ 0, %3 ]
  br label %4

4:                                                ; preds = %.preheader, %4
  %5 = tail call i32 @rand() #3
  %6 = sitofp i32 %5 to double
  %7 = fdiv double %6, 0x41DFFFFFFFC00000
  %8 = tail call i32 @rand() #3
  %9 = load double, ptr %0, align 8, !tbaa !5
  %10 = fcmp ugt double %7, %9
  br i1 %10, label %11, label %4, !llvm.loop !10

11:                                               ; preds = %4
  %12 = sitofp i32 %8 to double
  %13 = fdiv double %12, 0x41DFFFFFFFC00000
  %14 = tail call double @log(double noundef %7) #3
  %15 = fmul double %14, -2.000000e+00
  %16 = tail call double @sqrt(double noundef %15) #3
  %17 = fmul double %13, 0x401921FB54442D18
  %18 = tail call double @cos(double noundef %17) #3
  %19 = fmul double %16, %18
  %20 = fptrunc double %19 to float
  %21 = zext i32 %.019 to i64
  %22 = getelementptr inbounds float, ptr %2, i64 %21
  store float %20, ptr %22, align 4, !tbaa !12
  %23 = or disjoint i32 %.019, 1
  %24 = icmp ult i32 %23, %1
  br i1 %24, label %25, label %34

25:                                               ; preds = %11
  %26 = tail call double @log(double noundef %7) #3
  %27 = fmul double %26, -2.000000e+00
  %28 = tail call double @sqrt(double noundef %27) #3
  %29 = tail call double @sin(double noundef %17) #3
  %30 = fmul double %28, %29
  %31 = fptrunc double %30 to float
  %32 = zext i32 %23 to i64
  %33 = getelementptr inbounds float, ptr %2, i64 %32
  store float %31, ptr %33, align 4, !tbaa !12
  br label %34

34:                                               ; preds = %11, %25
  %35 = add i32 %.019, 2
  %36 = icmp ult i32 %35, %1
  br i1 %36, label %.preheader, label %._crit_edge, !llvm.loop !14

._crit_edge:                                      ; preds = %34, %3
  ret void
}

; Function Attrs: mustprogress nofree nounwind willreturn memory(write)
declare double @sqrt(double noundef) local_unnamed_addr #2

; Function Attrs: mustprogress nofree nounwind willreturn memory(write)
declare double @log(double noundef) local_unnamed_addr #2

; Function Attrs: mustprogress nofree nounwind willreturn memory(write)
declare double @cos(double noundef) local_unnamed_addr #2

; Function Attrs: mustprogress nofree nounwind willreturn memory(write)
declare double @sin(double noundef) local_unnamed_addr #2

attributes #0 = { nounwind "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #1 = { nounwind uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #2 = { mustprogress nofree nounwind willreturn memory(write) "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #3 = { nounwind }

!llvm.module.flags = !{!0, !1, !2, !3}
!llvm.ident = !{!4}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"clang version 19.1.0 (git@github.com:llvm/llvm-project.git a4bf6cd7cfb1a1421ba92bca9d017b49936c55e4)"}
!5 = !{!6, !7, i64 0}
!6 = !{!"normal_obj", !7, i64 0}
!7 = !{!"double", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}
!12 = !{!13, !13, i64 0}
!13 = !{!"float", !8, i64 0}
!14 = distinct !{!14, !11}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass