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

; 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: nounwind uwtable
define dso_local void @lpEncodeString(ptr noundef %0, ptr noundef %1, i32 noundef %2) #0 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store i32 %2, ptr %6, align 4, !tbaa !9
  %7 = load i32, ptr %6, align 4, !tbaa !9
  %8 = icmp ult i32 %7, 64
  br i1 %8, label %9, label %20

9:                                                ; preds = %3
  %10 = load i32, ptr %6, align 4, !tbaa !9
  %11 = or i32 %10, 128
  %12 = trunc i32 %11 to i8
  %13 = load ptr, ptr %4, align 8, !tbaa !5
  %14 = getelementptr inbounds i8, ptr %13, i64 0
  store i8 %12, ptr %14, align 1, !tbaa !11
  %15 = load ptr, ptr %4, align 8, !tbaa !5
  %16 = getelementptr inbounds i8, ptr %15, i64 1
  %17 = load ptr, ptr %5, align 8, !tbaa !5
  %18 = load i32, ptr %6, align 4, !tbaa !9
  %19 = zext i32 %18 to i64
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %16, ptr align 1 %17, i64 %19, i1 false)
  br label %72

20:                                               ; preds = %3
  %21 = load i32, ptr %6, align 4, !tbaa !9
  %22 = icmp ult i32 %21, 4096
  br i1 %22, label %23, label %40

23:                                               ; preds = %20
  %24 = load i32, ptr %6, align 4, !tbaa !9
  %25 = lshr i32 %24, 8
  %26 = or i32 %25, 224
  %27 = trunc i32 %26 to i8
  %28 = load ptr, ptr %4, align 8, !tbaa !5
  %29 = getelementptr inbounds i8, ptr %28, i64 0
  store i8 %27, ptr %29, align 1, !tbaa !11
  %30 = load i32, ptr %6, align 4, !tbaa !9
  %31 = and i32 %30, 255
  %32 = trunc i32 %31 to i8
  %33 = load ptr, ptr %4, align 8, !tbaa !5
  %34 = getelementptr inbounds i8, ptr %33, i64 1
  store i8 %32, ptr %34, align 1, !tbaa !11
  %35 = load ptr, ptr %4, align 8, !tbaa !5
  %36 = getelementptr inbounds i8, ptr %35, i64 2
  %37 = load ptr, ptr %5, align 8, !tbaa !5
  %38 = load i32, ptr %6, align 4, !tbaa !9
  %39 = zext i32 %38 to i64
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %36, ptr align 1 %37, i64 %39, i1 false)
  br label %71

40:                                               ; preds = %20
  %41 = load ptr, ptr %4, align 8, !tbaa !5
  %42 = getelementptr inbounds i8, ptr %41, i64 0
  store i8 -16, ptr %42, align 1, !tbaa !11
  %43 = load i32, ptr %6, align 4, !tbaa !9
  %44 = and i32 %43, 255
  %45 = trunc i32 %44 to i8
  %46 = load ptr, ptr %4, align 8, !tbaa !5
  %47 = getelementptr inbounds i8, ptr %46, i64 1
  store i8 %45, ptr %47, align 1, !tbaa !11
  %48 = load i32, ptr %6, align 4, !tbaa !9
  %49 = lshr i32 %48, 8
  %50 = and i32 %49, 255
  %51 = trunc i32 %50 to i8
  %52 = load ptr, ptr %4, align 8, !tbaa !5
  %53 = getelementptr inbounds i8, ptr %52, i64 2
  store i8 %51, ptr %53, align 1, !tbaa !11
  %54 = load i32, ptr %6, align 4, !tbaa !9
  %55 = lshr i32 %54, 16
  %56 = and i32 %55, 255
  %57 = trunc i32 %56 to i8
  %58 = load ptr, ptr %4, align 8, !tbaa !5
  %59 = getelementptr inbounds i8, ptr %58, i64 3
  store i8 %57, ptr %59, align 1, !tbaa !11
  %60 = load i32, ptr %6, align 4, !tbaa !9
  %61 = lshr i32 %60, 24
  %62 = and i32 %61, 255
  %63 = trunc i32 %62 to i8
  %64 = load ptr, ptr %4, align 8, !tbaa !5
  %65 = getelementptr inbounds i8, ptr %64, i64 4
  store i8 %63, ptr %65, align 1, !tbaa !11
  %66 = load ptr, ptr %4, align 8, !tbaa !5
  %67 = getelementptr inbounds i8, ptr %66, i64 5
  %68 = load ptr, ptr %5, align 8, !tbaa !5
  %69 = load i32, ptr %6, align 4, !tbaa !9
  %70 = zext i32 %69 to i64
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %67, ptr align 1 %68, i64 %70, i1 false)
  br label %71

71:                                               ; preds = %40, %23
  br label %72

72:                                               ; preds = %71, %9
  ret void
}

; 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) #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" }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }

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


; 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: mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: readwrite) uwtable
define dso_local void @lpEncodeString(ptr nocapture noundef writeonly %0, ptr nocapture noundef readonly %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = icmp ult i32 %2, 64
  br i1 %4, label %5, label %8

5:                                                ; preds = %3
  %6 = trunc nuw i32 %2 to i8
  %7 = or disjoint i8 %6, -128
  store i8 %7, ptr %0, align 1, !tbaa !5
  br label %28

8:                                                ; preds = %3
  %9 = icmp ult i32 %2, 4096
  br i1 %9, label %10, label %16

10:                                               ; preds = %8
  %11 = lshr i32 %2, 8
  %12 = trunc nuw i32 %11 to i8
  %13 = or disjoint i8 %12, -32
  store i8 %13, ptr %0, align 1, !tbaa !5
  %14 = trunc i32 %2 to i8
  %15 = getelementptr inbounds i8, ptr %0, i64 1
  store i8 %14, ptr %15, align 1, !tbaa !5
  br label %28

16:                                               ; preds = %8
  store i8 -16, ptr %0, align 1, !tbaa !5
  %17 = trunc i32 %2 to i8
  %18 = getelementptr inbounds i8, ptr %0, i64 1
  store i8 %17, ptr %18, align 1, !tbaa !5
  %19 = lshr i32 %2, 8
  %20 = trunc i32 %19 to i8
  %21 = getelementptr inbounds i8, ptr %0, i64 2
  store i8 %20, ptr %21, align 1, !tbaa !5
  %22 = lshr i32 %2, 16
  %23 = trunc i32 %22 to i8
  %24 = getelementptr inbounds i8, ptr %0, i64 3
  store i8 %23, ptr %24, align 1, !tbaa !5
  %25 = lshr i32 %2, 24
  %26 = trunc nuw i32 %25 to i8
  %27 = getelementptr inbounds i8, ptr %0, i64 4
  store i8 %26, ptr %27, align 1, !tbaa !5
  br label %28

28:                                               ; preds = %10, %16, %5
  %.sink26 = phi i64 [ 2, %10 ], [ 5, %16 ], [ 1, %5 ]
  %29 = getelementptr inbounds i8, ptr %0, i64 %.sink26
  %30 = zext i32 %2 to i64
  tail call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 1 %29, ptr align 1 %1, i64 %30, i1 false)
  ret void
}

; Function Attrs: mustprogress 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) #1

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: readwrite) 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 #1 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }

!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"}


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