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

; 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 hidden i32 @zipRawEntryLength(ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local i32 @ziplistLen(ptr noundef %0) #1 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #2
  store i32 0, ptr %3, align 4, !tbaa !9
  %5 = load ptr, ptr %2, align 8, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %5, i64 8
  %7 = load i16, ptr %6, align 2, !tbaa !11
  %8 = zext i16 %7 to i32
  %9 = icmp slt i32 %8, 65535
  br i1 %9, label %10, label %15

10:                                               ; preds = %1
  %11 = load ptr, ptr %2, align 8, !tbaa !5
  %12 = getelementptr inbounds i8, ptr %11, i64 8
  %13 = load i16, ptr %12, align 2, !tbaa !11
  %14 = zext i16 %13 to i32
  store i32 %14, ptr %3, align 4, !tbaa !9
  br label %40

15:                                               ; preds = %1
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #2
  %16 = load ptr, ptr %2, align 8, !tbaa !5
  %17 = getelementptr inbounds i8, ptr %16, i64 10
  store ptr %17, ptr %4, align 8, !tbaa !5
  br label %18

18:                                               ; preds = %23, %15
  %19 = load ptr, ptr %4, align 8, !tbaa !5
  %20 = load i8, ptr %19, align 1, !tbaa !13
  %21 = zext i8 %20 to i32
  %22 = icmp ne i32 %21, 255
  br i1 %22, label %23, label %31

23:                                               ; preds = %18
  %24 = load ptr, ptr %4, align 8, !tbaa !5
  %25 = call i32 @zipRawEntryLength(ptr noundef %24)
  %26 = load ptr, ptr %4, align 8, !tbaa !5
  %27 = zext i32 %25 to i64
  %28 = getelementptr inbounds i8, ptr %26, i64 %27
  store ptr %28, ptr %4, align 8, !tbaa !5
  %29 = load i32, ptr %3, align 4, !tbaa !9
  %30 = add i32 %29, 1
  store i32 %30, ptr %3, align 4, !tbaa !9
  br label %18, !llvm.loop !14

31:                                               ; preds = %18
  %32 = load i32, ptr %3, align 4, !tbaa !9
  %33 = icmp ult i32 %32, 65535
  br i1 %33, label %34, label %39

34:                                               ; preds = %31
  %35 = load i32, ptr %3, align 4, !tbaa !9
  %36 = trunc i32 %35 to i16
  %37 = load ptr, ptr %2, align 8, !tbaa !5
  %38 = getelementptr inbounds i8, ptr %37, i64 8
  store i16 %36, ptr %38, align 2, !tbaa !11
  br label %39

39:                                               ; preds = %34, %31
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #2
  br label %40

40:                                               ; preds = %39, %10
  %41 = load i32, ptr %3, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #2
  ret i32 %41
}

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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"short", !7, i64 0}
!13 = !{!7, !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"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 hidden i32 @zipRawEntryLength(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local i32 @ziplistLen(ptr noundef %0) local_unnamed_addr #0 {
  %2 = getelementptr inbounds i8, ptr %0, i64 8
  %3 = load i16, ptr %2, align 2, !tbaa !5
  %.not = icmp eq i16 %3, -1
  br i1 %.not, label %6, label %4

4:                                                ; preds = %1
  %5 = zext i16 %3 to i32
  br label %16

6:                                                ; preds = %1
  %7 = getelementptr inbounds i8, ptr %0, i64 10
  %8 = load i8, ptr %7, align 1, !tbaa !9
  %.not1213 = icmp eq i8 %8, -1
  br i1 %.not1213, label %._crit_edge.thread, label %.lr.ph

.lr.ph:                                           ; preds = %6, %.lr.ph
  %.015 = phi ptr [ %11, %.lr.ph ], [ %7, %6 ]
  %.01014 = phi i32 [ %12, %.lr.ph ], [ 0, %6 ]
  %9 = tail call i32 @zipRawEntryLength(ptr noundef nonnull %.015)
  %10 = zext i32 %9 to i64
  %11 = getelementptr inbounds i8, ptr %.015, i64 %10
  %12 = add i32 %.01014, 1
  %13 = load i8, ptr %11, align 1, !tbaa !9
  %.not12 = icmp eq i8 %13, -1
  br i1 %.not12, label %._crit_edge, label %.lr.ph, !llvm.loop !10

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

._crit_edge.thread:                               ; preds = %6, %._crit_edge
  %.010.lcssa17 = phi i32 [ %12, %._crit_edge ], [ 0, %6 ]
  %15 = trunc nuw i32 %.010.lcssa17 to i16
  store i16 %15, ptr %2, align 2, !tbaa !5
  br label %16

16:                                               ; preds = %._crit_edge, %._crit_edge.thread, %4
  %.1 = phi i32 [ %5, %4 ], [ %.010.lcssa17, %._crit_edge.thread ], [ %12, %._crit_edge ]
  ret i32 %.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" }

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


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