; LLVM IR from QiaoLiuHit/LSOTB-TIR :: vlfeat-0.9.19/vl (ikmeans)

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

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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @vl_ikm_push_one(ptr noundef %0, ptr noundef %1, i64 noundef %2, i64 noundef %3) #1 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, 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 i32, align 4
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store i64 %2, ptr %7, align 8, !tbaa !9
  store i64 %3, ptr %8, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #2
  store i64 -1, ptr %11, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #2
  store i32 0, ptr %12, align 4, !tbaa !11
  store i64 0, ptr %10, align 8, !tbaa !9
  br label %15

15:                                               ; preds = %58, %4
  %16 = load i64, ptr %10, align 8, !tbaa !9
  %17 = load i64, ptr %8, align 8, !tbaa !9
  %18 = icmp ult i64 %16, %17
  br i1 %18, label %19, label %61

19:                                               ; preds = %15
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #2
  store i32 0, ptr %13, align 4, !tbaa !11
  store i64 0, ptr %9, align 8, !tbaa !9
  br label %20

20:                                               ; preds = %44, %19
  %21 = load i64, ptr %9, align 8, !tbaa !9
  %22 = load i64, ptr %7, align 8, !tbaa !9
  %23 = icmp ult i64 %21, %22
  br i1 %23, label %24, label %47

24:                                               ; preds = %20
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #2
  %25 = load ptr, ptr %6, align 8, !tbaa !5
  %26 = load i64, ptr %9, align 8, !tbaa !9
  %27 = getelementptr inbounds i8, ptr %25, i64 %26
  %28 = load i8, ptr %27, align 1, !tbaa !13
  %29 = zext i8 %28 to i32
  %30 = load ptr, ptr %5, align 8, !tbaa !5
  %31 = load i64, ptr %10, align 8, !tbaa !9
  %32 = load i64, ptr %7, align 8, !tbaa !9
  %33 = mul i64 %31, %32
  %34 = load i64, ptr %9, align 8, !tbaa !9
  %35 = add i64 %33, %34
  %36 = getelementptr inbounds i32, ptr %30, i64 %35
  %37 = load i32, ptr %36, align 4, !tbaa !11
  %38 = sub nsw i32 %29, %37
  store i32 %38, ptr %14, align 4, !tbaa !11
  %39 = load i32, ptr %14, align 4, !tbaa !11
  %40 = load i32, ptr %14, align 4, !tbaa !11
  %41 = mul nsw i32 %39, %40
  %42 = load i32, ptr %13, align 4, !tbaa !11
  %43 = add nsw i32 %42, %41
  store i32 %43, ptr %13, align 4, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #2
  br label %44

44:                                               ; preds = %24
  %45 = load i64, ptr %9, align 8, !tbaa !9
  %46 = add i64 %45, 1
  store i64 %46, ptr %9, align 8, !tbaa !9
  br label %20, !llvm.loop !14

47:                                               ; preds = %20
  %48 = load i64, ptr %11, align 8, !tbaa !9
  %49 = icmp eq i64 %48, -1
  br i1 %49, label %54, label %50

50:                                               ; preds = %47
  %51 = load i32, ptr %13, align 4, !tbaa !11
  %52 = load i32, ptr %12, align 4, !tbaa !11
  %53 = icmp slt i32 %51, %52
  br i1 %53, label %54, label %57

54:                                               ; preds = %50, %47
  %55 = load i64, ptr %10, align 8, !tbaa !9
  store i64 %55, ptr %11, align 8, !tbaa !9
  %56 = load i32, ptr %13, align 4, !tbaa !11
  store i32 %56, ptr %12, align 4, !tbaa !11
  br label %57

57:                                               ; preds = %54, %50
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #2
  br label %58

58:                                               ; preds = %57
  %59 = load i64, ptr %10, align 8, !tbaa !9
  %60 = add i64 %59, 1
  store i64 %60, ptr %10, align 8, !tbaa !9
  br label %15, !llvm.loop !16

61:                                               ; preds = %15
  %62 = load i64, ptr %11, align 8, !tbaa !9
  %63 = trunc i64 %62 to i32
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #2
  ret i32 %63
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 = { 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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!7, !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = distinct !{!16, !15}


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

; Function Attrs: nofree norecurse nosync nounwind memory(argmem: read) uwtable
define dso_local i32 @vl_ikm_push_one(ptr nocapture noundef readonly %0, ptr nocapture noundef readonly %1, i64 noundef %2, i64 noundef %3) local_unnamed_addr #0 {
  %.not = icmp eq i64 %3, 0
  br i1 %.not, label %._crit_edge31, label %.preheader.lr.ph

.preheader.lr.ph:                                 ; preds = %4
  %.not33 = icmp eq i64 %2, 0
  br i1 %.not33, label %.preheader.preheader, label %.preheader.us.preheader

.preheader.us.preheader:                          ; preds = %.preheader.lr.ph
  %min.iters.check = icmp ult i64 %2, 8
  %n.vec = and i64 %2, -8
  %cmp.n = icmp eq i64 %n.vec, %2
  br label %.preheader.us

.preheader.preheader:                             ; preds = %.preheader.lr.ph
  %xtraiter = and i64 %3, 7
  %5 = icmp ult i64 %3, 8
  br i1 %5, label %._crit_edge31.loopexit.unr-lcssa, label %.preheader.preheader.new

.preheader.preheader.new:                         ; preds = %.preheader.preheader
  %unroll_iter = and i64 %3, -8
  br label %.preheader

.preheader.us:                                    ; preds = %.preheader.us.preheader, %._crit_edge.us
  %.02130.us = phi i32 [ %.1.us, %._crit_edge.us ], [ 0, %.preheader.us.preheader ]
  %.02229.us = phi i64 [ %.123.us, %._crit_edge.us ], [ -1, %.preheader.us.preheader ]
  %.02428.us = phi i64 [ %33, %._crit_edge.us ], [ 0, %.preheader.us.preheader ]
  %6 = mul i64 %.02428.us, %2
  %7 = getelementptr i32, ptr %0, i64 %6
  br i1 %min.iters.check, label %scalar.ph.preheader, label %vector.body

vector.body:                                      ; preds = %.preheader.us, %vector.body
  %index = phi i64 [ %index.next, %vector.body ], [ 0, %.preheader.us ]
  %vec.phi = phi <4 x i32> [ %18, %vector.body ], [ zeroinitializer, %.preheader.us ]
  %vec.phi39 = phi <4 x i32> [ %19, %vector.body ], [ zeroinitializer, %.preheader.us ]
  %8 = getelementptr inbounds i8, ptr %1, i64 %index
  %9 = getelementptr inbounds i8, ptr %8, i64 4
  %wide.load = load <4 x i8>, ptr %8, align 1, !tbaa !5
  %wide.load40 = load <4 x i8>, ptr %9, align 1, !tbaa !5
  %10 = zext <4 x i8> %wide.load to <4 x i32>
  %11 = zext <4 x i8> %wide.load40 to <4 x i32>
  %12 = getelementptr i32, ptr %7, i64 %index
  %13 = getelementptr i8, ptr %12, i64 16
  %wide.load41 = load <4 x i32>, ptr %12, align 4, !tbaa !8
  %wide.load42 = load <4 x i32>, ptr %13, align 4, !tbaa !8
  %14 = sub nsw <4 x i32> %10, %wide.load41
  %15 = sub nsw <4 x i32> %11, %wide.load42
  %16 = mul nsw <4 x i32> %14, %14
  %17 = mul nsw <4 x i32> %15, %15
  %18 = add <4 x i32> %16, %vec.phi
  %19 = add <4 x i32> %17, %vec.phi39
  %index.next = add nuw i64 %index, 8
  %20 = icmp eq i64 %index.next, %n.vec
  br i1 %20, label %middle.block, label %vector.body, !llvm.loop !10

middle.block:                                     ; preds = %vector.body
  %bin.rdx = add <4 x i32> %19, %18
  %21 = tail call i32 @llvm.vector.reduce.add.v4i32(<4 x i32> %bin.rdx)
  br i1 %cmp.n, label %._crit_edge.us, label %scalar.ph.preheader

scalar.ph.preheader:                              ; preds = %middle.block, %.preheader.us
  %.027.us.ph = phi i64 [ 0, %.preheader.us ], [ %n.vec, %middle.block ]
  %.02026.us.ph = phi i32 [ 0, %.preheader.us ], [ %21, %middle.block ]
  br label %scalar.ph

scalar.ph:                                        ; preds = %scalar.ph.preheader, %scalar.ph
  %.027.us = phi i64 [ %30, %scalar.ph ], [ %.027.us.ph, %scalar.ph.preheader ]
  %.02026.us = phi i32 [ %29, %scalar.ph ], [ %.02026.us.ph, %scalar.ph.preheader ]
  %22 = getelementptr inbounds i8, ptr %1, i64 %.027.us
  %23 = load i8, ptr %22, align 1, !tbaa !5
  %24 = zext i8 %23 to i32
  %25 = getelementptr i32, ptr %7, i64 %.027.us
  %26 = load i32, ptr %25, align 4, !tbaa !8
  %27 = sub nsw i32 %24, %26
  %28 = mul nsw i32 %27, %27
  %29 = add nuw nsw i32 %28, %.02026.us
  %30 = add nuw i64 %.027.us, 1
  %exitcond.not = icmp eq i64 %30, %2
  br i1 %exitcond.not, label %._crit_edge.us, label %scalar.ph, !llvm.loop !14

._crit_edge.us:                                   ; preds = %scalar.ph, %middle.block
  %.lcssa = phi i32 [ %21, %middle.block ], [ %29, %scalar.ph ]
  %31 = icmp eq i64 %.02229.us, -1
  %32 = icmp slt i32 %.lcssa, %.02130.us
  %or.cond.us = select i1 %31, i1 true, i1 %32
  %.123.us = select i1 %or.cond.us, i64 %.02428.us, i64 %.02229.us
  %.1.us = select i1 %or.cond.us, i32 %.lcssa, i32 %.02130.us
  %33 = add nuw i64 %.02428.us, 1
  %exitcond35.not = icmp eq i64 %33, %3
  br i1 %exitcond35.not, label %._crit_edge31, label %.preheader.us, !llvm.loop !15

.preheader:                                       ; preds = %.preheader, %.preheader.preheader.new
  %.02229 = phi i64 [ -1, %.preheader.preheader.new ], [ %.123, %.preheader ]
  %.02428 = phi i64 [ 0, %.preheader.preheader.new ], [ %35, %.preheader ]
  %niter = phi i64 [ 0, %.preheader.preheader.new ], [ %niter.next.7, %.preheader ]
  %34 = icmp eq i64 %.02229, -1
  %.123 = select i1 %34, i64 %.02428, i64 %.02229
  %35 = add nuw i64 %.02428, 8
  %niter.next.7 = add i64 %niter, 8
  %niter.ncmp.7 = icmp eq i64 %niter.next.7, %unroll_iter
  br i1 %niter.ncmp.7, label %._crit_edge31.loopexit.unr-lcssa, label %.preheader, !llvm.loop !15

._crit_edge31.loopexit.unr-lcssa:                 ; preds = %.preheader, %.preheader.preheader
  %.123.lcssa.ph = phi i64 [ poison, %.preheader.preheader ], [ %.123, %.preheader ]
  %.02229.unr = phi i64 [ -1, %.preheader.preheader ], [ %.123, %.preheader ]
  %.02428.unr = phi i64 [ 0, %.preheader.preheader ], [ %35, %.preheader ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge31, label %.preheader.epil

.preheader.epil:                                  ; preds = %._crit_edge31.loopexit.unr-lcssa, %.preheader.epil
  %.02229.epil = phi i64 [ %.123.epil, %.preheader.epil ], [ %.02229.unr, %._crit_edge31.loopexit.unr-lcssa ]
  %.02428.epil = phi i64 [ %37, %.preheader.epil ], [ %.02428.unr, %._crit_edge31.loopexit.unr-lcssa ]
  %epil.iter = phi i64 [ %epil.iter.next, %.preheader.epil ], [ 0, %._crit_edge31.loopexit.unr-lcssa ]
  %36 = icmp eq i64 %.02229.epil, -1
  %.123.epil = select i1 %36, i64 %.02428.epil, i64 %.02229.epil
  %37 = add nuw i64 %.02428.epil, 1
  %epil.iter.next = add i64 %epil.iter, 1
  %epil.iter.cmp.not = icmp eq i64 %epil.iter.next, %xtraiter
  br i1 %epil.iter.cmp.not, label %._crit_edge31, label %.preheader.epil, !llvm.loop !16

._crit_edge31:                                    ; preds = %._crit_edge.us, %._crit_edge31.loopexit.unr-lcssa, %.preheader.epil, %4
  %.022.lcssa = phi i64 [ -1, %4 ], [ %.123.lcssa.ph, %._crit_edge31.loopexit.unr-lcssa ], [ %.123.epil, %.preheader.epil ], [ %.123.us, %._crit_edge.us ]
  %38 = trunc i64 %.022.lcssa to i32
  ret i32 %38
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.vector.reduce.add.v4i32(<4 x i32>) #1

attributes #0 = { nofree norecurse nosync nounwind memory(argmem: read) 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 speculatable willreturn memory(none) }

!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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = !{!9, !9, i64 0}
!9 = !{!"int", !6, i64 0}
!10 = distinct !{!10, !11, !12, !13}
!11 = !{!"llvm.loop.mustprogress"}
!12 = !{!"llvm.loop.isvectorized", i32 1}
!13 = !{!"llvm.loop.unroll.runtime.disable"}
!14 = distinct !{!14, !11, !13, !12}
!15 = distinct !{!15, !11}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.unroll.disable"}


; Effective O3 passes: CorrelatedValuePropagationPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopInstSimplifyPass,LoopLoadEliminationPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,LoopVectorizePass,PostOrderFunctionAttrsPass,ReassociatePass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass