; LLVM IR from Innocentsax/sorting_algorithms :: 107-quick_sort_hoare (hoare_partition)

; 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
declare dso_local void @swap_ints(ptr 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: nounwind uwtable
define dso_local i32 @hoare_partition(ptr noundef %0, i64 noundef %1, i32 noundef %2, i32 noundef %3) #0 {
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i64 %1, ptr %6, align 8, !tbaa !9
  store i32 %2, ptr %7, align 4, !tbaa !11
  store i32 %3, ptr %8, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  %12 = load ptr, ptr %5, align 8, !tbaa !5
  %13 = load i32, ptr %8, align 4, !tbaa !11
  %14 = sext i32 %13 to i64
  %15 = getelementptr inbounds i32, ptr %12, i64 %14
  %16 = load i32, ptr %15, align 4, !tbaa !11
  store i32 %16, ptr %9, align 4, !tbaa !11
  %17 = load i32, ptr %7, align 4, !tbaa !11
  %18 = sub nsw i32 %17, 1
  store i32 %18, ptr %10, align 4, !tbaa !11
  %19 = load i32, ptr %8, align 4, !tbaa !11
  %20 = add nsw i32 %19, 1
  store i32 %20, ptr %11, align 4, !tbaa !11
  br label %21

21:                                               ; preds = %64, %4
  %22 = load i32, ptr %10, align 4, !tbaa !11
  %23 = load i32, ptr %11, align 4, !tbaa !11
  %24 = icmp slt i32 %22, %23
  br i1 %24, label %25, label %65

25:                                               ; preds = %21
  br label %26

26:                                               ; preds = %29, %25
  %27 = load i32, ptr %10, align 4, !tbaa !11
  %28 = add nsw i32 %27, 1
  store i32 %28, ptr %10, align 4, !tbaa !11
  br label %29

29:                                               ; preds = %26
  %30 = load ptr, ptr %5, align 8, !tbaa !5
  %31 = load i32, ptr %10, align 4, !tbaa !11
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds i32, ptr %30, i64 %32
  %34 = load i32, ptr %33, align 4, !tbaa !11
  %35 = load i32, ptr %9, align 4, !tbaa !11
  %36 = icmp slt i32 %34, %35
  br i1 %36, label %26, label %37, !llvm.loop !13

37:                                               ; preds = %29
  br label %38

38:                                               ; preds = %41, %37
  %39 = load i32, ptr %11, align 4, !tbaa !11
  %40 = add nsw i32 %39, -1
  store i32 %40, ptr %11, align 4, !tbaa !11
  br label %41

41:                                               ; preds = %38
  %42 = load ptr, ptr %5, align 8, !tbaa !5
  %43 = load i32, ptr %11, align 4, !tbaa !11
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds i32, ptr %42, i64 %44
  %46 = load i32, ptr %45, align 4, !tbaa !11
  %47 = load i32, ptr %9, align 4, !tbaa !11
  %48 = icmp sgt i32 %46, %47
  br i1 %48, label %38, label %49, !llvm.loop !15

49:                                               ; preds = %41
  %50 = load i32, ptr %10, align 4, !tbaa !11
  %51 = load i32, ptr %11, align 4, !tbaa !11
  %52 = icmp slt i32 %50, %51
  br i1 %52, label %53, label %64

53:                                               ; preds = %49
  %54 = load ptr, ptr %5, align 8, !tbaa !5
  %55 = load i32, ptr %10, align 4, !tbaa !11
  %56 = sext i32 %55 to i64
  %57 = getelementptr inbounds i32, ptr %54, i64 %56
  %58 = load ptr, ptr %5, align 8, !tbaa !5
  %59 = load i32, ptr %11, align 4, !tbaa !11
  %60 = sext i32 %59 to i64
  %61 = getelementptr inbounds i32, ptr %58, i64 %60
  call void @swap_ints(ptr noundef %57, ptr noundef %61)
  %62 = load ptr, ptr %5, align 8, !tbaa !5
  %63 = load i64, ptr %6, align 8, !tbaa !9
  call void @print_array(ptr noundef %62, i64 noundef %63)
  br label %64

64:                                               ; preds = %53, %49
  br label %21, !llvm.loop !16

65:                                               ; preds = %21
  %66 = load i32, ptr %10, align 4, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  ret i32 %66
}

declare void @print_array(ptr noundef, i64 noundef) #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}
!16 = distinct !{!16, !14}


; 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 dso_local void @swap_ints(ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local i32 @hoare_partition(ptr noundef %0, i64 noundef %1, i32 noundef %2, i32 noundef %3) local_unnamed_addr #0 {
  %5 = sext i32 %3 to i64
  %6 = getelementptr inbounds i32, ptr %0, i64 %5
  %7 = load i32, ptr %6, align 4, !tbaa !5
  %8 = add nsw i32 %2, -1
  %9 = add nsw i32 %3, 1
  %.not = icmp slt i32 %9, %2
  br i1 %.not, label %._crit_edge, label %.preheader24

.preheader24:                                     ; preds = %4, %24
  %.030 = phi i32 [ %25, %24 ], [ %9, %4 ]
  %.02229 = phi i32 [ %16, %24 ], [ %8, %4 ]
  %10 = sext i32 %.02229 to i64
  br label %11

11:                                               ; preds = %.preheader24, %11
  %indvars.iv = phi i64 [ %10, %.preheader24 ], [ %indvars.iv.next, %11 ]
  %indvars.iv.next = add nsw i64 %indvars.iv, 1
  %12 = getelementptr inbounds i32, ptr %0, i64 %indvars.iv.next
  %13 = load i32, ptr %12, align 4, !tbaa !5
  %14 = icmp slt i32 %13, %7
  br i1 %14, label %11, label %.preheader, !llvm.loop !9

.preheader:                                       ; preds = %11
  %15 = getelementptr inbounds i32, ptr %0, i64 %indvars.iv.next
  %16 = trunc nsw i64 %indvars.iv.next to i32
  %17 = sext i32 %.030 to i64
  br label %18

18:                                               ; preds = %.preheader, %18
  %indvars.iv35 = phi i64 [ %17, %.preheader ], [ %indvars.iv.next36, %18 ]
  %indvars.iv.next36 = add nsw i64 %indvars.iv35, -1
  %19 = getelementptr inbounds i32, ptr %0, i64 %indvars.iv.next36
  %20 = load i32, ptr %19, align 4, !tbaa !5
  %21 = icmp sgt i32 %20, %7
  br i1 %21, label %18, label %22, !llvm.loop !11

22:                                               ; preds = %18
  %23 = icmp slt i64 %indvars.iv.next, %indvars.iv.next36
  br i1 %23, label %24, label %._crit_edge

24:                                               ; preds = %22
  %25 = trunc nsw i64 %indvars.iv.next36 to i32
  %26 = getelementptr inbounds i32, ptr %0, i64 %indvars.iv.next36
  tail call void @swap_ints(ptr noundef nonnull %15, ptr noundef nonnull %26)
  tail call void @print_array(ptr noundef nonnull %0, i64 noundef %1) #2
  br label %.preheader24

._crit_edge:                                      ; preds = %22, %4
  %.022.lcssa = phi i32 [ %8, %4 ], [ %16, %22 ]
  ret i32 %.022.lcssa
}

declare void @print_array(ptr noundef, i64 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, !6, i64 0}
!6 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}


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