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

%struct._VlIKMFilt = type { i64, i64, i64, i32, i32, ptr, ptr }

; 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
declare hidden void @alloc(ptr noundef, i64 noundef, i64 noundef) #1

; Function Attrs: nounwind uwtable
declare hidden void @vl_ikm_init_helper(ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local void @vl_ikm_init_rand(ptr noundef %0, i64 noundef %1, i64 noundef %2) #1 {
  %4 = alloca ptr, align 8
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  %9 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i64 %1, ptr %5, align 8, !tbaa !9
  store i64 %2, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  %10 = call ptr @vl_get_rand()
  store ptr %10, ptr %9, align 8, !tbaa !5
  %11 = load ptr, ptr %4, align 8, !tbaa !5
  %12 = load i64, ptr %5, align 8, !tbaa !9
  %13 = load i64, ptr %6, align 8, !tbaa !9
  call void @alloc(ptr noundef %11, i64 noundef %12, i64 noundef %13)
  store i64 0, ptr %7, align 8, !tbaa !9
  br label %14

14:                                               ; preds = %39, %3
  %15 = load i64, ptr %7, align 8, !tbaa !9
  %16 = load i64, ptr %6, align 8, !tbaa !9
  %17 = icmp ult i64 %15, %16
  br i1 %17, label %18, label %42

18:                                               ; preds = %14
  store i64 0, ptr %8, align 8, !tbaa !9
  br label %19

19:                                               ; preds = %35, %18
  %20 = load i64, ptr %8, align 8, !tbaa !9
  %21 = load i64, ptr %5, align 8, !tbaa !9
  %22 = icmp ult i64 %20, %21
  br i1 %22, label %23, label %38

23:                                               ; preds = %19
  %24 = load ptr, ptr %9, align 8, !tbaa !5
  %25 = call i32 @vl_rand_uint32(ptr noundef %24)
  %26 = load ptr, ptr %4, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct._VlIKMFilt, ptr %26, i32 0, i32 5
  %28 = load ptr, ptr %27, align 8, !tbaa !11
  %29 = load i64, ptr %7, align 8, !tbaa !9
  %30 = load i64, ptr %5, align 8, !tbaa !9
  %31 = mul i64 %29, %30
  %32 = load i64, ptr %8, align 8, !tbaa !9
  %33 = add i64 %31, %32
  %34 = getelementptr inbounds i32, ptr %28, i64 %33
  store i32 %25, ptr %34, align 4, !tbaa !14
  br label %35

35:                                               ; preds = %23
  %36 = load i64, ptr %8, align 8, !tbaa !9
  %37 = add i64 %36, 1
  store i64 %37, ptr %8, align 8, !tbaa !9
  br label %19, !llvm.loop !15

38:                                               ; preds = %19
  br label %39

39:                                               ; preds = %38
  %40 = load i64, ptr %7, align 8, !tbaa !9
  %41 = add i64 %40, 1
  store i64 %41, ptr %7, align 8, !tbaa !9
  br label %14, !llvm.loop !17

42:                                               ; preds = %14
  %43 = load ptr, ptr %4, align 8, !tbaa !5
  call void @vl_ikm_init_helper(ptr noundef %43)
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  ret void
}

declare ptr @vl_get_rand() #2

declare i32 @vl_rand_uint32(ptr noundef) #2

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 = { "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 = !{!"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, !6, i64 32}
!12 = !{!"_VlIKMFilt", !10, i64 0, !10, i64 8, !10, i64 16, !13, i64 24, !13, i64 28, !6, i64 32, !6, i64 40}
!13 = !{!"int", !7, i64 0}
!14 = !{!13, !13, 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"

; Function Attrs: nounwind uwtable
declare hidden void @alloc(ptr noundef, i64 noundef, i64 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare hidden void @vl_ikm_init_helper(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @vl_ikm_init_rand(ptr noundef %0, i64 noundef %1, i64 noundef %2) local_unnamed_addr #0 {
  %4 = tail call ptr @vl_get_rand() #2
  tail call void @alloc(ptr noundef %0, i64 noundef %1, i64 noundef %2)
  %.not = icmp eq i64 %2, 0
  br i1 %.not, label %._crit_edge18, label %.preheader.lr.ph

.preheader.lr.ph:                                 ; preds = %3
  %.not19 = icmp eq i64 %1, 0
  %5 = getelementptr inbounds i8, ptr %0, i64 32
  br i1 %.not19, label %._crit_edge18, label %.preheader.us

.preheader.us:                                    ; preds = %.preheader.lr.ph, %._crit_edge.us
  %.017.us = phi i64 [ %13, %._crit_edge.us ], [ 0, %.preheader.lr.ph ]
  %6 = mul i64 %.017.us, %1
  br label %7

7:                                                ; preds = %.preheader.us, %7
  %.01416.us = phi i64 [ 0, %.preheader.us ], [ %12, %7 ]
  %8 = tail call i32 @vl_rand_uint32(ptr noundef %4) #2
  %9 = load ptr, ptr %5, align 8, !tbaa !5
  %10 = getelementptr i32, ptr %9, i64 %6
  %11 = getelementptr i32, ptr %10, i64 %.01416.us
  store i32 %8, ptr %11, align 4, !tbaa !12
  %12 = add nuw i64 %.01416.us, 1
  %exitcond.not = icmp eq i64 %12, %1
  br i1 %exitcond.not, label %._crit_edge.us, label %7, !llvm.loop !13

._crit_edge.us:                                   ; preds = %7
  %13 = add nuw i64 %.017.us, 1
  %exitcond21.not = icmp eq i64 %13, %2
  br i1 %exitcond21.not, label %._crit_edge18, label %.preheader.us, !llvm.loop !15

._crit_edge18:                                    ; preds = %._crit_edge.us, %.preheader.lr.ph, %3
  tail call void @vl_ikm_init_helper(ptr noundef %0)
  ret void
}

declare ptr @vl_get_rand() local_unnamed_addr #1

declare i32 @vl_rand_uint32(ptr noundef) local_unnamed_addr #1

attributes #0 = { 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 = { "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, !11, i64 32}
!6 = !{!"_VlIKMFilt", !7, i64 0, !7, i64 8, !7, i64 16, !10, i64 24, !10, i64 28, !11, i64 32, !11, i64 40}
!7 = !{!"long long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"any pointer", !8, i64 0}
!12 = !{!10, !10, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}


; Effective O3 passes: CorrelatedValuePropagationPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass