; LLVM IR from int32bit/leetcode :: algorithms/MedianofTwoSortedArrays (kth)

; 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: nounwind uwtable
define dso_local i32 @getkth(ptr noundef %0, i32 noundef %1, ptr noundef %2, i32 noundef %3, i32 noundef %4) #0 {
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  store ptr %0, ptr %7, align 8, !tbaa !5
  store i32 %1, ptr %8, align 4, !tbaa !9
  store ptr %2, ptr %9, align 8, !tbaa !5
  store i32 %3, ptr %10, align 4, !tbaa !9
  store i32 %4, ptr %11, align 4, !tbaa !9
  %15 = load i32, ptr %8, align 4, !tbaa !9
  %16 = load i32, ptr %10, align 4, !tbaa !9
  %17 = icmp sgt i32 %15, %16
  br i1 %17, label %18, label %25

18:                                               ; preds = %5
  %19 = load ptr, ptr %9, align 8, !tbaa !5
  %20 = load i32, ptr %10, align 4, !tbaa !9
  %21 = load ptr, ptr %7, align 8, !tbaa !5
  %22 = load i32, ptr %8, align 4, !tbaa !9
  %23 = load i32, ptr %11, align 4, !tbaa !9
  %24 = call i32 @getkth(ptr noundef %19, i32 noundef %20, ptr noundef %21, i32 noundef %22, i32 noundef %23)
  store i32 %24, ptr %6, align 4
  br label %97

25:                                               ; preds = %5
  %26 = load i32, ptr %8, align 4, !tbaa !9
  %27 = icmp eq i32 %26, 0
  br i1 %27, label %28, label %35

28:                                               ; preds = %25
  %29 = load ptr, ptr %9, align 8, !tbaa !5
  %30 = load i32, ptr %11, align 4, !tbaa !9
  %31 = sub nsw i32 %30, 1
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds i32, ptr %29, i64 %32
  %34 = load i32, ptr %33, align 4, !tbaa !9
  store i32 %34, ptr %6, align 4
  br label %97

35:                                               ; preds = %25
  %36 = load i32, ptr %11, align 4, !tbaa !9
  %37 = icmp eq i32 %36, 1
  br i1 %37, label %38, label %46

38:                                               ; preds = %35
  %39 = load ptr, ptr %7, align 8, !tbaa !5
  %40 = getelementptr inbounds i32, ptr %39, i64 0
  %41 = load i32, ptr %40, align 4, !tbaa !9
  %42 = load ptr, ptr %9, align 8, !tbaa !5
  %43 = getelementptr inbounds i32, ptr %42, i64 0
  %44 = load i32, ptr %43, align 4, !tbaa !9
  %45 = call i32 @min(i32 noundef %41, i32 noundef %44)
  store i32 %45, ptr %6, align 4
  br label %97

46:                                               ; preds = %35
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #3
  %47 = load i32, ptr %8, align 4, !tbaa !9
  %48 = load i32, ptr %11, align 4, !tbaa !9
  %49 = sdiv i32 %48, 2
  %50 = call i32 @min(i32 noundef %47, i32 noundef %49)
  store i32 %50, ptr %12, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #3
  %51 = load i32, ptr %10, align 4, !tbaa !9
  %52 = load i32, ptr %11, align 4, !tbaa !9
  %53 = sdiv i32 %52, 2
  %54 = call i32 @min(i32 noundef %51, i32 noundef %53)
  store i32 %54, ptr %13, align 4, !tbaa !9
  %55 = load ptr, ptr %7, align 8, !tbaa !5
  %56 = load i32, ptr %12, align 4, !tbaa !9
  %57 = sub nsw i32 %56, 1
  %58 = sext i32 %57 to i64
  %59 = getelementptr inbounds i32, ptr %55, i64 %58
  %60 = load i32, ptr %59, align 4, !tbaa !9
  %61 = load ptr, ptr %9, align 8, !tbaa !5
  %62 = load i32, ptr %13, align 4, !tbaa !9
  %63 = sub nsw i32 %62, 1
  %64 = sext i32 %63 to i64
  %65 = getelementptr inbounds i32, ptr %61, i64 %64
  %66 = load i32, ptr %65, align 4, !tbaa !9
  %67 = icmp sgt i32 %60, %66
  br i1 %67, label %68, label %82

68:                                               ; preds = %46
  %69 = load ptr, ptr %7, align 8, !tbaa !5
  %70 = load i32, ptr %8, align 4, !tbaa !9
  %71 = load ptr, ptr %9, align 8, !tbaa !5
  %72 = load i32, ptr %13, align 4, !tbaa !9
  %73 = sext i32 %72 to i64
  %74 = getelementptr inbounds i32, ptr %71, i64 %73
  %75 = load i32, ptr %10, align 4, !tbaa !9
  %76 = load i32, ptr %13, align 4, !tbaa !9
  %77 = sub nsw i32 %75, %76
  %78 = load i32, ptr %11, align 4, !tbaa !9
  %79 = load i32, ptr %13, align 4, !tbaa !9
  %80 = sub nsw i32 %78, %79
  %81 = call i32 @getkth(ptr noundef %69, i32 noundef %70, ptr noundef %74, i32 noundef %77, i32 noundef %80)
  store i32 %81, ptr %6, align 4
  store i32 1, ptr %14, align 4
  br label %96

82:                                               ; preds = %46
  %83 = load ptr, ptr %7, align 8, !tbaa !5
  %84 = load i32, ptr %12, align 4, !tbaa !9
  %85 = sext i32 %84 to i64
  %86 = getelementptr inbounds i32, ptr %83, i64 %85
  %87 = load i32, ptr %8, align 4, !tbaa !9
  %88 = load i32, ptr %12, align 4, !tbaa !9
  %89 = sub nsw i32 %87, %88
  %90 = load ptr, ptr %9, align 8, !tbaa !5
  %91 = load i32, ptr %10, align 4, !tbaa !9
  %92 = load i32, ptr %11, align 4, !tbaa !9
  %93 = load i32, ptr %12, align 4, !tbaa !9
  %94 = sub nsw i32 %92, %93
  %95 = call i32 @getkth(ptr noundef %86, i32 noundef %89, ptr noundef %90, i32 noundef %91, i32 noundef %94)
  store i32 %95, ptr %6, align 4
  store i32 1, ptr %14, align 4
  br label %96

96:                                               ; preds = %82, %68
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #3
  br label %97

97:                                               ; preds = %96, %38, %28, %18
  %98 = load i32, ptr %6, align 4
  ret i32 %98
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @min(i32 noundef, i32 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 = { 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 = { inlinehint 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 willreturn memory(argmem: readwrite) }
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 = !{!"int", !7, i64 0}


; 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
define dso_local i32 @getkth(ptr nocapture noundef readonly %0, i32 noundef %1, ptr nocapture noundef readonly %2, i32 noundef %3, i32 noundef %4) local_unnamed_addr #0 {
  br label %tailrecurse.outer.outer

tailrecurse.outer.outer:                          ; preds = %tailrecurse.outer.outer.backedge, %5
  %.tr.ph.ph = phi ptr [ %0, %5 ], [ %.tr.ph.ph.be, %tailrecurse.outer.outer.backedge ]
  %.tr42.ph.ph = phi i32 [ %1, %5 ], [ %.tr42.ph.ph.be, %tailrecurse.outer.outer.backedge ]
  %.tr43.ph.ph = phi ptr [ %2, %5 ], [ %.tr43.ph.ph.be, %tailrecurse.outer.outer.backedge ]
  %.tr44.ph.ph = phi i32 [ %3, %5 ], [ %.tr44.ph.ph.be, %tailrecurse.outer.outer.backedge ]
  %.tr45.ph.ph = phi i32 [ %4, %5 ], [ %.tr45.ph.ph.be, %tailrecurse.outer.outer.backedge ]
  br label %tailrecurse.outer

tailrecurse.outer:                                ; preds = %tailrecurse.outer.outer, %tailrecurse.outer
  %.tr.ph = phi ptr [ %.tr43.ph, %tailrecurse.outer ], [ %.tr.ph.ph, %tailrecurse.outer.outer ]
  %.tr42.ph = phi i32 [ %.tr44.ph, %tailrecurse.outer ], [ %.tr42.ph.ph, %tailrecurse.outer.outer ]
  %.tr43.ph = phi ptr [ %.tr.ph, %tailrecurse.outer ], [ %.tr43.ph.ph, %tailrecurse.outer.outer ]
  %.tr44.ph = phi i32 [ %.tr42.ph, %tailrecurse.outer ], [ %.tr44.ph.ph, %tailrecurse.outer.outer ]
  %6 = icmp sgt i32 %.tr42.ph, %.tr44.ph
  br i1 %6, label %tailrecurse.outer, label %.lr.ph

.lr.ph:                                           ; preds = %tailrecurse.outer
  %7 = icmp eq i32 %.tr42.ph, 0
  br i1 %7, label %.split.us, label %.lr.ph.split

.lr.ph.split:                                     ; preds = %.lr.ph, %tailrecurse
  %.tr4559 = phi i32 [ %31, %tailrecurse ], [ %.tr45.ph.ph, %.lr.ph ]
  %.tr4458 = phi i32 [ %30, %tailrecurse ], [ %.tr44.ph, %.lr.ph ]
  %.tr4357 = phi ptr [ %26, %tailrecurse ], [ %.tr43.ph, %.lr.ph ]
  %8 = icmp eq i32 %.tr4559, 1
  br i1 %8, label %13, label %17

.split.us:                                        ; preds = %.lr.ph
  %9 = sext i32 %.tr45.ph.ph to i64
  %10 = getelementptr i32, ptr %.tr43.ph, i64 %9
  %11 = getelementptr i8, ptr %10, i64 -4
  %12 = load i32, ptr %11, align 4, !tbaa !5
  br label %36

13:                                               ; preds = %.lr.ph.split
  %14 = load i32, ptr %.tr.ph, align 4, !tbaa !5
  %15 = load i32, ptr %.tr4357, align 4, !tbaa !5
  %16 = tail call i32 @min(i32 noundef %14, i32 noundef %15)
  br label %36

17:                                               ; preds = %.lr.ph.split
  %18 = sdiv i32 %.tr4559, 2
  %19 = tail call i32 @min(i32 noundef %.tr42.ph, i32 noundef %18)
  %20 = tail call i32 @min(i32 noundef %.tr4458, i32 noundef %18)
  %21 = sext i32 %19 to i64
  %22 = getelementptr i32, ptr %.tr.ph, i64 %21
  %23 = getelementptr i8, ptr %22, i64 -4
  %24 = load i32, ptr %23, align 4, !tbaa !5
  %25 = sext i32 %20 to i64
  %26 = getelementptr i32, ptr %.tr4357, i64 %25
  %27 = getelementptr i8, ptr %26, i64 -4
  %28 = load i32, ptr %27, align 4, !tbaa !5
  %29 = icmp sgt i32 %24, %28
  br i1 %29, label %tailrecurse, label %33

tailrecurse:                                      ; preds = %17
  %30 = sub nsw i32 %.tr4458, %20
  %31 = sub nsw i32 %.tr4559, %20
  %32 = icmp sgt i32 %.tr42.ph, %30
  br i1 %32, label %tailrecurse.outer.outer.backedge, label %.lr.ph.split

33:                                               ; preds = %17
  %34 = sub nsw i32 %.tr42.ph, %19
  %35 = sub nsw i32 %.tr4559, %19
  br label %tailrecurse.outer.outer.backedge

tailrecurse.outer.outer.backedge:                 ; preds = %tailrecurse, %33
  %.tr.ph.ph.be = phi ptr [ %22, %33 ], [ %26, %tailrecurse ]
  %.tr42.ph.ph.be = phi i32 [ %34, %33 ], [ %30, %tailrecurse ]
  %.tr43.ph.ph.be = phi ptr [ %.tr4357, %33 ], [ %.tr.ph, %tailrecurse ]
  %.tr44.ph.ph.be = phi i32 [ %.tr4458, %33 ], [ %.tr42.ph, %tailrecurse ]
  %.tr45.ph.ph.be = phi i32 [ %35, %33 ], [ %31, %tailrecurse ]
  br label %tailrecurse.outer.outer

36:                                               ; preds = %13, %.split.us
  %.1 = phi i32 [ %12, %.split.us ], [ %16, %13 ]
  ret i32 %.1
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @min(i32 noundef, i32 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 = { inlinehint 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" }

!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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}


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