; LLVM IR from ekoontz/graphlab :: src/graphlab/extern/metis/GKlib (blas)

; 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.gk_ckv_t = type { i8, i64 }

@.str = external hidden unnamed_addr constant [18 x i8], align 1

; 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 i64 @gk_cargmax_n(i64 noundef %0, ptr noundef %1, i64 noundef %2) #1 {
  %4 = alloca i64, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  %9 = alloca ptr, align 8
  store i64 %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !9
  store i64 %2, ptr %6, align 8, !tbaa !5
  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 = load i64, ptr %4, align 8, !tbaa !5
  %11 = call ptr @gk_ckvmalloc(i64 noundef %10, ptr noundef @.str)
  store ptr %11, ptr %9, align 8, !tbaa !9
  store i64 0, ptr %7, align 8, !tbaa !5
  br label %12

12:                                               ; preds = %30, %3
  %13 = load i64, ptr %7, align 8, !tbaa !5
  %14 = load i64, ptr %4, align 8, !tbaa !5
  %15 = icmp ult i64 %13, %14
  br i1 %15, label %16, label %33

16:                                               ; preds = %12
  %17 = load i64, ptr %7, align 8, !tbaa !5
  %18 = load ptr, ptr %9, align 8, !tbaa !9
  %19 = load i64, ptr %7, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.gk_ckv_t, ptr %18, i64 %19
  %21 = getelementptr inbounds %struct.gk_ckv_t, ptr %20, i32 0, i32 1
  store i64 %17, ptr %21, align 8, !tbaa !11
  %22 = load ptr, ptr %5, align 8, !tbaa !9
  %23 = load i64, ptr %7, align 8, !tbaa !5
  %24 = getelementptr inbounds i8, ptr %22, i64 %23
  %25 = load i8, ptr %24, align 1, !tbaa !13
  %26 = load ptr, ptr %9, align 8, !tbaa !9
  %27 = load i64, ptr %7, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.gk_ckv_t, ptr %26, i64 %27
  %29 = getelementptr inbounds %struct.gk_ckv_t, ptr %28, i32 0, i32 0
  store i8 %25, ptr %29, align 8, !tbaa !14
  br label %30

30:                                               ; preds = %16
  %31 = load i64, ptr %7, align 8, !tbaa !5
  %32 = add i64 %31, 1
  store i64 %32, ptr %7, align 8, !tbaa !5
  br label %12, !llvm.loop !15

33:                                               ; preds = %12
  %34 = load i64, ptr %4, align 8, !tbaa !5
  %35 = trunc i64 %34 to i32
  %36 = load ptr, ptr %9, align 8, !tbaa !9
  call void @gk_dckvsort(i32 noundef %35, ptr noundef %36)
  %37 = load ptr, ptr %9, align 8, !tbaa !9
  %38 = load i64, ptr %6, align 8, !tbaa !5
  %39 = sub i64 %38, 1
  %40 = getelementptr inbounds %struct.gk_ckv_t, ptr %37, i64 %39
  %41 = getelementptr inbounds %struct.gk_ckv_t, ptr %40, i32 0, i32 1
  %42 = load i64, ptr %41, align 8, !tbaa !11
  store i64 %42, ptr %8, align 8, !tbaa !5
  call void (ptr, ...) @gk_free(ptr noundef %9, ptr noundef null)
  %43 = load i64, ptr %8, align 8, !tbaa !5
  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 i64 %43
}

declare ptr @gk_ckvmalloc(i64 noundef, ptr noundef) #2

declare void @gk_dckvsort(i32 noundef, ptr noundef) #2

declare void @gk_free(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 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !6, i64 8}
!12 = !{!"", !7, i64 0, !6, i64 8}
!13 = !{!7, !7, i64 0}
!14 = !{!12, !7, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}


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

%struct.gk_ckv_t = type { i8, i64 }

@.str = external hidden unnamed_addr constant [18 x i8], align 1

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

; Function Attrs: mustprogress 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 i64 @gk_cargmax_n(i64 noundef %0, ptr nocapture noundef readonly %1, i64 noundef %2) local_unnamed_addr #1 {
  %4 = alloca ptr, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %4) #3
  %5 = tail call ptr @gk_ckvmalloc(i64 noundef %0, ptr noundef nonnull @.str) #3
  store ptr %5, ptr %4, align 8, !tbaa !5
  %.not = icmp eq i64 %0, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %3
  %xtraiter = and i64 %0, 1
  %6 = icmp eq i64 %0, 1
  br i1 %6, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph.preheader.new

.lr.ph.preheader.new:                             ; preds = %.lr.ph.preheader
  %unroll_iter = and i64 %0, -2
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph, %.lr.ph.preheader.new
  %.012 = phi i64 [ 0, %.lr.ph.preheader.new ], [ %16, %.lr.ph ]
  %niter = phi i64 [ 0, %.lr.ph.preheader.new ], [ %niter.next.1, %.lr.ph ]
  %7 = getelementptr inbounds %struct.gk_ckv_t, ptr %5, i64 %.012, i32 1
  store i64 %.012, ptr %7, align 8, !tbaa !9
  %8 = getelementptr inbounds i8, ptr %1, i64 %.012
  %9 = load i8, ptr %8, align 1, !tbaa !12
  %10 = getelementptr inbounds %struct.gk_ckv_t, ptr %5, i64 %.012
  store i8 %9, ptr %10, align 8, !tbaa !13
  %11 = or disjoint i64 %.012, 1
  %12 = getelementptr inbounds %struct.gk_ckv_t, ptr %5, i64 %11, i32 1
  store i64 %11, ptr %12, align 8, !tbaa !9
  %13 = getelementptr inbounds i8, ptr %1, i64 %11
  %14 = load i8, ptr %13, align 1, !tbaa !12
  %15 = getelementptr inbounds %struct.gk_ckv_t, ptr %5, i64 %11
  store i8 %14, ptr %15, align 8, !tbaa !13
  %16 = add nuw i64 %.012, 2
  %niter.next.1 = add i64 %niter, 2
  %niter.ncmp.1 = icmp eq i64 %niter.next.1, %unroll_iter
  br i1 %niter.ncmp.1, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph, !llvm.loop !14

._crit_edge.loopexit.unr-lcssa:                   ; preds = %.lr.ph, %.lr.ph.preheader
  %.012.unr = phi i64 [ 0, %.lr.ph.preheader ], [ %16, %.lr.ph ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge, label %.lr.ph.epil

.lr.ph.epil:                                      ; preds = %._crit_edge.loopexit.unr-lcssa
  %17 = getelementptr inbounds %struct.gk_ckv_t, ptr %5, i64 %.012.unr, i32 1
  store i64 %.012.unr, ptr %17, align 8, !tbaa !9
  %18 = getelementptr inbounds i8, ptr %1, i64 %.012.unr
  %19 = load i8, ptr %18, align 1, !tbaa !12
  %20 = getelementptr inbounds %struct.gk_ckv_t, ptr %5, i64 %.012.unr
  store i8 %19, ptr %20, align 8, !tbaa !13
  br label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph.epil, %._crit_edge.loopexit.unr-lcssa, %3
  %21 = trunc i64 %0 to i32
  tail call void @gk_dckvsort(i32 noundef %21, ptr noundef %5) #3
  %22 = getelementptr %struct.gk_ckv_t, ptr %5, i64 %2
  %23 = getelementptr i8, ptr %22, i64 -8
  %24 = load i64, ptr %23, align 8, !tbaa !9
  call void (ptr, ...) @gk_free(ptr noundef nonnull %4, ptr noundef null) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #3
  ret i64 %24
}

declare ptr @gk_ckvmalloc(i64 noundef, ptr noundef) local_unnamed_addr #2

declare void @gk_dckvsort(i32 noundef, ptr noundef) local_unnamed_addr #2

declare void @gk_free(ptr noundef, ...) local_unnamed_addr #2

attributes #0 = { mustprogress 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, !11, i64 8}
!10 = !{!"", !7, i64 0, !11, i64 8}
!11 = !{!"long", !7, i64 0}
!12 = !{!7, !7, i64 0}
!13 = !{!10, !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass