; LLVM IR from InnoFang/algo-set :: Data Structure/Sort/Shell Sort/main.ll (Z9shellSortRSt6vectorIiSaIiEE)

; 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: mustprogress nounwind uwtable
define dso_local void @_Z9shellSortRSt6vectorIiSaIiEE(ptr noundef nonnull align 8 dereferenceable(24) %0) #0 {
  %2 = alloca ptr, align 8
  %3 = alloca i64, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #2
  store i64 1, ptr %3, align 8, !tbaa !9
  br label %7

7:                                                ; preds = %13, %1
  %8 = load i64, ptr %3, align 8, !tbaa !9
  %9 = load ptr, ptr %2, align 8, !tbaa !5
  %10 = call noundef i64 @_ZNKSt6vectorIiSaIiEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %9) #2
  %11 = udiv i64 %10, 3
  %12 = icmp ult i64 %8, %11
  br i1 %12, label %13, label %17

13:                                               ; preds = %7
  %14 = load i64, ptr %3, align 8, !tbaa !9
  %15 = mul i64 %14, 3
  %16 = add i64 %15, 1
  store i64 %16, ptr %3, align 8, !tbaa !9
  br label %7, !llvm.loop !11

17:                                               ; preds = %7
  br label %18

18:                                               ; preds = %84, %17
  %19 = load i64, ptr %3, align 8, !tbaa !9
  %20 = icmp ugt i64 %19, 0
  br i1 %20, label %21, label %88

21:                                               ; preds = %18
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #2
  %22 = load i64, ptr %3, align 8, !tbaa !9
  %23 = trunc i64 %22 to i32
  store i32 %23, ptr %4, align 4, !tbaa !13
  br label %24

24:                                               ; preds = %77, %21
  %25 = load i32, ptr %4, align 4, !tbaa !13
  %26 = sext i32 %25 to i64
  %27 = load ptr, ptr %2, align 8, !tbaa !5
  %28 = call noundef i64 @_ZNKSt6vectorIiSaIiEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %27) #2
  %29 = icmp ult i64 %26, %28
  br i1 %29, label %31, label %30

30:                                               ; preds = %24
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #2
  br label %83

31:                                               ; preds = %24
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #2
  %32 = load ptr, ptr %2, align 8, !tbaa !5
  %33 = load i32, ptr %4, align 4, !tbaa !13
  %34 = sext i32 %33 to i64
  %35 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %32, i64 noundef %34) #2
  %36 = load i32, ptr %35, align 4, !tbaa !13
  store i32 %36, ptr %5, align 4, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #2
  %37 = load i32, ptr %4, align 4, !tbaa !13
  store i32 %37, ptr %6, align 4, !tbaa !13
  br label %38

38:                                               ; preds = %65, %31
  %39 = load i32, ptr %6, align 4, !tbaa !13
  %40 = icmp sgt i32 %39, 0
  br i1 %40, label %41, label %51

41:                                               ; preds = %38
  %42 = load ptr, ptr %2, align 8, !tbaa !5
  %43 = load i32, ptr %6, align 4, !tbaa !13
  %44 = sext i32 %43 to i64
  %45 = load i64, ptr %3, align 8, !tbaa !9
  %46 = sub i64 %44, %45
  %47 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %42, i64 noundef %46) #2
  %48 = load i32, ptr %47, align 4, !tbaa !13
  %49 = load i32, ptr %5, align 4, !tbaa !13
  %50 = icmp sgt i32 %48, %49
  br label %51

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

53:                                               ; preds = %51
  %54 = load ptr, ptr %2, align 8, !tbaa !5
  %55 = load i32, ptr %6, align 4, !tbaa !13
  %56 = sext i32 %55 to i64
  %57 = load i64, ptr %3, align 8, !tbaa !9
  %58 = sub i64 %56, %57
  %59 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %54, i64 noundef %58) #2
  %60 = load i32, ptr %59, align 4, !tbaa !13
  %61 = load ptr, ptr %2, align 8, !tbaa !5
  %62 = load i32, ptr %6, align 4, !tbaa !13
  %63 = sext i32 %62 to i64
  %64 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %61, i64 noundef %63) #2
  store i32 %60, ptr %64, align 4, !tbaa !13
  br label %65

65:                                               ; preds = %53
  %66 = load i64, ptr %3, align 8, !tbaa !9
  %67 = load i32, ptr %6, align 4, !tbaa !13
  %68 = sext i32 %67 to i64
  %69 = sub i64 %68, %66
  %70 = trunc i64 %69 to i32
  store i32 %70, ptr %6, align 4, !tbaa !13
  br label %38, !llvm.loop !15

71:                                               ; preds = %51
  %72 = load i32, ptr %5, align 4, !tbaa !13
  %73 = load ptr, ptr %2, align 8, !tbaa !5
  %74 = load i32, ptr %6, align 4, !tbaa !13
  %75 = sext i32 %74 to i64
  %76 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %73, i64 noundef %75) #2
  store i32 %72, ptr %76, align 4, !tbaa !13
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  br label %77

77:                                               ; preds = %71
  %78 = load i64, ptr %3, align 8, !tbaa !9
  %79 = load i32, ptr %4, align 4, !tbaa !13
  %80 = sext i32 %79 to i64
  %81 = add i64 %80, %78
  %82 = trunc i64 %81 to i32
  store i32 %82, ptr %4, align 4, !tbaa !13
  br label %24, !llvm.loop !16

83:                                               ; preds = %30
  br label %84

84:                                               ; preds = %83
  %85 = load i64, ptr %3, align 8, !tbaa !9
  %86 = sub i64 %85, 1
  %87 = udiv i64 %86, 3
  store i64 %87, ptr %3, align 8, !tbaa !9
  br label %18, !llvm.loop !17

88:                                               ; preds = %18
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #2
  ret void
}

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZNKSt6vectorIiSaIiEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24)) #0 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) #0 align 2

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

attributes #0 = { mustprogress 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 = { 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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{!14, !14, i64 0}
!14 = !{!"int", !7, i64 0}
!15 = distinct !{!15, !12}
!16 = distinct !{!16, !12}
!17 = distinct !{!17, !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 nounwind uwtable
define dso_local void @_Z9shellSortRSt6vectorIiSaIiEE(ptr noundef nonnull align 8 dereferenceable(24) %0) local_unnamed_addr #0 {
  %2 = tail call noundef i64 @_ZNKSt6vectorIiSaIiEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %0) #1
  %3 = icmp ugt i64 %2, 5
  br i1 %3, label %.lr.ph, label %.preheader.preheader

.lr.ph:                                           ; preds = %1, %.lr.ph
  %.02732 = phi i64 [ %5, %.lr.ph ], [ 1, %1 ]
  %4 = mul nuw i64 %.02732, 3
  %5 = add nuw i64 %4, 1
  %6 = tail call noundef i64 @_ZNKSt6vectorIiSaIiEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %0) #1
  %7 = udiv i64 %6, 3
  %8 = icmp ult i64 %5, %7
  br i1 %8, label %.lr.ph, label %.preheader.preheader, !llvm.loop !5

.preheader.preheader:                             ; preds = %.lr.ph, %1
  %.142.ph = phi i64 [ 1, %1 ], [ %5, %.lr.ph ]
  br label %.preheader

.preheader:                                       ; preds = %.preheader.preheader, %._crit_edge
  %.142 = phi i64 [ %13, %._crit_edge ], [ %.142.ph, %.preheader.preheader ]
  %sext39 = shl i64 %.142, 32
  %9 = ashr exact i64 %sext39, 32
  %10 = tail call noundef i64 @_ZNKSt6vectorIiSaIiEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %0) #1
  %11 = icmp ult i64 %9, %10
  br i1 %11, label %.lr.ph41, label %._crit_edge

._crit_edge:                                      ; preds = %.critedge, %.preheader
  %12 = add i64 %.142, -1
  %13 = udiv i64 %12, 3
  %.not = icmp ult i64 %12, 3
  br i1 %.not, label %34, label %.preheader, !llvm.loop !7

.lr.ph41:                                         ; preds = %.preheader, %.critedge
  %14 = phi i64 [ %31, %.critedge ], [ %9, %.preheader ]
  %.028.in40 = phi i64 [ %30, %.critedge ], [ %.142, %.preheader ]
  %15 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef %14) #1
  %16 = load i32, ptr %15, align 4, !tbaa !8
  %.033 = trunc i64 %.028.in40 to i32
  %17 = icmp sgt i32 %.033, 0
  br i1 %17, label %.lr.ph35, label %.critedge

.lr.ph35:                                         ; preds = %.lr.ph41, %23
  %.0.in34 = phi i64 [ %19, %23 ], [ %.028.in40, %.lr.ph41 ]
  %18 = and i64 %.0.in34, 2147483647
  %19 = sub i64 %18, %.142
  %20 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef %19) #1
  %21 = load i32, ptr %20, align 4, !tbaa !8
  %22 = icmp sgt i32 %21, %16
  br i1 %22, label %23, label %.critedge

23:                                               ; preds = %.lr.ph35
  %24 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef %19) #1
  %25 = load i32, ptr %24, align 4, !tbaa !8
  %26 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef %18) #1
  store i32 %25, ptr %26, align 4, !tbaa !8
  %.0 = trunc i64 %19 to i32
  %27 = icmp sgt i32 %.0, 0
  br i1 %27, label %.lr.ph35, label %.critedge, !llvm.loop !12

.critedge:                                        ; preds = %.lr.ph35, %23, %.lr.ph41
  %.0.in.lcssa = phi i64 [ %.028.in40, %.lr.ph41 ], [ %19, %23 ], [ %.0.in34, %.lr.ph35 ]
  %sext30 = shl i64 %.0.in.lcssa, 32
  %28 = ashr exact i64 %sext30, 32
  %29 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef %28) #1
  store i32 %16, ptr %29, align 4, !tbaa !8
  %30 = add i64 %14, %.142
  %sext = shl i64 %30, 32
  %31 = ashr exact i64 %sext, 32
  %32 = tail call noundef i64 @_ZNKSt6vectorIiSaIiEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %0) #1
  %33 = icmp ult i64 %31, %32
  br i1 %33, label %.lr.ph41, label %._crit_edge, !llvm.loop !13

34:                                               ; preds = %._crit_edge
  ret void
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZNKSt6vectorIiSaIiEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24)) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) local_unnamed_addr #0 align 2

attributes #0 = { mustprogress 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"}
!7 = distinct !{!7, !6}
!8 = !{!9, !9, i64 0}
!9 = !{!"int", !10, i64 0}
!10 = !{!"omnipotent char", !11, i64 0}
!11 = !{!"Simple C++ TBAA"}
!12 = distinct !{!12, !6}
!13 = distinct !{!13, !6}


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