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

; 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 zeroext i1 @skiplist_itor_last(ptr noundef %0) #1 {
  %2 = alloca i1, align 1
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #2
  %7 = load ptr, ptr %3, align 8, !tbaa !5
  %8 = getelementptr inbounds %struct.skiplist_itor, ptr %7, i32 0, i32 0
  %9 = load ptr, ptr %8, align 8, !tbaa !9
  %10 = getelementptr inbounds %struct.skiplist, ptr %9, i32 0, i32 0
  %11 = load ptr, ptr %10, align 8, !tbaa !11
  store ptr %11, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #2
  %12 = load ptr, ptr %3, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.skiplist_itor, ptr %12, i32 0, i32 0
  %14 = load ptr, ptr %13, align 8, !tbaa !9
  %15 = getelementptr inbounds %struct.skiplist, ptr %14, i32 0, i32 2
  %16 = load i32, ptr %15, align 4, !tbaa !15
  store i32 %16, ptr %5, align 4, !tbaa !16
  br label %17

17:                                               ; preds = %38, %1
  %18 = load i32, ptr %5, align 4, !tbaa !16
  %19 = add i32 %18, -1
  store i32 %19, ptr %5, align 4, !tbaa !16
  %20 = icmp ugt i32 %18, 0
  br i1 %20, label %22, label %21

21:                                               ; preds = %17
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  br label %39

22:                                               ; preds = %17
  br label %23

23:                                               ; preds = %31, %22
  %24 = load ptr, ptr %4, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.skip_node, ptr %24, i32 0, i32 4
  %26 = load i32, ptr %5, align 4, !tbaa !16
  %27 = zext i32 %26 to i64
  %28 = getelementptr inbounds [0 x ptr], ptr %25, i64 0, i64 %27
  %29 = load ptr, ptr %28, align 8, !tbaa !5
  %30 = icmp ne ptr %29, null
  br i1 %30, label %31, label %38

31:                                               ; preds = %23
  %32 = load ptr, ptr %4, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.skip_node, ptr %32, i32 0, i32 4
  %34 = load i32, ptr %5, align 4, !tbaa !16
  %35 = zext i32 %34 to i64
  %36 = getelementptr inbounds [0 x ptr], ptr %33, i64 0, i64 %35
  %37 = load ptr, ptr %36, align 8, !tbaa !5
  store ptr %37, ptr %4, align 8, !tbaa !5
  br label %23, !llvm.loop !17

38:                                               ; preds = %23
  br label %17, !llvm.loop !19

39:                                               ; preds = %21
  %40 = load ptr, ptr %4, align 8, !tbaa !5
  %41 = load ptr, ptr %3, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.skiplist_itor, ptr %41, i32 0, i32 0
  %43 = load ptr, ptr %42, align 8, !tbaa !9
  %44 = getelementptr inbounds %struct.skiplist, ptr %43, i32 0, i32 0
  %45 = load ptr, ptr %44, align 8, !tbaa !11
  %46 = icmp eq ptr %40, %45
  br i1 %46, label %47, label %50

47:                                               ; preds = %39
  %48 = load ptr, ptr %3, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.skiplist_itor, ptr %48, i32 0, i32 1
  store ptr null, ptr %49, align 8, !tbaa !20
  store i1 false, ptr %2, align 1
  store i32 1, ptr %6, align 4
  br label %54

50:                                               ; preds = %39
  %51 = load ptr, ptr %4, align 8, !tbaa !5
  %52 = load ptr, ptr %3, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.skiplist_itor, ptr %52, i32 0, i32 1
  store ptr %51, ptr %53, align 8, !tbaa !20
  store i1 true, ptr %2, align 1
  store i32 1, ptr %6, align 4
  br label %54

54:                                               ; preds = %50, %47
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #2
  %55 = load i1, ptr %2, align 1
  ret i1 %55
}

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


; 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(read, argmem: readwrite, inaccessiblemem: none) uwtable
define dso_local zeroext i1 @skiplist_itor_last(ptr nocapture noundef %0) local_unnamed_addr #0 {
  %2 = load ptr, ptr %0, align 8, !tbaa !5
  %3 = load ptr, ptr %2, align 8, !tbaa !10
  %4 = getelementptr inbounds i8, ptr %2, i64 12
  %5 = load i32, ptr %4, align 4, !tbaa !14
  %.not16 = icmp eq i32 %5, 0
  br i1 %.not16, label %._crit_edge.thread, label %.preheader.preheader

.preheader.preheader:                             ; preds = %1
  %6 = zext i32 %5 to i64
  %xtraiter = and i64 %6, 3
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %.preheader.prol.loopexit, label %.preheader.prol

.preheader.prol:                                  ; preds = %.preheader.preheader, %.loopexit.prol
  %indvars.iv.prol = phi i64 [ %7, %.loopexit.prol ], [ %6, %.preheader.preheader ]
  %.01217.prol = phi ptr [ %.1.prol, %.loopexit.prol ], [ %3, %.preheader.preheader ]
  %prol.iter = phi i64 [ %prol.iter.next, %.loopexit.prol ], [ 0, %.preheader.preheader ]
  %7 = add nsw i64 %indvars.iv.prol, -1
  br label %8

8:                                                ; preds = %8, %.preheader.prol
  %.1.prol = phi ptr [ %11, %8 ], [ %.01217.prol, %.preheader.prol ]
  %9 = getelementptr inbounds i8, ptr %.1.prol, i64 32
  %10 = getelementptr inbounds [0 x ptr], ptr %9, i64 0, i64 %7
  %11 = load ptr, ptr %10, align 8, !tbaa !15
  %.not15.prol = icmp eq ptr %11, null
  br i1 %.not15.prol, label %.loopexit.prol, label %8, !llvm.loop !16

.loopexit.prol:                                   ; preds = %8
  %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 %.preheader.prol.loopexit, label %.preheader.prol, !llvm.loop !18

.preheader.prol.loopexit:                         ; preds = %.loopexit.prol, %.preheader.preheader
  %.1.lcssa.lcssa.unr = phi ptr [ poison, %.preheader.preheader ], [ %.1.prol, %.loopexit.prol ]
  %indvars.iv.unr = phi i64 [ %6, %.preheader.preheader ], [ %7, %.loopexit.prol ]
  %.01217.unr = phi ptr [ %3, %.preheader.preheader ], [ %.1.prol, %.loopexit.prol ]
  %12 = icmp ult i32 %5, 4
  br i1 %12, label %._crit_edge, label %.preheader

.loopexit:                                        ; preds = %30
  %13 = add nsw i64 %indvars.iv, -2
  br label %14

14:                                               ; preds = %14, %.loopexit
  %.1.1 = phi ptr [ %17, %14 ], [ %.1, %.loopexit ]
  %15 = getelementptr inbounds i8, ptr %.1.1, i64 32
  %16 = getelementptr inbounds [0 x ptr], ptr %15, i64 0, i64 %13
  %17 = load ptr, ptr %16, align 8, !tbaa !15
  %.not15.1 = icmp eq ptr %17, null
  br i1 %.not15.1, label %.loopexit.1, label %14, !llvm.loop !16

.loopexit.1:                                      ; preds = %14
  %18 = add nsw i64 %indvars.iv, -3
  br label %19

19:                                               ; preds = %19, %.loopexit.1
  %.1.2 = phi ptr [ %22, %19 ], [ %.1.1, %.loopexit.1 ]
  %20 = getelementptr inbounds i8, ptr %.1.2, i64 32
  %21 = getelementptr inbounds [0 x ptr], ptr %20, i64 0, i64 %18
  %22 = load ptr, ptr %21, align 8, !tbaa !15
  %.not15.2 = icmp eq ptr %22, null
  br i1 %.not15.2, label %.loopexit.2, label %19, !llvm.loop !16

.loopexit.2:                                      ; preds = %19
  %23 = add nsw i64 %indvars.iv, -4
  br label %24

24:                                               ; preds = %24, %.loopexit.2
  %.1.3 = phi ptr [ %27, %24 ], [ %.1.2, %.loopexit.2 ]
  %25 = getelementptr inbounds i8, ptr %.1.3, i64 32
  %26 = getelementptr inbounds [0 x ptr], ptr %25, i64 0, i64 %23
  %27 = load ptr, ptr %26, align 8, !tbaa !15
  %.not15.3 = icmp eq ptr %27, null
  br i1 %.not15.3, label %.loopexit.3, label %24, !llvm.loop !16

.loopexit.3:                                      ; preds = %24
  %.not.wide.3 = icmp eq i64 %23, 0
  br i1 %.not.wide.3, label %._crit_edge, label %.preheader, !llvm.loop !20

.preheader:                                       ; preds = %.preheader.prol.loopexit, %.loopexit.3
  %indvars.iv = phi i64 [ %23, %.loopexit.3 ], [ %indvars.iv.unr, %.preheader.prol.loopexit ]
  %.01217 = phi ptr [ %.1.3, %.loopexit.3 ], [ %.01217.unr, %.preheader.prol.loopexit ]
  %28 = add nsw i64 %indvars.iv, -1
  br label %30

._crit_edge:                                      ; preds = %.loopexit.3, %.preheader.prol.loopexit
  %.1.lcssa.lcssa = phi ptr [ %.1.lcssa.lcssa.unr, %.preheader.prol.loopexit ], [ %.1.3, %.loopexit.3 ]
  %29 = icmp ne ptr %.1.lcssa.lcssa, %3
  %spec.select20 = select i1 %29, ptr %.1.lcssa.lcssa, ptr null
  br label %._crit_edge.thread

30:                                               ; preds = %30, %.preheader
  %.1 = phi ptr [ %33, %30 ], [ %.01217, %.preheader ]
  %31 = getelementptr inbounds i8, ptr %.1, i64 32
  %32 = getelementptr inbounds [0 x ptr], ptr %31, i64 0, i64 %28
  %33 = load ptr, ptr %32, align 8, !tbaa !15
  %.not15 = icmp eq ptr %33, null
  br i1 %.not15, label %.loopexit, label %30, !llvm.loop !16

._crit_edge.thread:                               ; preds = %._crit_edge, %1
  %34 = phi i1 [ false, %1 ], [ %29, %._crit_edge ]
  %.sink = phi ptr [ null, %1 ], [ %spec.select20, %._crit_edge ]
  %35 = getelementptr inbounds i8, ptr %0, i64 8
  store ptr %.sink, ptr %35, align 8
  ret i1 %34
}

attributes #0 = { nofree norecurse nosync nounwind memory(read, argmem: 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, !7, i64 0}
!6 = !{!"skiplist_itor", !7, i64 0, !7, i64 8}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!11, !7, i64 0}
!11 = !{!"skiplist", !7, i64 0, !12, i64 8, !12, i64 12, !7, i64 16, !13, i64 24}
!12 = !{!"int", !8, i64 0}
!13 = !{!"long", !8, i64 0}
!14 = !{!11, !12, i64 12}
!15 = !{!7, !7, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.unroll.disable"}
!20 = distinct !{!20, !17}


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