; LLVM IR from pingcap/tidb-bench :: abm/src/main.ll (ZN3abm6ColumnIlE8PopulateEmmm)

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

%"class.abm::Column" = type { ptr, i64 }

@.str = external hidden unnamed_addr constant [8 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [69 x i8], align 1
@__PRETTY_FUNCTION__._ZN3abm6ColumnIlE8PopulateEmmm = external hidden unnamed_addr constant [68 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [19 x i8], align 1

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN3abm6ColumnIlE8PopulateEmmm(ptr noundef nonnull align 8 dereferenceable(16) %0, i64 noundef %1, i64 noundef %2, i64 noundef %3) #0 align 2 {
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  %9 = alloca i64, align 8
  %10 = alloca i64, align 8
  %11 = alloca i64, align 8
  %12 = alloca i64, align 8
  %13 = alloca i32, align 4
  %14 = alloca i64, align 8
  %15 = alloca i64, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i64 %1, ptr %6, align 8, !tbaa !9
  store i64 %2, ptr %7, align 8, !tbaa !9
  store i64 %3, ptr %8, align 8, !tbaa !9
  %16 = load ptr, ptr %5, align 8
  %17 = load i64, ptr %8, align 8, !tbaa !9
  %18 = icmp ugt i64 %17, 0
  br i1 %18, label %19, label %20

19:                                               ; preds = %4
  br label %22

20:                                               ; preds = %4
  call void @__assert_fail(ptr noundef @.str, ptr noundef @.str.1, i32 noundef 54, ptr noundef @__PRETTY_FUNCTION__._ZN3abm6ColumnIlE8PopulateEmmm) #3
  unreachable

21:                                               ; No predecessors!
  br label %22

22:                                               ; preds = %21, %19
  %23 = load i64, ptr %8, align 8, !tbaa !9
  %24 = load i64, ptr %7, align 8, !tbaa !9
  %25 = load i64, ptr %6, align 8, !tbaa !9
  %26 = sub i64 %24, %25
  %27 = icmp ule i64 %23, %26
  br i1 %27, label %28, label %29

28:                                               ; preds = %22
  br label %31

29:                                               ; preds = %22
  call void @__assert_fail(ptr noundef @.str.2, ptr noundef @.str.1, i32 noundef 55, ptr noundef @__PRETTY_FUNCTION__._ZN3abm6ColumnIlE8PopulateEmmm) #3
  unreachable

30:                                               ; No predecessors!
  br label %31

31:                                               ; preds = %30, %28
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  %32 = load i64, ptr %7, align 8, !tbaa !9
  %33 = load i64, ptr %6, align 8, !tbaa !9
  %34 = sub i64 %32, %33
  %35 = load i64, ptr %8, align 8, !tbaa !9
  %36 = udiv i64 %34, %35
  store i64 %36, ptr %9, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  %37 = load i64, ptr %7, align 8, !tbaa !9
  %38 = load i64, ptr %6, align 8, !tbaa !9
  %39 = sub i64 %37, %38
  %40 = load i64, ptr %8, align 8, !tbaa !9
  %41 = urem i64 %39, %40
  store i64 %41, ptr %10, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  store i64 0, ptr %11, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #4
  %42 = load i64, ptr %6, align 8, !tbaa !9
  store i64 %42, ptr %12, align 8, !tbaa !9
  br label %43

43:                                               ; preds = %75, %31
  %44 = load i64, ptr %11, align 8, !tbaa !9
  %45 = load i64, ptr %8, align 8, !tbaa !9
  %46 = icmp ult i64 %44, %45
  br i1 %46, label %48, label %47

47:                                               ; preds = %43
  store i32 2, ptr %13, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  br label %78

48:                                               ; preds = %43
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #4
  %49 = load i64, ptr %12, align 8, !tbaa !9
  %50 = load i64, ptr %9, align 8, !tbaa !9
  %51 = add i64 %49, %50
  %52 = load i64, ptr %11, align 8, !tbaa !9
  %53 = load i64, ptr %10, align 8, !tbaa !9
  %54 = icmp ult i64 %52, %53
  %55 = zext i1 %54 to i64
  %56 = add i64 %51, %55
  store i64 %56, ptr %14, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #4
  %57 = load i64, ptr %12, align 8, !tbaa !9
  store i64 %57, ptr %15, align 8, !tbaa !9
  br label %58

58:                                               ; preds = %70, %48
  %59 = load i64, ptr %15, align 8, !tbaa !9
  %60 = load i64, ptr %14, align 8, !tbaa !9
  %61 = icmp ult i64 %59, %60
  br i1 %61, label %63, label %62

62:                                               ; preds = %58
  store i32 5, ptr %13, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #4
  br label %73

63:                                               ; preds = %58
  %64 = load i64, ptr %11, align 8, !tbaa !9
  %65 = add i64 %64, 1
  %66 = getelementptr inbounds %"class.abm::Column", ptr %16, i32 0, i32 0
  %67 = load ptr, ptr %66, align 8, !tbaa !11
  %68 = load i64, ptr %15, align 8, !tbaa !9
  %69 = getelementptr inbounds i64, ptr %67, i64 %68
  store i64 %65, ptr %69, align 8, !tbaa !9
  br label %70

70:                                               ; preds = %63
  %71 = load i64, ptr %15, align 8, !tbaa !9
  %72 = add i64 %71, 1
  store i64 %72, ptr %15, align 8, !tbaa !9
  br label %58, !llvm.loop !13

73:                                               ; preds = %62
  %74 = load i64, ptr %14, align 8, !tbaa !9
  store i64 %74, ptr %12, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #4
  br label %75

75:                                               ; preds = %73
  %76 = load i64, ptr %11, align 8, !tbaa !9
  %77 = add i64 %76, 1
  store i64 %77, ptr %11, align 8, !tbaa !9
  br label %43, !llvm.loop !15

78:                                               ; preds = %47
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  ret void
}

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #1

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

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

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 = { noreturn 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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { noreturn nounwind }
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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !6, i64 0}
!12 = !{!"_ZTSN3abm6ColumnIlEE", !6, i64 0, !10, i64 8}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !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"

@.str = external hidden unnamed_addr constant [8 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [69 x i8], align 1
@__PRETTY_FUNCTION__._ZN3abm6ColumnIlE8PopulateEmmm = external hidden unnamed_addr constant [68 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [19 x i8], align 1

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN3abm6ColumnIlE8PopulateEmmm(ptr nocapture noundef nonnull readonly align 8 dereferenceable(16) %0, i64 noundef %1, i64 noundef %2, i64 noundef %3) local_unnamed_addr #0 align 2 {
  %.not = icmp eq i64 %3, 0
  br i1 %.not, label %5, label %6

5:                                                ; preds = %4
  tail call void @__assert_fail(ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 54, ptr noundef nonnull @__PRETTY_FUNCTION__._ZN3abm6ColumnIlE8PopulateEmmm) #2
  unreachable

6:                                                ; preds = %4
  %7 = sub i64 %2, %1
  %.not30 = icmp ult i64 %7, %3
  br i1 %.not30, label %8, label %9

8:                                                ; preds = %6
  tail call void @__assert_fail(ptr noundef nonnull @.str.2, ptr noundef nonnull @.str.1, i32 noundef 55, ptr noundef nonnull @__PRETTY_FUNCTION__._ZN3abm6ColumnIlE8PopulateEmmm) #2
  unreachable

9:                                                ; preds = %6
  %10 = udiv i64 %7, %3
  %11 = urem i64 %7, %3
  %12 = load ptr, ptr %0, align 8
  br label %14

13:                                               ; preds = %._crit_edge
  ret void

14:                                               ; preds = %9, %._crit_edge
  %.02533 = phi i64 [ 0, %9 ], [ %20, %._crit_edge ]
  %.02632 = phi i64 [ %1, %9 ], [ %18, %._crit_edge ]
  %15 = add i64 %.02632, %10
  %16 = icmp ult i64 %.02533, %11
  %17 = zext i1 %16 to i64
  %18 = add i64 %15, %17
  %19 = icmp ult i64 %.02632, %18
  %20 = add nuw i64 %.02533, 1
  br i1 %19, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %14
  %21 = add i64 %10, %17
  %min.iters.check = icmp ult i64 %21, 4
  br i1 %min.iters.check, label %.lr.ph.preheader34, label %vector.ph

.lr.ph.preheader34:                               ; preds = %middle.block, %.lr.ph.preheader
  %.031.ph = phi i64 [ %.02632, %.lr.ph.preheader ], [ %ind.end, %middle.block ]
  br label %.lr.ph

vector.ph:                                        ; preds = %.lr.ph.preheader
  %n.vec = and i64 %21, -4
  %ind.end = add i64 %.02632, %n.vec
  %broadcast.splatinsert = insertelement <2 x i64> poison, i64 %20, i64 0
  %broadcast.splat = shufflevector <2 x i64> %broadcast.splatinsert, <2 x i64> poison, <2 x i32> zeroinitializer
  %22 = getelementptr i64, ptr %12, i64 %.02632
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %23 = getelementptr i64, ptr %22, i64 %index
  %24 = getelementptr inbounds i8, ptr %23, i64 16
  store <2 x i64> %broadcast.splat, ptr %23, align 8, !tbaa !5
  store <2 x i64> %broadcast.splat, ptr %24, align 8, !tbaa !5
  %index.next = add nuw i64 %index, 4
  %25 = icmp eq i64 %index.next, %n.vec
  br i1 %25, label %middle.block, label %vector.body, !llvm.loop !9

middle.block:                                     ; preds = %vector.body
  %cmp.n = icmp eq i64 %21, %n.vec
  br i1 %cmp.n, label %._crit_edge, label %.lr.ph.preheader34

._crit_edge:                                      ; preds = %.lr.ph, %middle.block, %14
  %exitcond.not = icmp eq i64 %20, %3
  br i1 %exitcond.not, label %13, label %14, !llvm.loop !13

.lr.ph:                                           ; preds = %.lr.ph.preheader34, %.lr.ph
  %.031 = phi i64 [ %27, %.lr.ph ], [ %.031.ph, %.lr.ph.preheader34 ]
  %26 = getelementptr inbounds i64, ptr %12, i64 %.031
  store i64 %20, ptr %26, align 8, !tbaa !5
  %27 = add nuw i64 %.031, 1
  %28 = icmp ult i64 %27, %18
  br i1 %28, label %.lr.ph, label %._crit_edge, !llvm.loop !14
}

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr 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 = { noreturn 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 = { noreturn 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++ TBAA"}
!9 = distinct !{!9, !10, !11, !12}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!"llvm.loop.isvectorized", i32 1}
!12 = !{!"llvm.loop.unroll.runtime.disable"}
!13 = distinct !{!13, !10}
!14 = distinct !{!14, !10, !12, !11}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopLoadEliminationPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,LoopVectorizePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass