; LLVM IR from kimwalisch/primesieve :: test (clear_primesieve_iterator2)

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

%struct.primesieve_iterator = type { i64, i64, i64, i64, ptr, ptr, i32 }

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

; Function Attrs: nounwind uwtable
declare dso_local void @check(i32 noundef) #0

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

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

6:                                                ; preds = %21, %0
  %7 = load i32, ptr %4, align 4, !tbaa !9
  %8 = icmp slt i32 %7, 10
  br i1 %8, label %10, label %9

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

10:                                               ; preds = %6
  call void @primesieve_clear(ptr noundef %2)
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  %11 = call i64 @primesieve_next_prime(ptr noundef %2)
  store i64 %11, ptr %5, align 8, !tbaa !5
  br label %12

12:                                               ; preds = %18, %10
  %13 = load i64, ptr %5, align 8, !tbaa !5
  %14 = icmp ult i64 %13, 100000
  br i1 %14, label %15, label %20

15:                                               ; preds = %12
  %16 = load i64, ptr %3, align 8, !tbaa !5
  %17 = add i64 %16, 1
  store i64 %17, ptr %3, align 8, !tbaa !5
  br label %18

18:                                               ; preds = %15
  %19 = call i64 @primesieve_next_prime(ptr noundef %2)
  store i64 %19, ptr %5, align 8, !tbaa !5
  br label %12, !llvm.loop !11

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

21:                                               ; preds = %20
  %22 = load i32, ptr %4, align 4, !tbaa !9
  %23 = add nsw i32 %22, 1
  store i32 %23, ptr %4, align 4, !tbaa !9
  br label %6, !llvm.loop !13

24:                                               ; preds = %9
  %25 = load i64, ptr %3, align 8, !tbaa !5
  %26 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i64 noundef %25)
  %27 = load i64, ptr %3, align 8, !tbaa !5
  %28 = icmp eq i64 %27, 95920
  %29 = zext i1 %28 to i32
  call void @check(i32 noundef %29)
  call void @primesieve_free_iterator(ptr noundef %2)
  %30 = call i32 (ptr, ...) @printf(ptr noundef @.str.3)
  %31 = call i32 (ptr, ...) @printf(ptr noundef @.str.4)
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #4
  call void @llvm.lifetime.end.p0(i64 56, ptr %2) #4
  ret i32 0
}

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

declare void @primesieve_init(ptr noundef) #1

declare void @primesieve_clear(ptr noundef) #1

; Function Attrs: inlinehint nounwind uwtable
declare hidden i64 @primesieve_next_prime(ptr noundef) #3

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

declare void @primesieve_free_iterator(ptr noundef) #1

attributes #0 = { 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 = { "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 = { inlinehint 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 #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", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !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"

%struct.primesieve_iterator = type { i64, i64, i64, i64, ptr, ptr, i32 }

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

; Function Attrs: nounwind uwtable
declare dso_local void @check(i32 noundef) local_unnamed_addr #0

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

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  %1 = alloca %struct.primesieve_iterator, align 8
  call void @llvm.lifetime.start.p0(i64 56, ptr nonnull %1) #5
  call void @primesieve_init(ptr noundef nonnull %1) #5
  call void @primesieve_clear(ptr noundef nonnull %1) #5
  %2 = call i64 @primesieve_next_prime(ptr noundef nonnull %1)
  %3 = icmp ult i64 %2, 100000
  br i1 %3, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %0, %.lr.ph
  %.18 = phi i64 [ %4, %.lr.ph ], [ 0, %0 ]
  %4 = add i64 %.18, 1
  %5 = call i64 @primesieve_next_prime(ptr noundef nonnull %1)
  %6 = icmp ult i64 %5, 100000
  br i1 %6, label %.lr.ph, label %._crit_edge, !llvm.loop !5

._crit_edge:                                      ; preds = %.lr.ph, %0
  %.1.lcssa = phi i64 [ 0, %0 ], [ %4, %.lr.ph ]
  call void @primesieve_clear(ptr noundef nonnull %1) #5
  %7 = call i64 @primesieve_next_prime(ptr noundef nonnull %1)
  %8 = icmp ult i64 %7, 100000
  br i1 %8, label %.lr.ph.1, label %._crit_edge.1

.lr.ph.1:                                         ; preds = %._crit_edge, %.lr.ph.1
  %.18.1 = phi i64 [ %9, %.lr.ph.1 ], [ %.1.lcssa, %._crit_edge ]
  %9 = add i64 %.18.1, 1
  %10 = call i64 @primesieve_next_prime(ptr noundef nonnull %1)
  %11 = icmp ult i64 %10, 100000
  br i1 %11, label %.lr.ph.1, label %._crit_edge.1, !llvm.loop !5

._crit_edge.1:                                    ; preds = %.lr.ph.1, %._crit_edge
  %.1.lcssa.1 = phi i64 [ %.1.lcssa, %._crit_edge ], [ %9, %.lr.ph.1 ]
  call void @primesieve_clear(ptr noundef nonnull %1) #5
  %12 = call i64 @primesieve_next_prime(ptr noundef nonnull %1)
  %13 = icmp ult i64 %12, 100000
  br i1 %13, label %.lr.ph.2, label %._crit_edge.2

.lr.ph.2:                                         ; preds = %._crit_edge.1, %.lr.ph.2
  %.18.2 = phi i64 [ %14, %.lr.ph.2 ], [ %.1.lcssa.1, %._crit_edge.1 ]
  %14 = add i64 %.18.2, 1
  %15 = call i64 @primesieve_next_prime(ptr noundef nonnull %1)
  %16 = icmp ult i64 %15, 100000
  br i1 %16, label %.lr.ph.2, label %._crit_edge.2, !llvm.loop !5

._crit_edge.2:                                    ; preds = %.lr.ph.2, %._crit_edge.1
  %.1.lcssa.2 = phi i64 [ %.1.lcssa.1, %._crit_edge.1 ], [ %14, %.lr.ph.2 ]
  call void @primesieve_clear(ptr noundef nonnull %1) #5
  %17 = call i64 @primesieve_next_prime(ptr noundef nonnull %1)
  %18 = icmp ult i64 %17, 100000
  br i1 %18, label %.lr.ph.3, label %._crit_edge.3

.lr.ph.3:                                         ; preds = %._crit_edge.2, %.lr.ph.3
  %.18.3 = phi i64 [ %19, %.lr.ph.3 ], [ %.1.lcssa.2, %._crit_edge.2 ]
  %19 = add i64 %.18.3, 1
  %20 = call i64 @primesieve_next_prime(ptr noundef nonnull %1)
  %21 = icmp ult i64 %20, 100000
  br i1 %21, label %.lr.ph.3, label %._crit_edge.3, !llvm.loop !5

._crit_edge.3:                                    ; preds = %.lr.ph.3, %._crit_edge.2
  %.1.lcssa.3 = phi i64 [ %.1.lcssa.2, %._crit_edge.2 ], [ %19, %.lr.ph.3 ]
  call void @primesieve_clear(ptr noundef nonnull %1) #5
  %22 = call i64 @primesieve_next_prime(ptr noundef nonnull %1)
  %23 = icmp ult i64 %22, 100000
  br i1 %23, label %.lr.ph.4, label %._crit_edge.4

.lr.ph.4:                                         ; preds = %._crit_edge.3, %.lr.ph.4
  %.18.4 = phi i64 [ %24, %.lr.ph.4 ], [ %.1.lcssa.3, %._crit_edge.3 ]
  %24 = add i64 %.18.4, 1
  %25 = call i64 @primesieve_next_prime(ptr noundef nonnull %1)
  %26 = icmp ult i64 %25, 100000
  br i1 %26, label %.lr.ph.4, label %._crit_edge.4, !llvm.loop !5

._crit_edge.4:                                    ; preds = %.lr.ph.4, %._crit_edge.3
  %.1.lcssa.4 = phi i64 [ %.1.lcssa.3, %._crit_edge.3 ], [ %24, %.lr.ph.4 ]
  call void @primesieve_clear(ptr noundef nonnull %1) #5
  %27 = call i64 @primesieve_next_prime(ptr noundef nonnull %1)
  %28 = icmp ult i64 %27, 100000
  br i1 %28, label %.lr.ph.5, label %._crit_edge.5

.lr.ph.5:                                         ; preds = %._crit_edge.4, %.lr.ph.5
  %.18.5 = phi i64 [ %29, %.lr.ph.5 ], [ %.1.lcssa.4, %._crit_edge.4 ]
  %29 = add i64 %.18.5, 1
  %30 = call i64 @primesieve_next_prime(ptr noundef nonnull %1)
  %31 = icmp ult i64 %30, 100000
  br i1 %31, label %.lr.ph.5, label %._crit_edge.5, !llvm.loop !5

._crit_edge.5:                                    ; preds = %.lr.ph.5, %._crit_edge.4
  %.1.lcssa.5 = phi i64 [ %.1.lcssa.4, %._crit_edge.4 ], [ %29, %.lr.ph.5 ]
  call void @primesieve_clear(ptr noundef nonnull %1) #5
  %32 = call i64 @primesieve_next_prime(ptr noundef nonnull %1)
  %33 = icmp ult i64 %32, 100000
  br i1 %33, label %.lr.ph.6, label %._crit_edge.6

.lr.ph.6:                                         ; preds = %._crit_edge.5, %.lr.ph.6
  %.18.6 = phi i64 [ %34, %.lr.ph.6 ], [ %.1.lcssa.5, %._crit_edge.5 ]
  %34 = add i64 %.18.6, 1
  %35 = call i64 @primesieve_next_prime(ptr noundef nonnull %1)
  %36 = icmp ult i64 %35, 100000
  br i1 %36, label %.lr.ph.6, label %._crit_edge.6, !llvm.loop !5

._crit_edge.6:                                    ; preds = %.lr.ph.6, %._crit_edge.5
  %.1.lcssa.6 = phi i64 [ %.1.lcssa.5, %._crit_edge.5 ], [ %34, %.lr.ph.6 ]
  call void @primesieve_clear(ptr noundef nonnull %1) #5
  %37 = call i64 @primesieve_next_prime(ptr noundef nonnull %1)
  %38 = icmp ult i64 %37, 100000
  br i1 %38, label %.lr.ph.7, label %._crit_edge.7

.lr.ph.7:                                         ; preds = %._crit_edge.6, %.lr.ph.7
  %.18.7 = phi i64 [ %39, %.lr.ph.7 ], [ %.1.lcssa.6, %._crit_edge.6 ]
  %39 = add i64 %.18.7, 1
  %40 = call i64 @primesieve_next_prime(ptr noundef nonnull %1)
  %41 = icmp ult i64 %40, 100000
  br i1 %41, label %.lr.ph.7, label %._crit_edge.7, !llvm.loop !5

._crit_edge.7:                                    ; preds = %.lr.ph.7, %._crit_edge.6
  %.1.lcssa.7 = phi i64 [ %.1.lcssa.6, %._crit_edge.6 ], [ %39, %.lr.ph.7 ]
  call void @primesieve_clear(ptr noundef nonnull %1) #5
  %42 = call i64 @primesieve_next_prime(ptr noundef nonnull %1)
  %43 = icmp ult i64 %42, 100000
  br i1 %43, label %.lr.ph.8, label %._crit_edge.8

.lr.ph.8:                                         ; preds = %._crit_edge.7, %.lr.ph.8
  %.18.8 = phi i64 [ %44, %.lr.ph.8 ], [ %.1.lcssa.7, %._crit_edge.7 ]
  %44 = add i64 %.18.8, 1
  %45 = call i64 @primesieve_next_prime(ptr noundef nonnull %1)
  %46 = icmp ult i64 %45, 100000
  br i1 %46, label %.lr.ph.8, label %._crit_edge.8, !llvm.loop !5

._crit_edge.8:                                    ; preds = %.lr.ph.8, %._crit_edge.7
  %.1.lcssa.8 = phi i64 [ %.1.lcssa.7, %._crit_edge.7 ], [ %44, %.lr.ph.8 ]
  call void @primesieve_clear(ptr noundef nonnull %1) #5
  %47 = call i64 @primesieve_next_prime(ptr noundef nonnull %1)
  %48 = icmp ult i64 %47, 100000
  br i1 %48, label %.lr.ph.9, label %._crit_edge.9

.lr.ph.9:                                         ; preds = %._crit_edge.8, %.lr.ph.9
  %.18.9 = phi i64 [ %49, %.lr.ph.9 ], [ %.1.lcssa.8, %._crit_edge.8 ]
  %49 = add i64 %.18.9, 1
  %50 = call i64 @primesieve_next_prime(ptr noundef nonnull %1)
  %51 = icmp ult i64 %50, 100000
  br i1 %51, label %.lr.ph.9, label %._crit_edge.9, !llvm.loop !5

._crit_edge.9:                                    ; preds = %.lr.ph.9, %._crit_edge.8
  %.1.lcssa.9 = phi i64 [ %.1.lcssa.8, %._crit_edge.8 ], [ %49, %.lr.ph.9 ]
  %52 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i64 noundef %.1.lcssa.9)
  %53 = icmp eq i64 %.1.lcssa.9, 95920
  %54 = zext i1 %53 to i32
  call void @check(i32 noundef %54)
  call void @primesieve_free_iterator(ptr noundef nonnull %1) #5
  %55 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3)
  %56 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.4)
  call void @llvm.lifetime.end.p0(i64 56, ptr nonnull %1) #5
  ret i32 0
}

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

declare void @primesieve_init(ptr noundef) local_unnamed_addr #3

declare void @primesieve_clear(ptr noundef) local_unnamed_addr #3

; Function Attrs: inlinehint nounwind uwtable
declare hidden i64 @primesieve_next_prime(ptr noundef) local_unnamed_addr #4

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

declare void @primesieve_free_iterator(ptr noundef) local_unnamed_addr #3

attributes #0 = { 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" }
attributes #2 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { inlinehint 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 #5 = { 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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}


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