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

@.str.4 = external hidden unnamed_addr constant [47 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [89 x i8], align 1
@stdout = external global ptr, align 8
@.str.6 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [8 x i8], align 1

; 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 void @ziplistRepr(ptr noundef %0) #1 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca %struct.zlentry, align 8
  %6 = alloca %struct.zlentry, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  store i32 0, ptr %4, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 32, ptr %5) #4
  %7 = load ptr, ptr %2, align 8, !tbaa !5
  %8 = load i32, ptr %7, align 4, !tbaa !9
  %9 = load ptr, ptr %2, align 8, !tbaa !5
  %10 = getelementptr inbounds i8, ptr %9, i64 8
  %11 = load i16, ptr %10, align 2, !tbaa !11
  %12 = zext i16 %11 to i32
  %13 = load ptr, ptr %2, align 8, !tbaa !5
  %14 = getelementptr inbounds i8, ptr %13, i64 4
  %15 = load i32, ptr %14, align 4, !tbaa !9
  %16 = call i32 (ptr, ...) @printf(ptr noundef @.str.4, i32 noundef %8, i32 noundef %12, i32 noundef %15)
  %17 = load ptr, ptr %2, align 8, !tbaa !5
  %18 = getelementptr inbounds i8, ptr %17, i64 10
  store ptr %18, ptr %3, align 8, !tbaa !5
  br label %19

19:                                               ; preds = %91, %1
  %20 = load ptr, ptr %3, align 8, !tbaa !5
  %21 = load i8, ptr %20, align 1, !tbaa !13
  %22 = zext i8 %21 to i32
  %23 = icmp ne i32 %22, 255
  br i1 %23, label %24, label %100

24:                                               ; preds = %19
  call void @llvm.lifetime.start.p0(i64 32, ptr %6) #4
  %25 = load ptr, ptr %3, align 8, !tbaa !5
  call void @zipEntry(ptr dead_on_unwind writable sret(%struct.zlentry) align 8 %6, ptr noundef %25)
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %5, ptr align 8 %6, i64 32, i1 false), !tbaa.struct !14
  call void @llvm.lifetime.end.p0(i64 32, ptr %6) #4
  %26 = load ptr, ptr %3, align 8, !tbaa !5
  %27 = ptrtoint ptr %26 to i64
  %28 = load i32, ptr %4, align 4, !tbaa !9
  %29 = load ptr, ptr %3, align 8, !tbaa !5
  %30 = load ptr, ptr %2, align 8, !tbaa !5
  %31 = ptrtoint ptr %29 to i64
  %32 = ptrtoint ptr %30 to i64
  %33 = sub i64 %31, %32
  %34 = getelementptr inbounds %struct.zlentry, ptr %5, i32 0, i32 4
  %35 = load i32, ptr %34, align 8, !tbaa !15
  %36 = getelementptr inbounds %struct.zlentry, ptr %5, i32 0, i32 3
  %37 = load i32, ptr %36, align 4, !tbaa !17
  %38 = add i32 %35, %37
  %39 = getelementptr inbounds %struct.zlentry, ptr %5, i32 0, i32 4
  %40 = load i32, ptr %39, align 8, !tbaa !15
  %41 = getelementptr inbounds %struct.zlentry, ptr %5, i32 0, i32 1
  %42 = load i32, ptr %41, align 4, !tbaa !18
  %43 = getelementptr inbounds %struct.zlentry, ptr %5, i32 0, i32 0
  %44 = load i32, ptr %43, align 8, !tbaa !19
  %45 = getelementptr inbounds %struct.zlentry, ptr %5, i32 0, i32 3
  %46 = load i32, ptr %45, align 4, !tbaa !17
  %47 = call i32 (ptr, ...) @printf(ptr noundef @.str.5, i64 noundef %27, i32 noundef %28, i64 noundef %33, i32 noundef %38, i32 noundef %40, i32 noundef %42, i32 noundef %44, i32 noundef %46)
  %48 = getelementptr inbounds %struct.zlentry, ptr %5, i32 0, i32 4
  %49 = load i32, ptr %48, align 8, !tbaa !15
  %50 = load ptr, ptr %3, align 8, !tbaa !5
  %51 = zext i32 %49 to i64
  %52 = getelementptr inbounds i8, ptr %50, i64 %51
  store ptr %52, ptr %3, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.zlentry, ptr %5, i32 0, i32 5
  %54 = load i8, ptr %53, align 4, !tbaa !20
  %55 = zext i8 %54 to i32
  %56 = and i32 %55, 192
  %57 = icmp slt i32 %56, 192
  br i1 %57, label %58, label %85

58:                                               ; preds = %24
  %59 = getelementptr inbounds %struct.zlentry, ptr %5, i32 0, i32 3
  %60 = load i32, ptr %59, align 4, !tbaa !17
  %61 = icmp ugt i32 %60, 40
  br i1 %61, label %62, label %70

62:                                               ; preds = %58
  %63 = load ptr, ptr %3, align 8, !tbaa !5
  %64 = load ptr, ptr @stdout, align 8, !tbaa !5
  %65 = call i64 @fwrite(ptr noundef %63, i64 noundef 40, i64 noundef 1, ptr noundef %64)
  %66 = icmp eq i64 %65, 0
  br i1 %66, label %67, label %68

67:                                               ; preds = %62
  call void @perror(ptr noundef @.str.6)
  br label %68

68:                                               ; preds = %67, %62
  %69 = call i32 (ptr, ...) @printf(ptr noundef @.str.7)
  br label %84

70:                                               ; preds = %58
  %71 = getelementptr inbounds %struct.zlentry, ptr %5, i32 0, i32 3
  %72 = load i32, ptr %71, align 4, !tbaa !17
  %73 = icmp ne i32 %72, 0
  br i1 %73, label %74, label %83

74:                                               ; preds = %70
  %75 = load ptr, ptr %3, align 8, !tbaa !5
  %76 = getelementptr inbounds %struct.zlentry, ptr %5, i32 0, i32 3
  %77 = load i32, ptr %76, align 4, !tbaa !17
  %78 = zext i32 %77 to i64
  %79 = load ptr, ptr @stdout, align 8, !tbaa !5
  %80 = call i64 @fwrite(ptr noundef %75, i64 noundef %78, i64 noundef 1, ptr noundef %79)
  %81 = icmp eq i64 %80, 0
  br i1 %81, label %82, label %83

82:                                               ; preds = %74
  call void @perror(ptr noundef @.str.6)
  br label %83

83:                                               ; preds = %82, %74, %70
  br label %84

84:                                               ; preds = %83, %68
  br label %91

85:                                               ; preds = %24
  %86 = load ptr, ptr %3, align 8, !tbaa !5
  %87 = getelementptr inbounds %struct.zlentry, ptr %5, i32 0, i32 5
  %88 = load i8, ptr %87, align 4, !tbaa !20
  %89 = call i64 @zipLoadInteger(ptr noundef %86, i8 noundef zeroext %88)
  %90 = call i32 (ptr, ...) @printf(ptr noundef @.str.8, i64 noundef %89)
  br label %91

91:                                               ; preds = %85, %84
  %92 = call i32 (ptr, ...) @printf(ptr noundef @.str.9)
  %93 = getelementptr inbounds %struct.zlentry, ptr %5, i32 0, i32 3
  %94 = load i32, ptr %93, align 4, !tbaa !17
  %95 = load ptr, ptr %3, align 8, !tbaa !5
  %96 = zext i32 %94 to i64
  %97 = getelementptr inbounds i8, ptr %95, i64 %96
  store ptr %97, ptr %3, align 8, !tbaa !5
  %98 = load i32, ptr %4, align 4, !tbaa !9
  %99 = add nsw i32 %98, 1
  store i32 %99, ptr %4, align 4, !tbaa !9
  br label %19, !llvm.loop !21

100:                                              ; preds = %19
  %101 = call i32 (ptr, ...) @printf(ptr noundef @.str.10)
  call void @llvm.lifetime.end.p0(i64 32, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #4
  ret void
}

declare i32 @printf(ptr noundef, ...) #3

declare i64 @fwrite(ptr noundef, i64 noundef, i64 noundef, ptr noundef) #3

declare void @perror(ptr noundef) #3

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

!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 = !{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, !13, i64 24, i64 8, !5}
!15 = !{!16, !10, i64 16}
!16 = !{!"zlentry", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !10, i64 16, !7, i64 20, !6, i64 24}
!17 = !{!16, !10, i64 12}
!18 = !{!16, !10, i64 4}
!19 = !{!16, !10, i64 0}
!20 = !{!16, !7, i64 20}
!21 = distinct !{!21, !22}
!22 = !{!"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"

%struct.zlentry = type { i32, i32, i32, i32, i32, i8, ptr }

@.str.4 = external hidden unnamed_addr constant [47 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [89 x i8], align 1
@stdout = external local_unnamed_addr global ptr, align 8
@.str.6 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [8 x i8], align 1

; 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 void @ziplistRepr(ptr noundef %0) local_unnamed_addr #1 {
  %2 = alloca %struct.zlentry, align 8
  %3 = load i32, ptr %0, align 4, !tbaa !5
  %4 = getelementptr inbounds i8, ptr %0, i64 8
  %5 = load i16, ptr %4, align 2, !tbaa !9
  %6 = zext i16 %5 to i32
  %7 = getelementptr inbounds i8, ptr %0, i64 4
  %8 = load i32, ptr %7, align 4, !tbaa !5
  %9 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.4, i32 noundef %3, i32 noundef %6, i32 noundef %8)
  %10 = getelementptr inbounds i8, ptr %0, i64 10
  %11 = load i8, ptr %10, align 1, !tbaa !11
  %.not27 = icmp eq i8 %11, -1
  br i1 %.not27, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %1
  %.sroa.4.0..sroa_idx = getelementptr inbounds i8, ptr %2, i64 4
  %.sroa.51.0..sroa_idx = getelementptr inbounds i8, ptr %2, i64 12
  %.sroa.11.0..sroa_idx = getelementptr inbounds i8, ptr %2, i64 16
  %.sroa.14.0..sroa_idx = getelementptr inbounds i8, ptr %2, i64 20
  %12 = ptrtoint ptr %0 to i64
  br label %13

13:                                               ; preds = %.lr.ph, %39
  %.029 = phi ptr [ %10, %.lr.ph ], [ %42, %39 ]
  %.02428 = phi i32 [ 0, %.lr.ph ], [ %43, %39 ]
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %2) #3
  call void @zipEntry(ptr dead_on_unwind nonnull writable sret(%struct.zlentry) align 8 %2, ptr noundef nonnull %.029)
  %.sroa.0.0.copyload = load i32, ptr %2, align 8, !tbaa !5
  %.sroa.4.0.copyload = load i32, ptr %.sroa.4.0..sroa_idx, align 4, !tbaa !5
  %.sroa.51.0.copyload = load i32, ptr %.sroa.51.0..sroa_idx, align 4, !tbaa !5
  %.sroa.11.0.copyload = load i32, ptr %.sroa.11.0..sroa_idx, align 8, !tbaa !5
  %.sroa.14.0.copyload = load i8, ptr %.sroa.14.0..sroa_idx, align 4, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %2) #3
  %14 = ptrtoint ptr %.029 to i64
  %15 = sub i64 %14, %12
  %16 = add i32 %.sroa.11.0.copyload, %.sroa.51.0.copyload
  %17 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.5, i64 noundef %14, i32 noundef %.02428, i64 noundef %15, i32 noundef %16, i32 noundef %.sroa.11.0.copyload, i32 noundef %.sroa.4.0.copyload, i32 noundef %.sroa.0.0.copyload, i32 noundef %.sroa.51.0.copyload)
  %18 = zext i32 %.sroa.11.0.copyload to i64
  %19 = getelementptr inbounds i8, ptr %.029, i64 %18
  %.not25 = icmp ugt i8 %.sroa.14.0.copyload, -65
  br i1 %.not25, label %36, label %20

20:                                               ; preds = %13
  %21 = icmp ugt i32 %.sroa.51.0.copyload, 40
  br i1 %21, label %22, label %29

22:                                               ; preds = %20
  %23 = load ptr, ptr @stdout, align 8, !tbaa !12
  %24 = call i64 @fwrite(ptr noundef nonnull %19, i64 noundef 40, i64 noundef 1, ptr noundef %23)
  %25 = icmp eq i64 %24, 0
  br i1 %25, label %26, label %27

26:                                               ; preds = %22
  call void @perror(ptr noundef nonnull @.str.6) #4
  br label %27

27:                                               ; preds = %26, %22
  %28 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.7)
  br label %39

29:                                               ; preds = %20
  %.not26 = icmp eq i32 %.sroa.51.0.copyload, 0
  br i1 %.not26, label %39, label %30

30:                                               ; preds = %29
  %31 = zext nneg i32 %.sroa.51.0.copyload to i64
  %32 = load ptr, ptr @stdout, align 8, !tbaa !12
  %33 = call i64 @fwrite(ptr noundef nonnull %19, i64 noundef %31, i64 noundef 1, ptr noundef %32)
  %34 = icmp eq i64 %33, 0
  br i1 %34, label %35, label %39

35:                                               ; preds = %30
  call void @perror(ptr noundef nonnull @.str.6) #4
  br label %39

36:                                               ; preds = %13
  %37 = call i64 @zipLoadInteger(ptr noundef nonnull %19, i8 noundef zeroext %.sroa.14.0.copyload)
  %38 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.8, i64 noundef %37)
  br label %39

39:                                               ; preds = %27, %35, %30, %29, %36
  %40 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.9)
  %41 = zext i32 %.sroa.51.0.copyload to i64
  %42 = getelementptr inbounds i8, ptr %19, i64 %41
  %43 = add nuw nsw i32 %.02428, 1
  %44 = load i8, ptr %42, align 1, !tbaa !11
  %.not = icmp eq i8 %44, -1
  br i1 %.not, label %._crit_edge, label %13, !llvm.loop !14

._crit_edge:                                      ; preds = %39, %1
  %45 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.10)
  ret void
}

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #2

; Function Attrs: nofree nounwind
declare noundef i64 @fwrite(ptr nocapture noundef, i64 noundef, i64 noundef, ptr nocapture noundef) local_unnamed_addr #2

; Function Attrs: nofree nounwind
declare void @perror(ptr nocapture noundef readonly) 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 "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 #3 = { nounwind }
attributes #4 = { cold }

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


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