; LLVM IR from Dev-XYS/Algorithms :: Primitive-Root (main)

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

@p = external dso_local global i64, align 8
@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [6 x i8], align 1

; Function Attrs: mustprogress uwtable
declare dso_local noundef i64 @_Z4qpowxx(i64 noundef, i64 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 norecurse uwtable
define dso_local noundef i32 @main() #2 {
  %1 = alloca i32, align 4
  %2 = alloca i64, align 8
  %3 = alloca i64, align 8
  %4 = alloca i64, align 8
  %5 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #4
  br label %6

6:                                                ; preds = %71, %0
  br label %7

7:                                                ; preds = %6
  %8 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @p)
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #4
  store i64 2, ptr %3, align 8, !tbaa !5
  br label %9

9:                                                ; preds = %67, %7
  %10 = load i64, ptr @p, align 8, !tbaa !5
  %11 = sub nsw i64 %10, 1
  store i64 %11, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #4
  store i64 2, ptr %4, align 8, !tbaa !5
  br label %12

12:                                               ; preds = %45, %9
  %13 = load i64, ptr %4, align 8, !tbaa !5
  %14 = load i64, ptr %4, align 8, !tbaa !5
  %15 = mul nsw i64 %13, %14
  %16 = load i64, ptr %2, align 8, !tbaa !5
  %17 = icmp sle i64 %15, %16
  br i1 %17, label %19, label %18

18:                                               ; preds = %12
  store i32 7, ptr %5, align 4
  br label %48

19:                                               ; preds = %12
  %20 = load i64, ptr %2, align 8, !tbaa !5
  %21 = load i64, ptr %4, align 8, !tbaa !5
  %22 = srem i64 %20, %21
  %23 = icmp eq i64 %22, 0
  br i1 %23, label %24, label %44

24:                                               ; preds = %19
  %25 = load i64, ptr %3, align 8, !tbaa !5
  %26 = load i64, ptr @p, align 8, !tbaa !5
  %27 = sub nsw i64 %26, 1
  %28 = load i64, ptr %4, align 8, !tbaa !5
  %29 = sdiv i64 %27, %28
  %30 = call noundef i64 @_Z4qpowxx(i64 noundef %25, i64 noundef %29)
  %31 = icmp eq i64 %30, 1
  br i1 %31, label %32, label %33

32:                                               ; preds = %24
  store i32 10, ptr %5, align 4
  br label %48

33:                                               ; preds = %24
  br label %34

34:                                               ; preds = %39, %33
  %35 = load i64, ptr %2, align 8, !tbaa !5
  %36 = load i64, ptr %4, align 8, !tbaa !5
  %37 = srem i64 %35, %36
  %38 = icmp eq i64 %37, 0
  br i1 %38, label %39, label %43

39:                                               ; preds = %34
  %40 = load i64, ptr %4, align 8, !tbaa !5
  %41 = load i64, ptr %2, align 8, !tbaa !5
  %42 = sdiv i64 %41, %40
  store i64 %42, ptr %2, align 8, !tbaa !5
  br label %34, !llvm.loop !9

43:                                               ; preds = %34
  br label %44

44:                                               ; preds = %43, %19
  br label %45

45:                                               ; preds = %44
  %46 = load i64, ptr %4, align 8, !tbaa !5
  %47 = add nsw i64 %46, 1
  store i64 %47, ptr %4, align 8, !tbaa !5
  br label %12, !llvm.loop !11

48:                                               ; preds = %32, %18
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #4
  %49 = load i32, ptr %5, align 4
  switch i32 %49, label %70 [
    i32 7, label %50
    i32 10, label %66
  ]

50:                                               ; preds = %48
  %51 = load i64, ptr %2, align 8, !tbaa !5
  %52 = icmp ne i64 %51, 1
  br i1 %52, label %53, label %63

53:                                               ; preds = %50
  %54 = load i64, ptr %3, align 8, !tbaa !5
  %55 = load i64, ptr @p, align 8, !tbaa !5
  %56 = sub nsw i64 %55, 1
  %57 = load i64, ptr %2, align 8, !tbaa !5
  %58 = sdiv i64 %56, %57
  %59 = call noundef i64 @_Z4qpowxx(i64 noundef %54, i64 noundef %58)
  %60 = icmp eq i64 %59, 1
  br i1 %60, label %61, label %62

61:                                               ; preds = %53
  br label %66

62:                                               ; preds = %53
  br label %63

63:                                               ; preds = %62, %50
  %64 = load i64, ptr %3, align 8, !tbaa !5
  %65 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i64 noundef %64)
  store i32 4, ptr %5, align 4
  br label %70

66:                                               ; preds = %61, %48
  br label %67

67:                                               ; preds = %66
  %68 = load i64, ptr %3, align 8, !tbaa !5
  %69 = add nsw i64 %68, 1
  store i64 %69, ptr %3, align 8, !tbaa !5
  br label %9, !llvm.loop !12

70:                                               ; preds = %63, %48
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #4
  br label %71

71:                                               ; preds = %70
  br label %6, !llvm.loop !13
}

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

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

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 = { mustprogress norecurse 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 = { "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 }

!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 long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple 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"

@p = external dso_local global i64, align 8
@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [6 x i8], align 1

; Function Attrs: mustprogress uwtable
declare dso_local noundef i64 @_Z4qpowxx(i64 noundef, i64 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress norecurse noreturn uwtable
define dso_local noundef i32 @main() local_unnamed_addr #1 {
  br label %1

1:                                                ; preds = %26, %0
  %2 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @p)
  br label %3

3:                                                ; preds = %.loopexit23, %1
  %.019 = phi i64 [ 2, %1 ], [ %25, %.loopexit23 ]
  %4 = load i64, ptr @p, align 8, !tbaa !5
  %5 = add nsw i64 %4, -1
  %.not26 = icmp slt i64 %4, 5
  br i1 %.not26, label %._crit_edge, label %.lr.ph29

.lr.ph29:                                         ; preds = %3, %.loopexit
  %.01828 = phi i64 [ %17, %.loopexit ], [ 2, %3 ]
  %.02027 = phi i64 [ %.2, %.loopexit ], [ %5, %3 ]
  %6 = srem i64 %.02027, %.01828
  %7 = icmp eq i64 %6, 0
  br i1 %7, label %8, label %.loopexit

8:                                                ; preds = %.lr.ph29
  %9 = load i64, ptr @p, align 8, !tbaa !5
  %10 = add nsw i64 %9, -1
  %11 = sdiv i64 %10, %.01828
  %12 = tail call noundef i64 @_Z4qpowxx(i64 noundef %.019, i64 noundef %11)
  %13 = icmp eq i64 %12, 1
  br i1 %13, label %.loopexit23, label %.lr.ph

.lr.ph:                                           ; preds = %8, %.lr.ph
  %.125 = phi i64 [ %14, %.lr.ph ], [ %.02027, %8 ]
  %14 = sdiv i64 %.125, %.01828
  %15 = srem i64 %14, %.01828
  %16 = icmp eq i64 %15, 0
  br i1 %16, label %.lr.ph, label %.loopexit, !llvm.loop !9

.loopexit:                                        ; preds = %.lr.ph, %.lr.ph29
  %.2 = phi i64 [ %.02027, %.lr.ph29 ], [ %14, %.lr.ph ]
  %17 = add nuw nsw i64 %.01828, 1
  %18 = mul nuw nsw i64 %17, %17
  %.not = icmp sgt i64 %18, %.2
  br i1 %.not, label %._crit_edge, label %.lr.ph29, !llvm.loop !11

._crit_edge:                                      ; preds = %.loopexit, %3
  %.020.lcssa = phi i64 [ %5, %3 ], [ %.2, %.loopexit ]
  %.not21 = icmp eq i64 %.020.lcssa, 1
  br i1 %.not21, label %26, label %19

19:                                               ; preds = %._crit_edge
  %20 = load i64, ptr @p, align 8, !tbaa !5
  %21 = add nsw i64 %20, -1
  %22 = sdiv i64 %21, %.020.lcssa
  %23 = tail call noundef i64 @_Z4qpowxx(i64 noundef %.019, i64 noundef %22)
  %24 = icmp eq i64 %23, 1
  br i1 %24, label %.loopexit23, label %26

.loopexit23:                                      ; preds = %8, %19
  %25 = add nuw nsw i64 %.019, 1
  br label %3, !llvm.loop !12

26:                                               ; preds = %._crit_edge, %19
  %27 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i64 noundef %.019)
  br label %1, !llvm.loop !13
}

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

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

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 = { mustprogress norecurse noreturn 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 = { 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" }

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


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