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

%struct.zlentry = type { i32, i32, i32, i32, i32, i8, 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 ptr @ziplistIndex(ptr noundef %0, i32 noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca %struct.zlentry, align 8
  %7 = alloca %struct.zlentry, align 8
  %8 = alloca %struct.zlentry, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  call void @llvm.lifetime.start.p0(i64 32, ptr %6) #3
  %9 = load i32, ptr %4, align 4, !tbaa !9
  %10 = icmp slt i32 %9, 0
  br i1 %10, label %11, label %48

11:                                               ; preds = %2
  %12 = load i32, ptr %4, align 4, !tbaa !9
  %13 = sub nsw i32 0, %12
  %14 = sub nsw i32 %13, 1
  store i32 %14, ptr %4, align 4, !tbaa !9
  %15 = load ptr, ptr %3, align 8, !tbaa !5
  %16 = load ptr, ptr %3, align 8, !tbaa !5
  %17 = getelementptr inbounds i8, ptr %16, i64 4
  %18 = load i32, ptr %17, align 4, !tbaa !9
  %19 = zext i32 %18 to i64
  %20 = getelementptr inbounds i8, ptr %15, i64 %19
  store ptr %20, ptr %5, align 8, !tbaa !5
  %21 = load ptr, ptr %5, align 8, !tbaa !5
  %22 = getelementptr inbounds i8, ptr %21, i64 0
  %23 = load i8, ptr %22, align 1, !tbaa !11
  %24 = zext i8 %23 to i32
  %25 = icmp ne i32 %24, 255
  br i1 %25, label %26, label %47

26:                                               ; preds = %11
  call void @llvm.lifetime.start.p0(i64 32, ptr %7) #3
  %27 = load ptr, ptr %5, align 8, !tbaa !5
  call void @zipEntry(ptr dead_on_unwind writable sret(%struct.zlentry) align 8 %7, ptr noundef %27)
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %6, ptr align 8 %7, i64 32, i1 false), !tbaa.struct !12
  call void @llvm.lifetime.end.p0(i64 32, ptr %7) #3
  br label %28

28:                                               ; preds = %38, %26
  %29 = getelementptr inbounds %struct.zlentry, ptr %6, i32 0, i32 1
  %30 = load i32, ptr %29, align 4, !tbaa !13
  %31 = icmp ugt i32 %30, 0
  br i1 %31, label %32, label %36

32:                                               ; preds = %28
  %33 = load i32, ptr %4, align 4, !tbaa !9
  %34 = add nsw i32 %33, -1
  store i32 %34, ptr %4, align 4, !tbaa !9
  %35 = icmp ne i32 %33, 0
  br label %36

36:                                               ; preds = %32, %28
  %37 = phi i1 [ false, %28 ], [ %35, %32 ]
  br i1 %37, label %38, label %46

38:                                               ; preds = %36
  %39 = getelementptr inbounds %struct.zlentry, ptr %6, i32 0, i32 1
  %40 = load i32, ptr %39, align 4, !tbaa !13
  %41 = load ptr, ptr %5, align 8, !tbaa !5
  %42 = zext i32 %40 to i64
  %43 = sub i64 0, %42
  %44 = getelementptr inbounds i8, ptr %41, i64 %43
  store ptr %44, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 32, ptr %8) #3
  %45 = load ptr, ptr %5, align 8, !tbaa !5
  call void @zipEntry(ptr dead_on_unwind writable sret(%struct.zlentry) align 8 %8, ptr noundef %45)
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %6, ptr align 8 %8, i64 32, i1 false), !tbaa.struct !12
  call void @llvm.lifetime.end.p0(i64 32, ptr %8) #3
  br label %28, !llvm.loop !15

46:                                               ; preds = %36
  br label %47

47:                                               ; preds = %46, %11
  br label %70

48:                                               ; preds = %2
  %49 = load ptr, ptr %3, align 8, !tbaa !5
  %50 = getelementptr inbounds i8, ptr %49, i64 10
  store ptr %50, ptr %5, align 8, !tbaa !5
  br label %51

51:                                               ; preds = %63, %48
  %52 = load ptr, ptr %5, align 8, !tbaa !5
  %53 = getelementptr inbounds i8, ptr %52, i64 0
  %54 = load i8, ptr %53, align 1, !tbaa !11
  %55 = zext i8 %54 to i32
  %56 = icmp ne i32 %55, 255
  br i1 %56, label %57, label %61

57:                                               ; preds = %51
  %58 = load i32, ptr %4, align 4, !tbaa !9
  %59 = add nsw i32 %58, -1
  store i32 %59, ptr %4, align 4, !tbaa !9
  %60 = icmp ne i32 %58, 0
  br label %61

61:                                               ; preds = %57, %51
  %62 = phi i1 [ false, %51 ], [ %60, %57 ]
  br i1 %62, label %63, label %69

63:                                               ; preds = %61
  %64 = load ptr, ptr %5, align 8, !tbaa !5
  %65 = call i32 @zipRawEntryLength(ptr noundef %64)
  %66 = load ptr, ptr %5, align 8, !tbaa !5
  %67 = zext i32 %65 to i64
  %68 = getelementptr inbounds i8, ptr %66, i64 %67
  store ptr %68, ptr %5, align 8, !tbaa !5
  br label %51, !llvm.loop !17

69:                                               ; preds = %61
  br label %70

70:                                               ; preds = %69, %47
  %71 = load ptr, ptr %5, align 8, !tbaa !5
  %72 = getelementptr inbounds i8, ptr %71, i64 0
  %73 = load i8, ptr %72, align 1, !tbaa !11
  %74 = zext i8 %73 to i32
  %75 = icmp eq i32 %74, 255
  br i1 %75, label %79, label %76

76:                                               ; preds = %70
  %77 = load i32, ptr %4, align 4, !tbaa !9
  %78 = icmp sgt i32 %77, 0
  br i1 %78, label %79, label %80

79:                                               ; preds = %76, %70
  br label %82

80:                                               ; preds = %76
  %81 = load ptr, ptr %5, align 8, !tbaa !5
  br label %82

82:                                               ; preds = %80, %79
  %83 = phi ptr [ null, %79 ], [ %81, %80 ]
  call void @llvm.lifetime.end.p0(i64 32, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  ret ptr %83
}

; Function Attrs: nounwind uwtable
declare hidden void @zipEntry(ptr dead_on_unwind noalias writable sret(%struct.zlentry) align 8, ptr noundef) #1

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #2

; Function Attrs: nounwind uwtable
declare hidden i32 @zipRawEntryLength(ptr noundef) #1

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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = !{i64 0, i64 4, !9, i64 4, i64 4, !9, i64 8, i64 4, !9, i64 12, i64 4, !9, i64 16, i64 4, !9, i64 20, i64 1, !11, i64 24, i64 8, !5}
!13 = !{!14, !10, i64 4}
!14 = !{!"zlentry", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !10, i64 16, !7, i64 20, !6, i64 24}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = distinct !{!17, !16}


; 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.zlentry = type { i32, i32, i32, i32, i32, i8, ptr }

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

; Function Attrs: mustprogress 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 ptr @ziplistIndex(ptr noundef %0, i32 noundef %1) local_unnamed_addr #1 {
  %3 = alloca %struct.zlentry, align 8
  %4 = alloca %struct.zlentry, align 8
  %5 = icmp slt i32 %1, 0
  br i1 %5, label %6, label %20

6:                                                ; preds = %2
  %7 = xor i32 %1, -1
  %8 = getelementptr inbounds i8, ptr %0, i64 4
  %9 = load i32, ptr %8, align 4, !tbaa !5
  %10 = zext i32 %9 to i64
  %11 = getelementptr inbounds i8, ptr %0, i64 %10
  %12 = load i8, ptr %11, align 1, !tbaa !9
  %.not30 = icmp eq i8 %12, -1
  br i1 %.not30, label %.critedge, label %13

13:                                               ; preds = %6
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %3) #2
  call void @zipEntry(ptr dead_on_unwind nonnull writable sret(%struct.zlentry) align 8 %3, ptr noundef nonnull %11)
  %.sroa.4.0..sroa_idx = getelementptr inbounds i8, ptr %3, i64 4
  %.sroa.4.0.copyload = load i32, ptr %.sroa.4.0..sroa_idx, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %3) #2
  %.not3142 = icmp eq i32 %.sroa.4.0.copyload, 0
  br i1 %.not3142, label %.critedge, label %.lr.ph46

.lr.ph46:                                         ; preds = %13
  %.sroa.4.0..sroa_idx5 = getelementptr inbounds i8, ptr %4, i64 4
  br label %14

14:                                               ; preds = %.lr.ph46, %15
  %.sroa.4.045 = phi i32 [ %.sroa.4.0.copyload, %.lr.ph46 ], [ %.sroa.4.0.copyload6, %15 ]
  %.044 = phi ptr [ %11, %.lr.ph46 ], [ %19, %15 ]
  %.02443 = phi i32 [ %7, %.lr.ph46 ], [ %16, %15 ]
  %.not32 = icmp eq i32 %.02443, 0
  br i1 %.not32, label %.critedge, label %15

15:                                               ; preds = %14
  %16 = add nsw i32 %.02443, -1
  %17 = zext i32 %.sroa.4.045 to i64
  %18 = sub nsw i64 0, %17
  %19 = getelementptr inbounds i8, ptr %.044, i64 %18
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %4) #2
  call void @zipEntry(ptr dead_on_unwind nonnull writable sret(%struct.zlentry) align 8 %4, ptr noundef nonnull %19)
  %.sroa.4.0.copyload6 = load i32, ptr %.sroa.4.0..sroa_idx5, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %4) #2
  %.not31 = icmp eq i32 %.sroa.4.0.copyload6, 0
  br i1 %.not31, label %.critedge, label %14, !llvm.loop !10

20:                                               ; preds = %2
  %21 = getelementptr inbounds i8, ptr %0, i64 10
  %22 = load i8, ptr %21, align 1, !tbaa !9
  %.not35 = icmp eq i8 %22, -1
  br i1 %.not35, label %.critedge, label %.lr.ph

.lr.ph:                                           ; preds = %20, %23
  %.137 = phi ptr [ %27, %23 ], [ %21, %20 ]
  %.12536 = phi i32 [ %24, %23 ], [ %1, %20 ]
  %.not29 = icmp eq i32 %.12536, 0
  br i1 %.not29, label %.critedge, label %23

23:                                               ; preds = %.lr.ph
  %24 = add nsw i32 %.12536, -1
  %25 = tail call i32 @zipRawEntryLength(ptr noundef nonnull %.137)
  %26 = zext i32 %25 to i64
  %27 = getelementptr inbounds i8, ptr %.137, i64 %26
  %28 = load i8, ptr %27, align 1, !tbaa !9
  %.not = icmp eq i8 %28, -1
  br i1 %.not, label %.critedge, label %.lr.ph, !llvm.loop !12

.critedge:                                        ; preds = %23, %.lr.ph, %14, %15, %20, %13, %6
  %.226 = phi i32 [ %7, %6 ], [ %7, %13 ], [ %1, %20 ], [ -1, %14 ], [ %16, %15 ], [ %24, %23 ], [ -1, %.lr.ph ]
  %.2 = phi ptr [ %11, %6 ], [ %11, %13 ], [ %21, %20 ], [ %.044, %14 ], [ %19, %15 ], [ %27, %23 ], [ %.137, %.lr.ph ]
  %29 = load i8, ptr %.2, align 1, !tbaa !9
  %30 = icmp eq i8 %29, -1
  %31 = icmp sgt i32 %.226, 0
  %or.cond = select i1 %30, i1 true, i1 %31
  %32 = select i1 %or.cond, ptr null, ptr %.2
  ret ptr %32
}

; Function Attrs: nounwind uwtable
declare hidden void @zipEntry(ptr dead_on_unwind noalias writable sret(%struct.zlentry) align 8, ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare hidden i32 @zipRawEntryLength(ptr noundef) local_unnamed_addr #1

attributes #0 = { mustprogress 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 = !{!"int", !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"}
!12 = distinct !{!12, !11}


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