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

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

%union.pthread_mutex_t = type { %struct.__pthread_mutex_s }
%struct.__pthread_mutex_s = type { i32, i32, i32, i32, i32, i16, i16, %struct.__pthread_internal_list }
%struct.__pthread_internal_list = type { ptr, ptr }

@used_memory_mutex = external dso_local global %union.pthread_mutex_t, align 8
@zmalloc_thread_safe = external hidden global i32, align 4
@used_memory = external hidden global i64, align 8

; Function Attrs: nounwind uwtable
declare dso_local ptr @zmalloc(i64 noundef) #0

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

; Function Attrs: nounwind uwtable
declare hidden void @zmalloc_oom(i64 noundef) #0

; Function Attrs: nounwind
declare i32 @pthread_mutex_lock(ptr noundef) #2

; Function Attrs: nounwind
declare i32 @pthread_mutex_unlock(ptr noundef) #2

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

; Function Attrs: nounwind uwtable
define dso_local ptr @zrealloc(ptr noundef %0, i64 noundef %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i64, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i64, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca i64, align 8
  %11 = alloca i64, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i64 %1, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  %12 = load ptr, ptr %4, align 8, !tbaa !5
  %13 = icmp eq ptr %12, null
  br i1 %13, label %14, label %17

14:                                               ; preds = %2
  %15 = load i64, ptr %5, align 8, !tbaa !9
  %16 = call ptr @zmalloc(i64 noundef %15)
  store ptr %16, ptr %3, align 8
  store i32 1, ptr %9, align 4
  br label %89

17:                                               ; preds = %2
  %18 = load ptr, ptr %4, align 8, !tbaa !5
  %19 = getelementptr inbounds i8, ptr %18, i64 -8
  store ptr %19, ptr %6, align 8, !tbaa !5
  %20 = load ptr, ptr %6, align 8, !tbaa !5
  %21 = load i64, ptr %20, align 8, !tbaa !9
  store i64 %21, ptr %7, align 8, !tbaa !9
  %22 = load ptr, ptr %6, align 8, !tbaa !5
  %23 = load i64, ptr %5, align 8, !tbaa !9
  %24 = add i64 %23, 8
  %25 = call ptr @realloc(ptr noundef %22, i64 noundef %24) #5
  store ptr %25, ptr %8, align 8, !tbaa !5
  %26 = load ptr, ptr %8, align 8, !tbaa !5
  %27 = icmp ne ptr %26, null
  br i1 %27, label %30, label %28

28:                                               ; preds = %17
  %29 = load i64, ptr %5, align 8, !tbaa !9
  call void @zmalloc_oom(i64 noundef %29)
  br label %30

30:                                               ; preds = %28, %17
  %31 = load i64, ptr %5, align 8, !tbaa !9
  %32 = load ptr, ptr %8, align 8, !tbaa !5
  store i64 %31, ptr %32, align 8, !tbaa !9
  br label %33

33:                                               ; preds = %30
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  %34 = load i64, ptr %7, align 8, !tbaa !9
  store i64 %34, ptr %10, align 8, !tbaa !9
  %35 = load i64, ptr %10, align 8, !tbaa !9
  %36 = and i64 %35, 7
  %37 = icmp ne i64 %36, 0
  br i1 %37, label %38, label %44

38:                                               ; preds = %33
  %39 = load i64, ptr %10, align 8, !tbaa !9
  %40 = and i64 %39, 7
  %41 = sub i64 8, %40
  %42 = load i64, ptr %10, align 8, !tbaa !9
  %43 = add i64 %42, %41
  store i64 %43, ptr %10, align 8, !tbaa !9
  br label %44

44:                                               ; preds = %38, %33
  %45 = load i32, ptr @zmalloc_thread_safe, align 4, !tbaa !11
  %46 = icmp ne i32 %45, 0
  br i1 %46, label %47, label %53

47:                                               ; preds = %44
  %48 = call i32 @pthread_mutex_lock(ptr noundef @used_memory_mutex) #4
  %49 = load i64, ptr %10, align 8, !tbaa !9
  %50 = load i64, ptr @used_memory, align 8, !tbaa !9
  %51 = sub i64 %50, %49
  store i64 %51, ptr @used_memory, align 8, !tbaa !9
  %52 = call i32 @pthread_mutex_unlock(ptr noundef @used_memory_mutex) #4
  br label %57

53:                                               ; preds = %44
  %54 = load i64, ptr %10, align 8, !tbaa !9
  %55 = load i64, ptr @used_memory, align 8, !tbaa !9
  %56 = sub i64 %55, %54
  store i64 %56, ptr @used_memory, align 8, !tbaa !9
  br label %57

57:                                               ; preds = %53, %47
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  br label %58

58:                                               ; preds = %57
  br label %59

59:                                               ; preds = %58
  br label %60

60:                                               ; preds = %59
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  %61 = load i64, ptr %5, align 8, !tbaa !9
  store i64 %61, ptr %11, align 8, !tbaa !9
  %62 = load i64, ptr %11, align 8, !tbaa !9
  %63 = and i64 %62, 7
  %64 = icmp ne i64 %63, 0
  br i1 %64, label %65, label %71

65:                                               ; preds = %60
  %66 = load i64, ptr %11, align 8, !tbaa !9
  %67 = and i64 %66, 7
  %68 = sub i64 8, %67
  %69 = load i64, ptr %11, align 8, !tbaa !9
  %70 = add i64 %69, %68
  store i64 %70, ptr %11, align 8, !tbaa !9
  br label %71

71:                                               ; preds = %65, %60
  %72 = load i32, ptr @zmalloc_thread_safe, align 4, !tbaa !11
  %73 = icmp ne i32 %72, 0
  br i1 %73, label %74, label %80

74:                                               ; preds = %71
  %75 = call i32 @pthread_mutex_lock(ptr noundef @used_memory_mutex) #4
  %76 = load i64, ptr %11, align 8, !tbaa !9
  %77 = load i64, ptr @used_memory, align 8, !tbaa !9
  %78 = add i64 %77, %76
  store i64 %78, ptr @used_memory, align 8, !tbaa !9
  %79 = call i32 @pthread_mutex_unlock(ptr noundef @used_memory_mutex) #4
  br label %84

80:                                               ; preds = %71
  %81 = load i64, ptr %11, align 8, !tbaa !9
  %82 = load i64, ptr @used_memory, align 8, !tbaa !9
  %83 = add i64 %82, %81
  store i64 %83, ptr @used_memory, align 8, !tbaa !9
  br label %84

84:                                               ; preds = %80, %74
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  br label %85

85:                                               ; preds = %84
  br label %86

86:                                               ; preds = %85
  %87 = load ptr, ptr %8, align 8, !tbaa !5
  %88 = getelementptr inbounds i8, ptr %87, i64 8
  store ptr %88, ptr %3, align 8
  store i32 1, ptr %9, align 4
  br label %89

89:                                               ; preds = %86, %14
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  %90 = load ptr, ptr %3, align 8
  ret ptr %90
}

; Function Attrs: nounwind allocsize(1)
declare ptr @realloc(ptr noundef, i64 noundef) #3

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 nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 allocsize(1) "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 allocsize(1) }

!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 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !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"

%union.pthread_mutex_t = type { %struct.__pthread_mutex_s }
%struct.__pthread_mutex_s = type { i32, i32, i32, i32, i32, i16, i16, %struct.__pthread_internal_list }
%struct.__pthread_internal_list = type { ptr, ptr }

@used_memory_mutex = external dso_local global %union.pthread_mutex_t, align 8
@zmalloc_thread_safe = external hidden local_unnamed_addr global i32, align 4
@used_memory = external hidden local_unnamed_addr global i64, align 8

; Function Attrs: nounwind uwtable
declare dso_local ptr @zmalloc(i64 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare hidden void @zmalloc_oom(i64 noundef) local_unnamed_addr #0

; Function Attrs: nounwind
declare i32 @pthread_mutex_lock(ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind
declare i32 @pthread_mutex_unlock(ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local ptr @zrealloc(ptr noundef %0, i64 noundef %1) local_unnamed_addr #0 {
  %3 = icmp eq ptr %0, null
  br i1 %3, label %4, label %6

4:                                                ; preds = %2
  %5 = tail call ptr @zmalloc(i64 noundef %1)
  br label %32

6:                                                ; preds = %2
  %7 = getelementptr inbounds i8, ptr %0, i64 -8
  %8 = load i64, ptr %7, align 8, !tbaa !5
  %9 = add i64 %1, 8
  %10 = tail call ptr @realloc(ptr noundef nonnull %7, i64 noundef %9) #3
  %.not = icmp eq ptr %10, null
  br i1 %.not, label %11, label %12

11:                                               ; preds = %6
  tail call void @zmalloc_oom(i64 noundef %1)
  br label %12

12:                                               ; preds = %11, %6
  store i64 %1, ptr %10, align 8, !tbaa !5
  %.biased = add i64 %8, 7
  %.023 = and i64 %.biased, -8
  %13 = load i32, ptr @zmalloc_thread_safe, align 4, !tbaa !9
  %.not29 = icmp eq i32 %13, 0
  br i1 %.not29, label %.thread, label %16

.thread:                                          ; preds = %12
  %14 = load i64, ptr @used_memory, align 8, !tbaa !5
  %15 = sub i64 %14, %.023
  store i64 %15, ptr @used_memory, align 8, !tbaa !5
  %.biased3335 = add i64 %1, 7
  %.036 = and i64 %.biased3335, -8
  br label %27

16:                                               ; preds = %12
  %17 = tail call i32 @pthread_mutex_lock(ptr noundef nonnull @used_memory_mutex) #4
  %18 = load i64, ptr @used_memory, align 8, !tbaa !5
  %19 = sub i64 %18, %.023
  store i64 %19, ptr @used_memory, align 8, !tbaa !5
  %20 = tail call i32 @pthread_mutex_unlock(ptr noundef nonnull @used_memory_mutex) #4
  %.pre = load i32, ptr @zmalloc_thread_safe, align 4, !tbaa !9
  %21 = icmp eq i32 %.pre, 0
  %.biased33 = add i64 %1, 7
  %.0 = and i64 %.biased33, -8
  br i1 %21, label %27, label %22

22:                                               ; preds = %16
  %23 = tail call i32 @pthread_mutex_lock(ptr noundef nonnull @used_memory_mutex) #4
  %24 = load i64, ptr @used_memory, align 8, !tbaa !5
  %25 = add i64 %24, %.0
  store i64 %25, ptr @used_memory, align 8, !tbaa !5
  %26 = tail call i32 @pthread_mutex_unlock(ptr noundef nonnull @used_memory_mutex) #4
  br label %30

27:                                               ; preds = %.thread, %16
  %.037 = phi i64 [ %.036, %.thread ], [ %.0, %16 ]
  %28 = load i64, ptr @used_memory, align 8, !tbaa !5
  %29 = add i64 %28, %.037
  store i64 %29, ptr @used_memory, align 8, !tbaa !5
  br label %30

30:                                               ; preds = %27, %22
  %31 = getelementptr inbounds i8, ptr %10, i64 8
  br label %32

32:                                               ; preds = %30, %4
  %.024 = phi ptr [ %5, %4 ], [ %31, %30 ]
  ret ptr %.024
}

; Function Attrs: mustprogress nounwind willreturn allockind("realloc") allocsize(1) memory(argmem: readwrite, inaccessiblemem: readwrite)
declare noalias noundef ptr @realloc(ptr allocptr nocapture noundef, i64 noundef) local_unnamed_addr #2

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 = { 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 #2 = { mustprogress nounwind willreturn allockind("realloc") allocsize(1) memory(argmem: readwrite, inaccessiblemem: readwrite) "alloc-family"="malloc" "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 allocsize(1) }
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 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}


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