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

; 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.0" = type { ptr, i64 }

@.str.1 = external hidden unnamed_addr constant [69 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [19 x i8], align 1
@__PRETTY_FUNCTION__._ZN3abm6ColumnIdE8PopulateEmmm = external hidden unnamed_addr constant [72 x i8], align 1

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

; 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 nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN3abm6ColumnIdE8PopulateEmmm(ptr noundef nonnull align 8 dereferenceable(16) %0, i64 noundef %1, i64 noundef %2, i64 noundef %3) #2 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 %7, align 8, !tbaa !9
  %18 = load i64, ptr %6, align 8, !tbaa !9
  %19 = sub i64 %17, %18
  %20 = load i64, ptr %8, align 8, !tbaa !9
  %21 = icmp uge i64 %19, %20
  br i1 %21, label %22, label %23

22:                                               ; preds = %4
  br label %25

23:                                               ; preds = %4
  call void @__assert_fail(ptr noundef @.str.3, ptr noundef @.str.1, i32 noundef 70, ptr noundef @__PRETTY_FUNCTION__._ZN3abm6ColumnIdE8PopulateEmmm) #3
  unreachable

24:                                               ; No predecessors!
  br label %25

25:                                               ; preds = %24, %22
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  %26 = load i64, ptr %7, align 8, !tbaa !9
  %27 = load i64, ptr %6, align 8, !tbaa !9
  %28 = sub i64 %26, %27
  %29 = load i64, ptr %8, align 8, !tbaa !9
  %30 = udiv i64 %28, %29
  store i64 %30, ptr %9, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  %31 = load i64, ptr %7, align 8, !tbaa !9
  %32 = load i64, ptr %6, align 8, !tbaa !9
  %33 = sub i64 %31, %32
  %34 = load i64, ptr %8, align 8, !tbaa !9
  %35 = urem i64 %33, %34
  store i64 %35, 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
  %36 = load i64, ptr %6, align 8, !tbaa !9
  store i64 %36, ptr %12, align 8, !tbaa !9
  br label %37

37:                                               ; preds = %70, %25
  %38 = load i64, ptr %11, align 8, !tbaa !9
  %39 = load i64, ptr %8, align 8, !tbaa !9
  %40 = icmp ult i64 %38, %39
  br i1 %40, label %42, label %41

41:                                               ; preds = %37
  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 %73

42:                                               ; preds = %37
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #4
  %43 = load i64, ptr %12, align 8, !tbaa !9
  %44 = load i64, ptr %9, align 8, !tbaa !9
  %45 = add i64 %43, %44
  %46 = load i64, ptr %11, align 8, !tbaa !9
  %47 = load i64, ptr %10, align 8, !tbaa !9
  %48 = icmp ult i64 %46, %47
  %49 = zext i1 %48 to i64
  %50 = add i64 %45, %49
  store i64 %50, ptr %14, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #4
  %51 = load i64, ptr %12, align 8, !tbaa !9
  store i64 %51, ptr %15, align 8, !tbaa !9
  br label %52

52:                                               ; preds = %65, %42
  %53 = load i64, ptr %15, align 8, !tbaa !9
  %54 = load i64, ptr %14, align 8, !tbaa !9
  %55 = icmp ult i64 %53, %54
  br i1 %55, label %57, label %56

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

57:                                               ; preds = %52
  %58 = load i64, ptr %11, align 8, !tbaa !9
  %59 = uitofp i64 %58 to double
  %60 = fadd double %59, 1.100000e+00
  %61 = getelementptr inbounds %"class.abm::Column.0", ptr %16, i32 0, i32 0
  %62 = load ptr, ptr %61, align 8, !tbaa !11
  %63 = load i64, ptr %15, align 8, !tbaa !9
  %64 = getelementptr inbounds double, ptr %62, i64 %63
  store double %60, ptr %64, align 8, !tbaa !13
  br label %65

65:                                               ; preds = %57
  %66 = load i64, ptr %15, align 8, !tbaa !9
  %67 = add i64 %66, 1
  store i64 %67, ptr %15, align 8, !tbaa !9
  br label %52, !llvm.loop !15

68:                                               ; preds = %56
  %69 = load i64, ptr %14, align 8, !tbaa !9
  store i64 %69, ptr %12, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #4
  br label %70

70:                                               ; preds = %68
  %71 = load i64, ptr %11, align 8, !tbaa !9
  %72 = add i64 %71, 1
  store i64 %72, ptr %11, align 8, !tbaa !9
  br label %37, !llvm.loop !17

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

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 = { 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 = !{!"_ZTSN3abm6ColumnIdEE", !6, i64 0, !10, i64 8}
!13 = !{!14, !14, i64 0}
!14 = !{!"double", !7, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = distinct !{!17, !16}


; 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.1 = external hidden unnamed_addr constant [69 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [19 x i8], align 1
@__PRETTY_FUNCTION__._ZN3abm6ColumnIdE8PopulateEmmm = external hidden unnamed_addr constant [72 x i8], align 1

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

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

6:                                                ; preds = %4
  tail call void @__assert_fail(ptr noundef nonnull @.str.3, ptr noundef nonnull @.str.1, i32 noundef 70, ptr noundef nonnull @__PRETTY_FUNCTION__._ZN3abm6ColumnIdE8PopulateEmmm) #3
  unreachable

7:                                                ; preds = %4
  %8 = udiv i64 %5, %3
  %9 = urem i64 %5, %3
  %10 = load ptr, ptr %0, align 8
  %umax = tail call i64 @llvm.umax.i64(i64 %3, i64 1)
  br label %12

11:                                               ; preds = %._crit_edge
  ret void

12:                                               ; preds = %7, %._crit_edge
  %.02431 = phi i64 [ 0, %7 ], [ %25, %._crit_edge ]
  %.02530 = phi i64 [ %1, %7 ], [ %16, %._crit_edge ]
  %13 = add i64 %.02530, %8
  %14 = icmp ult i64 %.02431, %9
  %15 = zext i1 %14 to i64
  %16 = add i64 %13, %15
  %17 = icmp ult i64 %.02530, %16
  br i1 %17, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %12
  %18 = uitofp i64 %.02431 to double
  %19 = fadd double %18, 1.100000e+00
  %20 = add i64 %8, %15
  %min.iters.check = icmp ult i64 %20, 4
  br i1 %min.iters.check, label %scalar.ph.preheader, label %vector.ph

scalar.ph.preheader:                              ; preds = %middle.block, %.lr.ph
  %.029.ph = phi i64 [ %.02530, %.lr.ph ], [ %ind.end, %middle.block ]
  br label %scalar.ph

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

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

middle.block:                                     ; preds = %vector.body
  %cmp.n = icmp eq i64 %20, %n.vec
  br i1 %cmp.n, label %._crit_edge, label %scalar.ph.preheader

._crit_edge:                                      ; preds = %scalar.ph, %middle.block, %12
  %25 = add nuw i64 %.02431, 1
  %exitcond.not = icmp eq i64 %25, %umax
  br i1 %exitcond.not, label %11, label %12, !llvm.loop !13

scalar.ph:                                        ; preds = %scalar.ph.preheader, %scalar.ph
  %.029 = phi i64 [ %27, %scalar.ph ], [ %.029.ph, %scalar.ph.preheader ]
  %26 = getelementptr inbounds double, ptr %10, i64 %.029
  store double %19, ptr %26, align 8, !tbaa !5
  %27 = add nuw i64 %.029, 1
  %28 = icmp ult i64 %27, %16
  br i1 %28, label %scalar.ph, label %._crit_edge, !llvm.loop !14
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.umax.i64(i64, i64) #2

attributes #0 = { 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 #1 = { 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 #2 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #3 = { 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 = !{!"double", !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,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopLoadEliminationPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,LoopVectorizePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass