; LLVM IR from priyankchheda/algorithms :: _other_languages/c_language/sorts/generic (sort)

; 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 allocsize(0)
declare noalias ptr @malloc(i64 noundef) #1

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #2

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

15:                                               ; preds = %83, %4
  %16 = load i64, ptr %9, align 8, !tbaa !9
  %17 = icmp ugt i64 %16, 0
  br i1 %17, label %18, label %86

18:                                               ; preds = %15
  %19 = load i64, ptr %9, align 8, !tbaa !9
  store i64 %19, ptr %10, align 8, !tbaa !9
  br label %20

20:                                               ; preds = %79, %18
  %21 = load i64, ptr %10, align 8, !tbaa !9
  %22 = load i64, ptr %6, align 8, !tbaa !9
  %23 = icmp ult i64 %21, %22
  br i1 %23, label %24, label %82

24:                                               ; preds = %20
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #4
  %25 = load i64, ptr %7, align 8, !tbaa !9
  %26 = call noalias ptr @malloc(i64 noundef %25) #5
  store ptr %26, ptr %12, align 8, !tbaa !5
  %27 = load ptr, ptr %12, align 8, !tbaa !5
  %28 = load ptr, ptr %5, align 8, !tbaa !5
  %29 = load i64, ptr %10, align 8, !tbaa !9
  %30 = load i64, ptr %7, align 8, !tbaa !9
  %31 = mul i64 %29, %30
  %32 = getelementptr inbounds i8, ptr %28, i64 %31
  %33 = load i64, ptr %7, align 8, !tbaa !9
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %27, ptr align 1 %32, i64 %33, i1 false)
  %34 = load i64, ptr %10, align 8, !tbaa !9
  store i64 %34, ptr %11, align 8, !tbaa !9
  br label %35

35:                                               ; preds = %67, %24
  %36 = load i64, ptr %11, align 8, !tbaa !9
  %37 = load i64, ptr %9, align 8, !tbaa !9
  %38 = icmp uge i64 %36, %37
  br i1 %38, label %39, label %51

39:                                               ; preds = %35
  %40 = load ptr, ptr %8, align 8, !tbaa !5
  %41 = load ptr, ptr %5, align 8, !tbaa !5
  %42 = load i64, ptr %11, align 8, !tbaa !9
  %43 = load i64, ptr %9, align 8, !tbaa !9
  %44 = sub i64 %42, %43
  %45 = load i64, ptr %7, align 8, !tbaa !9
  %46 = mul i64 %44, %45
  %47 = getelementptr inbounds i8, ptr %41, i64 %46
  %48 = load ptr, ptr %12, align 8, !tbaa !5
  %49 = call i32 %40(ptr noundef %47, ptr noundef %48)
  %50 = icmp sgt i32 %49, 0
  br label %51

51:                                               ; preds = %39, %35
  %52 = phi i1 [ false, %35 ], [ %50, %39 ]
  br i1 %52, label %53, label %71

53:                                               ; preds = %51
  %54 = load ptr, ptr %5, align 8, !tbaa !5
  %55 = load i64, ptr %11, align 8, !tbaa !9
  %56 = load i64, ptr %7, align 8, !tbaa !9
  %57 = mul i64 %55, %56
  %58 = getelementptr inbounds i8, ptr %54, i64 %57
  %59 = load ptr, ptr %5, align 8, !tbaa !5
  %60 = load i64, ptr %11, align 8, !tbaa !9
  %61 = load i64, ptr %9, align 8, !tbaa !9
  %62 = sub i64 %60, %61
  %63 = load i64, ptr %7, align 8, !tbaa !9
  %64 = mul i64 %62, %63
  %65 = getelementptr inbounds i8, ptr %59, i64 %64
  %66 = load i64, ptr %7, align 8, !tbaa !9
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %58, ptr align 1 %65, i64 %66, i1 false)
  br label %67

67:                                               ; preds = %53
  %68 = load i64, ptr %9, align 8, !tbaa !9
  %69 = load i64, ptr %11, align 8, !tbaa !9
  %70 = sub i64 %69, %68
  store i64 %70, ptr %11, align 8, !tbaa !9
  br label %35, !llvm.loop !11

71:                                               ; preds = %51
  %72 = load ptr, ptr %5, align 8, !tbaa !5
  %73 = load i64, ptr %11, align 8, !tbaa !9
  %74 = load i64, ptr %7, align 8, !tbaa !9
  %75 = mul i64 %73, %74
  %76 = getelementptr inbounds i8, ptr %72, i64 %75
  %77 = load ptr, ptr %12, align 8, !tbaa !5
  %78 = load i64, ptr %7, align 8, !tbaa !9
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %76, ptr align 1 %77, i64 %78, i1 false)
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #4
  br label %79

79:                                               ; preds = %71
  %80 = load i64, ptr %10, align 8, !tbaa !9
  %81 = add i64 %80, 1
  store i64 %81, ptr %10, align 8, !tbaa !9
  br label %20, !llvm.loop !13

82:                                               ; preds = %20
  br label %83

83:                                               ; preds = %82
  %84 = load i64, ptr %9, align 8, !tbaa !9
  %85 = udiv i64 %84, 2
  store i64 %85, ptr %9, align 8, !tbaa !9
  br label %15, !llvm.loop !14

86:                                               ; preds = %15
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nounwind allocsize(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 nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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 #4 = { nounwind }
attributes #5 = { nounwind allocsize(0) }

!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 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}
!14 = distinct !{!14, !12}


; 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: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #1

; Function Attrs: nounwind uwtable
define dso_local void @shell_sort(ptr noundef %0, i64 noundef %1, i64 noundef %2, ptr nocapture noundef readonly %3) local_unnamed_addr #2 {
  %.not46 = icmp ult i64 %1, 2
  br i1 %.not46, label %._crit_edge, label %.preheader

.loopexit:                                        ; preds = %.critedge, %.preheader
  %.not = icmp ult i64 %.047.in, 4
  br i1 %.not, label %._crit_edge, label %.preheader, !llvm.loop !5

.preheader:                                       ; preds = %4, %.loopexit
  %.047.in = phi i64 [ %.047, %.loopexit ], [ %1, %4 ]
  %.047 = lshr i64 %.047.in, 1
  %5 = icmp ult i64 %.047, %1
  br i1 %5, label %.lr.ph44, label %.loopexit

.lr.ph44:                                         ; preds = %.preheader, %.critedge
  %.03743 = phi i64 [ %18, %.critedge ], [ %.047, %.preheader ]
  %6 = tail call noalias ptr @malloc(i64 noundef %2) #3
  %7 = mul i64 %.03743, %2
  %8 = getelementptr inbounds i8, ptr %0, i64 %7
  tail call void @llvm.memcpy.p0.p0.i64(ptr align 1 %6, ptr align 1 %8, i64 %2, i1 false)
  %.not3839 = icmp ult i64 %.03743, %.047
  br i1 %.not3839, label %.critedge, label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph44, %15
  %.03640 = phi i64 [ %9, %15 ], [ %.03743, %.lr.ph44 ]
  %9 = sub i64 %.03640, %.047
  %10 = mul i64 %9, %2
  %11 = getelementptr inbounds i8, ptr %0, i64 %10
  %12 = tail call i32 %3(ptr noundef %11, ptr noundef %6) #4
  %13 = icmp sgt i32 %12, 0
  %14 = mul i64 %.03640, %2
  br i1 %13, label %15, label %.critedge

15:                                               ; preds = %.lr.ph
  %16 = getelementptr inbounds i8, ptr %0, i64 %14
  tail call void @llvm.memcpy.p0.p0.i64(ptr align 1 %16, ptr align 1 %11, i64 %2, i1 false)
  %.not38 = icmp ult i64 %9, %.047
  br i1 %.not38, label %.critedge, label %.lr.ph, !llvm.loop !7

.critedge:                                        ; preds = %15, %.lr.ph, %.lr.ph44
  %.pre-phi = phi i64 [ %7, %.lr.ph44 ], [ %10, %15 ], [ %14, %.lr.ph ]
  %17 = getelementptr inbounds i8, ptr %0, i64 %.pre-phi
  tail call void @llvm.memcpy.p0.p0.i64(ptr align 1 %17, ptr align 1 %6, i64 %2, i1 false)
  %18 = add nuw i64 %.03743, 1
  %exitcond.not = icmp eq i64 %18, %1
  br i1 %exitcond.not, label %.loopexit, label %.lr.ph44, !llvm.loop !8

._crit_edge:                                      ; preds = %.loopexit, %4
  ret void
}

attributes #0 = { mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" "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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #3 = { nounwind allocsize(0) }
attributes #4 = { 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"}
!7 = distinct !{!7, !6}
!8 = distinct !{!8, !6}


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