; 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: nounwind uwtable
define dso_local double @r8_choose(i32 noundef %0, i32 noundef %1) #1 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca double, align 8
  %6 = alloca double, align 8
  %7 = alloca double, align 8
  %8 = alloca double, align 8
  %9 = alloca double, align 8
  store i32 %0, ptr %3, align 4, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.start.p0(i64 8, 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
  %10 = load i32, ptr %3, align 4, !tbaa !5
  %11 = icmp slt i32 %10, 0
  br i1 %11, label %12, label %13

12:                                               ; preds = %2
  store double 0.000000e+00, ptr %9, align 8, !tbaa !9
  br label %76

13:                                               ; preds = %2
  %14 = load i32, ptr %4, align 4, !tbaa !5
  %15 = icmp eq i32 %14, 0
  br i1 %15, label %16, label %17

16:                                               ; preds = %13
  store double 1.000000e+00, ptr %9, align 8, !tbaa !9
  br label %75

17:                                               ; preds = %13
  %18 = load i32, ptr %4, align 4, !tbaa !5
  %19 = icmp eq i32 %18, 1
  br i1 %19, label %20, label %23

20:                                               ; preds = %17
  %21 = load i32, ptr %3, align 4, !tbaa !5
  %22 = sitofp i32 %21 to double
  store double %22, ptr %9, align 8, !tbaa !9
  br label %74

23:                                               ; preds = %17
  %24 = load i32, ptr %4, align 4, !tbaa !5
  %25 = icmp slt i32 1, %24
  br i1 %25, label %26, label %57

26:                                               ; preds = %23
  %27 = load i32, ptr %4, align 4, !tbaa !5
  %28 = load i32, ptr %3, align 4, !tbaa !5
  %29 = sub nsw i32 %28, 1
  %30 = icmp slt i32 %27, %29
  br i1 %30, label %31, label %57

31:                                               ; preds = %26
  %32 = load i32, ptr %3, align 4, !tbaa !5
  %33 = add nsw i32 %32, 1
  %34 = sitofp i32 %33 to double
  store double %34, ptr %5, align 8, !tbaa !9
  %35 = load double, ptr %5, align 8, !tbaa !9
  %36 = call double @r8_gamma_log(double noundef %35)
  store double %36, ptr %7, align 8, !tbaa !9
  %37 = load i32, ptr %4, align 4, !tbaa !5
  %38 = add nsw i32 %37, 1
  %39 = sitofp i32 %38 to double
  store double %39, ptr %5, align 8, !tbaa !9
  %40 = load double, ptr %5, align 8, !tbaa !9
  %41 = call double @r8_gamma_log(double noundef %40)
  store double %41, ptr %6, align 8, !tbaa !9
  %42 = load i32, ptr %3, align 4, !tbaa !5
  %43 = load i32, ptr %4, align 4, !tbaa !5
  %44 = sub nsw i32 %42, %43
  %45 = add nsw i32 %44, 1
  %46 = sitofp i32 %45 to double
  store double %46, ptr %5, align 8, !tbaa !9
  %47 = load double, ptr %5, align 8, !tbaa !9
  %48 = call double @r8_gamma_log(double noundef %47)
  store double %48, ptr %8, align 8, !tbaa !9
  %49 = load double, ptr %7, align 8, !tbaa !9
  %50 = load double, ptr %6, align 8, !tbaa !9
  %51 = fsub double %49, %50
  %52 = load double, ptr %8, align 8, !tbaa !9
  %53 = fsub double %51, %52
  %54 = call double @exp(double noundef %53) #3
  %55 = call i32 @r8_nint(double noundef %54)
  %56 = sitofp i32 %55 to double
  store double %56, ptr %9, align 8, !tbaa !9
  br label %73

57:                                               ; preds = %26, %23
  %58 = load i32, ptr %4, align 4, !tbaa !5
  %59 = load i32, ptr %3, align 4, !tbaa !5
  %60 = sub nsw i32 %59, 1
  %61 = icmp eq i32 %58, %60
  br i1 %61, label %62, label %65

62:                                               ; preds = %57
  %63 = load i32, ptr %3, align 4, !tbaa !5
  %64 = sitofp i32 %63 to double
  store double %64, ptr %9, align 8, !tbaa !9
  br label %72

65:                                               ; preds = %57
  %66 = load i32, ptr %4, align 4, !tbaa !5
  %67 = load i32, ptr %3, align 4, !tbaa !5
  %68 = icmp eq i32 %66, %67
  br i1 %68, label %69, label %70

69:                                               ; preds = %65
  store double 1.000000e+00, ptr %9, align 8, !tbaa !9
  br label %71

70:                                               ; preds = %65
  store double 0.000000e+00, ptr %9, align 8, !tbaa !9
  br label %71

71:                                               ; preds = %70, %69
  br label %72

72:                                               ; preds = %71, %62
  br label %73

73:                                               ; preds = %72, %31
  br label %74

74:                                               ; preds = %73, %20
  br label %75

75:                                               ; preds = %74, %16
  br label %76

76:                                               ; preds = %75, %12
  %77 = load double, ptr %9, align 8, !tbaa !9
  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 8, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  ret double %77
}

; Function Attrs: nounwind uwtable
declare dso_local double @r8_gamma_log(double noundef) #1

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

; Function Attrs: nounwind
declare double @exp(double noundef) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 #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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"double", !7, i64 0}


; 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 uwtable
define dso_local double @r8_choose(i32 noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = icmp slt i32 %0, 0
  br i1 %3, label %32, label %4

4:                                                ; preds = %2
  switch i32 %1, label %7 [
    i32 0, label %32
    i32 1, label %5
  ]

5:                                                ; preds = %4
  %6 = uitofp nneg i32 %0 to double
  br label %32

7:                                                ; preds = %4
  %8 = icmp sgt i32 %1, 1
  %9 = add nsw i32 %0, -1
  %10 = icmp sgt i32 %9, %1
  %or.cond = select i1 %8, i1 %10, i1 false
  br i1 %or.cond, label %11, label %26

11:                                               ; preds = %7
  %12 = add nuw i32 %0, 1
  %13 = uitofp nneg i32 %12 to double
  %14 = tail call double @r8_gamma_log(double noundef %13)
  %15 = add nuw nsw i32 %1, 1
  %16 = uitofp nneg i32 %15 to double
  %17 = tail call double @r8_gamma_log(double noundef %16)
  %18 = sub i32 %12, %1
  %19 = sitofp i32 %18 to double
  %20 = tail call double @r8_gamma_log(double noundef %19)
  %21 = fsub double %14, %17
  %22 = fsub double %21, %20
  %23 = tail call double @exp(double noundef %22) #2
  %24 = tail call i32 @r8_nint(double noundef %23)
  %25 = sitofp i32 %24 to double
  br label %32

26:                                               ; preds = %7
  %27 = icmp eq i32 %9, %1
  br i1 %27, label %28, label %30

28:                                               ; preds = %26
  %29 = uitofp nneg i32 %0 to double
  br label %32

30:                                               ; preds = %26
  %31 = icmp eq i32 %1, %0
  %. = select i1 %31, double 1.000000e+00, double 0.000000e+00
  br label %32

32:                                               ; preds = %30, %4, %2, %11, %28, %5
  %.0 = phi double [ %6, %5 ], [ %25, %11 ], [ %29, %28 ], [ 0.000000e+00, %2 ], [ 1.000000e+00, %4 ], [ %., %30 ]
  ret double %.0
}

; Function Attrs: nounwind uwtable
declare dso_local double @r8_gamma_log(double noundef) local_unnamed_addr #0

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

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

attributes #0 = { 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 #1 = { 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 #2 = { 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)"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass