; LLVM IR from InnoFang/algo-set :: template/algorithm/combination_number.ll (Z2C2mm)

; 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: mustprogress nounwind uwtable
define dso_local noundef i64 @_Z2C2mm(i64 noundef %0, i64 noundef %1) #1 {
  %3 = alloca i64, align 8
  %4 = alloca i64, align 8
  %5 = alloca i64, align 8
  %6 = alloca double, align 8
  %7 = alloca i64, align 8
  %8 = alloca double, align 8
  %9 = alloca i64, align 8
  %10 = alloca i64, align 8
  %11 = alloca double, align 8
  store i64 %0, ptr %4, align 8, !tbaa !5
  store i64 %1, ptr %5, align 8, !tbaa !5
  %12 = load i64, ptr %4, align 8, !tbaa !5
  %13 = load i64, ptr %5, align 8, !tbaa !5
  %14 = icmp ult i64 %12, %13
  br i1 %14, label %15, label %16

15:                                               ; preds = %2
  store i64 0, ptr %3, align 8
  br label %68

16:                                               ; preds = %2
  %17 = load i64, ptr %5, align 8, !tbaa !5
  %18 = load i64, ptr %4, align 8, !tbaa !5
  %19 = lshr i64 %18, 1
  %20 = icmp ult i64 %17, %19
  br i1 %20, label %21, label %25

21:                                               ; preds = %16
  %22 = load i64, ptr %4, align 8, !tbaa !5
  %23 = load i64, ptr %5, align 8, !tbaa !5
  %24 = sub i64 %22, %23
  store i64 %24, ptr %5, align 8, !tbaa !5
  br label %25

25:                                               ; preds = %21, %16
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  store double 0.000000e+00, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  %26 = load i64, ptr %5, align 8, !tbaa !5
  %27 = add i64 %26, 1
  store i64 %27, ptr %7, align 8, !tbaa !5
  br label %28

28:                                               ; preds = %39, %25
  %29 = load i64, ptr %7, align 8, !tbaa !5
  %30 = load i64, ptr %4, align 8, !tbaa !5
  %31 = icmp ule i64 %29, %30
  br i1 %31, label %33, label %32

32:                                               ; preds = %28
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  br label %42

33:                                               ; preds = %28
  %34 = load i64, ptr %7, align 8, !tbaa !5
  %35 = uitofp i64 %34 to double
  %36 = call double @log(double noundef %35) #4
  %37 = load double, ptr %6, align 8, !tbaa !9
  %38 = fadd double %37, %36
  store double %38, ptr %6, align 8, !tbaa !9
  br label %39

39:                                               ; preds = %33
  %40 = load i64, ptr %7, align 8, !tbaa !5
  %41 = add i64 %40, 1
  store i64 %41, ptr %7, align 8, !tbaa !5
  br label %28, !llvm.loop !11

42:                                               ; preds = %32
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  store double 0.000000e+00, ptr %8, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  %43 = load i64, ptr %4, align 8, !tbaa !5
  %44 = load i64, ptr %5, align 8, !tbaa !5
  %45 = sub i64 %43, %44
  store i64 %45, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  store i64 1, ptr %10, align 8, !tbaa !5
  br label %46

46:                                               ; preds = %57, %42
  %47 = load i64, ptr %10, align 8, !tbaa !5
  %48 = load i64, ptr %9, align 8, !tbaa !5
  %49 = icmp ule i64 %47, %48
  br i1 %49, label %51, label %50

50:                                               ; preds = %46
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  br label %60

51:                                               ; preds = %46
  %52 = load i64, ptr %10, align 8, !tbaa !5
  %53 = uitofp i64 %52 to double
  %54 = call double @log(double noundef %53) #4
  %55 = load double, ptr %8, align 8, !tbaa !9
  %56 = fadd double %55, %54
  store double %56, ptr %8, align 8, !tbaa !9
  br label %57

57:                                               ; preds = %51
  %58 = load i64, ptr %10, align 8, !tbaa !5
  %59 = add i64 %58, 1
  store i64 %59, ptr %10, align 8, !tbaa !5
  br label %46, !llvm.loop !13

60:                                               ; preds = %50
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  %61 = load double, ptr %6, align 8, !tbaa !9
  %62 = load double, ptr %8, align 8, !tbaa !9
  %63 = fsub double %61, %62
  %64 = call double @exp(double noundef %63) #4
  store double %64, ptr %11, align 8, !tbaa !9
  %65 = load double, ptr %11, align 8, !tbaa !9
  %66 = call double @llvm.round.f64(double %65)
  %67 = fptoui double %66 to i64
  store i64 %67, ptr %3, align 8
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  br label %68

68:                                               ; preds = %60, %15
  %69 = load i64, ptr %3, align 8
  ret i64 %69
}

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

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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.round.f64(double) #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress 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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #4 = { 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 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"double", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}


; 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 nofree nounwind memory(write) uwtable
define dso_local noundef i64 @_Z2C2mm(i64 noundef %0, i64 noundef %1) local_unnamed_addr #0 {
  %3 = icmp ult i64 %0, %1
  br i1 %3, label %20, label %4

4:                                                ; preds = %2
  %5 = lshr i64 %0, 1
  %6 = icmp ugt i64 %5, %1
  %7 = sub i64 %0, %1
  %spec.select = select i1 %6, i64 %7, i64 %1
  %.02530 = add i64 %spec.select, 1
  %.not31 = icmp ugt i64 %.02530, %0
  br i1 %.not31, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %.lr.ph, %4
  %.026.lcssa = phi double [ 0.000000e+00, %4 ], [ %11, %.lr.ph ]
  %8 = sub i64 %0, %spec.select
  %.not2934 = icmp eq i64 %spec.select, %0
  br i1 %.not2934, label %._crit_edge39, label %.lr.ph38

.lr.ph:                                           ; preds = %4, %.lr.ph
  %.02533 = phi i64 [ %.025, %.lr.ph ], [ %.02530, %4 ]
  %.02632 = phi double [ %11, %.lr.ph ], [ 0.000000e+00, %4 ]
  %9 = uitofp i64 %.02533 to double
  %10 = tail call double @log(double noundef %9) #3
  %11 = fadd double %.02632, %10
  %.025 = add i64 %.02533, 1
  %.not = icmp ugt i64 %.025, %0
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !5

._crit_edge39:                                    ; preds = %.lr.ph38, %._crit_edge
  %.024.lcssa = phi double [ 0.000000e+00, %._crit_edge ], [ %18, %.lr.ph38 ]
  %12 = fsub double %.026.lcssa, %.024.lcssa
  %13 = tail call double @exp(double noundef %12) #3
  %14 = tail call double @llvm.round.f64(double %13)
  %15 = fptoui double %14 to i64
  br label %20

.lr.ph38:                                         ; preds = %._crit_edge, %.lr.ph38
  %.02236 = phi i64 [ %19, %.lr.ph38 ], [ 1, %._crit_edge ]
  %.02435 = phi double [ %18, %.lr.ph38 ], [ 0.000000e+00, %._crit_edge ]
  %16 = uitofp i64 %.02236 to double
  %17 = tail call double @log(double noundef %16) #3
  %18 = fadd double %.02435, %17
  %19 = add i64 %.02236, 1
  %.not29 = icmp ugt i64 %19, %8
  br i1 %.not29, label %._crit_edge39, label %.lr.ph38, !llvm.loop !7

20:                                               ; preds = %2, %._crit_edge39
  %.0 = phi i64 [ %15, %._crit_edge39 ], [ 0, %2 ]
  ret i64 %.0
}

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

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

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.round.f64(double) #2

attributes #0 = { mustprogress nofree nounwind memory(write) 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 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}
!7 = distinct !{!7, !6}


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