; 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
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
define dso_local i32 @ziplistGet(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3) #1 {
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca %struct.zlentry, align 8
  %11 = alloca i32, align 4
  %12 = alloca %struct.zlentry, align 8
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store ptr %2, ptr %8, align 8, !tbaa !5
  store ptr %3, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 32, ptr %10) #3
  %13 = load ptr, ptr %6, align 8, !tbaa !5
  %14 = icmp eq ptr %13, null
  br i1 %14, label %21, label %15

15:                                               ; preds = %4
  %16 = load ptr, ptr %6, align 8, !tbaa !5
  %17 = getelementptr inbounds i8, ptr %16, i64 0
  %18 = load i8, ptr %17, align 1, !tbaa !9
  %19 = zext i8 %18 to i32
  %20 = icmp eq i32 %19, 255
  br i1 %20, label %21, label %22

21:                                               ; preds = %15, %4
  store i32 0, ptr %5, align 4
  store i32 1, ptr %11, align 4
  br label %63

22:                                               ; preds = %15
  %23 = load ptr, ptr %7, align 8, !tbaa !5
  %24 = icmp ne ptr %23, null
  br i1 %24, label %25, label %27

25:                                               ; preds = %22
  %26 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr null, ptr %26, align 8, !tbaa !5
  br label %27

27:                                               ; preds = %25, %22
  call void @llvm.lifetime.start.p0(i64 32, ptr %12) #3
  %28 = load ptr, ptr %6, align 8, !tbaa !5
  call void @zipEntry(ptr dead_on_unwind writable sret(%struct.zlentry) align 8 %12, ptr noundef %28)
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %10, ptr align 8 %12, i64 32, i1 false), !tbaa.struct !10
  call void @llvm.lifetime.end.p0(i64 32, ptr %12) #3
  %29 = getelementptr inbounds %struct.zlentry, ptr %10, i32 0, i32 5
  %30 = load i8, ptr %29, align 4, !tbaa !13
  %31 = zext i8 %30 to i32
  %32 = and i32 %31, 192
  %33 = icmp slt i32 %32, 192
  br i1 %33, label %34, label %48

34:                                               ; preds = %27
  %35 = load ptr, ptr %7, align 8, !tbaa !5
  %36 = icmp ne ptr %35, null
  br i1 %36, label %37, label %47

37:                                               ; preds = %34
  %38 = getelementptr inbounds %struct.zlentry, ptr %10, i32 0, i32 3
  %39 = load i32, ptr %38, align 4, !tbaa !15
  %40 = load ptr, ptr %8, align 8, !tbaa !5
  store i32 %39, ptr %40, align 4, !tbaa !11
  %41 = load ptr, ptr %6, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.zlentry, ptr %10, i32 0, i32 4
  %43 = load i32, ptr %42, align 8, !tbaa !16
  %44 = zext i32 %43 to i64
  %45 = getelementptr inbounds i8, ptr %41, i64 %44
  %46 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %45, ptr %46, align 8, !tbaa !5
  br label %47

47:                                               ; preds = %37, %34
  br label %62

48:                                               ; preds = %27
  %49 = load ptr, ptr %9, align 8, !tbaa !5
  %50 = icmp ne ptr %49, null
  br i1 %50, label %51, label %61

51:                                               ; preds = %48
  %52 = load ptr, ptr %6, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.zlentry, ptr %10, i32 0, i32 4
  %54 = load i32, ptr %53, align 8, !tbaa !16
  %55 = zext i32 %54 to i64
  %56 = getelementptr inbounds i8, ptr %52, i64 %55
  %57 = getelementptr inbounds %struct.zlentry, ptr %10, i32 0, i32 5
  %58 = load i8, ptr %57, align 4, !tbaa !13
  %59 = call i64 @zipLoadInteger(ptr noundef %56, i8 noundef zeroext %58)
  %60 = load ptr, ptr %9, align 8, !tbaa !5
  store i64 %59, ptr %60, align 8, !tbaa !17
  br label %61

61:                                               ; preds = %51, %48
  br label %62

62:                                               ; preds = %61, %47
  store i32 1, ptr %5, align 4
  store i32 1, ptr %11, align 4
  br label %63

63:                                               ; preds = %62, %21
  call void @llvm.lifetime.end.p0(i64 32, ptr %10) #3
  %64 = load i32, ptr %5, align 4
  ret i32 %64
}

; Function Attrs: nounwind uwtable
declare hidden i64 @zipLoadInteger(ptr noundef, i8 noundef zeroext) #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 = !{!7, !7, i64 0}
!10 = !{i64 0, i64 4, !11, i64 4, i64 4, !11, i64 8, i64 4, !11, i64 12, i64 4, !11, i64 16, i64 4, !11, i64 20, i64 1, !9, i64 24, i64 8, !5}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !7, i64 20}
!14 = !{!"zlentry", !12, i64 0, !12, i64 4, !12, i64 8, !12, i64 12, !12, i64 16, !7, i64 20, !6, i64 24}
!15 = !{!14, !12, i64 12}
!16 = !{!14, !12, i64 16}
!17 = !{!18, !18, i64 0}
!18 = !{!"long long", !7, i64 0}


; 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
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
define dso_local range(i32 0, 2) i32 @ziplistGet(ptr noundef %0, ptr noundef writeonly %1, ptr nocapture noundef writeonly %2, ptr noundef writeonly %3) local_unnamed_addr #1 {
  %5 = alloca %struct.zlentry, align 8
  %6 = icmp eq ptr %0, null
  br i1 %6, label %22, label %7

7:                                                ; preds = %4
  %8 = load i8, ptr %0, align 1, !tbaa !5
  %9 = icmp eq i8 %8, -1
  br i1 %9, label %22, label %10

10:                                               ; preds = %7
  %.not = icmp eq ptr %1, null
  br i1 %.not, label %12, label %11

11:                                               ; preds = %10
  store ptr null, ptr %1, align 8, !tbaa !8
  br label %12

12:                                               ; preds = %11, %10
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %5) #2
  call void @zipEntry(ptr dead_on_unwind nonnull writable sret(%struct.zlentry) align 8 %5, ptr noundef nonnull %0)
  %.sroa.3.0..sroa_idx = getelementptr inbounds i8, ptr %5, i64 12
  %.sroa.3.0.copyload = load i32, ptr %.sroa.3.0..sroa_idx, align 4, !tbaa !10
  %.sroa.4.0..sroa_idx = getelementptr inbounds i8, ptr %5, i64 16
  %.sroa.4.0.copyload = load i32, ptr %.sroa.4.0..sroa_idx, align 8, !tbaa !10
  %.sroa.6.0..sroa_idx = getelementptr inbounds i8, ptr %5, i64 20
  %.sroa.6.0.copyload = load i8, ptr %.sroa.6.0..sroa_idx, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %5) #2
  %.not17 = icmp ugt i8 %.sroa.6.0.copyload, -65
  br i1 %.not17, label %17, label %13

13:                                               ; preds = %12
  br i1 %.not, label %22, label %14

14:                                               ; preds = %13
  store i32 %.sroa.3.0.copyload, ptr %2, align 4, !tbaa !10
  %15 = zext i32 %.sroa.4.0.copyload to i64
  %16 = getelementptr inbounds i8, ptr %0, i64 %15
  store ptr %16, ptr %1, align 8, !tbaa !8
  br label %22

17:                                               ; preds = %12
  %.not18 = icmp eq ptr %3, null
  br i1 %.not18, label %22, label %18

18:                                               ; preds = %17
  %19 = zext i32 %.sroa.4.0.copyload to i64
  %20 = getelementptr inbounds i8, ptr %0, i64 %19
  %21 = call i64 @zipLoadInteger(ptr noundef nonnull %20, i8 noundef zeroext %.sroa.6.0.copyload)
  store i64 %21, ptr %3, align 8, !tbaa !12
  br label %22

22:                                               ; preds = %14, %13, %18, %17, %4, %7
  %.0 = phi i32 [ 0, %7 ], [ 0, %4 ], [ 1, %17 ], [ 1, %18 ], [ 1, %13 ], [ 1, %14 ]
  ret i32 %.0
}

; Function Attrs: nounwind uwtable
declare hidden i64 @zipLoadInteger(ptr noundef, i8 noundef zeroext) 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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = !{!9, !9, i64 0}
!9 = !{!"any pointer", !6, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"int", !6, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"long long", !6, i64 0}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass