; LLVM IR from Innocentsax/sorting_algorithms :: 1000-sort_deck (insertion_sort_deck_kind)

; 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"

%struct.deck_node_s = type { ptr, ptr, ptr }
%struct.card_s = type { ptr, i32 }

; Function Attrs: nounwind uwtable
define dso_local void @insertion_sort_deck_kind(ptr noundef %0) #0 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #2
  %6 = load ptr, ptr %2, align 8, !tbaa !5
  %7 = load ptr, ptr %6, align 8, !tbaa !5
  %8 = getelementptr inbounds %struct.deck_node_s, ptr %7, i32 0, i32 2
  %9 = load ptr, ptr %8, align 8, !tbaa !9
  store ptr %9, ptr %3, align 8, !tbaa !5
  br label %10

10:                                               ; preds = %83, %1
  %11 = load ptr, ptr %3, align 8, !tbaa !5
  %12 = icmp ne ptr %11, null
  br i1 %12, label %13, label %85

13:                                               ; preds = %10
  %14 = load ptr, ptr %3, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.deck_node_s, ptr %14, i32 0, i32 2
  %16 = load ptr, ptr %15, align 8, !tbaa !9
  store ptr %16, ptr %5, align 8, !tbaa !5
  %17 = load ptr, ptr %3, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.deck_node_s, ptr %17, i32 0, i32 1
  %19 = load ptr, ptr %18, align 8, !tbaa !11
  store ptr %19, ptr %4, align 8, !tbaa !5
  br label %20

20:                                               ; preds = %75, %13
  %21 = load ptr, ptr %4, align 8, !tbaa !5
  %22 = icmp ne ptr %21, null
  br i1 %22, label %23, label %35

23:                                               ; preds = %20
  %24 = load ptr, ptr %4, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.deck_node_s, ptr %24, i32 0, i32 0
  %26 = load ptr, ptr %25, align 8, !tbaa !12
  %27 = getelementptr inbounds %struct.card_s, ptr %26, i32 0, i32 1
  %28 = load i32, ptr %27, align 8, !tbaa !13
  %29 = load ptr, ptr %3, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.deck_node_s, ptr %29, i32 0, i32 0
  %31 = load ptr, ptr %30, align 8, !tbaa !12
  %32 = getelementptr inbounds %struct.card_s, ptr %31, i32 0, i32 1
  %33 = load i32, ptr %32, align 8, !tbaa !13
  %34 = icmp ugt i32 %28, %33
  br label %35

35:                                               ; preds = %23, %20
  %36 = phi i1 [ false, %20 ], [ %34, %23 ]
  br i1 %36, label %37, label %82

37:                                               ; preds = %35
  %38 = load ptr, ptr %3, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.deck_node_s, ptr %38, i32 0, i32 2
  %40 = load ptr, ptr %39, align 8, !tbaa !9
  %41 = load ptr, ptr %4, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.deck_node_s, ptr %41, i32 0, i32 2
  store ptr %40, ptr %42, align 8, !tbaa !9
  %43 = load ptr, ptr %3, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.deck_node_s, ptr %43, i32 0, i32 2
  %45 = load ptr, ptr %44, align 8, !tbaa !9
  %46 = icmp ne ptr %45, null
  br i1 %46, label %47, label %53

47:                                               ; preds = %37
  %48 = load ptr, ptr %4, align 8, !tbaa !5
  %49 = load ptr, ptr %3, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.deck_node_s, ptr %49, i32 0, i32 2
  %51 = load ptr, ptr %50, align 8, !tbaa !9
  %52 = getelementptr inbounds %struct.deck_node_s, ptr %51, i32 0, i32 1
  store ptr %48, ptr %52, align 8, !tbaa !11
  br label %53

53:                                               ; preds = %47, %37
  %54 = load ptr, ptr %4, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.deck_node_s, ptr %54, i32 0, i32 1
  %56 = load ptr, ptr %55, align 8, !tbaa !11
  %57 = load ptr, ptr %3, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.deck_node_s, ptr %57, i32 0, i32 1
  store ptr %56, ptr %58, align 8, !tbaa !11
  %59 = load ptr, ptr %4, align 8, !tbaa !5
  %60 = load ptr, ptr %3, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.deck_node_s, ptr %60, i32 0, i32 2
  store ptr %59, ptr %61, align 8, !tbaa !9
  %62 = load ptr, ptr %4, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.deck_node_s, ptr %62, i32 0, i32 1
  %64 = load ptr, ptr %63, align 8, !tbaa !11
  %65 = icmp ne ptr %64, null
  br i1 %65, label %66, label %72

66:                                               ; preds = %53
  %67 = load ptr, ptr %3, align 8, !tbaa !5
  %68 = load ptr, ptr %4, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.deck_node_s, ptr %68, i32 0, i32 1
  %70 = load ptr, ptr %69, align 8, !tbaa !11
  %71 = getelementptr inbounds %struct.deck_node_s, ptr %70, i32 0, i32 2
  store ptr %67, ptr %71, align 8, !tbaa !9
  br label %75

72:                                               ; preds = %53
  %73 = load ptr, ptr %3, align 8, !tbaa !5
  %74 = load ptr, ptr %2, align 8, !tbaa !5
  store ptr %73, ptr %74, align 8, !tbaa !5
  br label %75

75:                                               ; preds = %72, %66
  %76 = load ptr, ptr %3, align 8, !tbaa !5
  %77 = load ptr, ptr %4, align 8, !tbaa !5
  %78 = getelementptr inbounds %struct.deck_node_s, ptr %77, i32 0, i32 1
  store ptr %76, ptr %78, align 8, !tbaa !11
  %79 = load ptr, ptr %3, align 8, !tbaa !5
  %80 = getelementptr inbounds %struct.deck_node_s, ptr %79, i32 0, i32 1
  %81 = load ptr, ptr %80, align 8, !tbaa !11
  store ptr %81, ptr %4, align 8, !tbaa !5
  br label %20, !llvm.loop !16

82:                                               ; preds = %35
  br label %83

83:                                               ; preds = %82
  %84 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %84, ptr %3, align 8, !tbaa !5
  br label %10, !llvm.loop !18

85:                                               ; preds = %10
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #2
  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: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { 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/C++ TBAA"}
!9 = !{!10, !6, i64 16}
!10 = !{!"deck_node_s", !6, i64 0, !6, i64 8, !6, i64 16}
!11 = !{!10, !6, i64 8}
!12 = !{!10, !6, i64 0}
!13 = !{!14, !15, i64 8}
!14 = !{!"card_s", !6, i64 0, !15, i64 8}
!15 = !{!"int", !7, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}
!18 = distinct !{!18, !17}


; 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(readwrite, inaccessiblemem: none) uwtable
define dso_local void @insertion_sort_deck_kind(ptr nocapture noundef %0) local_unnamed_addr #0 {
  %2 = load ptr, ptr %0, align 8, !tbaa !5
  %3 = getelementptr inbounds i8, ptr %2, i64 16
  %4 = load ptr, ptr %3, align 8, !tbaa !9
  %.not35 = icmp eq ptr %4, null
  br i1 %.not35, label %._crit_edge, label %.lr.ph37

.lr.ph37:                                         ; preds = %1, %.critedge
  %.036 = phi ptr [ %6, %.critedge ], [ %4, %1 ]
  %5 = getelementptr inbounds i8, ptr %.036, i64 16
  %6 = load ptr, ptr %5, align 8, !tbaa !9
  %7 = getelementptr inbounds i8, ptr %.036, i64 8
  %.02531 = load ptr, ptr %7, align 8, !tbaa !11
  %.not2832 = icmp eq ptr %.02531, null
  br i1 %.not2832, label %.critedge, label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph37, %20
  %.02533 = phi ptr [ %.025, %20 ], [ %.02531, %.lr.ph37 ]
  %8 = load ptr, ptr %.02533, align 8, !tbaa !12
  %9 = getelementptr inbounds i8, ptr %8, i64 8
  %10 = load i32, ptr %9, align 8, !tbaa !13
  %11 = load ptr, ptr %.036, align 8, !tbaa !12
  %12 = getelementptr inbounds i8, ptr %11, i64 8
  %13 = load i32, ptr %12, align 8, !tbaa !13
  %14 = icmp ugt i32 %10, %13
  br i1 %14, label %15, label %.critedge

15:                                               ; preds = %.lr.ph
  %16 = load ptr, ptr %5, align 8, !tbaa !9
  %17 = getelementptr inbounds i8, ptr %.02533, i64 16
  store ptr %16, ptr %17, align 8, !tbaa !9
  %.not29 = icmp eq ptr %16, null
  br i1 %.not29, label %20, label %18

18:                                               ; preds = %15
  %19 = getelementptr inbounds i8, ptr %16, i64 8
  store ptr %.02533, ptr %19, align 8, !tbaa !11
  br label %20

20:                                               ; preds = %18, %15
  %21 = getelementptr inbounds i8, ptr %.02533, i64 8
  %22 = load ptr, ptr %21, align 8, !tbaa !11
  store ptr %22, ptr %7, align 8, !tbaa !11
  store ptr %.02533, ptr %5, align 8, !tbaa !9
  %.not30 = icmp eq ptr %22, null
  %23 = getelementptr inbounds i8, ptr %22, i64 16
  %.sink = select i1 %.not30, ptr %0, ptr %23
  store ptr %.036, ptr %.sink, align 8, !tbaa !5
  store ptr %.036, ptr %21, align 8, !tbaa !11
  %.025 = load ptr, ptr %7, align 8, !tbaa !11
  %.not28 = icmp eq ptr %.025, null
  br i1 %.not28, label %.critedge, label %.lr.ph, !llvm.loop !16

.critedge:                                        ; preds = %20, %.lr.ph, %.lr.ph37
  %.not = icmp eq ptr %6, null
  br i1 %.not, label %._crit_edge, label %.lr.ph37, !llvm.loop !18

._crit_edge:                                      ; preds = %.critedge, %1
  ret void
}

attributes #0 = { nofree norecurse nosync nounwind memory(readwrite, inaccessiblemem: none) 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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !6, i64 16}
!10 = !{!"deck_node_s", !6, i64 0, !6, i64 8, !6, i64 16}
!11 = !{!10, !6, i64 8}
!12 = !{!10, !6, i64 0}
!13 = !{!14, !15, i64 8}
!14 = !{!"card_s", !6, i64 0, !15, i64 8}
!15 = !{!"int", !7, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}
!18 = distinct !{!18, !17}


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