; LLVM IR from fmela/libdict :: src (skiplist)

; 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.skiplist = type { ptr, i32, i32, ptr, i64 }
%struct.skip_node = type { ptr, ptr, ptr, i32, [0 x ptr] }

@dict_free_func = external global ptr, align 8

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

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

; Function Attrs: nounwind uwtable
define dso_local i64 @skiplist_clear(ptr noundef %0, ptr noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i64, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #2
  %8 = load ptr, ptr %3, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct.skiplist, ptr %8, i32 0, i32 0
  %10 = load ptr, ptr %9, align 8, !tbaa !9
  %11 = getelementptr inbounds %struct.skip_node, ptr %10, i32 0, i32 4
  %12 = getelementptr inbounds [0 x ptr], ptr %11, i64 0, i64 0
  %13 = load ptr, ptr %12, align 8, !tbaa !5
  store ptr %13, ptr %5, align 8, !tbaa !5
  br label %14

14:                                               ; preds = %32, %2
  %15 = load ptr, ptr %5, align 8, !tbaa !5
  %16 = icmp ne ptr %15, null
  br i1 %16, label %17, label %36

17:                                               ; preds = %14
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #2
  %18 = load ptr, ptr %5, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.skip_node, ptr %18, i32 0, i32 4
  %20 = getelementptr inbounds [0 x ptr], ptr %19, i64 0, i64 0
  %21 = load ptr, ptr %20, align 8, !tbaa !5
  store ptr %21, ptr %6, align 8, !tbaa !5
  %22 = load ptr, ptr %4, align 8, !tbaa !5
  %23 = icmp ne ptr %22, null
  br i1 %23, label %24, label %32

24:                                               ; preds = %17
  %25 = load ptr, ptr %4, align 8, !tbaa !5
  %26 = load ptr, ptr %5, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.skip_node, ptr %26, i32 0, i32 0
  %28 = load ptr, ptr %27, align 8, !tbaa !5
  %29 = load ptr, ptr %5, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.skip_node, ptr %29, i32 0, i32 1
  %31 = load ptr, ptr %30, align 8, !tbaa !5
  call void %25(ptr noundef %28, ptr noundef %31)
  br label %32

32:                                               ; preds = %24, %17
  %33 = load ptr, ptr @dict_free_func, align 8, !tbaa !5
  %34 = load ptr, ptr %5, align 8, !tbaa !5
  call void %33(ptr noundef %34)
  %35 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %35, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #2
  br label %14, !llvm.loop !13

36:                                               ; preds = %14
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #2
  %37 = load ptr, ptr %3, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.skiplist, ptr %37, i32 0, i32 4
  %39 = load i64, ptr %38, align 8, !tbaa !15
  store i64 %39, ptr %7, align 8, !tbaa !16
  %40 = load ptr, ptr %3, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.skiplist, ptr %40, i32 0, i32 4
  store i64 0, ptr %41, align 8, !tbaa !15
  %42 = load ptr, ptr %3, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.skiplist, ptr %42, i32 0, i32 0
  %44 = load ptr, ptr %43, align 8, !tbaa !9
  %45 = getelementptr inbounds %struct.skip_node, ptr %44, i32 0, i32 4
  %46 = load ptr, ptr %3, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.skiplist, ptr %46, i32 0, i32 2
  %48 = load i32, ptr %47, align 4, !tbaa !17
  %49 = zext i32 %48 to i64
  %50 = getelementptr inbounds [0 x ptr], ptr %45, i64 0, i64 %49
  store ptr null, ptr %50, align 8, !tbaa !5
  br label %51

51:                                               ; preds = %56, %36
  %52 = load ptr, ptr %3, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.skiplist, ptr %52, i32 0, i32 2
  %54 = load i32, ptr %53, align 4, !tbaa !17
  %55 = icmp ne i32 %54, 0
  br i1 %55, label %56, label %67

56:                                               ; preds = %51
  %57 = load ptr, ptr %3, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.skiplist, ptr %57, i32 0, i32 0
  %59 = load ptr, ptr %58, align 8, !tbaa !9
  %60 = getelementptr inbounds %struct.skip_node, ptr %59, i32 0, i32 4
  %61 = load ptr, ptr %3, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.skiplist, ptr %61, i32 0, i32 2
  %63 = load i32, ptr %62, align 4, !tbaa !17
  %64 = add i32 %63, -1
  store i32 %64, ptr %62, align 4, !tbaa !17
  %65 = zext i32 %64 to i64
  %66 = getelementptr inbounds [0 x ptr], ptr %60, i64 0, i64 %65
  store ptr null, ptr %66, align 8, !tbaa !5
  br label %51, !llvm.loop !18

67:                                               ; preds = %51
  %68 = load i64, ptr %7, align 8, !tbaa !16
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #2
  ret i64 %68
}

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, !6, i64 0}
!10 = !{!"skiplist", !6, i64 0, !11, i64 8, !11, i64 12, !6, i64 16, !12, i64 24}
!11 = !{!"int", !7, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = !{!10, !12, i64 24}
!16 = !{!12, !12, i64 0}
!17 = !{!10, !11, i64 12}
!18 = distinct !{!18, !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"

@dict_free_func = external local_unnamed_addr global ptr, align 8

; Function Attrs: nounwind uwtable
define dso_local i64 @skiplist_clear(ptr nocapture noundef %0, ptr noundef readonly %1) local_unnamed_addr #0 {
  %3 = load ptr, ptr %0, align 8, !tbaa !5
  %4 = getelementptr inbounds i8, ptr %3, i64 32
  %5 = load ptr, ptr %4, align 8, !tbaa !12
  %.not20 = icmp eq ptr %5, null
  br i1 %.not20, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %2
  %.not19 = icmp eq ptr %1, null
  br i1 %.not19, label %.lr.ph.split.us, label %.lr.ph.split

.lr.ph.split.us:                                  ; preds = %.lr.ph, %.lr.ph.split.us
  %.021.us = phi ptr [ %7, %.lr.ph.split.us ], [ %5, %.lr.ph ]
  %6 = getelementptr inbounds i8, ptr %.021.us, i64 32
  %7 = load ptr, ptr %6, align 8, !tbaa !12
  %8 = load ptr, ptr @dict_free_func, align 8, !tbaa !12
  tail call void %8(ptr noundef nonnull %.021.us) #1
  %.not.us = icmp eq ptr %7, null
  br i1 %.not.us, label %._crit_edge, label %.lr.ph.split.us, !llvm.loop !13

.lr.ph.split:                                     ; preds = %.lr.ph, %.lr.ph.split
  %.021 = phi ptr [ %10, %.lr.ph.split ], [ %5, %.lr.ph ]
  %9 = getelementptr inbounds i8, ptr %.021, i64 32
  %10 = load ptr, ptr %9, align 8, !tbaa !12
  %11 = load ptr, ptr %.021, align 8, !tbaa !12
  %12 = getelementptr inbounds i8, ptr %.021, i64 8
  %13 = load ptr, ptr %12, align 8, !tbaa !12
  tail call void %1(ptr noundef %11, ptr noundef %13) #1
  %14 = load ptr, ptr @dict_free_func, align 8, !tbaa !12
  tail call void %14(ptr noundef nonnull %.021) #1
  %.not = icmp eq ptr %10, null
  br i1 %.not, label %._crit_edge, label %.lr.ph.split, !llvm.loop !13

._crit_edge:                                      ; preds = %.lr.ph.split, %.lr.ph.split.us, %2
  %15 = getelementptr inbounds i8, ptr %0, i64 24
  %16 = load i64, ptr %15, align 8, !tbaa !15
  store i64 0, ptr %15, align 8, !tbaa !15
  %17 = load ptr, ptr %0, align 8, !tbaa !5
  %18 = getelementptr inbounds i8, ptr %17, i64 32
  %19 = getelementptr inbounds i8, ptr %0, i64 12
  %20 = load i32, ptr %19, align 4, !tbaa !16
  %21 = zext i32 %20 to i64
  %22 = getelementptr inbounds [0 x ptr], ptr %18, i64 0, i64 %21
  store ptr null, ptr %22, align 8, !tbaa !12
  %.not1822 = icmp eq i32 %20, 0
  br i1 %.not1822, label %44, label %.lr.ph24.preheader

.lr.ph24.preheader:                               ; preds = %._crit_edge
  %xtraiter = and i64 %21, 3
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %.lr.ph24.prol.loopexit, label %.lr.ph24.prol

.lr.ph24.prol:                                    ; preds = %.lr.ph24.preheader, %.lr.ph24.prol
  %indvars.iv.prol = phi i64 [ %25, %.lr.ph24.prol ], [ %21, %.lr.ph24.preheader ]
  %prol.iter = phi i64 [ %prol.iter.next, %.lr.ph24.prol ], [ 0, %.lr.ph24.preheader ]
  %23 = load ptr, ptr %0, align 8, !tbaa !5
  %24 = getelementptr inbounds i8, ptr %23, i64 32
  %25 = add nsw i64 %indvars.iv.prol, -1
  %26 = getelementptr inbounds [0 x ptr], ptr %24, i64 0, i64 %25
  store ptr null, ptr %26, align 8, !tbaa !12
  %prol.iter.next = add i64 %prol.iter, 1
  %prol.iter.cmp.not = icmp eq i64 %prol.iter.next, %xtraiter
  br i1 %prol.iter.cmp.not, label %.lr.ph24.prol.loopexit, label %.lr.ph24.prol, !llvm.loop !17

.lr.ph24.prol.loopexit:                           ; preds = %.lr.ph24.prol, %.lr.ph24.preheader
  %indvars.iv.unr = phi i64 [ %21, %.lr.ph24.preheader ], [ %25, %.lr.ph24.prol ]
  %27 = icmp ult i32 %20, 4
  br i1 %27, label %._crit_edge25, label %.lr.ph24

.lr.ph24:                                         ; preds = %.lr.ph24.prol.loopexit, %.lr.ph24
  %indvars.iv = phi i64 [ %42, %.lr.ph24 ], [ %indvars.iv.unr, %.lr.ph24.prol.loopexit ]
  %28 = load ptr, ptr %0, align 8, !tbaa !5
  %29 = getelementptr inbounds i8, ptr %28, i64 32
  %30 = add nsw i64 %indvars.iv, -1
  %31 = getelementptr inbounds [0 x ptr], ptr %29, i64 0, i64 %30
  store ptr null, ptr %31, align 8, !tbaa !12
  %32 = load ptr, ptr %0, align 8, !tbaa !5
  %33 = getelementptr inbounds i8, ptr %32, i64 32
  %34 = add nsw i64 %indvars.iv, -2
  %35 = getelementptr inbounds [0 x ptr], ptr %33, i64 0, i64 %34
  store ptr null, ptr %35, align 8, !tbaa !12
  %36 = load ptr, ptr %0, align 8, !tbaa !5
  %37 = getelementptr inbounds i8, ptr %36, i64 32
  %38 = add nsw i64 %indvars.iv, -3
  %39 = getelementptr inbounds [0 x ptr], ptr %37, i64 0, i64 %38
  store ptr null, ptr %39, align 8, !tbaa !12
  %40 = load ptr, ptr %0, align 8, !tbaa !5
  %41 = getelementptr inbounds i8, ptr %40, i64 32
  %42 = add nsw i64 %indvars.iv, -4
  %43 = getelementptr inbounds [0 x ptr], ptr %41, i64 0, i64 %42
  store ptr null, ptr %43, align 8, !tbaa !12
  %.not18.wide.3 = icmp eq i64 %42, 0
  br i1 %.not18.wide.3, label %._crit_edge25, label %.lr.ph24, !llvm.loop !19

._crit_edge25:                                    ; preds = %.lr.ph24, %.lr.ph24.prol.loopexit
  store i32 0, ptr %19, align 4, !tbaa !16
  br label %44

44:                                               ; preds = %._crit_edge25, %._crit_edge
  ret i64 %16
}

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 = { 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, !7, i64 0}
!6 = !{!"skiplist", !7, i64 0, !10, i64 8, !10, i64 12, !7, i64 16, !11, i64 24}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"long", !8, i64 0}
!12 = !{!7, !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = !{!6, !11, i64 24}
!16 = !{!6, !10, i64 12}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.unroll.disable"}
!19 = distinct !{!19, !14}


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