; LLVM IR from Jatin-Nagpal/CP-Devils :: Algorithms/Hashing.ll (Z3prex)

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

@Mi = external dso_local global [2 x i64], align 16
@M = external dso_local global [2 x i64], align 16
@D = external dso_local global [2 x i64], align 16
@po = external dso_local global [2005 x [2 x i64]], align 16
@poi = external dso_local global [2005 x [2 x i64]], align 16

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z3prex(i64 noundef %0) #0 {
  %2 = alloca i64, align 8
  %3 = alloca i64, align 8
  %4 = alloca i32, align 4
  %5 = alloca i64, align 8
  store i64 %0, ptr %2, align 8, !tbaa !5
  store i64 1, ptr getelementptr inbounds ([2 x i64], ptr @poi, i64 0, i64 1), align 8, !tbaa !5
  store i64 1, ptr @poi, align 16, !tbaa !5
  store i64 1, ptr getelementptr inbounds ([2 x i64], ptr @po, i64 0, i64 1), align 8, !tbaa !5
  store i64 1, ptr @po, align 16, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #2
  store i64 1, ptr %3, align 8, !tbaa !5
  br label %6

6:                                                ; preds = %58, %1
  %7 = load i64, ptr %3, align 8, !tbaa !5
  %8 = load i64, ptr %2, align 8, !tbaa !5
  %9 = add nsw i64 %8, 1
  %10 = icmp slt i64 %7, %9
  br i1 %10, label %12, label %11

11:                                               ; preds = %6
  store i32 2, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #2
  br label %61

12:                                               ; preds = %6
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #2
  store i64 0, ptr %5, align 8, !tbaa !5
  br label %13

13:                                               ; preds = %54, %12
  %14 = load i64, ptr %5, align 8, !tbaa !5
  %15 = icmp slt i64 %14, 2
  br i1 %15, label %17, label %16

16:                                               ; preds = %13
  store i32 5, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #2
  br label %57

17:                                               ; preds = %13
  %18 = load i64, ptr %3, align 8, !tbaa !5
  %19 = sub nsw i64 %18, 1
  %20 = getelementptr inbounds [2005 x [2 x i64]], ptr @po, i64 0, i64 %19
  %21 = load i64, ptr %5, align 8, !tbaa !5
  %22 = getelementptr inbounds [2 x i64], ptr %20, i64 0, i64 %21
  %23 = load i64, ptr %22, align 8, !tbaa !5
  %24 = load i64, ptr %5, align 8, !tbaa !5
  %25 = getelementptr inbounds [2 x i64], ptr @D, i64 0, i64 %24
  %26 = load i64, ptr %25, align 8, !tbaa !5
  %27 = mul nsw i64 %23, %26
  %28 = load i64, ptr %5, align 8, !tbaa !5
  %29 = getelementptr inbounds [2 x i64], ptr @M, i64 0, i64 %28
  %30 = load i64, ptr %29, align 8, !tbaa !5
  %31 = srem i64 %27, %30
  %32 = load i64, ptr %3, align 8, !tbaa !5
  %33 = getelementptr inbounds [2005 x [2 x i64]], ptr @po, i64 0, i64 %32
  %34 = load i64, ptr %5, align 8, !tbaa !5
  %35 = getelementptr inbounds [2 x i64], ptr %33, i64 0, i64 %34
  store i64 %31, ptr %35, align 8, !tbaa !5
  %36 = load i64, ptr %3, align 8, !tbaa !5
  %37 = sub nsw i64 %36, 1
  %38 = getelementptr inbounds [2005 x [2 x i64]], ptr @poi, i64 0, i64 %37
  %39 = load i64, ptr %5, align 8, !tbaa !5
  %40 = getelementptr inbounds [2 x i64], ptr %38, i64 0, i64 %39
  %41 = load i64, ptr %40, align 8, !tbaa !5
  %42 = load i64, ptr %5, align 8, !tbaa !5
  %43 = getelementptr inbounds [2 x i64], ptr @Mi, i64 0, i64 %42
  %44 = load i64, ptr %43, align 8, !tbaa !5
  %45 = mul nsw i64 %41, %44
  %46 = load i64, ptr %5, align 8, !tbaa !5
  %47 = getelementptr inbounds [2 x i64], ptr @M, i64 0, i64 %46
  %48 = load i64, ptr %47, align 8, !tbaa !5
  %49 = srem i64 %45, %48
  %50 = load i64, ptr %3, align 8, !tbaa !5
  %51 = getelementptr inbounds [2005 x [2 x i64]], ptr @poi, i64 0, i64 %50
  %52 = load i64, ptr %5, align 8, !tbaa !5
  %53 = getelementptr inbounds [2 x i64], ptr %51, i64 0, i64 %52
  store i64 %49, ptr %53, align 8, !tbaa !5
  br label %54

54:                                               ; preds = %17
  %55 = load i64, ptr %5, align 8, !tbaa !5
  %56 = add nsw i64 %55, 1
  store i64 %56, ptr %5, align 8, !tbaa !5
  br label %13, !llvm.loop !9

57:                                               ; preds = %16
  br label %58

58:                                               ; preds = %57
  %59 = load i64, ptr %3, align 8, !tbaa !5
  %60 = add nsw i64 %59, 1
  store i64 %60, ptr %3, align 8, !tbaa !5
  br label %6, !llvm.loop !11

61:                                               ; preds = %11
  ret void
}

; 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

attributes #0 = { 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 #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 = !{!"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}


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

@Mi = external dso_local local_unnamed_addr global [2 x i64], align 16
@M = external dso_local local_unnamed_addr global [2 x i64], align 16
@D = external dso_local local_unnamed_addr global [2 x i64], align 16
@po = external dso_local local_unnamed_addr global [2005 x [2 x i64]], align 16
@poi = external dso_local local_unnamed_addr global [2005 x [2 x i64]], align 16

; Function Attrs: mustprogress nofree norecurse nosync nounwind memory(readwrite, argmem: none, inaccessiblemem: none) uwtable
define dso_local void @_Z3prex(i64 noundef %0) local_unnamed_addr #0 {
  store i64 1, ptr getelementptr inbounds (i8, ptr @poi, i64 8), align 8, !tbaa !5
  store i64 1, ptr @poi, align 16, !tbaa !5
  store i64 1, ptr getelementptr inbounds (i8, ptr @po, i64 8), align 8, !tbaa !5
  store i64 1, ptr @po, align 16, !tbaa !5
  %.not19 = icmp slt i64 %0, 1
  br i1 %.not19, label %._crit_edge, label %.preheader.preheader

.preheader.preheader:                             ; preds = %1
  %.pre = load i64, ptr @D, align 16, !tbaa !5
  %.pre21 = load i64, ptr @M, align 16, !tbaa !5
  %.pre22 = load i64, ptr @Mi, align 16, !tbaa !5
  %.pre23 = load i64, ptr getelementptr inbounds (i8, ptr @D, i64 8), align 8, !tbaa !5
  %.pre24 = load i64, ptr getelementptr inbounds (i8, ptr @M, i64 8), align 8, !tbaa !5
  %.pre25 = load i64, ptr getelementptr inbounds (i8, ptr @Mi, i64 8), align 8, !tbaa !5
  br label %.preheader

.preheader:                                       ; preds = %.preheader.preheader, %.preheader
  %2 = phi i64 [ %16, %.preheader ], [ 1, %.preheader.preheader ]
  %3 = phi i64 [ %13, %.preheader ], [ 1, %.preheader.preheader ]
  %4 = phi i64 [ %10, %.preheader ], [ 1, %.preheader.preheader ]
  %5 = phi i64 [ %7, %.preheader ], [ 1, %.preheader.preheader ]
  %.01720 = phi i64 [ %18, %.preheader ], [ 1, %.preheader.preheader ]
  %6 = mul nsw i64 %.pre, %5
  %7 = srem i64 %6, %.pre21
  %8 = getelementptr inbounds [2005 x [2 x i64]], ptr @po, i64 0, i64 %.01720, i64 0
  store i64 %7, ptr %8, align 16, !tbaa !5
  %9 = mul nsw i64 %.pre22, %4
  %10 = srem i64 %9, %.pre21
  %11 = getelementptr inbounds [2005 x [2 x i64]], ptr @poi, i64 0, i64 %.01720, i64 0
  store i64 %10, ptr %11, align 16, !tbaa !5
  %12 = mul nsw i64 %.pre23, %3
  %13 = srem i64 %12, %.pre24
  %14 = getelementptr inbounds [2005 x [2 x i64]], ptr @po, i64 0, i64 %.01720, i64 1
  store i64 %13, ptr %14, align 8, !tbaa !5
  %15 = mul nsw i64 %.pre25, %2
  %16 = srem i64 %15, %.pre24
  %17 = getelementptr inbounds [2005 x [2 x i64]], ptr @poi, i64 0, i64 %.01720, i64 1
  store i64 %16, ptr %17, align 8, !tbaa !5
  %18 = add nuw i64 %.01720, 1
  %exitcond.not = icmp eq i64 %.01720, %0
  br i1 %exitcond.not, label %._crit_edge, label %.preheader, !llvm.loop !9

._crit_edge:                                      ; preds = %.preheader, %1
  ret void
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind memory(readwrite, argmem: none, inaccessiblemem: none) 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" }

!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"}


; Effective O3 passes: BDCEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass