; LLVM IR from upupming/algorithm :: AdvancedLevel_C++/1015. Reversible Primes (20) (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"

@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [5 x i8], align 1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_Z7isprimei(i32 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 i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca [100 x i32], align 16
  %6 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #4
  br label %7

7:                                                ; preds = %55, %20, %0
  %8 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %2)
  %9 = icmp ne i32 %8, -1
  br i1 %9, label %10, label %61

10:                                               ; preds = %7
  %11 = load i32, ptr %2, align 4, !tbaa !5
  %12 = icmp slt i32 %11, 0
  br i1 %12, label %13, label %14

13:                                               ; preds = %10
  br label %61

14:                                               ; preds = %10
  %15 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %3)
  %16 = load i32, ptr %2, align 4, !tbaa !5
  %17 = call noundef zeroext i1 @_Z7isprimei(i32 noundef %16)
  %18 = zext i1 %17 to i32
  %19 = icmp eq i32 %18, 0
  br i1 %19, label %20, label %22

20:                                               ; preds = %14
  %21 = call i32 (ptr, ...) @printf(ptr noundef @.str.1)
  br label %7, !llvm.loop !9

22:                                               ; preds = %14
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  store i32 0, ptr %4, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 400, ptr %5) #4
  br label %23

23:                                               ; preds = %34, %22
  %24 = load i32, ptr %2, align 4, !tbaa !5
  %25 = load i32, ptr %3, align 4, !tbaa !5
  %26 = srem i32 %24, %25
  %27 = load i32, ptr %4, align 4, !tbaa !5
  %28 = add nsw i32 %27, 1
  store i32 %28, ptr %4, align 4, !tbaa !5
  %29 = sext i32 %27 to i64
  %30 = getelementptr inbounds [100 x i32], ptr %5, i64 0, i64 %29
  store i32 %26, ptr %30, align 4, !tbaa !5
  %31 = load i32, ptr %2, align 4, !tbaa !5
  %32 = load i32, ptr %3, align 4, !tbaa !5
  %33 = sdiv i32 %31, %32
  store i32 %33, ptr %2, align 4, !tbaa !5
  br label %34

34:                                               ; preds = %23
  %35 = load i32, ptr %2, align 4, !tbaa !5
  %36 = icmp ne i32 %35, 0
  br i1 %36, label %23, label %37, !llvm.loop !11

37:                                               ; preds = %34
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  store i32 0, ptr %6, align 4, !tbaa !5
  br label %38

38:                                               ; preds = %52, %37
  %39 = load i32, ptr %6, align 4, !tbaa !5
  %40 = load i32, ptr %4, align 4, !tbaa !5
  %41 = icmp slt i32 %39, %40
  br i1 %41, label %43, label %42

42:                                               ; preds = %38
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  br label %55

43:                                               ; preds = %38
  %44 = load i32, ptr %2, align 4, !tbaa !5
  %45 = load i32, ptr %3, align 4, !tbaa !5
  %46 = mul nsw i32 %44, %45
  %47 = load i32, ptr %6, align 4, !tbaa !5
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds [100 x i32], ptr %5, i64 0, i64 %48
  %50 = load i32, ptr %49, align 4, !tbaa !5
  %51 = add nsw i32 %46, %50
  store i32 %51, ptr %2, align 4, !tbaa !5
  br label %52

52:                                               ; preds = %43
  %53 = load i32, ptr %6, align 4, !tbaa !5
  %54 = add nsw i32 %53, 1
  store i32 %54, ptr %6, align 4, !tbaa !5
  br label %38, !llvm.loop !12

55:                                               ; preds = %42
  %56 = load i32, ptr %2, align 4, !tbaa !5
  %57 = call noundef zeroext i1 @_Z7isprimei(i32 noundef %56)
  %58 = zext i1 %57 to i64
  %59 = select i1 %57, ptr @.str.3, ptr @.str.1
  %60 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, ptr noundef %59)
  call void @llvm.lifetime.end.p0(i64 400, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #4
  br label %7, !llvm.loop !9

61:                                               ; preds = %13, %7
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #4
  ret i32 0
}

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

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

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 = { 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 = !{!"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 = distinct !{!12, !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"

@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [5 x i8], align 1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_Z7isprimei(i32 noundef) local_unnamed_addr #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: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: mustprogress norecurse nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #2 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca [100 x i32], align 16
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %2) #4
  %4 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %1)
  %5 = icmp eq i32 %4, -1
  %6 = load i32, ptr %1, align 4
  %7 = icmp slt i32 %6, 0
  %or.cond12 = select i1 %5, i1 true, i1 %7
  br i1 %or.cond12, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %0, %.backedge
  %8 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %2)
  %9 = load i32, ptr %1, align 4, !tbaa !5
  %10 = call noundef zeroext i1 @_Z7isprimei(i32 noundef %9)
  br i1 %10, label %17, label %11

11:                                               ; preds = %.lr.ph
  %12 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1)
  br label %.backedge

.backedge:                                        ; preds = %11, %.epilog-lcssa
  %13 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %1)
  %14 = icmp eq i32 %13, -1
  %15 = load i32, ptr %1, align 4
  %16 = icmp slt i32 %15, 0
  %or.cond = select i1 %14, i1 true, i1 %16
  br i1 %or.cond, label %._crit_edge, label %.lr.ph, !llvm.loop !9

17:                                               ; preds = %.lr.ph
  call void @llvm.lifetime.start.p0(i64 400, ptr nonnull %3) #4
  %18 = load i32, ptr %2, align 4, !tbaa !5
  %.promoted = load i32, ptr %1, align 4, !tbaa !5
  br label %19

19:                                               ; preds = %19, %17
  %indvars.iv18 = phi i32 [ %indvars.iv.next19, %19 ], [ 1, %17 ]
  %indvars.iv = phi i64 [ %indvars.iv.next, %19 ], [ 0, %17 ]
  %20 = phi i32 [ %23, %19 ], [ %.promoted, %17 ]
  %21 = srem i32 %20, %18
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %22 = getelementptr inbounds [100 x i32], ptr %3, i64 0, i64 %indvars.iv
  store i32 %21, ptr %22, align 4, !tbaa !5
  %23 = sdiv i32 %20, %18
  %.not = icmp eq i32 %23, 0
  %indvars.iv.next19 = add nuw i32 %indvars.iv18, 1
  br i1 %.not, label %.preheader, label %19, !llvm.loop !11

.preheader:                                       ; preds = %19
  %wide.trip.count = zext i32 %indvars.iv18 to i64
  %xtraiter = and i64 %wide.trip.count, 3
  %24 = icmp ult i64 %indvars.iv, 3
  br i1 %24, label %.unr-lcssa, label %.preheader.new

.preheader.new:                                   ; preds = %.preheader
  %unroll_iter = and i64 %wide.trip.count, 4294967292
  br label %33

.unr-lcssa:                                       ; preds = %33, %.preheader
  %.lcssa.ph = phi i32 [ poison, %.preheader ], [ %50, %33 ]
  %indvars.iv15.unr = phi i64 [ 0, %.preheader ], [ %indvars.iv.next16.3, %33 ]
  %.unr = phi i32 [ 0, %.preheader ], [ %50, %33 ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %.epilog-lcssa, label %.epil.preheader

.epil.preheader:                                  ; preds = %.unr-lcssa, %.epil.preheader
  %indvars.iv15.epil = phi i64 [ %indvars.iv.next16.epil, %.epil.preheader ], [ %indvars.iv15.unr, %.unr-lcssa ]
  %25 = phi i32 [ %29, %.epil.preheader ], [ %.unr, %.unr-lcssa ]
  %epil.iter = phi i64 [ %epil.iter.next, %.epil.preheader ], [ 0, %.unr-lcssa ]
  %26 = mul nsw i32 %25, %18
  %27 = getelementptr inbounds [100 x i32], ptr %3, i64 0, i64 %indvars.iv15.epil
  %28 = load i32, ptr %27, align 4, !tbaa !5
  %29 = add nsw i32 %26, %28
  %indvars.iv.next16.epil = add nuw nsw i64 %indvars.iv15.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 %.epilog-lcssa, label %.epil.preheader, !llvm.loop !12

.epilog-lcssa:                                    ; preds = %.epil.preheader, %.unr-lcssa
  %.lcssa = phi i32 [ %.lcssa.ph, %.unr-lcssa ], [ %29, %.epil.preheader ]
  store i32 %.lcssa, ptr %1, align 4, !tbaa !5
  %30 = call noundef zeroext i1 @_Z7isprimei(i32 noundef %.lcssa)
  %31 = select i1 %30, ptr @.str.3, ptr @.str.1
  %32 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, ptr noundef nonnull %31)
  call void @llvm.lifetime.end.p0(i64 400, ptr nonnull %3) #4
  br label %.backedge

33:                                               ; preds = %33, %.preheader.new
  %indvars.iv15 = phi i64 [ 0, %.preheader.new ], [ %indvars.iv.next16.3, %33 ]
  %34 = phi i32 [ 0, %.preheader.new ], [ %50, %33 ]
  %niter = phi i64 [ 0, %.preheader.new ], [ %niter.next.3, %33 ]
  %35 = mul nsw i32 %34, %18
  %36 = getelementptr inbounds [100 x i32], ptr %3, i64 0, i64 %indvars.iv15
  %37 = load i32, ptr %36, align 16, !tbaa !5
  %38 = add nsw i32 %35, %37
  %indvars.iv.next16 = or disjoint i64 %indvars.iv15, 1
  %39 = mul nsw i32 %38, %18
  %40 = getelementptr inbounds [100 x i32], ptr %3, i64 0, i64 %indvars.iv.next16
  %41 = load i32, ptr %40, align 4, !tbaa !5
  %42 = add nsw i32 %39, %41
  %indvars.iv.next16.1 = or disjoint i64 %indvars.iv15, 2
  %43 = mul nsw i32 %42, %18
  %44 = getelementptr inbounds [100 x i32], ptr %3, i64 0, i64 %indvars.iv.next16.1
  %45 = load i32, ptr %44, align 8, !tbaa !5
  %46 = add nsw i32 %43, %45
  %indvars.iv.next16.2 = or disjoint i64 %indvars.iv15, 3
  %47 = mul nsw i32 %46, %18
  %48 = getelementptr inbounds [100 x i32], ptr %3, i64 0, i64 %indvars.iv.next16.2
  %49 = load i32, ptr %48, align 4, !tbaa !5
  %50 = add nsw i32 %47, %49
  %indvars.iv.next16.3 = add nuw nsw i64 %indvars.iv15, 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 %.unr-lcssa, label %33, !llvm.loop !14

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

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

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

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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { mustprogress 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 #3 = { 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 #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++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.unroll.disable"}
!14 = distinct !{!14, !10}


; Effective O3 passes: DSEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopInstSimplifyPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass