; LLVM IR from yourtion/LearningMasteringAlgorithms-C :: source (cover)

; 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.List_ = type { i32, ptr, ptr, ptr, ptr }
%struct.ListElmt_ = type { ptr, ptr }
%struct.KSet_ = type { ptr, %struct.List_ }

; Function Attrs: nounwind uwtable
define dso_local i32 @cover(ptr noundef %0, ptr noundef %1, ptr noundef %2) #0 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca %struct.List_, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 40, ptr %8) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  store ptr null, ptr %11, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #3
  %15 = load ptr, ptr %7, align 8, !tbaa !5
  %16 = load ptr, ptr %6, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.List_, ptr %16, i32 0, i32 1
  %18 = load ptr, ptr %17, align 8, !tbaa !9
  call void @set_init(ptr noundef %15, ptr noundef %18, ptr noundef null)
  br label %19

19:                                               ; preds = %111, %3
  %20 = load ptr, ptr %5, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.List_, ptr %20, i32 0, i32 0
  %22 = load i32, ptr %21, align 8, !tbaa !12
  %23 = icmp sgt i32 %22, 0
  br i1 %23, label %24, label %29

24:                                               ; preds = %19
  %25 = load ptr, ptr %6, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.List_, ptr %25, i32 0, i32 0
  %27 = load i32, ptr %26, align 8, !tbaa !12
  %28 = icmp sgt i32 %27, 0
  br label %29

29:                                               ; preds = %24, %19
  %30 = phi i1 [ false, %19 ], [ %28, %24 ]
  br i1 %30, label %31, label %112

31:                                               ; preds = %29
  store i32 0, ptr %13, align 4, !tbaa !13
  %32 = load ptr, ptr %6, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.List_, ptr %32, i32 0, i32 3
  %34 = load ptr, ptr %33, align 8, !tbaa !14
  store ptr %34, ptr %10, align 8, !tbaa !5
  br label %35

35:                                               ; preds = %57, %31
  %36 = load ptr, ptr %10, align 8, !tbaa !5
  %37 = icmp ne ptr %36, null
  br i1 %37, label %38, label %61

38:                                               ; preds = %35
  %39 = load ptr, ptr %10, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.ListElmt_, ptr %39, i32 0, i32 0
  %41 = load ptr, ptr %40, align 8, !tbaa !15
  %42 = getelementptr inbounds %struct.KSet_, ptr %41, i32 0, i32 1
  %43 = load ptr, ptr %5, align 8, !tbaa !5
  %44 = call i32 @set_intersection(ptr noundef %8, ptr noundef %42, ptr noundef %43)
  %45 = icmp ne i32 %44, 0
  br i1 %45, label %46, label %47

46:                                               ; preds = %38
  store i32 -1, ptr %4, align 4
  store i32 1, ptr %14, align 4
  br label %119

47:                                               ; preds = %38
  %48 = getelementptr inbounds %struct.List_, ptr %8, i32 0, i32 0
  %49 = load i32, ptr %48, align 8, !tbaa !12
  %50 = load i32, ptr %13, align 4, !tbaa !13
  %51 = icmp sgt i32 %49, %50
  br i1 %51, label %52, label %56

52:                                               ; preds = %47
  %53 = load ptr, ptr %10, align 8, !tbaa !5
  store ptr %53, ptr %11, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.List_, ptr %8, i32 0, i32 0
  %55 = load i32, ptr %54, align 8, !tbaa !12
  store i32 %55, ptr %13, align 4, !tbaa !13
  br label %56

56:                                               ; preds = %52, %47
  call void @list_destroy(ptr noundef %8)
  br label %57

57:                                               ; preds = %56
  %58 = load ptr, ptr %10, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.ListElmt_, ptr %58, i32 0, i32 1
  %60 = load ptr, ptr %59, align 8, !tbaa !17
  store ptr %60, ptr %10, align 8, !tbaa !5
  br label %35, !llvm.loop !18

61:                                               ; preds = %35
  %62 = load i32, ptr %13, align 4, !tbaa !13
  %63 = icmp eq i32 %62, 0
  br i1 %63, label %64, label %65

64:                                               ; preds = %61
  store i32 1, ptr %4, align 4
  store i32 1, ptr %14, align 4
  br label %119

65:                                               ; preds = %61
  %66 = load ptr, ptr %11, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.ListElmt_, ptr %66, i32 0, i32 0
  %68 = load ptr, ptr %67, align 8, !tbaa !15
  store ptr %68, ptr %9, align 8, !tbaa !5
  %69 = load ptr, ptr %7, align 8, !tbaa !5
  %70 = load ptr, ptr %9, align 8, !tbaa !5
  %71 = call i32 @set_insert(ptr noundef %69, ptr noundef %70)
  %72 = icmp ne i32 %71, 0
  br i1 %72, label %73, label %74

73:                                               ; preds = %65
  store i32 -1, ptr %4, align 4
  store i32 1, ptr %14, align 4
  br label %119

74:                                               ; preds = %65
  %75 = load ptr, ptr %11, align 8, !tbaa !5
  %76 = getelementptr inbounds %struct.ListElmt_, ptr %75, i32 0, i32 0
  %77 = load ptr, ptr %76, align 8, !tbaa !15
  %78 = getelementptr inbounds %struct.KSet_, ptr %77, i32 0, i32 1
  %79 = getelementptr inbounds %struct.List_, ptr %78, i32 0, i32 3
  %80 = load ptr, ptr %79, align 8, !tbaa !20
  store ptr %80, ptr %10, align 8, !tbaa !5
  br label %81

81:                                               ; preds = %102, %74
  %82 = load ptr, ptr %10, align 8, !tbaa !5
  %83 = icmp ne ptr %82, null
  br i1 %83, label %84, label %106

84:                                               ; preds = %81
  %85 = load ptr, ptr %10, align 8, !tbaa !5
  %86 = getelementptr inbounds %struct.ListElmt_, ptr %85, i32 0, i32 0
  %87 = load ptr, ptr %86, align 8, !tbaa !15
  store ptr %87, ptr %12, align 8, !tbaa !5
  %88 = load ptr, ptr %5, align 8, !tbaa !5
  %89 = call i32 @set_remove(ptr noundef %88, ptr noundef %12)
  %90 = icmp eq i32 %89, 0
  br i1 %90, label %91, label %101

91:                                               ; preds = %84
  %92 = load ptr, ptr %5, align 8, !tbaa !5
  %93 = getelementptr inbounds %struct.List_, ptr %92, i32 0, i32 2
  %94 = load ptr, ptr %93, align 8, !tbaa !22
  %95 = icmp ne ptr %94, null
  br i1 %95, label %96, label %101

96:                                               ; preds = %91
  %97 = load ptr, ptr %5, align 8, !tbaa !5
  %98 = getelementptr inbounds %struct.List_, ptr %97, i32 0, i32 2
  %99 = load ptr, ptr %98, align 8, !tbaa !22
  %100 = load ptr, ptr %12, align 8, !tbaa !5
  call void %99(ptr noundef %100)
  br label %101

101:                                              ; preds = %96, %91, %84
  br label %102

102:                                              ; preds = %101
  %103 = load ptr, ptr %10, align 8, !tbaa !5
  %104 = getelementptr inbounds %struct.ListElmt_, ptr %103, i32 0, i32 1
  %105 = load ptr, ptr %104, align 8, !tbaa !17
  store ptr %105, ptr %10, align 8, !tbaa !5
  br label %81, !llvm.loop !23

106:                                              ; preds = %81
  %107 = load ptr, ptr %6, align 8, !tbaa !5
  %108 = call i32 @set_remove(ptr noundef %107, ptr noundef %9)
  %109 = icmp ne i32 %108, 0
  br i1 %109, label %110, label %111

110:                                              ; preds = %106
  store i32 -1, ptr %4, align 4
  store i32 1, ptr %14, align 4
  br label %119

111:                                              ; preds = %106
  br label %19, !llvm.loop !24

112:                                              ; preds = %29
  %113 = load ptr, ptr %5, align 8, !tbaa !5
  %114 = getelementptr inbounds %struct.List_, ptr %113, i32 0, i32 0
  %115 = load i32, ptr %114, align 8, !tbaa !12
  %116 = icmp sgt i32 %115, 0
  br i1 %116, label %117, label %118

117:                                              ; preds = %112
  store i32 -1, ptr %4, align 4
  store i32 1, ptr %14, align 4
  br label %119

118:                                              ; preds = %112
  store i32 0, ptr %4, align 4
  store i32 1, ptr %14, align 4
  br label %119

119:                                              ; preds = %118, %117, %110, %73, %64, %46
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 40, ptr %8) #3
  %120 = load i32, ptr %4, align 4
  ret i32 %120
}

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

declare void @set_init(ptr noundef, ptr noundef, ptr noundef) #2

declare i32 @set_intersection(ptr noundef, ptr noundef, ptr noundef) #2

declare void @list_destroy(ptr noundef) #2

declare i32 @set_insert(ptr noundef, ptr noundef) #2

declare i32 @set_remove(ptr noundef, ptr noundef) #2

; 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 = { "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 8}
!10 = !{!"List_", !11, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32}
!11 = !{!"int", !7, i64 0}
!12 = !{!10, !11, i64 0}
!13 = !{!11, !11, i64 0}
!14 = !{!10, !6, i64 24}
!15 = !{!16, !6, i64 0}
!16 = !{!"ListElmt_", !6, i64 0, !6, i64 8}
!17 = !{!16, !6, i64 8}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}
!20 = !{!21, !6, i64 32}
!21 = !{!"KSet_", !6, i64 0, !10, i64 8}
!22 = !{!10, !6, i64 16}
!23 = distinct !{!23, !19}
!24 = distinct !{!24, !19}


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

%struct.List_ = type { i32, ptr, ptr, ptr, ptr }

; Function Attrs: nounwind uwtable
define dso_local range(i32 -1, 2) i32 @cover(ptr noundef %0, ptr noundef %1, ptr noundef %2) local_unnamed_addr #0 {
  %4 = alloca %struct.List_, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  call void @llvm.lifetime.start.p0(i64 40, ptr nonnull %4) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %5) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %6) #4
  %7 = getelementptr inbounds i8, ptr %1, i64 8
  %8 = load ptr, ptr %7, align 8, !tbaa !5
  tail call void @set_init(ptr noundef %2, ptr noundef %8, ptr noundef null) #4
  %9 = getelementptr inbounds i8, ptr %1, i64 24
  %10 = getelementptr inbounds i8, ptr %0, i64 16
  br label %11

11:                                               ; preds = %._crit_edge52, %3
  %.023 = phi ptr [ null, %3 ], [ %spec.select, %._crit_edge52 ]
  %12 = load i32, ptr %0, align 8, !tbaa !11
  %13 = icmp sgt i32 %12, 0
  br i1 %13, label %14, label %.critedge

14:                                               ; preds = %11
  %15 = load i32, ptr %1, align 8, !tbaa !11
  %16 = icmp sgt i32 %15, 0
  br i1 %16, label %17, label %.critedge

17:                                               ; preds = %14
  %.02541 = load ptr, ptr %9, align 8, !tbaa !12
  %.not42 = icmp eq ptr %.02541, null
  br i1 %.not42, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %17, %21
  %.02545 = phi ptr [ %.025, %21 ], [ %.02541, %17 ]
  %.044 = phi i32 [ %spec.select35, %21 ], [ 0, %17 ]
  %.12443 = phi ptr [ %spec.select, %21 ], [ %.023, %17 ]
  %18 = load ptr, ptr %.02545, align 8, !tbaa !13
  %19 = getelementptr inbounds i8, ptr %18, i64 8
  %20 = call i32 @set_intersection(ptr noundef nonnull %4, ptr noundef nonnull %19, ptr noundef nonnull %0) #4
  %.not34 = icmp eq i32 %20, 0
  br i1 %.not34, label %21, label %.loopexit

21:                                               ; preds = %.lr.ph
  %22 = load i32, ptr %4, align 8, !tbaa !11
  %23 = icmp sgt i32 %22, %.044
  %spec.select = select i1 %23, ptr %.02545, ptr %.12443
  %spec.select35 = call i32 @llvm.smax.i32(i32 %22, i32 %.044)
  call void @list_destroy(ptr noundef nonnull %4) #4
  %24 = getelementptr inbounds i8, ptr %.02545, i64 8
  %.025 = load ptr, ptr %24, align 8, !tbaa !12
  %.not = icmp eq ptr %.025, null
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !15

._crit_edge:                                      ; preds = %21
  %25 = icmp eq i32 %spec.select35, 0
  br i1 %25, label %.loopexit, label %26

26:                                               ; preds = %._crit_edge
  %27 = load ptr, ptr %spec.select, align 8, !tbaa !13
  store ptr %27, ptr %5, align 8, !tbaa !12
  %28 = call i32 @set_insert(ptr noundef %2, ptr noundef %27) #4
  %.not30 = icmp eq i32 %28, 0
  br i1 %.not30, label %29, label %.loopexit

29:                                               ; preds = %26
  %30 = load ptr, ptr %spec.select, align 8, !tbaa !13
  %31 = getelementptr inbounds i8, ptr %30, i64 32
  %.12647 = load ptr, ptr %31, align 8, !tbaa !12
  %.not3148 = icmp eq ptr %.12647, null
  br i1 %.not3148, label %._crit_edge52, label %.lr.ph51

.lr.ph51:                                         ; preds = %29, %39
  %.12649 = phi ptr [ %.126, %39 ], [ %.12647, %29 ]
  %32 = load ptr, ptr %.12649, align 8, !tbaa !13
  store ptr %32, ptr %6, align 8, !tbaa !12
  %33 = call i32 @set_remove(ptr noundef nonnull %0, ptr noundef nonnull %6) #4
  %34 = icmp eq i32 %33, 0
  br i1 %34, label %35, label %39

35:                                               ; preds = %.lr.ph51
  %36 = load ptr, ptr %10, align 8, !tbaa !17
  %.not33 = icmp eq ptr %36, null
  br i1 %.not33, label %39, label %37

37:                                               ; preds = %35
  %38 = load ptr, ptr %6, align 8, !tbaa !12
  call void %36(ptr noundef %38) #4
  br label %39

39:                                               ; preds = %.lr.ph51, %35, %37
  %40 = getelementptr inbounds i8, ptr %.12649, i64 8
  %.126 = load ptr, ptr %40, align 8, !tbaa !12
  %.not31 = icmp eq ptr %.126, null
  br i1 %.not31, label %._crit_edge52, label %.lr.ph51, !llvm.loop !18

._crit_edge52:                                    ; preds = %39, %29
  %41 = call i32 @set_remove(ptr noundef nonnull %1, ptr noundef nonnull %5) #4
  %.not32 = icmp eq i32 %41, 0
  br i1 %.not32, label %11, label %.loopexit, !llvm.loop !19

.critedge:                                        ; preds = %11, %14
  %. = sext i1 %13 to i32
  br label %.loopexit

.loopexit:                                        ; preds = %17, %._crit_edge52, %26, %._crit_edge, %.lr.ph, %.critedge
  %.027 = phi i32 [ %., %.critedge ], [ -1, %.lr.ph ], [ 1, %17 ], [ -1, %._crit_edge52 ], [ -1, %26 ], [ 1, %._crit_edge ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %6) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %5) #4
  call void @llvm.lifetime.end.p0(i64 40, ptr nonnull %4) #4
  ret i32 %.027
}

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

declare void @set_init(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

declare i32 @set_intersection(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

declare void @list_destroy(ptr noundef) local_unnamed_addr #2

declare i32 @set_insert(ptr noundef, ptr noundef) local_unnamed_addr #2

declare i32 @set_remove(ptr noundef, ptr noundef) local_unnamed_addr #2

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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.smax.i32(i32, i32) #3

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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #4 = { 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, !10, i64 8}
!6 = !{!"List_", !7, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !10, i64 32}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!6, !7, i64 0}
!12 = !{!10, !10, i64 0}
!13 = !{!14, !10, i64 0}
!14 = !{!"ListElmt_", !10, i64 0, !10, i64 8}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = !{!6, !10, i64 16}
!18 = distinct !{!18, !16}
!19 = distinct !{!19, !16}


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