; LLVM IR from vmartinv/eldiego :: math/criba.ll (Z10crearcribav)

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

@criba = external dso_local global [100001 x i32], align 16
@__const._Z10crearcribav.w = external hidden unnamed_addr constant [8 x i32], align 16

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z10crearcribav() #0 {
  %1 = alloca [8 x i32], align 16
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 32, ptr %1) #3
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %1, ptr align 16 @__const._Z10crearcribav.w, i64 32, i1 false)
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #3
  store i32 25, ptr %2, align 4, !tbaa !5
  br label %9

9:                                                ; preds = %17, %0
  %10 = load i32, ptr %2, align 4, !tbaa !5
  %11 = icmp sle i32 %10, 100000
  br i1 %11, label %13, label %12

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

13:                                               ; preds = %9
  %14 = load i32, ptr %2, align 4, !tbaa !5
  %15 = sext i32 %14 to i64
  %16 = getelementptr inbounds [100001 x i32], ptr @criba, i64 0, i64 %15
  store i32 5, ptr %16, align 4, !tbaa !5
  br label %17

17:                                               ; preds = %13
  %18 = load i32, ptr %2, align 4, !tbaa !5
  %19 = add nsw i32 %18, 10
  store i32 %19, ptr %2, align 4, !tbaa !5
  br label %9, !llvm.loop !9

20:                                               ; preds = %12
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  store i32 9, ptr %3, align 4, !tbaa !5
  br label %21

21:                                               ; preds = %29, %20
  %22 = load i32, ptr %3, align 4, !tbaa !5
  %23 = icmp sle i32 %22, 100000
  br i1 %23, label %25, label %24

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

25:                                               ; preds = %21
  %26 = load i32, ptr %3, align 4, !tbaa !5
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds [100001 x i32], ptr @criba, i64 0, i64 %27
  store i32 3, ptr %28, align 4, !tbaa !5
  br label %29

29:                                               ; preds = %25
  %30 = load i32, ptr %3, align 4, !tbaa !5
  %31 = add nsw i32 %30, 6
  store i32 %31, ptr %3, align 4, !tbaa !5
  br label %21, !llvm.loop !11

32:                                               ; preds = %24
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  store i32 4, ptr %4, align 4, !tbaa !5
  br label %33

33:                                               ; preds = %41, %32
  %34 = load i32, ptr %4, align 4, !tbaa !5
  %35 = icmp sle i32 %34, 100000
  br i1 %35, label %37, label %36

36:                                               ; preds = %33
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  br label %44

37:                                               ; preds = %33
  %38 = load i32, ptr %4, align 4, !tbaa !5
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds [100001 x i32], ptr @criba, i64 0, i64 %39
  store i32 2, ptr %40, align 4, !tbaa !5
  br label %41

41:                                               ; preds = %37
  %42 = load i32, ptr %4, align 4, !tbaa !5
  %43 = add nsw i32 %42, 2
  store i32 %43, ptr %4, align 4, !tbaa !5
  br label %33, !llvm.loop !12

44:                                               ; preds = %36
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  store i32 7, ptr %5, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  store i32 0, ptr %6, align 4, !tbaa !5
  br label %45

45:                                               ; preds = %84, %44
  %46 = load i32, ptr %5, align 4, !tbaa !5
  %47 = load i32, ptr %5, align 4, !tbaa !5
  %48 = mul nsw i32 %46, %47
  %49 = icmp sle i32 %48, 100000
  br i1 %49, label %51, label %50

50:                                               ; preds = %45
  store i32 11, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  br label %93

51:                                               ; preds = %45
  %52 = load i32, ptr %5, align 4, !tbaa !5
  %53 = sext i32 %52 to i64
  %54 = getelementptr inbounds [100001 x i32], ptr @criba, i64 0, i64 %53
  %55 = load i32, ptr %54, align 4, !tbaa !5
  %56 = icmp ne i32 %55, 0
  br i1 %56, label %83, label %57

57:                                               ; preds = %51
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  %58 = load i32, ptr %5, align 4, !tbaa !5
  %59 = load i32, ptr %5, align 4, !tbaa !5
  %60 = mul nsw i32 %58, %59
  store i32 %60, ptr %8, align 4, !tbaa !5
  br label %61

61:                                               ; preds = %77, %57
  %62 = load i32, ptr %8, align 4, !tbaa !5
  %63 = icmp sle i32 %62, 100000
  br i1 %63, label %65, label %64

64:                                               ; preds = %61
  store i32 14, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  br label %82

65:                                               ; preds = %61
  %66 = load i32, ptr %8, align 4, !tbaa !5
  %67 = sext i32 %66 to i64
  %68 = getelementptr inbounds [100001 x i32], ptr @criba, i64 0, i64 %67
  %69 = load i32, ptr %68, align 4, !tbaa !5
  %70 = icmp ne i32 %69, 0
  br i1 %70, label %76, label %71

71:                                               ; preds = %65
  %72 = load i32, ptr %5, align 4, !tbaa !5
  %73 = load i32, ptr %8, align 4, !tbaa !5
  %74 = sext i32 %73 to i64
  %75 = getelementptr inbounds [100001 x i32], ptr @criba, i64 0, i64 %74
  store i32 %72, ptr %75, align 4, !tbaa !5
  br label %76

76:                                               ; preds = %71, %65
  br label %77

77:                                               ; preds = %76
  %78 = load i32, ptr %5, align 4, !tbaa !5
  %79 = shl i32 %78, 1
  %80 = load i32, ptr %8, align 4, !tbaa !5
  %81 = add nsw i32 %80, %79
  store i32 %81, ptr %8, align 4, !tbaa !5
  br label %61, !llvm.loop !13

82:                                               ; preds = %64
  br label %83

83:                                               ; preds = %82, %51
  br label %84

84:                                               ; preds = %83
  %85 = load i32, ptr %6, align 4, !tbaa !5
  %86 = add nsw i32 %85, 1
  store i32 %86, ptr %6, align 4, !tbaa !5
  %87 = and i32 %85, 7
  %88 = sext i32 %87 to i64
  %89 = getelementptr inbounds [8 x i32], ptr %1, i64 0, i64 %88
  %90 = load i32, ptr %89, align 4, !tbaa !5
  %91 = load i32, ptr %5, align 4, !tbaa !5
  %92 = add nsw i32 %91, %90
  store i32 %92, ptr %5, align 4, !tbaa !5
  br label %45, !llvm.loop !14

93:                                               ; preds = %50
  call void @llvm.lifetime.end.p0(i64 32, 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: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #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 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 = { nocallback nofree 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 = !{!"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}
!13 = distinct !{!13, !10}
!14 = distinct !{!14, !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"

@criba = external dso_local local_unnamed_addr global [100001 x i32], align 16
@__const._Z10crearcribav.w = external hidden unnamed_addr constant [8 x i32], align 16

; Function Attrs: mustprogress nofree norecurse nosync nounwind memory(readwrite, argmem: none, inaccessiblemem: none) uwtable
define dso_local void @_Z10crearcribav() local_unnamed_addr #0 {
  br label %1

1:                                                ; preds = %1, %0
  %indvars.iv = phi i64 [ 25, %0 ], [ %indvars.iv.next.1, %1 ]
  %2 = getelementptr inbounds [100001 x i32], ptr @criba, i64 0, i64 %indvars.iv
  store i32 5, ptr %2, align 4, !tbaa !5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 10
  %3 = getelementptr inbounds [100001 x i32], ptr @criba, i64 0, i64 %indvars.iv.next
  store i32 5, ptr %3, align 4, !tbaa !5
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 20
  %4 = icmp ult i64 %indvars.iv, 99981
  br i1 %4, label %1, label %.preheader31, !llvm.loop !9

.preheader31:                                     ; preds = %1, %.preheader31
  %indvars.iv40 = phi i64 [ %indvars.iv.next41.1, %.preheader31 ], [ 9, %1 ]
  %5 = getelementptr inbounds [100001 x i32], ptr @criba, i64 0, i64 %indvars.iv40
  store i32 3, ptr %5, align 4, !tbaa !5
  %indvars.iv.next41 = add nuw nsw i64 %indvars.iv40, 6
  %6 = getelementptr inbounds [100001 x i32], ptr @criba, i64 0, i64 %indvars.iv.next41
  store i32 3, ptr %6, align 4, !tbaa !5
  %indvars.iv.next41.1 = add nuw nsw i64 %indvars.iv40, 12
  %7 = icmp ult i64 %indvars.iv40, 99989
  br i1 %7, label %.preheader31, label %.preheader30, !llvm.loop !11

.preheader30:                                     ; preds = %.preheader31, %.preheader30.7
  %indvars.iv43 = phi i64 [ %indvars.iv.next44.7, %.preheader30.7 ], [ 4, %.preheader31 ]
  %8 = getelementptr inbounds [100001 x i32], ptr @criba, i64 0, i64 %indvars.iv43
  store i32 2, ptr %8, align 16, !tbaa !5
  %indvars.iv.next44 = or disjoint i64 %indvars.iv43, 2
  %9 = getelementptr inbounds [100001 x i32], ptr @criba, i64 0, i64 %indvars.iv.next44
  store i32 2, ptr %9, align 8, !tbaa !5
  %indvars.iv.next44.1 = add nuw nsw i64 %indvars.iv43, 4
  %10 = getelementptr inbounds [100001 x i32], ptr @criba, i64 0, i64 %indvars.iv.next44.1
  store i32 2, ptr %10, align 16, !tbaa !5
  %indvars.iv.next44.2 = add nuw nsw i64 %indvars.iv43, 6
  %11 = getelementptr inbounds [100001 x i32], ptr @criba, i64 0, i64 %indvars.iv.next44.2
  store i32 2, ptr %11, align 8, !tbaa !5
  %indvars.iv.next44.3 = add nuw nsw i64 %indvars.iv43, 8
  %12 = getelementptr inbounds [100001 x i32], ptr @criba, i64 0, i64 %indvars.iv.next44.3
  store i32 2, ptr %12, align 16, !tbaa !5
  %indvars.iv.next44.4 = add nuw nsw i64 %indvars.iv43, 10
  %13 = getelementptr inbounds [100001 x i32], ptr @criba, i64 0, i64 %indvars.iv.next44.4
  store i32 2, ptr %13, align 8, !tbaa !5
  %indvars.iv.next44.5 = add nuw nsw i64 %indvars.iv43, 12
  %14 = getelementptr inbounds [100001 x i32], ptr @criba, i64 0, i64 %indvars.iv.next44.5
  store i32 2, ptr %14, align 16, !tbaa !5
  %15 = icmp ult i64 %indvars.iv43, 99987
  br i1 %15, label %.preheader30.7, label %.preheader29, !llvm.loop !12

.preheader30.7:                                   ; preds = %.preheader30
  %indvars.iv.next44.6 = add nuw nsw i64 %indvars.iv43, 14
  %16 = getelementptr inbounds [100001 x i32], ptr @criba, i64 0, i64 %indvars.iv.next44.6
  store i32 2, ptr %16, align 8, !tbaa !5
  %indvars.iv.next44.7 = add nuw nsw i64 %indvars.iv43, 16
  br label %.preheader30

17:                                               ; preds = %.loopexit
  ret void

.preheader29:                                     ; preds = %.preheader30, %.loopexit
  %18 = phi i32 [ %37, %.loopexit ], [ 49, %.preheader30 ]
  %.02238 = phi i32 [ %31, %.loopexit ], [ 0, %.preheader30 ]
  %.02336 = phi i32 [ %36, %.loopexit ], [ 7, %.preheader30 ]
  %19 = sext i32 %.02336 to i64
  %20 = getelementptr inbounds [100001 x i32], ptr @criba, i64 0, i64 %19
  %21 = load i32, ptr %20, align 4, !tbaa !5
  %.not = icmp eq i32 %21, 0
  br i1 %.not, label %.lr.ph, label %.loopexit

.lr.ph:                                           ; preds = %.preheader29
  %22 = shl i32 %.02336, 1
  %23 = zext nneg i32 %18 to i64
  %24 = sext i32 %22 to i64
  br label %25

25:                                               ; preds = %.lr.ph, %29
  %indvars.iv46 = phi i64 [ %23, %.lr.ph ], [ %indvars.iv.next47, %29 ]
  %26 = getelementptr inbounds [100001 x i32], ptr @criba, i64 0, i64 %indvars.iv46
  %27 = load i32, ptr %26, align 4, !tbaa !5
  %.not28 = icmp eq i32 %27, 0
  br i1 %.not28, label %28, label %29

28:                                               ; preds = %25
  store i32 %.02336, ptr %26, align 4, !tbaa !5
  br label %29

29:                                               ; preds = %25, %28
  %indvars.iv.next47 = add nsw i64 %indvars.iv46, %24
  %30 = icmp slt i64 %indvars.iv.next47, 100001
  br i1 %30, label %25, label %.loopexit, !llvm.loop !13

.loopexit:                                        ; preds = %29, %.preheader29
  %31 = add nuw nsw i32 %.02238, 1
  %32 = and i32 %.02238, 7
  %33 = zext nneg i32 %32 to i64
  %34 = getelementptr inbounds [8 x i32], ptr @__const._Z10crearcribav.w, i64 0, i64 %33
  %35 = load i32, ptr %34, align 4, !tbaa !5
  %36 = add nsw i32 %35, %.02336
  %37 = mul nsw i32 %36, %36
  %38 = icmp ult i32 %37, 100001
  br i1 %38, label %.preheader29, label %17, !llvm.loop !14
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind memory(readwrite, argmem: none, inaccessiblemem: none) 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 = !{!"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}
!13 = distinct !{!13, !10}
!14 = distinct !{!14, !10}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass