; LLVM IR from ShahjalalShohag/code-library :: Graph Theory/Minimum Mean Weight Cycle.ll (Z2okid)

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

@vis = external dso_local global [702 x i8], align 16
@d = external dso_local global [702 x double], align 16

; Function Attrs: mustprogress uwtable
declare dso_local noundef zeroext i1 @_Z4spfaid(i32 noundef, double noundef) #0

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

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

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

9:                                                ; preds = %21, %2
  %10 = load i32, ptr %6, align 4, !tbaa !5
  %11 = load i32, ptr %4, align 4, !tbaa !5
  %12 = icmp sle i32 %10, %11
  br i1 %12, label %14, label %13

13:                                               ; preds = %9
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  br label %24

14:                                               ; preds = %9
  %15 = load i32, ptr %6, align 4, !tbaa !5
  %16 = sext i32 %15 to i64
  %17 = getelementptr inbounds [702 x double], ptr @d, i64 0, i64 %16
  store double 0.000000e+00, ptr %17, align 8, !tbaa !9
  %18 = load i32, ptr %6, align 4, !tbaa !5
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds [702 x i8], ptr @vis, i64 0, i64 %19
  store i8 0, ptr %20, align 1, !tbaa !11
  br label %21

21:                                               ; preds = %14
  %22 = load i32, ptr %6, align 4, !tbaa !5
  %23 = add nsw i32 %22, 1
  store i32 %23, ptr %6, align 4, !tbaa !5
  br label %9, !llvm.loop !13

24:                                               ; preds = %13
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #2
  store i32 1, ptr %7, align 4, !tbaa !5
  br label %25

25:                                               ; preds = %36, %24
  %26 = load i32, ptr %7, align 4, !tbaa !5
  %27 = load i32, ptr %4, align 4, !tbaa !5
  %28 = icmp sle i32 %26, %27
  br i1 %28, label %30, label %29

29:                                               ; preds = %25
  store i32 5, ptr %8, align 4
  br label %39

30:                                               ; preds = %25
  %31 = load i32, ptr %7, align 4, !tbaa !5
  %32 = load double, ptr %5, align 8, !tbaa !9
  %33 = call noundef zeroext i1 @_Z4spfaid(i32 noundef %31, double noundef %32)
  br i1 %33, label %35, label %34

34:                                               ; preds = %30
  store i1 true, ptr %3, align 1
  store i32 1, ptr %8, align 4
  br label %39

35:                                               ; preds = %30
  br label %36

36:                                               ; preds = %35
  %37 = load i32, ptr %7, align 4, !tbaa !5
  %38 = add nsw i32 %37, 1
  store i32 %38, ptr %7, align 4, !tbaa !5
  br label %25, !llvm.loop !15

39:                                               ; preds = %34, %29
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  %40 = load i32, ptr %8, align 4
  switch i32 %40, label %44 [
    i32 5, label %41
    i32 1, label %42
  ]

41:                                               ; preds = %39
  store i1 false, ptr %3, align 1
  br label %42

42:                                               ; preds = %41, %39
  %43 = load i1, ptr %3, align 1
  ret i1 %43

44:                                               ; preds = %39
  unreachable
}

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


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

@vis = external dso_local local_unnamed_addr global [702 x i8], align 16
@d = external dso_local local_unnamed_addr global [702 x double], align 16

; Function Attrs: mustprogress uwtable
declare dso_local noundef zeroext i1 @_Z4spfaid(i32 noundef, double noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_Z2okid(i32 noundef %0, double noundef %1) local_unnamed_addr #0 {
  %.not16 = icmp slt i32 %0, 1
  br i1 %.not16, label %._crit_edge, label %.lr.ph21.preheader

.lr.ph21.preheader:                               ; preds = %2
  %3 = zext nneg i32 %0 to i64
  %4 = shl nuw nsw i64 %3, 3
  tail call void @llvm.memset.p0.i64(ptr nonnull align 8 getelementptr inbounds (i8, ptr @d, i64 8), i8 0, i64 %4, i1 false), !tbaa !5
  tail call void @llvm.memset.p0.i64(ptr nonnull align 1 getelementptr inbounds (i8, ptr @vis, i64 1), i8 0, i64 %3, i1 false), !tbaa !9
  %5 = tail call noundef zeroext i1 @_Z4spfaid(i32 noundef 1, double noundef %1)
  br i1 %5, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %.lr.ph21.preheader, %.lr.ph21
  %.0111926 = phi i32 [ %6, %.lr.ph21 ], [ 1, %.lr.ph21.preheader ]
  %exitcond.not = icmp eq i32 %.0111926, %0
  br i1 %exitcond.not, label %._crit_edge.loopexit, label %.lr.ph21, !llvm.loop !11

.lr.ph21:                                         ; preds = %.lr.ph
  %6 = add nuw i32 %.0111926, 1
  %7 = tail call noundef zeroext i1 @_Z4spfaid(i32 noundef %6, double noundef %1)
  br i1 %7, label %.lr.ph, label %._crit_edge.loopexit, !llvm.loop !11

._crit_edge.loopexit:                             ; preds = %.lr.ph, %.lr.ph21
  %.not15.le = icmp slt i32 %.0111926, %0
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %.lr.ph21.preheader, %2
  %.not15.lcssa = phi i1 [ false, %2 ], [ true, %.lr.ph21.preheader ], [ %.not15.le, %._crit_edge.loopexit ]
  ret i1 %.not15.lcssa
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #1

attributes #0 = { mustprogress 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 = { nocallback nofree nounwind willreturn memory(argmem: write) }

!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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"bool", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


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