; LLVM IR from priyankchheda/algorithms :: _other_languages/c_language/sorts/shell_sort (shell_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: nounwind uwtable
define dso_local void @shell_sort(ptr noundef %0, i64 noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca i64, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i64 %1, ptr %4, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #2
  %9 = load i64, ptr %4, align 8, !tbaa !9
  %10 = udiv i64 %9, 2
  %11 = trunc i64 %10 to i32
  store i32 %11, ptr %5, align 4, !tbaa !11
  br label %12

12:                                               ; preds = %71, %2
  %13 = load i32, ptr %5, align 4, !tbaa !11
  %14 = icmp sgt i32 %13, 0
  br i1 %14, label %15, label %74

15:                                               ; preds = %12
  %16 = load i32, ptr %5, align 4, !tbaa !11
  store i32 %16, ptr %6, align 4, !tbaa !11
  br label %17

17:                                               ; preds = %67, %15
  %18 = load i32, ptr %6, align 4, !tbaa !11
  %19 = sext i32 %18 to i64
  %20 = load i64, ptr %4, align 8, !tbaa !9
  %21 = icmp ult i64 %19, %20
  br i1 %21, label %22, label %70

22:                                               ; preds = %17
  %23 = load ptr, ptr %3, align 8, !tbaa !5
  %24 = load i32, ptr %6, align 4, !tbaa !11
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds i32, ptr %23, i64 %25
  %27 = load i32, ptr %26, align 4, !tbaa !11
  store i32 %27, ptr %8, align 4, !tbaa !11
  %28 = load i32, ptr %6, align 4, !tbaa !11
  store i32 %28, ptr %7, align 4, !tbaa !11
  br label %29

29:                                               ; preds = %57, %22
  %30 = load i32, ptr %7, align 4, !tbaa !11
  %31 = load i32, ptr %5, align 4, !tbaa !11
  %32 = icmp sge i32 %30, %31
  br i1 %32, label %33, label %43

33:                                               ; preds = %29
  %34 = load ptr, ptr %3, align 8, !tbaa !5
  %35 = load i32, ptr %7, align 4, !tbaa !11
  %36 = load i32, ptr %5, align 4, !tbaa !11
  %37 = sub nsw i32 %35, %36
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds i32, ptr %34, i64 %38
  %40 = load i32, ptr %39, align 4, !tbaa !11
  %41 = load i32, ptr %8, align 4, !tbaa !11
  %42 = icmp sgt i32 %40, %41
  br label %43

43:                                               ; preds = %33, %29
  %44 = phi i1 [ false, %29 ], [ %42, %33 ]
  br i1 %44, label %45, label %61

45:                                               ; preds = %43
  %46 = load ptr, ptr %3, align 8, !tbaa !5
  %47 = load i32, ptr %7, align 4, !tbaa !11
  %48 = load i32, ptr %5, align 4, !tbaa !11
  %49 = sub nsw i32 %47, %48
  %50 = sext i32 %49 to i64
  %51 = getelementptr inbounds i32, ptr %46, i64 %50
  %52 = load i32, ptr %51, align 4, !tbaa !11
  %53 = load ptr, ptr %3, align 8, !tbaa !5
  %54 = load i32, ptr %7, align 4, !tbaa !11
  %55 = sext i32 %54 to i64
  %56 = getelementptr inbounds i32, ptr %53, i64 %55
  store i32 %52, ptr %56, align 4, !tbaa !11
  br label %57

57:                                               ; preds = %45
  %58 = load i32, ptr %5, align 4, !tbaa !11
  %59 = load i32, ptr %7, align 4, !tbaa !11
  %60 = sub nsw i32 %59, %58
  store i32 %60, ptr %7, align 4, !tbaa !11
  br label %29, !llvm.loop !13

61:                                               ; preds = %43
  %62 = load i32, ptr %8, align 4, !tbaa !11
  %63 = load ptr, ptr %3, align 8, !tbaa !5
  %64 = load i32, ptr %7, align 4, !tbaa !11
  %65 = sext i32 %64 to i64
  %66 = getelementptr inbounds i32, ptr %63, i64 %65
  store i32 %62, ptr %66, align 4, !tbaa !11
  br label %67

67:                                               ; preds = %61
  %68 = load i32, ptr %6, align 4, !tbaa !11
  %69 = add nsw i32 %68, 1
  store i32 %69, ptr %6, align 4, !tbaa !11
  br label %17, !llvm.loop !15

70:                                               ; preds = %17
  br label %71

71:                                               ; preds = %70
  %72 = load i32, ptr %5, align 4, !tbaa !11
  %73 = sdiv i32 %72, 2
  store i32 %73, ptr %5, align 4, !tbaa !11
  br label %12, !llvm.loop !16

74:                                               ; preds = %12
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  ret void
}

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

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 = !{!"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: nofree norecurse nosync nounwind memory(argmem: readwrite) uwtable
define dso_local void @shell_sort(ptr nocapture noundef %0, i64 noundef %1) local_unnamed_addr #0 {
  %3 = lshr i64 %1, 1
  %4 = trunc i64 %3 to i32
  %5 = icmp sgt i32 %4, 0
  br i1 %5, label %.preheader, label %._crit_edge36

.preheader:                                       ; preds = %2, %._crit_edge
  %.035 = phi i32 [ %22, %._crit_edge ], [ %4, %2 ]
  %6 = zext nneg i32 %.035 to i64
  %7 = icmp ult i64 %6, %1
  br i1 %7, label %.lr.ph34, label %._crit_edge

.lr.ph34:                                         ; preds = %.preheader, %.critedge
  %indvars.iv = phi i64 [ %indvars.iv.next, %.critedge ], [ %6, %.preheader ]
  %8 = getelementptr inbounds i32, ptr %0, i64 %indvars.iv
  %9 = load i32, ptr %8, align 4, !tbaa !5
  %.not29 = icmp ult i64 %indvars.iv, %6
  %10 = trunc nuw i64 %indvars.iv to i32
  br i1 %.not29, label %.critedge, label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph34, %16
  %.02530 = phi i32 [ %11, %16 ], [ %10, %.lr.ph34 ]
  %11 = sub nsw i32 %.02530, %.035
  %12 = sext i32 %11 to i64
  %13 = getelementptr inbounds i32, ptr %0, i64 %12
  %14 = load i32, ptr %13, align 4, !tbaa !5
  %15 = icmp sgt i32 %14, %9
  br i1 %15, label %16, label %.critedge

16:                                               ; preds = %.lr.ph
  %17 = zext nneg i32 %.02530 to i64
  %18 = getelementptr inbounds i32, ptr %0, i64 %17
  store i32 %14, ptr %18, align 4, !tbaa !5
  %.not = icmp slt i32 %11, %.035
  br i1 %.not, label %.critedge, label %.lr.ph, !llvm.loop !9

.critedge:                                        ; preds = %.lr.ph, %16, %.lr.ph34
  %.025.lcssa = phi i32 [ %10, %.lr.ph34 ], [ %11, %16 ], [ %.02530, %.lr.ph ]
  %19 = sext i32 %.025.lcssa to i64
  %20 = getelementptr inbounds i32, ptr %0, i64 %19
  store i32 %9, ptr %20, align 4, !tbaa !5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %21 = icmp ult i64 %indvars.iv.next, %1
  br i1 %21, label %.lr.ph34, label %._crit_edge, !llvm.loop !11

._crit_edge:                                      ; preds = %.critedge, %.preheader
  %22 = lshr i32 %.035, 1
  %.not37 = icmp ult i32 %.035, 2
  br i1 %.not37, label %._crit_edge36, label %.preheader, !llvm.loop !12

._crit_edge36:                                    ; preds = %._crit_edge, %2
  ret void
}

attributes #0 = { nofree norecurse nosync nounwind memory(argmem: readwrite) 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"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}
!12 = distinct !{!12, !10}


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