; 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
declare hidden i64 @zipLoadInteger(ptr noundef, i8 noundef zeroext) #1

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

19:                                               ; preds = %3
  store i32 0, ptr %4, align 4
  store i32 1, ptr %12, align 4
  br label %65

20:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 32, ptr %13) #4
  %21 = load ptr, ptr %5, align 8, !tbaa !5
  call void @zipEntry(ptr dead_on_unwind writable sret(%struct.zlentry) align 8 %13, ptr noundef %21)
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %8, ptr align 8 %13, i64 32, i1 false), !tbaa.struct !12
  call void @llvm.lifetime.end.p0(i64 32, ptr %13) #4
  %22 = getelementptr inbounds %struct.zlentry, ptr %8, i32 0, i32 5
  %23 = load i8, ptr %22, align 4, !tbaa !13
  %24 = zext i8 %23 to i32
  %25 = and i32 %24, 192
  %26 = icmp slt i32 %25, 192
  br i1 %26, label %27, label %45

27:                                               ; preds = %20
  %28 = getelementptr inbounds %struct.zlentry, ptr %8, i32 0, i32 3
  %29 = load i32, ptr %28, align 4, !tbaa !15
  %30 = load i32, ptr %7, align 4, !tbaa !9
  %31 = icmp eq i32 %29, %30
  br i1 %31, label %32, label %44

32:                                               ; preds = %27
  %33 = load ptr, ptr %5, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.zlentry, ptr %8, i32 0, i32 4
  %35 = load i32, ptr %34, align 8, !tbaa !16
  %36 = zext i32 %35 to i64
  %37 = getelementptr inbounds i8, ptr %33, i64 %36
  %38 = load ptr, ptr %6, align 8, !tbaa !5
  %39 = load i32, ptr %7, align 4, !tbaa !9
  %40 = zext i32 %39 to i64
  %41 = call i32 @memcmp(ptr noundef %37, ptr noundef %38, i64 noundef %40) #5
  %42 = icmp eq i32 %41, 0
  %43 = zext i1 %42 to i32
  store i32 %43, ptr %4, align 4
  store i32 1, ptr %12, align 4
  br label %65

44:                                               ; preds = %27
  store i32 0, ptr %4, align 4
  store i32 1, ptr %12, align 4
  br label %65

45:                                               ; preds = %20
  %46 = load ptr, ptr %6, align 8, !tbaa !5
  %47 = load i32, ptr %7, align 4, !tbaa !9
  %48 = call i32 @zipTryEncoding(ptr noundef %46, i32 noundef %47, ptr noundef %11, ptr noundef %9)
  %49 = icmp ne i32 %48, 0
  br i1 %49, label %50, label %63

50:                                               ; preds = %45
  %51 = load ptr, ptr %5, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.zlentry, ptr %8, i32 0, i32 4
  %53 = load i32, ptr %52, align 8, !tbaa !16
  %54 = zext i32 %53 to i64
  %55 = getelementptr inbounds i8, ptr %51, i64 %54
  %56 = getelementptr inbounds %struct.zlentry, ptr %8, i32 0, i32 5
  %57 = load i8, ptr %56, align 4, !tbaa !13
  %58 = call i64 @zipLoadInteger(ptr noundef %55, i8 noundef zeroext %57)
  store i64 %58, ptr %10, align 8, !tbaa !17
  %59 = load i64, ptr %10, align 8, !tbaa !17
  %60 = load i64, ptr %11, align 8, !tbaa !17
  %61 = icmp eq i64 %59, %60
  %62 = zext i1 %61 to i32
  store i32 %62, ptr %4, align 4
  store i32 1, ptr %12, align 4
  br label %65

63:                                               ; preds = %45
  br label %64

64:                                               ; preds = %63
  store i32 0, ptr %4, align 4
  store i32 1, ptr %12, align 4
  br label %65

65:                                               ; preds = %64, %50, %44, %32, %19
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 1, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 32, ptr %8) #4
  %66 = load i32, ptr %4, align 4
  ret i32 %66
}

; Function Attrs: nounwind willreturn memory(read)
declare i32 @memcmp(ptr noundef, ptr noundef, i64 noundef) #3

; Function Attrs: nounwind uwtable
declare hidden i32 @zipTryEncoding(ptr noundef, i32 noundef, ptr noundef, 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 willreturn memory(read) "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 #4 = { nounwind }
attributes #5 = { nounwind willreturn memory(read) }

!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, !7, i64 20}
!14 = !{!"zlentry", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !10, i64 16, !7, i64 20, !6, i64 24}
!15 = !{!14, !10, i64 12}
!16 = !{!14, !10, 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
declare hidden i64 @zipLoadInteger(ptr noundef, i8 noundef zeroext) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 2) i32 @ziplistCompare(ptr noundef %0, ptr noundef %1, i32 noundef %2) local_unnamed_addr #1 {
  %4 = alloca i8, align 1
  %5 = alloca i64, align 8
  %6 = alloca %struct.zlentry, align 8
  call void @llvm.lifetime.start.p0(i64 1, ptr nonnull %4) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %5) #3
  %7 = load i8, ptr %0, align 1, !tbaa !5
  %8 = icmp eq i8 %7, -1
  br i1 %8, label %25, label %9

9:                                                ; preds = %3
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %6) #3
  call void @zipEntry(ptr dead_on_unwind nonnull writable sret(%struct.zlentry) align 8 %6, ptr noundef nonnull %0)
  %.sroa.3.0..sroa_idx = getelementptr inbounds i8, ptr %6, i64 12
  %.sroa.3.0.copyload = load i32, ptr %.sroa.3.0..sroa_idx, align 4, !tbaa !8
  %.sroa.4.0..sroa_idx = getelementptr inbounds i8, ptr %6, i64 16
  %.sroa.4.0.copyload = load i32, ptr %.sroa.4.0..sroa_idx, align 8, !tbaa !8
  %.sroa.6.0..sroa_idx = getelementptr inbounds i8, ptr %6, 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 %6) #3
  %.not = icmp ugt i8 %.sroa.6.0.copyload, -65
  br i1 %.not, label %17, label %10

10:                                               ; preds = %9
  %11 = icmp eq i32 %.sroa.3.0.copyload, %2
  br i1 %11, label %12, label %25

12:                                               ; preds = %10
  %13 = zext i32 %.sroa.4.0.copyload to i64
  %14 = getelementptr inbounds i8, ptr %0, i64 %13
  %15 = zext i32 %2 to i64
  %bcmp = call i32 @bcmp(ptr nonnull %14, ptr %1, i64 %15)
  %16 = icmp eq i32 %bcmp, 0
  br label %25

17:                                               ; preds = %9
  %18 = call i32 @zipTryEncoding(ptr noundef %1, i32 noundef %2, ptr noundef nonnull %5, ptr noundef nonnull %4)
  %.not13 = icmp eq i32 %18, 0
  br i1 %.not13, label %25, label %19

19:                                               ; preds = %17
  %20 = zext i32 %.sroa.4.0.copyload to i64
  %21 = getelementptr inbounds i8, ptr %0, i64 %20
  %22 = call i64 @zipLoadInteger(ptr noundef nonnull %21, i8 noundef zeroext %.sroa.6.0.copyload)
  %23 = load i64, ptr %5, align 8, !tbaa !10
  %24 = icmp eq i64 %22, %23
  br label %25

25:                                               ; preds = %17, %10, %3, %19, %12
  %.0.shrunk = phi i1 [ %16, %12 ], [ %24, %19 ], [ false, %3 ], [ false, %10 ], [ false, %17 ]
  %.0 = zext i1 %.0.shrunk to i32
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %5) #3
  call void @llvm.lifetime.end.p0(i64 1, ptr nonnull %4) #3
  ret i32 %.0
}

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

; Function Attrs: nofree nounwind willreturn memory(argmem: read)
declare i32 @bcmp(ptr nocapture, ptr nocapture, i64) local_unnamed_addr #2

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 = { nofree nounwind willreturn memory(argmem: read) }
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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = !{!9, !9, i64 0}
!9 = !{!"int", !6, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"long long", !6, i64 0}


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