; LLVM IR from ippeb/ACM-ICPC :: algebra/prime_generator/prime_generator.ll (Z5sievev)

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

@B = external dso_local global [1048577 x i8], align 16
@P = external dso_local global [1048577 x i32], align 16
@pcnt = external dso_local global i32, align 4
@n = external dso_local global i32, align 4

; Function Attrs: mustprogress uwtable
define dso_local void @_Z5sievev() #0 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  store i8 1, ptr @B, align 16, !tbaa !5
  store i8 1, ptr getelementptr inbounds ([1048577 x i8], ptr @B, i64 0, i64 1), align 1, !tbaa !5
  store i32 0, ptr @pcnt, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #3
  %6 = load i32, ptr @n, align 4, !tbaa !9
  %7 = call noundef double @_ZSt4sqrtIiEN9__gnu_cxx11__enable_ifIXsr12__is_integerIT_EE7__valueEdE6__typeES2_(i32 noundef %6)
  %8 = fadd double %7, 1.000000e+00
  %9 = fptosi double %8 to i32
  store i32 %9, ptr %1, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #3
  store i32 2, ptr %2, align 4, !tbaa !9
  br label %10

10:                                               ; preds = %45, %0
  %11 = load i32, ptr %2, align 4, !tbaa !9
  %12 = load i32, ptr %1, align 4, !tbaa !9
  %13 = icmp sle i32 %11, %12
  br i1 %13, label %15, label %14

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

15:                                               ; preds = %10
  %16 = load i32, ptr %2, align 4, !tbaa !9
  %17 = sext i32 %16 to i64
  %18 = getelementptr inbounds [1048577 x i8], ptr @B, i64 0, i64 %17
  %19 = load i8, ptr %18, align 1, !tbaa !5, !range !11, !noundef !12
  %20 = trunc i8 %19 to i1
  br i1 %20, label %44, label %21

21:                                               ; preds = %15
  %22 = load i32, ptr %2, align 4, !tbaa !9
  %23 = load i32, ptr @pcnt, align 4, !tbaa !9
  %24 = add nsw i32 %23, 1
  store i32 %24, ptr @pcnt, align 4, !tbaa !9
  %25 = sext i32 %23 to i64
  %26 = getelementptr inbounds [1048577 x i32], ptr @P, i64 0, i64 %25
  store i32 %22, ptr %26, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  store i32 2, ptr %4, align 4, !tbaa !9
  br label %27

27:                                               ; preds = %40, %21
  %28 = load i32, ptr %4, align 4, !tbaa !9
  %29 = load i32, ptr %2, align 4, !tbaa !9
  %30 = mul nsw i32 %28, %29
  %31 = load i32, ptr @n, align 4, !tbaa !9
  %32 = icmp sle i32 %30, %31
  br i1 %32, label %34, label %33

33:                                               ; preds = %27
  store i32 5, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  br label %43

34:                                               ; preds = %27
  %35 = load i32, ptr %4, align 4, !tbaa !9
  %36 = load i32, ptr %2, align 4, !tbaa !9
  %37 = mul nsw i32 %35, %36
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds [1048577 x i8], ptr @B, i64 0, i64 %38
  store i8 1, ptr %39, align 1, !tbaa !5
  br label %40

40:                                               ; preds = %34
  %41 = load i32, ptr %4, align 4, !tbaa !9
  %42 = add nsw i32 %41, 1
  store i32 %42, ptr %4, align 4, !tbaa !9
  br label %27, !llvm.loop !13

43:                                               ; preds = %33
  br label %44

44:                                               ; preds = %43, %15
  br label %45

45:                                               ; preds = %44
  %46 = load i32, ptr %2, align 4, !tbaa !9
  %47 = add nsw i32 %46, 1
  store i32 %47, ptr %2, align 4, !tbaa !9
  br label %10, !llvm.loop !15

48:                                               ; preds = %14
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  %49 = load i32, ptr %1, align 4, !tbaa !9
  %50 = add nsw i32 %49, 1
  store i32 %50, ptr %5, align 4, !tbaa !9
  br label %51

51:                                               ; preds = %69, %48
  %52 = load i32, ptr %5, align 4, !tbaa !9
  %53 = load i32, ptr @n, align 4, !tbaa !9
  %54 = icmp sle i32 %52, %53
  br i1 %54, label %56, label %55

55:                                               ; preds = %51
  store i32 8, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  br label %72

56:                                               ; preds = %51
  %57 = load i32, ptr %5, align 4, !tbaa !9
  %58 = sext i32 %57 to i64
  %59 = getelementptr inbounds [1048577 x i8], ptr @B, i64 0, i64 %58
  %60 = load i8, ptr %59, align 1, !tbaa !5, !range !11, !noundef !12
  %61 = trunc i8 %60 to i1
  br i1 %61, label %68, label %62

62:                                               ; preds = %56
  %63 = load i32, ptr %5, align 4, !tbaa !9
  %64 = load i32, ptr @pcnt, align 4, !tbaa !9
  %65 = add nsw i32 %64, 1
  store i32 %65, ptr @pcnt, align 4, !tbaa !9
  %66 = sext i32 %64 to i64
  %67 = getelementptr inbounds [1048577 x i32], ptr @P, i64 0, i64 %66
  store i32 %63, ptr %67, align 4, !tbaa !9
  br label %68

68:                                               ; preds = %62, %56
  br label %69

69:                                               ; preds = %68
  %70 = load i32, ptr %5, align 4, !tbaa !9
  %71 = add nsw i32 %70, 1
  store i32 %71, ptr %5, align 4, !tbaa !9
  br label %51, !llvm.loop !16

72:                                               ; preds = %55
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #3
  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: inlinehint mustprogress nounwind uwtable
declare dso_local noundef double @_ZSt4sqrtIiEN9__gnu_cxx11__enable_ifIXsr12__is_integerIT_EE7__valueEdE6__typeES2_(i32 noundef) #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 = { inlinehint 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 #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 = !{!"bool", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{i8 0, i8 2}
!12 = !{}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}
!16 = distinct !{!16, !14}


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

@B = external dso_local local_unnamed_addr global [1048577 x i8], align 16
@P = external dso_local local_unnamed_addr global [1048577 x i32], align 16
@pcnt = external dso_local local_unnamed_addr global i32, align 4
@n = external dso_local local_unnamed_addr global i32, align 4

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z5sievev() local_unnamed_addr #0 {
  store i8 1, ptr @B, align 16, !tbaa !5
  store i8 1, ptr getelementptr inbounds (i8, ptr @B, i64 1), align 1, !tbaa !5
  store i32 0, ptr @pcnt, align 4, !tbaa !9
  %1 = load i32, ptr @n, align 4, !tbaa !9
  %2 = tail call noundef double @_ZSt4sqrtIiEN9__gnu_cxx11__enable_ifIXsr12__is_integerIT_EE7__valueEdE6__typeES2_(i32 noundef %1)
  %3 = fadd double %2, 1.000000e+00
  %4 = fptosi double %3 to i32
  %.not23 = icmp slt i32 %4, 2
  %.pre = load i32, ptr @n, align 4
  %pcnt.promoted26.pre = load i32, ptr @pcnt, align 4, !tbaa !9
  br i1 %.not23, label %.preheader, label %.lr.ph25

.lr.ph25:                                         ; preds = %0
  %5 = add nuw i32 %4, 1
  %wide.trip.count = zext i32 %5 to i64
  br label %18

.preheader:                                       ; preds = %.loopexit, %0
  %pcnt.promoted26 = phi i32 [ %pcnt.promoted26.pre, %0 ], [ %34, %.loopexit ]
  %.not19.not28 = icmp sgt i32 %.pre, %4
  br i1 %.not19.not28, label %.lr.ph30.preheader, label %._crit_edge

.lr.ph30.preheader:                               ; preds = %.preheader
  %6 = sext i32 %4 to i64
  %wide.trip.count38 = sext i32 %.pre to i64
  %7 = sub nsw i64 %wide.trip.count38, %6
  %xtraiter = and i64 %7, 1
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %.lr.ph30.prol.loopexit, label %.lr.ph30.prol

.lr.ph30.prol:                                    ; preds = %.lr.ph30.preheader
  %indvars.iv.next36.prol = add nsw i64 %6, 1
  %8 = getelementptr inbounds [1048577 x i8], ptr @B, i64 0, i64 %indvars.iv.next36.prol
  %9 = load i8, ptr %8, align 1, !tbaa !5, !range !11, !noundef !12
  %10 = trunc nuw i8 %9 to i1
  br i1 %10, label %.lr.ph30.prol.loopexit, label %11

11:                                               ; preds = %.lr.ph30.prol
  %12 = add nsw i32 %pcnt.promoted26, 1
  store i32 %12, ptr @pcnt, align 4, !tbaa !9
  %13 = sext i32 %pcnt.promoted26 to i64
  %14 = getelementptr inbounds [1048577 x i32], ptr @P, i64 0, i64 %13
  %15 = trunc nsw i64 %indvars.iv.next36.prol to i32
  store i32 %15, ptr %14, align 4, !tbaa !9
  br label %.lr.ph30.prol.loopexit

.lr.ph30.prol.loopexit:                           ; preds = %.lr.ph30.prol, %11, %.lr.ph30.preheader
  %indvars.iv35.unr = phi i64 [ %6, %.lr.ph30.preheader ], [ %indvars.iv.next36.prol, %11 ], [ %indvars.iv.next36.prol, %.lr.ph30.prol ]
  %.unr = phi i32 [ %pcnt.promoted26, %.lr.ph30.preheader ], [ %pcnt.promoted26, %.lr.ph30.prol ], [ %12, %11 ]
  %16 = add nsw i64 %wide.trip.count38, -1
  %17 = icmp eq i64 %16, %6
  br i1 %17, label %._crit_edge, label %.lr.ph30

18:                                               ; preds = %.lr.ph25, %.loopexit
  %indvars.iv32 = phi i64 [ 2, %.lr.ph25 ], [ %indvars.iv.next33, %.loopexit ]
  %19 = phi i32 [ %pcnt.promoted26.pre, %.lr.ph25 ], [ %34, %.loopexit ]
  %20 = getelementptr inbounds [1048577 x i8], ptr @B, i64 0, i64 %indvars.iv32
  %21 = load i8, ptr %20, align 1, !tbaa !5, !range !11, !noundef !12
  %22 = trunc nuw i8 %21 to i1
  br i1 %22, label %.loopexit, label %23

23:                                               ; preds = %18
  %24 = add nsw i32 %19, 1
  store i32 %24, ptr @pcnt, align 4, !tbaa !9
  %25 = sext i32 %19 to i64
  %26 = getelementptr inbounds [1048577 x i32], ptr @P, i64 0, i64 %25
  %27 = trunc nuw nsw i64 %indvars.iv32 to i32
  store i32 %27, ptr %26, align 4, !tbaa !9
  %indvars.iv32.tr = trunc i64 %indvars.iv32 to i32
  %28 = shl i32 %indvars.iv32.tr, 1
  %.not2021 = icmp sgt i32 %28, %.pre
  br i1 %.not2021, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %23, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 2, %23 ]
  %29 = phi i32 [ %33, %.lr.ph ], [ %28, %23 ]
  %30 = zext nneg i32 %29 to i64
  %31 = getelementptr inbounds [1048577 x i8], ptr @B, i64 0, i64 %30
  store i8 1, ptr %31, align 1, !tbaa !5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %32 = mul nuw nsw i64 %indvars.iv.next, %indvars.iv32
  %33 = trunc nuw i64 %32 to i32
  %.not20 = icmp slt i32 %.pre, %33
  br i1 %.not20, label %.loopexit, label %.lr.ph, !llvm.loop !13

.loopexit:                                        ; preds = %.lr.ph, %23, %18
  %34 = phi i32 [ %19, %18 ], [ %24, %23 ], [ %24, %.lr.ph ]
  %indvars.iv.next33 = add nuw nsw i64 %indvars.iv32, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next33, %wide.trip.count
  br i1 %exitcond.not, label %.preheader, label %18, !llvm.loop !15

._crit_edge:                                      ; preds = %.lr.ph30.prol.loopexit, %53, %.preheader
  ret void

.lr.ph30:                                         ; preds = %.lr.ph30.prol.loopexit, %53
  %indvars.iv35 = phi i64 [ %indvars.iv.next36.1, %53 ], [ %indvars.iv35.unr, %.lr.ph30.prol.loopexit ]
  %35 = phi i32 [ %54, %53 ], [ %.unr, %.lr.ph30.prol.loopexit ]
  %indvars.iv.next36 = add nsw i64 %indvars.iv35, 1
  %36 = getelementptr inbounds [1048577 x i8], ptr @B, i64 0, i64 %indvars.iv.next36
  %37 = load i8, ptr %36, align 1, !tbaa !5, !range !11, !noundef !12
  %38 = trunc nuw i8 %37 to i1
  br i1 %38, label %.lr.ph30.1, label %39

39:                                               ; preds = %.lr.ph30
  %40 = add nsw i32 %35, 1
  store i32 %40, ptr @pcnt, align 4, !tbaa !9
  %41 = sext i32 %35 to i64
  %42 = getelementptr inbounds [1048577 x i32], ptr @P, i64 0, i64 %41
  %43 = trunc nsw i64 %indvars.iv.next36 to i32
  store i32 %43, ptr %42, align 4, !tbaa !9
  br label %.lr.ph30.1

.lr.ph30.1:                                       ; preds = %.lr.ph30, %39
  %44 = phi i32 [ %35, %.lr.ph30 ], [ %40, %39 ]
  %indvars.iv.next36.1 = add nsw i64 %indvars.iv35, 2
  %45 = getelementptr inbounds [1048577 x i8], ptr @B, i64 0, i64 %indvars.iv.next36.1
  %46 = load i8, ptr %45, align 1, !tbaa !5, !range !11, !noundef !12
  %47 = trunc nuw i8 %46 to i1
  br i1 %47, label %53, label %48

48:                                               ; preds = %.lr.ph30.1
  %49 = add nsw i32 %44, 1
  store i32 %49, ptr @pcnt, align 4, !tbaa !9
  %50 = sext i32 %44 to i64
  %51 = getelementptr inbounds [1048577 x i32], ptr @P, i64 0, i64 %50
  %52 = trunc nsw i64 %indvars.iv.next36.1 to i32
  store i32 %52, ptr %51, align 4, !tbaa !9
  br label %53

53:                                               ; preds = %48, %.lr.ph30.1
  %54 = phi i32 [ %44, %.lr.ph30.1 ], [ %49, %48 ]
  %exitcond39.not.1 = icmp eq i64 %indvars.iv.next36.1, %wide.trip.count38
  br i1 %exitcond39.not.1, label %._crit_edge, label %.lr.ph30, !llvm.loop !16
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef double @_ZSt4sqrtIiEN9__gnu_cxx11__enable_ifIXsr12__is_integerIT_EE7__valueEdE6__typeES2_(i32 noundef) local_unnamed_addr #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 = { inlinehint 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" }

!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 = !{!"bool", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{i8 0, i8 2}
!12 = !{}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}
!16 = distinct !{!16, !14}


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