; LLVM IR from VastoLorde95/Competitive-Programming :: CodeChef/WF/Easy Medium/SECUBE/A.ll (Z3prev)

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

%"class.std::bitset" = type { %"struct.std::_Base_bitset" }
%"struct.std::_Base_bitset" = type { [15626 x i64] }

@ok = external dso_local global [101 x %"class.std::bitset"], align 16

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

6:                                                ; preds = %46, %0
  %7 = load i32, ptr %3, align 4, !tbaa !5
  %8 = icmp sle i32 %7, 100
  br i1 %8, label %10, label %9

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

10:                                               ; preds = %6
  %11 = load i32, ptr %3, align 4, !tbaa !5
  %12 = load i32, ptr %3, align 4, !tbaa !5
  %13 = mul nsw i32 %11, %12
  %14 = load i32, ptr %3, align 4, !tbaa !5
  %15 = mul nsw i32 %13, %14
  store i32 %15, ptr %1, align 4, !tbaa !5
  %16 = load i32, ptr %3, align 4, !tbaa !5
  %17 = sext i32 %16 to i64
  %18 = getelementptr inbounds [101 x %"class.std::bitset"], ptr @ok, i64 0, i64 %17
  %19 = call noundef nonnull align 8 dereferenceable(125008) ptr @_ZNSt6bitsetILm1000001EE3setEmb(ptr noundef nonnull align 8 dereferenceable(125008) %18, i64 noundef 0, i1 noundef zeroext true)
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #2
  store i64 1, ptr %5, align 8, !tbaa !9
  br label %20

20:                                               ; preds = %42, %10
  %21 = load i64, ptr %5, align 8, !tbaa !9
  %22 = load i32, ptr %1, align 4, !tbaa !5
  %23 = sext i32 %22 to i64
  %24 = icmp slt i64 %21, %23
  br i1 %24, label %26, label %25

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

26:                                               ; preds = %20
  %27 = load i64, ptr %5, align 8, !tbaa !9
  %28 = load i64, ptr %5, align 8, !tbaa !9
  %29 = mul nsw i64 %27, %28
  %30 = load i64, ptr %5, align 8, !tbaa !9
  %31 = mul nsw i64 %29, %30
  %32 = load i32, ptr %1, align 4, !tbaa !5
  %33 = sext i32 %32 to i64
  %34 = srem i64 %31, %33
  %35 = trunc i64 %34 to i32
  store i32 %35, ptr %2, align 4, !tbaa !5
  %36 = load i32, ptr %3, align 4, !tbaa !5
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds [101 x %"class.std::bitset"], ptr @ok, i64 0, i64 %37
  %39 = load i32, ptr %2, align 4, !tbaa !5
  %40 = sext i32 %39 to i64
  %41 = call noundef nonnull align 8 dereferenceable(125008) ptr @_ZNSt6bitsetILm1000001EE3setEmb(ptr noundef nonnull align 8 dereferenceable(125008) %38, i64 noundef %40, i1 noundef zeroext true)
  br label %42

42:                                               ; preds = %26
  %43 = load i64, ptr %5, align 8, !tbaa !9
  %44 = add nsw i64 %43, 1
  store i64 %44, ptr %5, align 8, !tbaa !9
  br label %20, !llvm.loop !11

45:                                               ; preds = %25
  br label %46

46:                                               ; preds = %45
  %47 = load i32, ptr %3, align 4, !tbaa !5
  %48 = add nsw i32 %47, 1
  store i32 %48, ptr %3, align 4, !tbaa !5
  br label %6, !llvm.loop !13

49:                                               ; preds = %9
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #2
  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: mustprogress uwtable
declare dso_local noundef nonnull align 8 dereferenceable(125008) ptr @_ZNSt6bitsetILm1000001EE3setEmb(ptr noundef nonnull align 8 dereferenceable(125008), i64 noundef, i1 noundef zeroext) #0 align 2

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


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

%"class.std::bitset" = type { %"struct.std::_Base_bitset" }
%"struct.std::_Base_bitset" = type { [15626 x i64] }

@ok = external dso_local global [101 x %"class.std::bitset"], align 16

; Function Attrs: mustprogress uwtable
define dso_local void @_Z3prev() local_unnamed_addr #0 {
  br label %2

1:                                                ; preds = %._crit_edge
  ret void

2:                                                ; preds = %0, %._crit_edge
  %indvars.iv25 = phi i64 [ 1, %0 ], [ %indvars.iv.next26, %._crit_edge ]
  %indvars.iv23 = phi i64 [ 12, %0 ], [ %indvars.iv.next24, %._crit_edge ]
  %indvars.iv21 = phi i32 [ 1, %0 ], [ %indvars.iv.next22, %._crit_edge ]
  %indvars.iv19 = phi i32 [ 7, %0 ], [ %indvars.iv.next20, %._crit_edge ]
  %3 = zext i32 %indvars.iv21 to i64
  %4 = mul i64 %indvars.iv25, %indvars.iv25
  %5 = and i64 %4, 4294967295
  %6 = mul nuw nsw i64 %5, %indvars.iv25
  %7 = getelementptr inbounds [101 x %"class.std::bitset"], ptr @ok, i64 0, i64 %indvars.iv25
  %8 = tail call noundef nonnull align 8 dereferenceable(125008) ptr @_ZNSt6bitsetILm1000001EE3setEmb(ptr noundef nonnull align 8 dereferenceable(125008) %7, i64 noundef 0, i1 noundef zeroext true)
  %.wide = icmp ugt i64 %6, 1
  br i1 %.wide, label %.lr.ph, label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph, %2
  %indvars.iv.next26 = add nuw nsw i64 %indvars.iv25, 1
  %indvars.iv.next24 = add nuw nsw i64 %indvars.iv23, 6
  %9 = trunc nuw nsw i64 %indvars.iv23 to i32
  %indvars.iv.next20 = add i32 %indvars.iv19, %9
  %indvars.iv.next22 = add i32 %indvars.iv21, %indvars.iv19
  %exitcond30.not = icmp eq i64 %indvars.iv.next26, 101
  br i1 %exitcond30.not, label %1, label %2, !llvm.loop !5

.lr.ph:                                           ; preds = %2, %.lr.ph
  %.017 = phi i64 [ %14, %.lr.ph ], [ 1, %2 ]
  %10 = mul nuw nsw i64 %.017, %.017
  %11 = mul nuw nsw i64 %10, %.017
  %12 = urem i64 %11, %6
  %13 = tail call noundef nonnull align 8 dereferenceable(125008) ptr @_ZNSt6bitsetILm1000001EE3setEmb(ptr noundef nonnull align 8 dereferenceable(125008) %7, i64 noundef %12, i1 noundef zeroext true)
  %14 = add nuw nsw i64 %.017, 1
  %exitcond.not = icmp eq i64 %14, %3
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !7
}

; Function Attrs: mustprogress uwtable
declare dso_local noundef nonnull align 8 dereferenceable(125008) ptr @_ZNSt6bitsetILm1000001EE3setEmb(ptr noundef nonnull align 8 dereferenceable(125008), i64 noundef, i1 noundef zeroext) local_unnamed_addr #0 align 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" }

!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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}
!7 = distinct !{!7, !6}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass