; LLVM IR from ADJA/algos :: NumberTheory (NumberByPermutation)

; 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 i32, align 4
@f = external dso_local global [20 x i32], align 16
@p = external dso_local global [20 x i32], align 16
@used = external dso_local global [20 x i8], align 16
@ans = external dso_local global i32, align 4
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [4 x i8], align 1

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

8:                                                ; preds = %18, %0
  %9 = load i32, ptr %2, align 4, !tbaa !5
  %10 = load i32, ptr @n, align 4, !tbaa !5
  %11 = icmp sle i32 %9, %10
  br i1 %11, label %13, label %12

12:                                               ; preds = %8
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #3
  br label %21

13:                                               ; preds = %8
  %14 = load i32, ptr %2, align 4, !tbaa !5
  %15 = sext i32 %14 to i64
  %16 = getelementptr inbounds [20 x i32], ptr @p, i64 0, i64 %15
  %17 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %16)
  br label %18

18:                                               ; preds = %13
  %19 = load i32, ptr %2, align 4, !tbaa !5
  %20 = add nsw i32 %19, 1
  store i32 %20, ptr %2, align 4, !tbaa !5
  br label %8, !llvm.loop !9

21:                                               ; preds = %12
  store i32 1, ptr @f, align 16, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  store i32 1, ptr %3, align 4, !tbaa !5
  br label %22

22:                                               ; preds = %38, %21
  %23 = load i32, ptr %3, align 4, !tbaa !5
  %24 = load i32, ptr @n, align 4, !tbaa !5
  %25 = icmp sle i32 %23, %24
  br i1 %25, label %27, label %26

26:                                               ; preds = %22
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  br label %41

27:                                               ; preds = %22
  %28 = load i32, ptr %3, align 4, !tbaa !5
  %29 = sub nsw i32 %28, 1
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [20 x i32], ptr @f, i64 0, i64 %30
  %32 = load i32, ptr %31, align 4, !tbaa !5
  %33 = load i32, ptr %3, align 4, !tbaa !5
  %34 = mul nsw i32 %32, %33
  %35 = load i32, ptr %3, align 4, !tbaa !5
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds [20 x i32], ptr @f, i64 0, i64 %36
  store i32 %34, ptr %37, align 4, !tbaa !5
  br label %38

38:                                               ; preds = %27
  %39 = load i32, ptr %3, align 4, !tbaa !5
  %40 = add nsw i32 %39, 1
  store i32 %40, ptr %3, align 4, !tbaa !5
  br label %22, !llvm.loop !11

41:                                               ; preds = %26
  store i32 1, ptr @ans, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  store i32 1, ptr %4, align 4, !tbaa !5
  br label %42

42:                                               ; preds = %85, %41
  %43 = load i32, ptr %4, align 4, !tbaa !5
  %44 = load i32, ptr @n, align 4, !tbaa !5
  %45 = icmp sle i32 %43, %44
  br i1 %45, label %47, label %46

46:                                               ; preds = %42
  store i32 8, ptr %5, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  br label %88

47:                                               ; preds = %42
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  store i32 1, ptr %6, align 4, !tbaa !5
  br label %48

48:                                               ; preds = %80, %47
  %49 = load i32, ptr %6, align 4, !tbaa !5
  %50 = load i32, ptr @n, align 4, !tbaa !5
  %51 = icmp sle i32 %49, %50
  br i1 %51, label %53, label %52

52:                                               ; preds = %48
  store i32 11, ptr %5, align 4
  br label %83

53:                                               ; preds = %48
  %54 = load i32, ptr %6, align 4, !tbaa !5
  %55 = sext i32 %54 to i64
  %56 = getelementptr inbounds [20 x i8], ptr @used, i64 0, i64 %55
  %57 = load i8, ptr %56, align 1, !tbaa !12, !range !14, !noundef !15
  %58 = trunc i8 %57 to i1
  br i1 %58, label %59, label %60

59:                                               ; preds = %53
  br label %80

60:                                               ; preds = %53
  %61 = load i32, ptr %4, align 4, !tbaa !5
  %62 = sext i32 %61 to i64
  %63 = getelementptr inbounds [20 x i32], ptr @p, i64 0, i64 %62
  %64 = load i32, ptr %63, align 4, !tbaa !5
  %65 = load i32, ptr %6, align 4, !tbaa !5
  %66 = icmp eq i32 %64, %65
  br i1 %66, label %67, label %71

67:                                               ; preds = %60
  %68 = load i32, ptr %6, align 4, !tbaa !5
  %69 = sext i32 %68 to i64
  %70 = getelementptr inbounds [20 x i8], ptr @used, i64 0, i64 %69
  store i8 1, ptr %70, align 1, !tbaa !12
  store i32 11, ptr %5, align 4
  br label %83

71:                                               ; preds = %60
  %72 = load i32, ptr @n, align 4, !tbaa !5
  %73 = load i32, ptr %4, align 4, !tbaa !5
  %74 = sub nsw i32 %72, %73
  %75 = sext i32 %74 to i64
  %76 = getelementptr inbounds [20 x i32], ptr @f, i64 0, i64 %75
  %77 = load i32, ptr %76, align 4, !tbaa !5
  %78 = load i32, ptr @ans, align 4, !tbaa !5
  %79 = add nsw i32 %78, %77
  store i32 %79, ptr @ans, align 4, !tbaa !5
  br label %80

80:                                               ; preds = %71, %59
  %81 = load i32, ptr %6, align 4, !tbaa !5
  %82 = add nsw i32 %81, 1
  store i32 %82, ptr %6, align 4, !tbaa !5
  br label %48, !llvm.loop !16

83:                                               ; preds = %67, %52
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  br label %84

84:                                               ; preds = %83
  br label %85

85:                                               ; preds = %84
  %86 = load i32, ptr %4, align 4, !tbaa !5
  %87 = add nsw i32 %86, 1
  store i32 %87, ptr %4, align 4, !tbaa !5
  br label %42, !llvm.loop !17

88:                                               ; preds = %46
  %89 = load i32, ptr @ans, align 4, !tbaa !5
  %90 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i32 noundef %89)
  ret i32 0
}

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

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

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

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

attributes #0 = { 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 #1 = { "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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}
!12 = !{!13, !13, i64 0}
!13 = !{!"bool", !7, i64 0}
!14 = !{i8 0, i8 2}
!15 = !{}
!16 = distinct !{!16, !10}
!17 = distinct !{!17, !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 global i32, align 4
@f = external dso_local local_unnamed_addr global [20 x i32], align 16
@p = external dso_local global [20 x i32], align 16
@used = external dso_local local_unnamed_addr global [20 x i8], align 16
@ans = external dso_local local_unnamed_addr global i32, align 4
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: mustprogress nofree norecurse nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  %1 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n)
  %2 = load i32, ptr @n, align 4, !tbaa !5
  %.not25 = icmp slt i32 %2, 1
  br i1 %.not25, label %._crit_edge.thread, label %.lr.ph

._crit_edge.thread:                               ; preds = %0
  store i32 1, ptr @f, align 16, !tbaa !5
  br label %._crit_edge31.thread

._crit_edge:                                      ; preds = %.lr.ph
  store i32 1, ptr @f, align 16, !tbaa !5
  %.not2127 = icmp slt i32 %7, 1
  br i1 %.not2127, label %._crit_edge31.thread, label %.lr.ph30.preheader

.lr.ph30.preheader:                               ; preds = %._crit_edge
  %3 = zext nneg i32 %7 to i64
  %xtraiter = and i64 %3, 3
  %4 = icmp ult i32 %7, 4
  br i1 %4, label %._crit_edge31.unr-lcssa, label %.lr.ph30.preheader.new

.lr.ph30.preheader.new:                           ; preds = %.lr.ph30.preheader
  %unroll_iter = and i64 %3, 2147483644
  br label %.lr.ph30

.lr.ph:                                           ; preds = %0, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 1, %0 ]
  %5 = getelementptr inbounds [20 x i32], ptr @p, i64 0, i64 %indvars.iv
  %6 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %5)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %7 = load i32, ptr @n, align 4, !tbaa !5
  %8 = sext i32 %7 to i64
  %.not.not = icmp slt i64 %indvars.iv, %8
  br i1 %.not.not, label %.lr.ph, label %._crit_edge, !llvm.loop !9

._crit_edge31.thread:                             ; preds = %._crit_edge.thread, %._crit_edge
  store i32 1, ptr @ans, align 4, !tbaa !5
  br label %._crit_edge47

._crit_edge31.unr-lcssa:                          ; preds = %.lr.ph30, %.lr.ph30.preheader
  %.unr = phi i32 [ 1, %.lr.ph30.preheader ], [ %26, %.lr.ph30 ]
  %indvars.iv52.unr = phi i64 [ 1, %.lr.ph30.preheader ], [ %indvars.iv.next53.3, %.lr.ph30 ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge31, label %.lr.ph30.epil

.lr.ph30.epil:                                    ; preds = %._crit_edge31.unr-lcssa, %.lr.ph30.epil
  %9 = phi i32 [ %11, %.lr.ph30.epil ], [ %.unr, %._crit_edge31.unr-lcssa ]
  %indvars.iv52.epil = phi i64 [ %indvars.iv.next53.epil, %.lr.ph30.epil ], [ %indvars.iv52.unr, %._crit_edge31.unr-lcssa ]
  %epil.iter = phi i64 [ %epil.iter.next, %.lr.ph30.epil ], [ 0, %._crit_edge31.unr-lcssa ]
  %10 = trunc nuw nsw i64 %indvars.iv52.epil to i32
  %11 = mul nsw i32 %9, %10
  %12 = getelementptr inbounds [20 x i32], ptr @f, i64 0, i64 %indvars.iv52.epil
  store i32 %11, ptr %12, align 4, !tbaa !5
  %indvars.iv.next53.epil = add nuw nsw i64 %indvars.iv52.epil, 1
  %epil.iter.next = add i64 %epil.iter, 1
  %epil.iter.cmp.not = icmp eq i64 %epil.iter.next, %xtraiter
  br i1 %epil.iter.cmp.not, label %._crit_edge31, label %.lr.ph30.epil, !llvm.loop !11

._crit_edge31:                                    ; preds = %.lr.ph30.epil, %._crit_edge31.unr-lcssa
  store i32 1, ptr @ans, align 4, !tbaa !5
  br i1 %.not2127, label %._crit_edge47, label %.preheader.preheader

.preheader.preheader:                             ; preds = %._crit_edge31
  %13 = add nuw i32 %7, 1
  %14 = zext nneg i32 %7 to i64
  %wide.trip.count63 = zext i32 %13 to i64
  br label %.preheader

.lr.ph30:                                         ; preds = %.lr.ph30, %.lr.ph30.preheader.new
  %15 = phi i32 [ 1, %.lr.ph30.preheader.new ], [ %26, %.lr.ph30 ]
  %indvars.iv52 = phi i64 [ 1, %.lr.ph30.preheader.new ], [ %indvars.iv.next53.3, %.lr.ph30 ]
  %niter = phi i64 [ 0, %.lr.ph30.preheader.new ], [ %niter.next.3, %.lr.ph30 ]
  %16 = trunc nuw nsw i64 %indvars.iv52 to i32
  %17 = mul nsw i32 %15, %16
  %18 = getelementptr inbounds [20 x i32], ptr @f, i64 0, i64 %indvars.iv52
  store i32 %17, ptr %18, align 4, !tbaa !5
  %indvars.iv.next53 = add nuw nsw i64 %indvars.iv52, 1
  %19 = trunc nuw nsw i64 %indvars.iv.next53 to i32
  %20 = mul nsw i32 %17, %19
  %21 = getelementptr inbounds [20 x i32], ptr @f, i64 0, i64 %indvars.iv.next53
  store i32 %20, ptr %21, align 4, !tbaa !5
  %indvars.iv.next53.1 = add nuw nsw i64 %indvars.iv52, 2
  %22 = trunc nuw nsw i64 %indvars.iv.next53.1 to i32
  %23 = mul nsw i32 %20, %22
  %24 = getelementptr inbounds [20 x i32], ptr @f, i64 0, i64 %indvars.iv.next53.1
  store i32 %23, ptr %24, align 4, !tbaa !5
  %indvars.iv.next53.2 = add nuw nsw i64 %indvars.iv52, 3
  %25 = trunc nuw nsw i64 %indvars.iv.next53.2 to i32
  %26 = mul nsw i32 %23, %25
  %27 = getelementptr inbounds [20 x i32], ptr @f, i64 0, i64 %indvars.iv.next53.2
  store i32 %26, ptr %27, align 4, !tbaa !5
  %indvars.iv.next53.3 = add nuw nsw i64 %indvars.iv52, 4
  %niter.next.3 = add i64 %niter, 4
  %niter.ncmp.3 = icmp eq i64 %niter.next.3, %unroll_iter
  br i1 %niter.ncmp.3, label %._crit_edge31.unr-lcssa, label %.lr.ph30, !llvm.loop !13

.preheader:                                       ; preds = %.preheader.preheader, %..loopexit_crit_edge
  %indvars.iv60 = phi i64 [ 1, %.preheader.preheader ], [ %indvars.iv.next61, %..loopexit_crit_edge ]
  %ans.promoted4144 = phi i32 [ 1, %.preheader.preheader ], [ %ans.promoted37, %..loopexit_crit_edge ]
  %28 = getelementptr inbounds [20 x i32], ptr @p, i64 0, i64 %indvars.iv60
  %29 = sub nsw i64 %14, %indvars.iv60
  %30 = getelementptr inbounds [20 x i32], ptr @f, i64 0, i64 %29
  br label %33

._crit_edge47:                                    ; preds = %..loopexit_crit_edge, %._crit_edge31.thread, %._crit_edge31
  %31 = phi i32 [ 1, %._crit_edge31 ], [ 1, %._crit_edge31.thread ], [ %ans.promoted37, %..loopexit_crit_edge ]
  %32 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %31)
  ret i32 0

33:                                               ; preds = %.preheader, %47
  %indvars.iv55 = phi i64 [ 1, %.preheader ], [ %indvars.iv.next56, %47 ]
  %ans.promoted39 = phi i32 [ %ans.promoted4144, %.preheader ], [ %ans.promoted38, %47 ]
  %34 = phi i32 [ %ans.promoted4144, %.preheader ], [ %48, %47 ]
  %35 = getelementptr inbounds [20 x i8], ptr @used, i64 0, i64 %indvars.iv55
  %36 = load i8, ptr %35, align 1, !tbaa !14, !range !16, !noundef !17
  %37 = trunc nuw i8 %36 to i1
  br i1 %37, label %47, label %38

38:                                               ; preds = %33
  %39 = load i32, ptr %28, align 4, !tbaa !5
  %40 = zext i32 %39 to i64
  %41 = icmp eq i64 %indvars.iv55, %40
  br i1 %41, label %42, label %44

42:                                               ; preds = %38
  %43 = getelementptr inbounds [20 x i8], ptr @used, i64 0, i64 %indvars.iv55
  store i8 1, ptr %43, align 1, !tbaa !14
  br label %..loopexit_crit_edge

44:                                               ; preds = %38
  %45 = load i32, ptr %30, align 4, !tbaa !5
  %46 = add nsw i32 %34, %45
  store i32 %46, ptr @ans, align 4, !tbaa !5
  br label %47

47:                                               ; preds = %33, %44
  %ans.promoted38 = phi i32 [ %ans.promoted39, %33 ], [ %46, %44 ]
  %48 = phi i32 [ %34, %33 ], [ %46, %44 ]
  %indvars.iv.next56 = add nuw nsw i64 %indvars.iv55, 1
  %exitcond59.not = icmp eq i64 %indvars.iv.next56, %wide.trip.count63
  br i1 %exitcond59.not, label %..loopexit_crit_edge, label %33, !llvm.loop !18

..loopexit_crit_edge:                             ; preds = %47, %42
  %ans.promoted37 = phi i32 [ %ans.promoted39, %42 ], [ %ans.promoted38, %47 ]
  %indvars.iv.next61 = add nuw nsw i64 %indvars.iv60, 1
  %exitcond64.not = icmp eq i64 %indvars.iv.next61, %wide.trip.count63
  br i1 %exitcond64.not, label %._crit_edge47, label %.preheader, !llvm.loop !19
}

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

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

attributes #0 = { mustprogress nofree norecurse 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 = { 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.unroll.disable"}
!13 = distinct !{!13, !10}
!14 = !{!15, !15, i64 0}
!15 = !{!"bool", !7, i64 0}
!16 = !{i8 0, i8 2}
!17 = !{}
!18 = distinct !{!18, !10}
!19 = distinct !{!19, !10}


; Effective O3 passes: BDCEPass,CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopInstSimplifyPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass