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

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

@small_primes = external dso_local constant [25 x i64], align 16
@large_primes = external dso_local constant [20 x i64], align 16
@.str.2 = external hidden unnamed_addr constant [18 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [18 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [24 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.6 = 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 i64, align 8
  %3 = alloca i64, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  store i64 0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  %6 = call ptr @primesieve_generate_primes(i64 noundef 0, i64 noundef 100, ptr noundef %3, i32 noundef 13)
  store ptr %6, ptr %4, align 8, !tbaa !9
  %7 = load i64, ptr %3, align 8, !tbaa !5
  %8 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i64 noundef %7)
  %9 = load i64, ptr %3, align 8, !tbaa !5
  %10 = icmp eq i64 %9, 25
  %11 = zext i1 %10 to i32
  call void @check(i32 noundef %11)
  store i64 0, ptr %2, align 8, !tbaa !5
  br label %12

12:                                               ; preds = %32, %0
  %13 = load i64, ptr %2, align 8, !tbaa !5
  %14 = load i64, ptr %3, align 8, !tbaa !5
  %15 = icmp ult i64 %13, %14
  br i1 %15, label %16, label %35

16:                                               ; preds = %12
  %17 = load i64, ptr %2, align 8, !tbaa !5
  %18 = load ptr, ptr %4, align 8, !tbaa !9
  %19 = load i64, ptr %2, align 8, !tbaa !5
  %20 = getelementptr inbounds i64, ptr %18, i64 %19
  %21 = load i64, ptr %20, align 8, !tbaa !5
  %22 = call i32 (ptr, ...) @printf(ptr noundef @.str.3, i64 noundef %17, i64 noundef %21)
  %23 = load ptr, ptr %4, align 8, !tbaa !9
  %24 = load i64, ptr %2, align 8, !tbaa !5
  %25 = getelementptr inbounds i64, ptr %23, i64 %24
  %26 = load i64, ptr %25, align 8, !tbaa !5
  %27 = load i64, ptr %2, align 8, !tbaa !5
  %28 = getelementptr inbounds [25 x i64], ptr @small_primes, i64 0, i64 %27
  %29 = load i64, ptr %28, align 8, !tbaa !5
  %30 = icmp eq i64 %26, %29
  %31 = zext i1 %30 to i32
  call void @check(i32 noundef %31)
  br label %32

32:                                               ; preds = %16
  %33 = load i64, ptr %2, align 8, !tbaa !5
  %34 = add i64 %33, 1
  store i64 %34, ptr %2, align 8, !tbaa !5
  br label %12, !llvm.loop !11

35:                                               ; preds = %12
  %36 = load ptr, ptr %4, align 8, !tbaa !9
  call void @primesieve_free(ptr noundef %36)
  %37 = call ptr @primesieve_generate_primes(i64 noundef 0, i64 noundef 1000, ptr noundef %3, i32 noundef 13)
  store ptr %37, ptr %4, align 8, !tbaa !9
  %38 = load i64, ptr %3, align 8, !tbaa !5
  %39 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i64 noundef %38)
  %40 = load i64, ptr %3, align 8, !tbaa !5
  %41 = icmp eq i64 %40, 168
  %42 = zext i1 %41 to i32
  call void @check(i32 noundef %42)
  %43 = load ptr, ptr %4, align 8, !tbaa !9
  call void @primesieve_free(ptr noundef %43)
  %44 = call ptr @primesieve_generate_primes(i64 noundef 0, i64 noundef 1000000, ptr noundef %3, i32 noundef 13)
  store ptr %44, ptr %4, align 8, !tbaa !9
  %45 = load i64, ptr %3, align 8, !tbaa !5
  %46 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i64 noundef %45)
  %47 = load i64, ptr %3, align 8, !tbaa !5
  %48 = icmp eq i64 %47, 78498
  %49 = zext i1 %48 to i32
  call void @check(i32 noundef %49)
  %50 = load ptr, ptr %4, align 8, !tbaa !9
  call void @primesieve_free(ptr noundef %50)
  %51 = call ptr @primesieve_generate_primes(i64 noundef 1000003, i64 noundef 9999991, ptr noundef %3, i32 noundef 13)
  store ptr %51, ptr %4, align 8, !tbaa !9
  %52 = load i64, ptr %3, align 8, !tbaa !5
  %53 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i64 noundef %52)
  %54 = load i64, ptr %3, align 8, !tbaa !5
  %55 = icmp eq i64 %54, 586081
  %56 = zext i1 %55 to i32
  call void @check(i32 noundef %56)
  %57 = load ptr, ptr %4, align 8, !tbaa !9
  call void @primesieve_free(ptr noundef %57)
  %58 = call ptr @primesieve_generate_primes(i64 noundef 1000000, i64 noundef 1000000, ptr noundef %3, i32 noundef 13)
  store ptr %58, ptr %4, align 8, !tbaa !9
  %59 = load i64, ptr %3, align 8, !tbaa !5
  %60 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i64 noundef %59)
  %61 = load i64, ptr %3, align 8, !tbaa !5
  %62 = icmp eq i64 %61, 0
  %63 = zext i1 %62 to i32
  call void @check(i32 noundef %63)
  %64 = load ptr, ptr %4, align 8, !tbaa !9
  call void @primesieve_free(ptr noundef %64)
  %65 = call ptr @primesieve_generate_primes(i64 noundef -944, i64 noundef -1, ptr noundef %3, i32 noundef 13)
  store ptr %65, ptr %4, align 8, !tbaa !9
  %66 = load i64, ptr %3, align 8, !tbaa !5
  %67 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i64 noundef %66)
  %68 = load i64, ptr %3, align 8, !tbaa !5
  %69 = icmp eq i64 %68, 20
  %70 = zext i1 %69 to i32
  call void @check(i32 noundef %70)
  store i64 0, ptr %2, align 8, !tbaa !5
  br label %71

71:                                               ; preds = %91, %35
  %72 = load i64, ptr %2, align 8, !tbaa !5
  %73 = load i64, ptr %3, align 8, !tbaa !5
  %74 = icmp ult i64 %72, %73
  br i1 %74, label %75, label %94

75:                                               ; preds = %71
  %76 = load i64, ptr %2, align 8, !tbaa !5
  %77 = load ptr, ptr %4, align 8, !tbaa !9
  %78 = load i64, ptr %2, align 8, !tbaa !5
  %79 = getelementptr inbounds i64, ptr %77, i64 %78
  %80 = load i64, ptr %79, align 8, !tbaa !5
  %81 = call i32 (ptr, ...) @printf(ptr noundef @.str.3, i64 noundef %76, i64 noundef %80)
  %82 = load ptr, ptr %4, align 8, !tbaa !9
  %83 = load i64, ptr %2, align 8, !tbaa !5
  %84 = getelementptr inbounds i64, ptr %82, i64 %83
  %85 = load i64, ptr %84, align 8, !tbaa !5
  %86 = load i64, ptr %2, align 8, !tbaa !5
  %87 = getelementptr inbounds [20 x i64], ptr @large_primes, i64 0, i64 %86
  %88 = load i64, ptr %87, align 8, !tbaa !5
  %89 = icmp eq i64 %85, %88
  %90 = zext i1 %89 to i32
  call void @check(i32 noundef %90)
  br label %91

91:                                               ; preds = %75
  %92 = load i64, ptr %2, align 8, !tbaa !5
  %93 = add i64 %92, 1
  store i64 %93, ptr %2, align 8, !tbaa !5
  br label %71, !llvm.loop !13

94:                                               ; preds = %71
  %95 = load ptr, ptr %4, align 8, !tbaa !9
  call void @primesieve_free(ptr noundef %95)
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  %96 = call ptr @primesieve_generate_primes(i64 noundef 2147482648, i64 noundef 2147484648, ptr noundef %3, i32 noundef 10)
  store ptr %96, ptr %5, align 8, !tbaa !9
  %97 = call i32 (ptr, ...) @printf(ptr noundef @.str.4)
  %98 = load ptr, ptr %5, align 8, !tbaa !9
  %99 = icmp eq ptr %98, null
  %100 = zext i1 %99 to i32
  call void @check(i32 noundef %100)
  %101 = call i32 (ptr, ...) @printf(ptr noundef @.str.5)
  %102 = call i32 (ptr, ...) @printf(ptr noundef @.str.6)
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #3
  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 ptr @primesieve_generate_primes(i64 noundef, i64 noundef, ptr noundef, i32 noundef) #1

declare void @primesieve_free(ptr noundef) #1

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

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 = { 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 = !{!"any pointer", !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"

@small_primes = external dso_local local_unnamed_addr constant [25 x i64], align 16
@large_primes = external dso_local local_unnamed_addr constant [20 x i64], align 16
@.str.2 = external hidden unnamed_addr constant [18 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [18 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [24 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.6 = 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 i64, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %1) #4
  store i64 0, ptr %1, align 8, !tbaa !5
  %2 = call ptr @primesieve_generate_primes(i64 noundef 0, i64 noundef 100, ptr noundef nonnull %1, i32 noundef 13) #4
  %3 = load i64, ptr %1, align 8, !tbaa !5
  %4 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i64 noundef %3)
  %5 = load i64, ptr %1, align 8, !tbaa !5
  %6 = icmp eq i64 %5, 25
  %7 = zext i1 %6 to i32
  call void @check(i32 noundef %7)
  %8 = load i64, ptr %1, align 8, !tbaa !5
  %.not = icmp eq i64 %8, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %0, %.lr.ph
  %.022 = phi i64 [ %17, %.lr.ph ], [ 0, %0 ]
  %9 = getelementptr inbounds i64, ptr %2, i64 %.022
  %10 = load i64, ptr %9, align 8, !tbaa !5
  %11 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3, i64 noundef %.022, i64 noundef %10)
  %12 = load i64, ptr %9, align 8, !tbaa !5
  %13 = getelementptr inbounds [25 x i64], ptr @small_primes, i64 0, i64 %.022
  %14 = load i64, ptr %13, align 8, !tbaa !5
  %15 = icmp eq i64 %12, %14
  %16 = zext i1 %15 to i32
  call void @check(i32 noundef %16)
  %17 = add nuw i64 %.022, 1
  %18 = load i64, ptr %1, align 8, !tbaa !5
  %19 = icmp ult i64 %17, %18
  br i1 %19, label %.lr.ph, label %._crit_edge, !llvm.loop !9

._crit_edge:                                      ; preds = %.lr.ph, %0
  call void @primesieve_free(ptr noundef %2) #4
  %20 = call ptr @primesieve_generate_primes(i64 noundef 0, i64 noundef 1000, ptr noundef nonnull %1, i32 noundef 13) #4
  %21 = load i64, ptr %1, align 8, !tbaa !5
  %22 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i64 noundef %21)
  %23 = load i64, ptr %1, align 8, !tbaa !5
  %24 = icmp eq i64 %23, 168
  %25 = zext i1 %24 to i32
  call void @check(i32 noundef %25)
  call void @primesieve_free(ptr noundef %20) #4
  %26 = call ptr @primesieve_generate_primes(i64 noundef 0, i64 noundef 1000000, ptr noundef nonnull %1, i32 noundef 13) #4
  %27 = load i64, ptr %1, align 8, !tbaa !5
  %28 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i64 noundef %27)
  %29 = load i64, ptr %1, align 8, !tbaa !5
  %30 = icmp eq i64 %29, 78498
  %31 = zext i1 %30 to i32
  call void @check(i32 noundef %31)
  call void @primesieve_free(ptr noundef %26) #4
  %32 = call ptr @primesieve_generate_primes(i64 noundef 1000003, i64 noundef 9999991, ptr noundef nonnull %1, i32 noundef 13) #4
  %33 = load i64, ptr %1, align 8, !tbaa !5
  %34 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i64 noundef %33)
  %35 = load i64, ptr %1, align 8, !tbaa !5
  %36 = icmp eq i64 %35, 586081
  %37 = zext i1 %36 to i32
  call void @check(i32 noundef %37)
  call void @primesieve_free(ptr noundef %32) #4
  %38 = call ptr @primesieve_generate_primes(i64 noundef 1000000, i64 noundef 1000000, ptr noundef nonnull %1, i32 noundef 13) #4
  %39 = load i64, ptr %1, align 8, !tbaa !5
  %40 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i64 noundef %39)
  %41 = load i64, ptr %1, align 8, !tbaa !5
  %42 = icmp eq i64 %41, 0
  %43 = zext i1 %42 to i32
  call void @check(i32 noundef %43)
  call void @primesieve_free(ptr noundef %38) #4
  %44 = call ptr @primesieve_generate_primes(i64 noundef -944, i64 noundef -1, ptr noundef nonnull %1, i32 noundef 13) #4
  %45 = load i64, ptr %1, align 8, !tbaa !5
  %46 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i64 noundef %45)
  %47 = load i64, ptr %1, align 8, !tbaa !5
  %48 = icmp eq i64 %47, 20
  %49 = zext i1 %48 to i32
  call void @check(i32 noundef %49)
  %50 = load i64, ptr %1, align 8, !tbaa !5
  %.not27 = icmp eq i64 %50, 0
  br i1 %.not27, label %._crit_edge26, label %.lr.ph25

.lr.ph25:                                         ; preds = %._crit_edge, %.lr.ph25
  %.123 = phi i64 [ %59, %.lr.ph25 ], [ 0, %._crit_edge ]
  %51 = getelementptr inbounds i64, ptr %44, i64 %.123
  %52 = load i64, ptr %51, align 8, !tbaa !5
  %53 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3, i64 noundef %.123, i64 noundef %52)
  %54 = load i64, ptr %51, align 8, !tbaa !5
  %55 = getelementptr inbounds [20 x i64], ptr @large_primes, i64 0, i64 %.123
  %56 = load i64, ptr %55, align 8, !tbaa !5
  %57 = icmp eq i64 %54, %56
  %58 = zext i1 %57 to i32
  call void @check(i32 noundef %58)
  %59 = add nuw i64 %.123, 1
  %60 = load i64, ptr %1, align 8, !tbaa !5
  %61 = icmp ult i64 %59, %60
  br i1 %61, label %.lr.ph25, label %._crit_edge26, !llvm.loop !11

._crit_edge26:                                    ; preds = %.lr.ph25, %._crit_edge
  call void @primesieve_free(ptr noundef %44) #4
  %62 = call ptr @primesieve_generate_primes(i64 noundef 2147482648, i64 noundef 2147484648, ptr noundef nonnull %1, i32 noundef 10) #4
  %63 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.4)
  %64 = icmp eq ptr %62, null
  %65 = zext i1 %64 to i32
  call void @check(i32 noundef %65)
  %66 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.5)
  %67 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.6)
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %1) #4
  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 ptr @primesieve_generate_primes(i64 noundef, i64 noundef, ptr noundef, i32 noundef) local_unnamed_addr #3

declare void @primesieve_free(ptr noundef) local_unnamed_addr #3

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

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 = { 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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass