; LLVM IR from CLASS-SZ/class_sz :: class-sz/tools (r8lib)

; 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"

; 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: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #1

; Function Attrs: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #2

; Function Attrs: nounwind uwtable
declare dso_local void @i4vec_zeros(i32 noundef, ptr noundef) #3

; Function Attrs: nounwind uwtable
declare dso_local i32 @r8_nint(double noundef) #3

; Function Attrs: nounwind uwtable
define dso_local ptr @r8vec_histogram(i32 noundef %0, ptr noundef %1, double noundef %2, double noundef %3, i32 noundef %4) #3 {
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca double, align 8
  %9 = alloca double, align 8
  %10 = alloca i32, align 4
  %11 = alloca double, align 8
  %12 = alloca ptr, align 8
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  store i32 %0, ptr %6, align 4, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !9
  store double %2, ptr %8, align 8, !tbaa !11
  store double %3, ptr %9, align 8, !tbaa !11
  store i32 %4, ptr %10, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #4
  %15 = load i32, ptr %10, align 4, !tbaa !5
  %16 = add nsw i32 %15, 2
  %17 = sext i32 %16 to i64
  %18 = mul i64 %17, 4
  %19 = call noalias ptr @malloc(i64 noundef %18) #5
  store ptr %19, ptr %12, align 8, !tbaa !9
  %20 = load i32, ptr %10, align 4, !tbaa !5
  %21 = add nsw i32 %20, 2
  %22 = load ptr, ptr %12, align 8, !tbaa !9
  call void @i4vec_zeros(i32 noundef %21, ptr noundef %22)
  %23 = load double, ptr %9, align 8, !tbaa !11
  %24 = load double, ptr %8, align 8, !tbaa !11
  %25 = fsub double %23, %24
  %26 = load i32, ptr %10, align 4, !tbaa !5
  %27 = mul nsw i32 2, %26
  %28 = sitofp i32 %27 to double
  %29 = fdiv double %25, %28
  store double %29, ptr %11, align 8, !tbaa !11
  store i32 0, ptr %13, align 4, !tbaa !5
  br label %30

30:                                               ; preds = %122, %5
  %31 = load i32, ptr %13, align 4, !tbaa !5
  %32 = load i32, ptr %6, align 4, !tbaa !5
  %33 = icmp slt i32 %31, %32
  br i1 %33, label %34, label %125

34:                                               ; preds = %30
  %35 = load ptr, ptr %7, align 8, !tbaa !9
  %36 = load i32, ptr %13, align 4, !tbaa !5
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds double, ptr %35, i64 %37
  %39 = load double, ptr %38, align 8, !tbaa !11
  %40 = load double, ptr %8, align 8, !tbaa !11
  %41 = fcmp olt double %39, %40
  br i1 %41, label %42, label %49

42:                                               ; preds = %34
  %43 = load ptr, ptr %12, align 8, !tbaa !9
  %44 = getelementptr inbounds i32, ptr %43, i64 0
  %45 = load i32, ptr %44, align 4, !tbaa !5
  %46 = add nsw i32 %45, 1
  %47 = load ptr, ptr %12, align 8, !tbaa !9
  %48 = getelementptr inbounds i32, ptr %47, i64 0
  store i32 %46, ptr %48, align 4, !tbaa !5
  br label %121

49:                                               ; preds = %34
  %50 = load ptr, ptr %7, align 8, !tbaa !9
  %51 = load i32, ptr %13, align 4, !tbaa !5
  %52 = sext i32 %51 to i64
  %53 = getelementptr inbounds double, ptr %50, i64 %52
  %54 = load double, ptr %53, align 8, !tbaa !11
  %55 = load double, ptr %9, align 8, !tbaa !11
  %56 = fcmp ole double %54, %55
  br i1 %56, label %57, label %98

57:                                               ; preds = %49
  %58 = load double, ptr %9, align 8, !tbaa !11
  %59 = load double, ptr %11, align 8, !tbaa !11
  %60 = fsub double %58, %59
  %61 = load ptr, ptr %7, align 8, !tbaa !9
  %62 = load i32, ptr %13, align 4, !tbaa !5
  %63 = sext i32 %62 to i64
  %64 = getelementptr inbounds double, ptr %61, i64 %63
  %65 = load double, ptr %64, align 8, !tbaa !11
  %66 = fsub double %60, %65
  %67 = load double, ptr %11, align 8, !tbaa !11
  %68 = fneg double %67
  %69 = load ptr, ptr %7, align 8, !tbaa !9
  %70 = load i32, ptr %13, align 4, !tbaa !5
  %71 = sext i32 %70 to i64
  %72 = getelementptr inbounds double, ptr %69, i64 %71
  %73 = load double, ptr %72, align 8, !tbaa !11
  %74 = fadd double %68, %73
  %75 = load double, ptr %8, align 8, !tbaa !11
  %76 = fsub double %74, %75
  %77 = load i32, ptr %10, align 4, !tbaa !5
  %78 = sitofp i32 %77 to double
  %79 = fmul double %76, %78
  %80 = call double @llvm.fmuladd.f64(double %66, double 1.000000e+00, double %79)
  %81 = load double, ptr %9, align 8, !tbaa !11
  %82 = load double, ptr %11, align 8, !tbaa !11
  %83 = call double @llvm.fmuladd.f64(double -2.000000e+00, double %82, double %81)
  %84 = load double, ptr %8, align 8, !tbaa !11
  %85 = fsub double %83, %84
  %86 = fdiv double %80, %85
  %87 = call i32 @r8_nint(double noundef %86)
  store i32 %87, ptr %14, align 4, !tbaa !5
  %88 = load ptr, ptr %12, align 8, !tbaa !9
  %89 = load i32, ptr %14, align 4, !tbaa !5
  %90 = sext i32 %89 to i64
  %91 = getelementptr inbounds i32, ptr %88, i64 %90
  %92 = load i32, ptr %91, align 4, !tbaa !5
  %93 = add nsw i32 %92, 1
  %94 = load ptr, ptr %12, align 8, !tbaa !9
  %95 = load i32, ptr %14, align 4, !tbaa !5
  %96 = sext i32 %95 to i64
  %97 = getelementptr inbounds i32, ptr %94, i64 %96
  store i32 %93, ptr %97, align 4, !tbaa !5
  br label %120

98:                                               ; preds = %49
  %99 = load double, ptr %9, align 8, !tbaa !11
  %100 = load ptr, ptr %7, align 8, !tbaa !9
  %101 = load i32, ptr %13, align 4, !tbaa !5
  %102 = sext i32 %101 to i64
  %103 = getelementptr inbounds double, ptr %100, i64 %102
  %104 = load double, ptr %103, align 8, !tbaa !11
  %105 = fcmp olt double %99, %104
  br i1 %105, label %106, label %119

106:                                              ; preds = %98
  %107 = load ptr, ptr %12, align 8, !tbaa !9
  %108 = load i32, ptr %10, align 4, !tbaa !5
  %109 = add nsw i32 %108, 1
  %110 = sext i32 %109 to i64
  %111 = getelementptr inbounds i32, ptr %107, i64 %110
  %112 = load i32, ptr %111, align 4, !tbaa !5
  %113 = add nsw i32 %112, 1
  %114 = load ptr, ptr %12, align 8, !tbaa !9
  %115 = load i32, ptr %10, align 4, !tbaa !5
  %116 = add nsw i32 %115, 1
  %117 = sext i32 %116 to i64
  %118 = getelementptr inbounds i32, ptr %114, i64 %117
  store i32 %113, ptr %118, align 4, !tbaa !5
  br label %119

119:                                              ; preds = %106, %98
  br label %120

120:                                              ; preds = %119, %57
  br label %121

121:                                              ; preds = %120, %42
  br label %122

122:                                              ; preds = %121
  %123 = load i32, ptr %13, align 4, !tbaa !5
  %124 = add nsw i32 %123, 1
  store i32 %124, ptr %13, align 4, !tbaa !5
  br label %30, !llvm.loop !13

125:                                              ; preds = %30
  %126 = load ptr, ptr %12, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  ret ptr %126
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #2 = { nounwind allocsize(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 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 #4 = { nounwind }
attributes #5 = { nounwind allocsize(0) }

!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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"double", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}


; 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: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #0

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local void @i4vec_zeros(i32 noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
declare dso_local i32 @r8_nint(double noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
define dso_local noundef ptr @r8vec_histogram(i32 noundef %0, ptr nocapture noundef readonly %1, double noundef %2, double noundef %3, i32 noundef %4) local_unnamed_addr #2 {
  %6 = add nsw i32 %4, 2
  %7 = sext i32 %6 to i64
  %8 = shl nsw i64 %7, 2
  %9 = tail call noalias ptr @malloc(i64 noundef %8) #3
  tail call void @i4vec_zeros(i32 noundef %6, ptr noundef %9)
  %10 = fsub double %3, %2
  %11 = shl nsw i32 %4, 1
  %12 = sitofp i32 %11 to double
  %13 = fdiv double %10, %12
  %14 = icmp sgt i32 %0, 0
  br i1 %14, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %5
  %invariant.gep = getelementptr i8, ptr %9, i64 4
  %15 = fsub double %3, %13
  %16 = sitofp i32 %4 to double
  %17 = tail call double @llvm.fmuladd.f64(double %13, double -2.000000e+00, double %3)
  %18 = fsub double %17, %2
  %19 = sext i32 %4 to i64
  %gep = getelementptr i32, ptr %invariant.gep, i64 %19
  %wide.trip.count = zext nneg i32 %0 to i64
  br label %20

20:                                               ; preds = %.lr.ph, %40
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %40 ]
  %21 = getelementptr inbounds double, ptr %1, i64 %indvars.iv
  %22 = load double, ptr %21, align 8, !tbaa !5
  %23 = fcmp olt double %22, %2
  br i1 %23, label %.sink.split, label %24

24:                                               ; preds = %20
  %25 = fcmp ugt double %22, %3
  br i1 %25, label %36, label %26

26:                                               ; preds = %24
  %27 = fsub double %15, %22
  %28 = fsub double %22, %13
  %29 = fsub double %28, %2
  %30 = fmul double %29, %16
  %31 = fadd double %27, %30
  %32 = fdiv double %31, %18
  %33 = tail call i32 @r8_nint(double noundef %32)
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds i32, ptr %9, i64 %34
  br label %.sink.split

36:                                               ; preds = %24
  %37 = fcmp ogt double %22, %3
  br i1 %37, label %.sink.split, label %40

.sink.split:                                      ; preds = %36, %20, %26
  %.sink = phi ptr [ %35, %26 ], [ %9, %20 ], [ %gep, %36 ]
  %38 = load i32, ptr %.sink, align 4, !tbaa !9
  %39 = add nsw i32 %38, 1
  store i32 %39, ptr %.sink, align 4, !tbaa !9
  br label %40

40:                                               ; preds = %.sink.split, %36
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge, label %20, !llvm.loop !11

._crit_edge:                                      ; preds = %40, %5
  ret ptr %9
}

attributes #0 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #1 = { mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" "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 allocsize(0) }

!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 = !{!"double", !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 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass