; LLVM IR from soupi/3-C-Sorting-Algorithms :: QuickSort (place_pivot)

; 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 @place_pivot(ptr noundef %0, i32 noundef %1, i32 noundef %2, ptr noundef %3, ptr noundef %4) #1 {
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store i32 %1, ptr %7, align 4, !tbaa !9
  store i32 %2, ptr %8, align 4, !tbaa !9
  store ptr %3, ptr %9, align 8, !tbaa !5
  store ptr %4, ptr %10, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #2
  %14 = load i32, ptr %7, align 4, !tbaa !9
  store i32 %14, ptr %11, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #2
  %15 = load i32, ptr %7, align 4, !tbaa !9
  %16 = add nsw i32 %15, 1
  store i32 %16, ptr %12, align 4, !tbaa !9
  %17 = load i32, ptr %7, align 4, !tbaa !9
  %18 = add nsw i32 %17, 1
  store i32 %18, ptr %13, align 4, !tbaa !9
  br label %19

19:                                               ; preds = %44, %5
  %20 = load i32, ptr %13, align 4, !tbaa !9
  %21 = load i32, ptr %8, align 4, !tbaa !9
  %22 = icmp sle i32 %20, %21
  br i1 %22, label %23, label %47

23:                                               ; preds = %19
  %24 = load ptr, ptr %9, align 8, !tbaa !5
  %25 = load ptr, ptr %6, align 8, !tbaa !5
  %26 = load i32, ptr %13, align 4, !tbaa !9
  %27 = load i32, ptr %11, align 4, !tbaa !9
  %28 = call i32 %24(ptr noundef %25, i32 noundef %26, i32 noundef %27)
  %29 = icmp ne i32 %28, 0
  br i1 %29, label %30, label %43

30:                                               ; preds = %23
  %31 = load ptr, ptr %10, align 8, !tbaa !5
  %32 = load ptr, ptr %6, align 8, !tbaa !5
  %33 = load i32, ptr %13, align 4, !tbaa !9
  %34 = load i32, ptr %12, align 4, !tbaa !9
  call void %31(ptr noundef %32, i32 noundef %33, i32 noundef %34)
  %35 = load ptr, ptr %10, align 8, !tbaa !5
  %36 = load ptr, ptr %6, align 8, !tbaa !5
  %37 = load i32, ptr %11, align 4, !tbaa !9
  %38 = load i32, ptr %12, align 4, !tbaa !9
  call void %35(ptr noundef %36, i32 noundef %37, i32 noundef %38)
  %39 = load i32, ptr %11, align 4, !tbaa !9
  %40 = add nsw i32 %39, 1
  store i32 %40, ptr %11, align 4, !tbaa !9
  %41 = load i32, ptr %12, align 4, !tbaa !9
  %42 = add nsw i32 %41, 1
  store i32 %42, ptr %12, align 4, !tbaa !9
  br label %43

43:                                               ; preds = %30, %23
  br label %44

44:                                               ; preds = %43
  %45 = load i32, ptr %13, align 4, !tbaa !9
  %46 = add nsw i32 %45, 1
  store i32 %46, ptr %13, align 4, !tbaa !9
  br label %19, !llvm.loop !11

47:                                               ; preds = %19
  %48 = load i32, ptr %11, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #2
  ret i32 %48
}

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 = !{!"int", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"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"

; Function Attrs: nounwind uwtable
define dso_local i32 @place_pivot(ptr noundef %0, i32 noundef %1, i32 noundef %2, ptr nocapture noundef readonly %3, ptr nocapture noundef readonly %4) local_unnamed_addr #0 {
  %.not24.not = icmp slt i32 %1, %2
  br i1 %.not24.not, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %5
  %6 = add nsw i32 %1, 1
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %11
  %.027 = phi i32 [ %12, %11 ], [ %6, %.lr.ph.preheader ]
  %.02026 = phi i32 [ %.1, %11 ], [ %6, %.lr.ph.preheader ]
  %.02125 = phi i32 [ %.122, %11 ], [ %1, %.lr.ph.preheader ]
  %7 = tail call i32 %3(ptr noundef %0, i32 noundef %.027, i32 noundef %.02125) #1
  %.not23 = icmp eq i32 %7, 0
  br i1 %.not23, label %11, label %8

8:                                                ; preds = %.lr.ph
  tail call void %4(ptr noundef %0, i32 noundef %.027, i32 noundef %.02026) #1
  tail call void %4(ptr noundef %0, i32 noundef %.02125, i32 noundef %.02026) #1
  %9 = add nsw i32 %.02125, 1
  %10 = add nsw i32 %.02026, 1
  br label %11

11:                                               ; preds = %.lr.ph, %8
  %.122 = phi i32 [ %9, %8 ], [ %.02125, %.lr.ph ]
  %.1 = phi i32 [ %10, %8 ], [ %.02026, %.lr.ph ]
  %12 = add i32 %.027, 1
  %exitcond.not = icmp eq i32 %.027, %2
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !5

._crit_edge:                                      ; preds = %11, %5
  %.021.lcssa = phi i32 [ %1, %5 ], [ %.122, %11 ]
  ret i32 %.021.lcssa
}

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 = { 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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}


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