; LLVM IR from Innocentsax/sorting_algorithms :: 100-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: 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 void @shell_sort(ptr noundef %0, i64 noundef %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca i64, align 8
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  %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 8, ptr %5) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  %9 = load ptr, ptr %3, align 8, !tbaa !5
  %10 = icmp eq ptr %9, null
  br i1 %10, label %14, label %11

11:                                               ; preds = %2
  %12 = load i64, ptr %4, align 8, !tbaa !9
  %13 = icmp ult i64 %12, 2
  br i1 %13, label %14, label %15

14:                                               ; preds = %11, %2
  store i32 1, ptr %8, align 4
  br label %78

15:                                               ; preds = %11
  store i64 1, ptr %5, align 8, !tbaa !9
  br label %16

16:                                               ; preds = %21, %15
  %17 = load i64, ptr %5, align 8, !tbaa !9
  %18 = load i64, ptr %4, align 8, !tbaa !9
  %19 = udiv i64 %18, 3
  %20 = icmp ult i64 %17, %19
  br i1 %20, label %21, label %25

21:                                               ; preds = %16
  %22 = load i64, ptr %5, align 8, !tbaa !9
  %23 = mul i64 %22, 3
  %24 = add i64 %23, 1
  store i64 %24, ptr %5, align 8, !tbaa !9
  br label %16, !llvm.loop !11

25:                                               ; preds = %16
  br label %26

26:                                               ; preds = %74, %25
  %27 = load i64, ptr %5, align 8, !tbaa !9
  %28 = icmp uge i64 %27, 1
  br i1 %28, label %29, label %77

29:                                               ; preds = %26
  %30 = load i64, ptr %5, align 8, !tbaa !9
  store i64 %30, ptr %6, align 8, !tbaa !9
  br label %31

31:                                               ; preds = %68, %29
  %32 = load i64, ptr %6, align 8, !tbaa !9
  %33 = load i64, ptr %4, align 8, !tbaa !9
  %34 = icmp ult i64 %32, %33
  br i1 %34, label %35, label %71

35:                                               ; preds = %31
  %36 = load i64, ptr %6, align 8, !tbaa !9
  store i64 %36, ptr %7, align 8, !tbaa !9
  br label %37

37:                                               ; preds = %55, %35
  %38 = load i64, ptr %7, align 8, !tbaa !9
  %39 = load i64, ptr %5, align 8, !tbaa !9
  %40 = icmp uge i64 %38, %39
  br i1 %40, label %41, label %53

41:                                               ; preds = %37
  %42 = load ptr, ptr %3, align 8, !tbaa !5
  %43 = load i64, ptr %7, align 8, !tbaa !9
  %44 = load i64, ptr %5, align 8, !tbaa !9
  %45 = sub i64 %43, %44
  %46 = getelementptr inbounds i32, ptr %42, i64 %45
  %47 = load i32, ptr %46, align 4, !tbaa !13
  %48 = load ptr, ptr %3, align 8, !tbaa !5
  %49 = load i64, ptr %7, align 8, !tbaa !9
  %50 = getelementptr inbounds i32, ptr %48, i64 %49
  %51 = load i32, ptr %50, align 4, !tbaa !13
  %52 = icmp sgt i32 %47, %51
  br label %53

53:                                               ; preds = %41, %37
  %54 = phi i1 [ false, %37 ], [ %52, %41 ]
  br i1 %54, label %55, label %67

55:                                               ; preds = %53
  %56 = load ptr, ptr %3, align 8, !tbaa !5
  %57 = load i64, ptr %7, align 8, !tbaa !9
  %58 = getelementptr inbounds i32, ptr %56, i64 %57
  %59 = load ptr, ptr %3, align 8, !tbaa !5
  %60 = load i64, ptr %7, align 8, !tbaa !9
  %61 = load i64, ptr %5, align 8, !tbaa !9
  %62 = sub i64 %60, %61
  %63 = getelementptr inbounds i32, ptr %59, i64 %62
  call void @swap_ints(ptr noundef %58, ptr noundef %63)
  %64 = load i64, ptr %5, align 8, !tbaa !9
  %65 = load i64, ptr %7, align 8, !tbaa !9
  %66 = sub i64 %65, %64
  store i64 %66, ptr %7, align 8, !tbaa !9
  br label %37, !llvm.loop !15

67:                                               ; preds = %53
  br label %68

68:                                               ; preds = %67
  %69 = load i64, ptr %6, align 8, !tbaa !9
  %70 = add i64 %69, 1
  store i64 %70, ptr %6, align 8, !tbaa !9
  br label %31, !llvm.loop !16

71:                                               ; preds = %31
  %72 = load ptr, ptr %3, align 8, !tbaa !5
  %73 = load i64, ptr %4, align 8, !tbaa !9
  call void @print_array(ptr noundef %72, i64 noundef %73)
  br label %74

74:                                               ; preds = %71
  %75 = load i64, ptr %5, align 8, !tbaa !9
  %76 = udiv i64 %75, 3
  store i64 %76, ptr %5, align 8, !tbaa !9
  br label %26, !llvm.loop !17

77:                                               ; preds = %26
  store i32 0, ptr %8, align 4
  br label %78

78:                                               ; preds = %77, %14
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  %79 = load i32, ptr %8, align 4
  switch i32 %79, label %81 [
    i32 0, label %80
    i32 1, label %80
  ]

80:                                               ; preds = %78, %78
  ret void

81:                                               ; preds = %78
  unreachable
}

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 = 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: nounwind uwtable
declare dso_local void @swap_ints(ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @shell_sort(ptr noundef %0, i64 noundef %1) local_unnamed_addr #0 {
  %3 = icmp eq ptr %0, null
  %4 = icmp ult i64 %1, 2
  %or.cond = or i1 %3, %4
  br i1 %or.cond, label %.loopexit, label %.preheader35

.preheader35:                                     ; preds = %2
  %5 = udiv i64 %1, 3
  %6 = icmp ugt i64 %1, 5
  br i1 %6, label %.lr.ph, label %.preheader33.preheader

.lr.ph:                                           ; preds = %.preheader35, %.lr.ph
  %.02936 = phi i64 [ %8, %.lr.ph ], [ 1, %.preheader35 ]
  %7 = mul nuw i64 %.02936, 3
  %8 = add nuw i64 %7, 1
  %9 = icmp ult i64 %8, %5
  br i1 %9, label %.lr.ph, label %.preheader33.preheader, !llvm.loop !5

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

.preheader33:                                     ; preds = %.preheader33.preheader, %._crit_edge
  %.142 = phi i64 [ %19, %._crit_edge ], [ %.142.ph, %.preheader33.preheader ]
  %10 = icmp ult i64 %.142, %1
  br i1 %10, label %.preheader, label %._crit_edge

.preheader:                                       ; preds = %.preheader33, %.critedge
  %.02841 = phi i64 [ %18, %.critedge ], [ %.142, %.preheader33 ]
  %.not3237 = icmp ult i64 %.02841, %.142
  br i1 %.not3237, label %.critedge, label %.lr.ph39

.lr.ph39:                                         ; preds = %.preheader, %17
  %.038 = phi i64 [ %11, %17 ], [ %.02841, %.preheader ]
  %11 = sub i64 %.038, %.142
  %12 = getelementptr inbounds i32, ptr %0, i64 %11
  %13 = load i32, ptr %12, align 4, !tbaa !7
  %14 = getelementptr inbounds i32, ptr %0, i64 %.038
  %15 = load i32, ptr %14, align 4, !tbaa !7
  %16 = icmp sgt i32 %13, %15
  br i1 %16, label %17, label %.critedge

17:                                               ; preds = %.lr.ph39
  tail call void @swap_ints(ptr noundef nonnull %14, ptr noundef nonnull %12)
  %.not32 = icmp ult i64 %11, %.142
  br i1 %.not32, label %.critedge, label %.lr.ph39, !llvm.loop !11

.critedge:                                        ; preds = %17, %.lr.ph39, %.preheader
  %18 = add i64 %.02841, 1
  %exitcond.not = icmp eq i64 %18, %1
  br i1 %exitcond.not, label %._crit_edge, label %.preheader, !llvm.loop !12

._crit_edge:                                      ; preds = %.critedge, %.preheader33
  tail call void @print_array(ptr noundef %0, i64 noundef %1) #2
  %19 = udiv i64 %.142, 3
  %.not = icmp ult i64 %.142, 3
  br i1 %.not, label %.loopexit, label %.preheader33, !llvm.loop !13

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

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


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