; LLVM IR from yinqiwen/ardb :: src/common/redis (listpack)

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

; 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
declare dso_local ptr @lpNext(ptr noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local ptr @lpFirst(ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local i32 @lpLength(ptr noundef %0) #1 {
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #2
  %8 = load ptr, ptr %3, align 8, !tbaa !5
  %9 = getelementptr inbounds i8, ptr %8, i64 4
  %10 = load i8, ptr %9, align 1, !tbaa !9
  %11 = zext i8 %10 to i32
  %12 = shl i32 %11, 0
  %13 = load ptr, ptr %3, align 8, !tbaa !5
  %14 = getelementptr inbounds i8, ptr %13, i64 5
  %15 = load i8, ptr %14, align 1, !tbaa !9
  %16 = zext i8 %15 to i32
  %17 = shl i32 %16, 8
  %18 = or i32 %12, %17
  store i32 %18, ptr %4, align 4, !tbaa !10
  %19 = load i32, ptr %4, align 4, !tbaa !10
  %20 = icmp ne i32 %19, 65535
  br i1 %20, label %21, label %23

21:                                               ; preds = %1
  %22 = load i32, ptr %4, align 4, !tbaa !10
  store i32 %22, ptr %2, align 4
  store i32 1, ptr %5, align 4
  br label %55

23:                                               ; preds = %1
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #2
  store i32 0, ptr %6, align 4, !tbaa !10
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #2
  %24 = load ptr, ptr %3, align 8, !tbaa !5
  %25 = call ptr @lpFirst(ptr noundef %24)
  store ptr %25, ptr %7, align 8, !tbaa !5
  br label %26

26:                                               ; preds = %29, %23
  %27 = load ptr, ptr %7, align 8, !tbaa !5
  %28 = icmp ne ptr %27, null
  br i1 %28, label %29, label %35

29:                                               ; preds = %26
  %30 = load i32, ptr %6, align 4, !tbaa !10
  %31 = add i32 %30, 1
  store i32 %31, ptr %6, align 4, !tbaa !10
  %32 = load ptr, ptr %3, align 8, !tbaa !5
  %33 = load ptr, ptr %7, align 8, !tbaa !5
  %34 = call ptr @lpNext(ptr noundef %32, ptr noundef %33)
  store ptr %34, ptr %7, align 8, !tbaa !5
  br label %26, !llvm.loop !12

35:                                               ; preds = %26
  %36 = load i32, ptr %6, align 4, !tbaa !10
  %37 = icmp ult i32 %36, 65535
  br i1 %37, label %38, label %53

38:                                               ; preds = %35
  br label %39

39:                                               ; preds = %38
  %40 = load i32, ptr %6, align 4, !tbaa !10
  %41 = and i32 %40, 255
  %42 = trunc i32 %41 to i8
  %43 = load ptr, ptr %3, align 8, !tbaa !5
  %44 = getelementptr inbounds i8, ptr %43, i64 4
  store i8 %42, ptr %44, align 1, !tbaa !9
  %45 = load i32, ptr %6, align 4, !tbaa !10
  %46 = lshr i32 %45, 8
  %47 = and i32 %46, 255
  %48 = trunc i32 %47 to i8
  %49 = load ptr, ptr %3, align 8, !tbaa !5
  %50 = getelementptr inbounds i8, ptr %49, i64 5
  store i8 %48, ptr %50, align 1, !tbaa !9
  br label %51

51:                                               ; preds = %39
  br label %52

52:                                               ; preds = %51
  br label %53

53:                                               ; preds = %52, %35
  %54 = load i32, ptr %6, align 4, !tbaa !10
  store i32 %54, ptr %2, align 4
  store i32 1, ptr %5, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  br label %55

55:                                               ; preds = %53, %21
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #2
  %56 = load i32, ptr %2, align 4
  ret i32 %56
}

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 = !{!7, !7, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"int", !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}


; 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 ptr @lpNext(ptr noundef, ptr noundef) local_unnamed_addr #0

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

; Function Attrs: nounwind uwtable
define dso_local i32 @lpLength(ptr noundef %0) local_unnamed_addr #0 {
  %2 = getelementptr inbounds i8, ptr %0, i64 4
  %3 = load i8, ptr %2, align 1, !tbaa !5
  %4 = zext i8 %3 to i32
  %5 = getelementptr inbounds i8, ptr %0, i64 5
  %6 = load i8, ptr %5, align 1, !tbaa !5
  %7 = zext i8 %6 to i32
  %8 = shl nuw nsw i32 %7, 8
  %9 = or disjoint i32 %8, %4
  %.not = icmp eq i32 %9, 65535
  br i1 %.not, label %10, label %18

10:                                               ; preds = %1
  %11 = tail call ptr @lpFirst(ptr noundef nonnull %0)
  %.not1819 = icmp eq ptr %11, null
  br i1 %.not1819, label %._crit_edge.thread, label %.lr.ph

.lr.ph:                                           ; preds = %10, %.lr.ph
  %.021 = phi ptr [ %13, %.lr.ph ], [ %11, %10 ]
  %.01520 = phi i32 [ %12, %.lr.ph ], [ 0, %10 ]
  %12 = add i32 %.01520, 1
  %13 = tail call ptr @lpNext(ptr noundef %0, ptr noundef nonnull %.021)
  %.not18 = icmp eq ptr %13, null
  br i1 %.not18, label %._crit_edge, label %.lr.ph, !llvm.loop !8

._crit_edge:                                      ; preds = %.lr.ph
  %14 = icmp ult i32 %12, 65535
  br i1 %14, label %._crit_edge.thread, label %18

._crit_edge.thread:                               ; preds = %10, %._crit_edge
  %.015.lcssa23 = phi i32 [ %12, %._crit_edge ], [ 0, %10 ]
  %15 = trunc i32 %.015.lcssa23 to i8
  store i8 %15, ptr %2, align 1, !tbaa !5
  %16 = lshr i32 %.015.lcssa23, 8
  %17 = trunc nuw i32 %16 to i8
  store i8 %17, ptr %5, align 1, !tbaa !5
  br label %18

18:                                               ; preds = %._crit_edge, %._crit_edge.thread, %1
  %.016 = phi i32 [ %9, %1 ], [ %.015.lcssa23, %._crit_edge.thread ], [ %12, %._crit_edge ]
  ret i32 %.016
}

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

!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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = distinct !{!8, !9}
!9 = !{!"llvm.loop.mustprogress"}


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