; LLVM IR from MinhasKamal/AlgorithmImplementations :: playWithNumbers/factorial (FactorsOfFactorial)

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

@n = external dso_local global [25 x i32], align 16
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [8 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [2 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i32 @main() #0 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  br label %6

6:                                                ; preds = %77, %75, %0
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #3
  store i32 0, ptr %2, align 4, !tbaa !5
  br label %7

7:                                                ; preds = %14, %6
  %8 = load i32, ptr %2, align 4, !tbaa !5
  %9 = icmp slt i32 %8, 25
  br i1 %9, label %10, label %17

10:                                               ; preds = %7
  %11 = load i32, ptr %2, align 4, !tbaa !5
  %12 = sext i32 %11 to i64
  %13 = getelementptr inbounds [25 x i32], ptr @n, i64 0, i64 %12
  store i32 0, ptr %13, align 4, !tbaa !5
  br label %14

14:                                               ; preds = %10
  %15 = load i32, ptr %2, align 4, !tbaa !5
  %16 = add nsw i32 %15, 1
  store i32 %16, ptr %2, align 4, !tbaa !5
  br label %7, !llvm.loop !9

17:                                               ; preds = %7
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  %18 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %3)
  %19 = load i32, ptr %3, align 4, !tbaa !5
  %20 = icmp eq i32 %19, 0
  br i1 %20, label %21, label %22

21:                                               ; preds = %17
  store i32 2, ptr %5, align 4
  br label %75

22:                                               ; preds = %17
  %23 = load i32, ptr %3, align 4, !tbaa !5
  %24 = icmp sgt i32 %23, 100
  br i1 %24, label %28, label %25

25:                                               ; preds = %22
  %26 = load i32, ptr %3, align 4, !tbaa !5
  %27 = icmp slt i32 %26, 2
  br i1 %27, label %28, label %29

28:                                               ; preds = %25, %22
  store i32 3, ptr %5, align 4
  br label %75

29:                                               ; preds = %25
  store i32 2, ptr %4, align 4, !tbaa !5
  br label %30

30:                                               ; preds = %36, %29
  %31 = load i32, ptr %4, align 4, !tbaa !5
  %32 = load i32, ptr %3, align 4, !tbaa !5
  %33 = icmp sle i32 %31, %32
  br i1 %33, label %34, label %39

34:                                               ; preds = %30
  %35 = load i32, ptr %4, align 4, !tbaa !5
  call void @varify(i32 noundef %35)
  br label %36

36:                                               ; preds = %34
  %37 = load i32, ptr %4, align 4, !tbaa !5
  %38 = add nsw i32 %37, 1
  store i32 %38, ptr %4, align 4, !tbaa !5
  br label %30, !llvm.loop !11

39:                                               ; preds = %30
  store i32 24, ptr %4, align 4, !tbaa !5
  br label %40

40:                                               ; preds = %47, %39
  %41 = load i32, ptr %4, align 4, !tbaa !5
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds [25 x i32], ptr @n, i64 0, i64 %42
  %44 = load i32, ptr %43, align 4, !tbaa !5
  %45 = icmp eq i32 %44, 0
  br i1 %45, label %46, label %50

46:                                               ; preds = %40
  br label %47

47:                                               ; preds = %46
  %48 = load i32, ptr %4, align 4, !tbaa !5
  %49 = add nsw i32 %48, -1
  store i32 %49, ptr %4, align 4, !tbaa !5
  br label %40, !llvm.loop !12

50:                                               ; preds = %40
  %51 = load i32, ptr %3, align 4, !tbaa !5
  %52 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i32 noundef %51)
  store i32 0, ptr %3, align 4, !tbaa !5
  br label %53

53:                                               ; preds = %70, %50
  %54 = load i32, ptr %3, align 4, !tbaa !5
  %55 = load i32, ptr %4, align 4, !tbaa !5
  %56 = icmp sle i32 %54, %55
  br i1 %56, label %57, label %73

57:                                               ; preds = %53
  %58 = load i32, ptr %3, align 4, !tbaa !5
  %59 = sext i32 %58 to i64
  %60 = getelementptr inbounds [25 x i32], ptr @n, i64 0, i64 %59
  %61 = load i32, ptr %60, align 4, !tbaa !5
  %62 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i32 noundef %61)
  %63 = load i32, ptr %3, align 4, !tbaa !5
  %64 = add nsw i32 %63, 1
  %65 = srem i32 %64, 15
  %66 = icmp eq i32 %65, 0
  br i1 %66, label %67, label %69

67:                                               ; preds = %57
  %68 = call i32 (ptr, ...) @printf(ptr noundef @.str.3)
  br label %69

69:                                               ; preds = %67, %57
  br label %70

70:                                               ; preds = %69
  %71 = load i32, ptr %3, align 4, !tbaa !5
  %72 = add nsw i32 %71, 1
  store i32 %72, ptr %3, align 4, !tbaa !5
  br label %53, !llvm.loop !13

73:                                               ; preds = %53
  %74 = call i32 (ptr, ...) @printf(ptr noundef @.str.4)
  store i32 0, ptr %5, align 4
  br label %75

75:                                               ; preds = %73, %28, %21
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #3
  %76 = load i32, ptr %5, align 4
  switch i32 %76, label %79 [
    i32 0, label %77
    i32 2, label %78
    i32 3, label %6
  ]

77:                                               ; preds = %75
  br label %6

78:                                               ; preds = %75
  ret i32 0

79:                                               ; preds = %75
  unreachable
}

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

declare i32 @__isoc99_scanf(ptr noundef, ...) #2

; Function Attrs: nounwind uwtable
declare dso_local void @varify(i32 noundef) #0

declare i32 @printf(ptr noundef, ...) #2

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { "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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}
!12 = distinct !{!12, !10}
!13 = distinct !{!13, !10}


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

@n = external dso_local local_unnamed_addr global [25 x i32], align 16
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [8 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [2 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  %1 = alloca i32, align 4
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(100) @n, i8 0, i64 100, i1 false), !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #4
  %2 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %1)
  %3 = load i32, ptr %1, align 4
  %4 = icmp eq i32 %3, 0
  br i1 %4, label %._crit_edge32, label %.lr.ph31

.lr.ph31:                                         ; preds = %0, %28
  %5 = phi i32 [ %30, %28 ], [ %3, %0 ]
  %6 = add i32 %5, -101
  %or.cond = icmp ult i32 %6, -99
  br i1 %or.cond, label %28, label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph31, %.lr.ph
  %.01122 = phi i32 [ %7, %.lr.ph ], [ 2, %.lr.ph31 ]
  call void @varify(i32 noundef %.01122)
  %7 = add nuw nsw i32 %.01122, 1
  %8 = load i32, ptr %1, align 4, !tbaa !5
  %.not.not = icmp slt i32 %.01122, %8
  br i1 %.not.not, label %.lr.ph, label %.preheader, !llvm.loop !9

.preheader:                                       ; preds = %.lr.ph, %.preheader
  %indvars.iv = phi i64 [ %indvars.iv.next, %.preheader ], [ 24, %.lr.ph ]
  %9 = getelementptr inbounds [25 x i32], ptr @n, i64 0, i64 %indvars.iv
  %10 = load i32, ptr %9, align 4, !tbaa !5
  %11 = icmp eq i32 %10, 0
  %indvars.iv.next = add nsw i64 %indvars.iv, -1
  br i1 %11, label %.preheader, label %12, !llvm.loop !11

12:                                               ; preds = %.preheader
  %13 = trunc nsw i64 %indvars.iv to i32
  %14 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %8)
  store i32 0, ptr %1, align 4, !tbaa !5
  %.not1523 = icmp slt i64 %indvars.iv, 0
  br i1 %.not1523, label %._crit_edge, label %.lr.ph25

.lr.ph25:                                         ; preds = %12, %25
  %storemerge24 = phi i32 [ %.pre-phi, %25 ], [ 0, %12 ]
  %15 = sext i32 %storemerge24 to i64
  %16 = getelementptr inbounds [25 x i32], ptr @n, i64 0, i64 %15
  %17 = load i32, ptr %16, align 4, !tbaa !5
  %18 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i32 noundef %17)
  %19 = load i32, ptr %1, align 4, !tbaa !5
  %20 = add nsw i32 %19, 1
  %21 = srem i32 %20, 15
  %22 = icmp eq i32 %21, 0
  br i1 %22, label %23, label %25

23:                                               ; preds = %.lr.ph25
  %24 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3)
  %.pre = load i32, ptr %1, align 4, !tbaa !5
  %.pre29 = add nsw i32 %.pre, 1
  br label %25

25:                                               ; preds = %.lr.ph25, %23
  %.pre-phi = phi i32 [ %20, %.lr.ph25 ], [ %.pre29, %23 ]
  %26 = phi i32 [ %19, %.lr.ph25 ], [ %.pre, %23 ]
  store i32 %.pre-phi, ptr %1, align 4, !tbaa !5
  %.not15.not = icmp slt i32 %26, %13
  br i1 %.not15.not, label %.lr.ph25, label %._crit_edge, !llvm.loop !12

._crit_edge:                                      ; preds = %25, %12
  %27 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.4)
  br label %28

28:                                               ; preds = %.lr.ph31, %._crit_edge
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #4
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(100) @n, i8 0, i64 100, i1 false), !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #4
  %29 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %1)
  %30 = load i32, ptr %1, align 4
  %31 = icmp eq i32 %30, 0
  br i1 %31, label %._crit_edge32, label %.lr.ph31

._crit_edge32:                                    ; preds = %28, %0
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #4
  ret i32 0
}

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

; Function Attrs: nofree nounwind
declare noundef i32 @__isoc99_scanf(ptr nocapture noundef readonly, ...) local_unnamed_addr #2

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

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #2

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

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

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


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