; LLVM IR from Innocentsax/sorting_algorithms :: 101-cocktail_sort_list (cocktail_sort_list)

; 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.listint_s = type { i32, ptr, ptr }

; Function Attrs: nounwind uwtable
declare dso_local void @swap_node_ahead(ptr noundef, 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
declare dso_local void @swap_node_behind(ptr noundef, ptr noundef, ptr noundef) #0

; Function Attrs: nounwind uwtable
define dso_local void @cocktail_sort_list(ptr noundef %0) #0 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %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) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  store i32 0, ptr %5, align 4, !tbaa !9
  %7 = load ptr, ptr %2, align 8, !tbaa !5
  %8 = icmp eq ptr %7, null
  br i1 %8, label %19, label %9

9:                                                ; preds = %1
  %10 = load ptr, ptr %2, align 8, !tbaa !5
  %11 = load ptr, ptr %10, align 8, !tbaa !5
  %12 = icmp eq ptr %11, null
  br i1 %12, label %19, label %13

13:                                               ; preds = %9
  %14 = load ptr, ptr %2, align 8, !tbaa !5
  %15 = load ptr, ptr %14, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.listint_s, ptr %15, i32 0, i32 2
  %17 = load ptr, ptr %16, align 8, !tbaa !11
  %18 = icmp eq ptr %17, null
  br i1 %18, label %19, label %20

19:                                               ; preds = %13, %9, %1
  store i32 1, ptr %6, align 4
  br label %92

20:                                               ; preds = %13
  %21 = load ptr, ptr %2, align 8, !tbaa !5
  %22 = load ptr, ptr %21, align 8, !tbaa !5
  store ptr %22, ptr %3, align 8, !tbaa !5
  br label %23

23:                                               ; preds = %28, %20
  %24 = load ptr, ptr %3, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.listint_s, ptr %24, i32 0, i32 2
  %26 = load ptr, ptr %25, align 8, !tbaa !11
  %27 = icmp ne ptr %26, null
  br i1 %27, label %28, label %32

28:                                               ; preds = %23
  %29 = load ptr, ptr %3, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.listint_s, ptr %29, i32 0, i32 2
  %31 = load ptr, ptr %30, align 8, !tbaa !11
  store ptr %31, ptr %3, align 8, !tbaa !5
  br label %23, !llvm.loop !13

32:                                               ; preds = %23
  br label %33

33:                                               ; preds = %90, %32
  %34 = load i32, ptr %5, align 4, !tbaa !9
  %35 = icmp eq i32 %34, 0
  br i1 %35, label %36, label %91

36:                                               ; preds = %33
  store i32 1, ptr %5, align 4, !tbaa !9
  %37 = load ptr, ptr %2, align 8, !tbaa !5
  %38 = load ptr, ptr %37, align 8, !tbaa !5
  store ptr %38, ptr %4, align 8, !tbaa !5
  br label %39

39:                                               ; preds = %58, %36
  %40 = load ptr, ptr %4, align 8, !tbaa !5
  %41 = load ptr, ptr %3, align 8, !tbaa !5
  %42 = icmp ne ptr %40, %41
  br i1 %42, label %43, label %62

43:                                               ; preds = %39
  %44 = load ptr, ptr %4, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.listint_s, ptr %44, i32 0, i32 0
  %46 = load i32, ptr %45, align 8, !tbaa !15
  %47 = load ptr, ptr %4, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.listint_s, ptr %47, i32 0, i32 2
  %49 = load ptr, ptr %48, align 8, !tbaa !11
  %50 = getelementptr inbounds %struct.listint_s, ptr %49, i32 0, i32 0
  %51 = load i32, ptr %50, align 8, !tbaa !15
  %52 = icmp sgt i32 %46, %51
  br i1 %52, label %53, label %57

53:                                               ; preds = %43
  %54 = load ptr, ptr %2, align 8, !tbaa !5
  call void @swap_node_ahead(ptr noundef %54, ptr noundef %3, ptr noundef %4)
  %55 = load ptr, ptr %2, align 8, !tbaa !5
  %56 = load ptr, ptr %55, align 8, !tbaa !5
  call void @print_list(ptr noundef %56)
  store i32 0, ptr %5, align 4, !tbaa !9
  br label %57

57:                                               ; preds = %53, %43
  br label %58

58:                                               ; preds = %57
  %59 = load ptr, ptr %4, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.listint_s, ptr %59, i32 0, i32 2
  %61 = load ptr, ptr %60, align 8, !tbaa !11
  store ptr %61, ptr %4, align 8, !tbaa !5
  br label %39, !llvm.loop !16

62:                                               ; preds = %39
  %63 = load ptr, ptr %4, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.listint_s, ptr %63, i32 0, i32 1
  %65 = load ptr, ptr %64, align 8, !tbaa !17
  store ptr %65, ptr %4, align 8, !tbaa !5
  br label %66

66:                                               ; preds = %86, %62
  %67 = load ptr, ptr %4, align 8, !tbaa !5
  %68 = load ptr, ptr %2, align 8, !tbaa !5
  %69 = load ptr, ptr %68, align 8, !tbaa !5
  %70 = icmp ne ptr %67, %69
  br i1 %70, label %71, label %90

71:                                               ; preds = %66
  %72 = load ptr, ptr %4, align 8, !tbaa !5
  %73 = getelementptr inbounds %struct.listint_s, ptr %72, i32 0, i32 0
  %74 = load i32, ptr %73, align 8, !tbaa !15
  %75 = load ptr, ptr %4, align 8, !tbaa !5
  %76 = getelementptr inbounds %struct.listint_s, ptr %75, i32 0, i32 1
  %77 = load ptr, ptr %76, align 8, !tbaa !17
  %78 = getelementptr inbounds %struct.listint_s, ptr %77, i32 0, i32 0
  %79 = load i32, ptr %78, align 8, !tbaa !15
  %80 = icmp slt i32 %74, %79
  br i1 %80, label %81, label %85

81:                                               ; preds = %71
  %82 = load ptr, ptr %2, align 8, !tbaa !5
  call void @swap_node_behind(ptr noundef %82, ptr noundef %3, ptr noundef %4)
  %83 = load ptr, ptr %2, align 8, !tbaa !5
  %84 = load ptr, ptr %83, align 8, !tbaa !5
  call void @print_list(ptr noundef %84)
  store i32 0, ptr %5, align 4, !tbaa !9
  br label %85

85:                                               ; preds = %81, %71
  br label %86

86:                                               ; preds = %85
  %87 = load ptr, ptr %4, align 8, !tbaa !5
  %88 = getelementptr inbounds %struct.listint_s, ptr %87, i32 0, i32 1
  %89 = load ptr, ptr %88, align 8, !tbaa !17
  store ptr %89, ptr %4, align 8, !tbaa !5
  br label %66, !llvm.loop !18

90:                                               ; preds = %66
  br label %33, !llvm.loop !19

91:                                               ; preds = %33
  store i32 0, ptr %6, align 4
  br label %92

92:                                               ; preds = %91, %19
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  %93 = load i32, ptr %6, align 4
  switch i32 %93, label %95 [
    i32 0, label %94
    i32 1, label %94
  ]

94:                                               ; preds = %92, %92
  ret void

95:                                               ; preds = %92
  unreachable
}

declare void @print_list(ptr 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 = !{!"int", !7, i64 0}
!11 = !{!12, !6, i64 16}
!12 = !{!"listint_s", !10, i64 0, !6, i64 8, !6, i64 16}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = !{!12, !10, i64 0}
!16 = distinct !{!16, !14}
!17 = !{!12, !6, i64 8}
!18 = distinct !{!18, !14}
!19 = distinct !{!19, !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: nounwind uwtable
declare dso_local void @swap_node_ahead(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #0

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

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

; Function Attrs: nounwind uwtable
declare dso_local void @swap_node_behind(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @cocktail_sort_list(ptr noundef %0) local_unnamed_addr #0 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #3
  %4 = icmp eq ptr %0, null
  br i1 %4, label %.loopexit22, label %5

5:                                                ; preds = %1
  %6 = load ptr, ptr %0, align 8, !tbaa !5
  %7 = icmp eq ptr %6, null
  br i1 %7, label %.loopexit22, label %8

8:                                                ; preds = %5
  %9 = getelementptr inbounds i8, ptr %6, i64 16
  %10 = load ptr, ptr %9, align 8, !tbaa !9
  %11 = icmp eq ptr %10, null
  br i1 %11, label %.loopexit22, label %.preheader23

.preheader23:                                     ; preds = %8, %.preheader23
  %storemerge = phi ptr [ %13, %.preheader23 ], [ %6, %8 ]
  %12 = getelementptr inbounds i8, ptr %storemerge, i64 16
  %13 = load ptr, ptr %12, align 8, !tbaa !9
  %.not = icmp eq ptr %13, null
  br i1 %.not, label %.preheader21, label %.preheader23, !llvm.loop !12

.preheader21:                                     ; preds = %.preheader23
  store ptr %storemerge, ptr %2, align 8, !tbaa !5
  br label %.preheader20

.loopexit:                                        ; preds = %40, %.preheader
  %14 = phi ptr [ %20, %.preheader ], [ %41, %40 ]
  %15 = phi ptr [ %21, %.preheader ], [ %41, %40 ]
  %.3.lcssa = phi i32 [ %.1.lcssa, %.preheader ], [ %.4, %40 ]
  %16 = icmp eq i32 %.3.lcssa, 0
  br i1 %16, label %.preheader20, label %.loopexit22, !llvm.loop !14

.preheader20:                                     ; preds = %.preheader21, %.loopexit
  %17 = phi ptr [ %6, %.preheader21 ], [ %14, %.loopexit ]
  %18 = phi ptr [ %6, %.preheader21 ], [ %15, %.loopexit ]
  store ptr %18, ptr %3, align 8, !tbaa !5
  %19 = load ptr, ptr %2, align 8, !tbaa !5
  %.not1725 = icmp eq ptr %18, %19
  br i1 %.not1725, label %.preheader, label %.lr.ph

.preheader.loopexit:                              ; preds = %30
  %.pre41 = load ptr, ptr %0, align 8, !tbaa !5
  br label %.preheader

.preheader:                                       ; preds = %.preheader.loopexit, %.preheader20
  %20 = phi ptr [ %17, %.preheader20 ], [ %.pre41, %.preheader.loopexit ]
  %21 = phi ptr [ %18, %.preheader20 ], [ %.pre41, %.preheader.loopexit ]
  %.1.lcssa = phi i32 [ 1, %.preheader20 ], [ %.2, %.preheader.loopexit ]
  %storemerge16.lcssa = phi ptr [ %18, %.preheader20 ], [ %storemerge16, %.preheader.loopexit ]
  %storemerge18.in29 = getelementptr inbounds i8, ptr %storemerge16.lcssa, i64 8
  %storemerge1830 = load ptr, ptr %storemerge18.in29, align 8, !tbaa !15
  store ptr %storemerge1830, ptr %3, align 8, !tbaa !5
  %.not1931 = icmp eq ptr %storemerge1830, %21
  br i1 %.not1931, label %.loopexit, label %.lr.ph34

.lr.ph:                                           ; preds = %.preheader20, %30
  %22 = phi ptr [ %31, %30 ], [ %19, %.preheader20 ]
  %storemerge1627 = phi ptr [ %storemerge16, %30 ], [ %18, %.preheader20 ]
  %.126 = phi i32 [ %.2, %30 ], [ 1, %.preheader20 ]
  %23 = load i32, ptr %storemerge1627, align 8, !tbaa !16
  %24 = getelementptr inbounds i8, ptr %storemerge1627, i64 16
  %25 = load ptr, ptr %24, align 8, !tbaa !5
  %26 = load i32, ptr %25, align 8, !tbaa !16
  %27 = icmp sgt i32 %23, %26
  br i1 %27, label %28, label %30

28:                                               ; preds = %.lr.ph
  call void @swap_node_ahead(ptr noundef nonnull %0, ptr noundef nonnull %2, ptr noundef nonnull %3)
  %29 = load ptr, ptr %0, align 8, !tbaa !5
  call void @print_list(ptr noundef %29) #3
  %.pre = load ptr, ptr %3, align 8, !tbaa !5
  %.phi.trans.insert = getelementptr inbounds i8, ptr %.pre, i64 16
  %storemerge16.pre = load ptr, ptr %.phi.trans.insert, align 8, !tbaa !5
  %.pre40 = load ptr, ptr %2, align 8, !tbaa !5
  br label %30

30:                                               ; preds = %.lr.ph, %28
  %31 = phi ptr [ %.pre40, %28 ], [ %22, %.lr.ph ]
  %storemerge16 = phi ptr [ %storemerge16.pre, %28 ], [ %25, %.lr.ph ]
  %.2 = phi i32 [ 0, %28 ], [ %.126, %.lr.ph ]
  store ptr %storemerge16, ptr %3, align 8, !tbaa !5
  %.not17 = icmp eq ptr %storemerge16, %31
  br i1 %.not17, label %.preheader.loopexit, label %.lr.ph, !llvm.loop !17

.lr.ph34:                                         ; preds = %.preheader, %40
  %32 = phi ptr [ %41, %40 ], [ %20, %.preheader ]
  %storemerge1833 = phi ptr [ %storemerge18, %40 ], [ %storemerge1830, %.preheader ]
  %.332 = phi i32 [ %.4, %40 ], [ %.1.lcssa, %.preheader ]
  %33 = load i32, ptr %storemerge1833, align 8, !tbaa !16
  %34 = getelementptr inbounds i8, ptr %storemerge1833, i64 8
  %35 = load ptr, ptr %34, align 8, !tbaa !15
  %36 = load i32, ptr %35, align 8, !tbaa !16
  %37 = icmp slt i32 %33, %36
  br i1 %37, label %38, label %40

38:                                               ; preds = %.lr.ph34
  call void @swap_node_behind(ptr noundef nonnull %0, ptr noundef nonnull %2, ptr noundef nonnull %3)
  %39 = load ptr, ptr %0, align 8, !tbaa !5
  call void @print_list(ptr noundef %39) #3
  %.pre42 = load ptr, ptr %3, align 8, !tbaa !5
  %storemerge18.in.phi.trans.insert = getelementptr inbounds i8, ptr %.pre42, i64 8
  %storemerge18.pre = load ptr, ptr %storemerge18.in.phi.trans.insert, align 8, !tbaa !15
  %.pre44 = load ptr, ptr %0, align 8, !tbaa !5
  br label %40

40:                                               ; preds = %.lr.ph34, %38
  %41 = phi ptr [ %.pre44, %38 ], [ %32, %.lr.ph34 ]
  %storemerge18 = phi ptr [ %storemerge18.pre, %38 ], [ %35, %.lr.ph34 ]
  %.4 = phi i32 [ 0, %38 ], [ %.332, %.lr.ph34 ]
  store ptr %storemerge18, ptr %3, align 8, !tbaa !5
  %.not19 = icmp eq ptr %storemerge18, %41
  br i1 %.not19, label %.loopexit, label %.lr.ph34, !llvm.loop !18

.loopexit22:                                      ; preds = %.loopexit, %1, %5, %8
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #3
  ret void
}

declare void @print_list(ptr noundef) local_unnamed_addr #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 = { mustprogress 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, !6, i64 16}
!10 = !{!"listint_s", !11, i64 0, !6, i64 8, !6, i64 16}
!11 = !{!"int", !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = distinct !{!14, !13}
!15 = !{!10, !6, i64 8}
!16 = !{!10, !11, i64 0}
!17 = distinct !{!17, !13}
!18 = distinct !{!18, !13}


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