; LLVM IR from DanEngelbrecht/longtail :: lib/hpcdcchunker (longtail_hpcdcchunker)

; 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.Longtail_LogFieldFmt_Private = type { ptr, ptr, ptr }
%struct.Longtail_LogContextFmt_Private = type { ptr, ptr, i64 }
%struct.Longtail_HPCDCChunkerAPI = type { %struct.Longtail_ChunkerAPI, ptr, [232 x ptr], i32 }
%struct.Longtail_ChunkerAPI = type { %struct.Longtail_API, ptr, ptr, ptr, ptr, ptr }
%struct.Longtail_API = type { ptr }

@.str = external hidden unnamed_addr constant [98 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [3 x i8], align 1
@__func__.HPCDCChunker_Dispose = external hidden unnamed_addr constant [21 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [4 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

declare void @Longtail_CallLogger(ptr noundef, ptr noundef, i32 noundef, ptr noundef, i32 noundef, ptr noundef, ...) #1

; 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
define dso_local void @HPCDCChunker_Dispose(ptr noundef %0) #2 {
  %2 = alloca ptr, align 8
  %3 = alloca [1 x %struct.Longtail_LogFieldFmt_Private], align 16
  %4 = alloca %struct.Longtail_LogContextFmt_Private, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 24, ptr %3) #3
  %7 = getelementptr inbounds %struct.Longtail_LogFieldFmt_Private, ptr %3, i32 0, i32 0
  store ptr @.str.2, ptr %7, align 8, !tbaa !9
  %8 = getelementptr inbounds %struct.Longtail_LogFieldFmt_Private, ptr %3, i32 0, i32 1
  store ptr @.str.3, ptr %8, align 8, !tbaa !11
  %9 = getelementptr inbounds %struct.Longtail_LogFieldFmt_Private, ptr %3, i32 0, i32 2
  %10 = load ptr, ptr %2, align 8, !tbaa !5
  %11 = ptrtoint ptr %10 to i64
  %12 = inttoptr i64 %11 to ptr
  store ptr %12, ptr %9, align 8, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 24, ptr %4) #3
  %13 = getelementptr inbounds %struct.Longtail_LogContextFmt_Private, ptr %4, i32 0, i32 0
  store ptr null, ptr %13, align 8, !tbaa !13
  %14 = getelementptr inbounds %struct.Longtail_LogContextFmt_Private, ptr %4, i32 0, i32 1
  %15 = getelementptr inbounds [1 x %struct.Longtail_LogFieldFmt_Private], ptr %3, i64 0, i64 0
  store ptr %15, ptr %14, align 8, !tbaa !16
  %16 = getelementptr inbounds %struct.Longtail_LogContextFmt_Private, ptr %4, i32 0, i32 2
  store i64 1, ptr %16, align 8, !tbaa !17
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  store ptr %4, ptr %5, align 8, !tbaa !5
  %17 = load ptr, ptr %5, align 8, !tbaa !5
  call void (ptr, ptr, i32, ptr, i32, ptr, ...) @Longtail_CallLogger(ptr noundef @.str, ptr noundef @__func__.HPCDCChunker_Dispose, i32 noundef 316, ptr noundef %17, i32 noundef 0, ptr noundef @.str.4, ptr noundef @.str.5)
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %18 = load ptr, ptr %2, align 8, !tbaa !5
  store ptr %18, ptr %6, align 8, !tbaa !5
  %19 = load ptr, ptr %6, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.Longtail_HPCDCChunkerAPI, ptr %19, i32 0, i32 1
  %21 = load ptr, ptr %20, align 8, !tbaa !18
  call void @Longtail_LockSpinLock(ptr noundef %21)
  br label %22

22:                                               ; preds = %27, %1
  %23 = load ptr, ptr %6, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.Longtail_HPCDCChunkerAPI, ptr %23, i32 0, i32 3
  %25 = load i32, ptr %24, align 8, !tbaa !23
  %26 = icmp ugt i32 %25, 0
  br i1 %26, label %27, label %47

27:                                               ; preds = %22
  %28 = load ptr, ptr %6, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.Longtail_HPCDCChunkerAPI, ptr %28, i32 0, i32 3
  %30 = load i32, ptr %29, align 8, !tbaa !23
  %31 = add i32 %30, -1
  store i32 %31, ptr %29, align 8, !tbaa !23
  %32 = load ptr, ptr %6, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.Longtail_HPCDCChunkerAPI, ptr %32, i32 0, i32 2
  %34 = load ptr, ptr %6, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.Longtail_HPCDCChunkerAPI, ptr %34, i32 0, i32 3
  %36 = load i32, ptr %35, align 8, !tbaa !23
  %37 = zext i32 %36 to i64
  %38 = getelementptr inbounds [232 x ptr], ptr %33, i64 0, i64 %37
  %39 = load ptr, ptr %38, align 8, !tbaa !5
  call void @Longtail_Free(ptr noundef %39)
  %40 = load ptr, ptr %6, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.Longtail_HPCDCChunkerAPI, ptr %40, i32 0, i32 2
  %42 = load ptr, ptr %6, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.Longtail_HPCDCChunkerAPI, ptr %42, i32 0, i32 3
  %44 = load i32, ptr %43, align 8, !tbaa !23
  %45 = zext i32 %44 to i64
  %46 = getelementptr inbounds [232 x ptr], ptr %41, i64 0, i64 %45
  store ptr null, ptr %46, align 8, !tbaa !5
  br label %22, !llvm.loop !24

47:                                               ; preds = %22
  %48 = load ptr, ptr %6, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.Longtail_HPCDCChunkerAPI, ptr %48, i32 0, i32 1
  %50 = load ptr, ptr %49, align 8, !tbaa !18
  call void @Longtail_UnlockSpinLock(ptr noundef %50)
  %51 = load ptr, ptr %6, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.Longtail_HPCDCChunkerAPI, ptr %51, i32 0, i32 1
  %53 = load ptr, ptr %52, align 8, !tbaa !18
  call void @Longtail_DeleteSpinLock(ptr noundef %53)
  %54 = load ptr, ptr %6, align 8, !tbaa !5
  call void @Longtail_Free(ptr noundef %54)
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 24, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 24, ptr %3) #3
  ret void
}

declare void @Longtail_LockSpinLock(ptr noundef) #1

declare void @Longtail_Free(ptr noundef) #1

declare void @Longtail_UnlockSpinLock(ptr noundef) #1

declare void @Longtail_DeleteSpinLock(ptr noundef) #1

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #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 #2 = { 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 #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 = !{!10, !6, i64 0}
!10 = !{!"Longtail_LogFieldFmt_Private", !6, i64 0, !6, i64 8, !6, i64 16}
!11 = !{!10, !6, i64 8}
!12 = !{!10, !6, i64 16}
!13 = !{!14, !6, i64 0}
!14 = !{!"Longtail_LogContextFmt_Private", !6, i64 0, !6, i64 8, !15, i64 16}
!15 = !{!"long", !7, i64 0}
!16 = !{!14, !6, i64 8}
!17 = !{!14, !15, i64 16}
!18 = !{!19, !6, i64 48}
!19 = !{!"Longtail_HPCDCChunkerAPI", !20, i64 0, !6, i64 48, !7, i64 56, !22, i64 1912}
!20 = !{!"Longtail_ChunkerAPI", !21, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40}
!21 = !{!"Longtail_API", !6, i64 0}
!22 = !{!"int", !7, i64 0}
!23 = !{!19, !22, i64 1912}
!24 = distinct !{!24, !25}
!25 = !{!"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.Longtail_LogFieldFmt_Private = type { ptr, ptr, ptr }
%struct.Longtail_LogContextFmt_Private = type { ptr, ptr, i64 }

@.str = external hidden unnamed_addr constant [98 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [3 x i8], align 1
@__func__.HPCDCChunker_Dispose = external hidden unnamed_addr constant [21 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [4 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

declare void @Longtail_CallLogger(ptr noundef, ptr noundef, i32 noundef, ptr noundef, i32 noundef, ptr noundef, ...) local_unnamed_addr #1

; 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
define dso_local void @HPCDCChunker_Dispose(ptr noundef %0) local_unnamed_addr #2 {
  %2 = alloca [1 x %struct.Longtail_LogFieldFmt_Private], align 16
  %3 = alloca %struct.Longtail_LogContextFmt_Private, align 8
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %2) #3
  store ptr @.str.2, ptr %2, align 16, !tbaa !5
  %4 = getelementptr inbounds i8, ptr %2, i64 8
  store ptr @.str.3, ptr %4, align 8, !tbaa !10
  %5 = getelementptr inbounds i8, ptr %2, i64 16
  store ptr %0, ptr %5, align 16, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %3) #3
  store ptr null, ptr %3, align 8, !tbaa !12
  %6 = getelementptr inbounds i8, ptr %3, i64 8
  store ptr %2, ptr %6, align 8, !tbaa !15
  %7 = getelementptr inbounds i8, ptr %3, i64 16
  store i64 1, ptr %7, align 8, !tbaa !16
  call void (ptr, ptr, i32, ptr, i32, ptr, ...) @Longtail_CallLogger(ptr noundef nonnull @.str, ptr noundef nonnull @__func__.HPCDCChunker_Dispose, i32 noundef 316, ptr noundef nonnull %3, i32 noundef 0, ptr noundef nonnull @.str.4, ptr noundef nonnull @.str.5) #3
  %8 = getelementptr inbounds i8, ptr %0, i64 48
  %9 = load ptr, ptr %8, align 8, !tbaa !17
  call void @Longtail_LockSpinLock(ptr noundef %9) #3
  %10 = getelementptr inbounds i8, ptr %0, i64 1912
  %11 = load i32, ptr %10, align 8, !tbaa !22
  %.not13 = icmp eq i32 %11, 0
  br i1 %.not13, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %1
  %12 = getelementptr inbounds i8, ptr %0, i64 56
  br label %13

13:                                               ; preds = %.lr.ph, %13
  %14 = phi i32 [ %11, %.lr.ph ], [ %19, %13 ]
  %15 = add i32 %14, -1
  store i32 %15, ptr %10, align 8, !tbaa !22
  %16 = zext i32 %15 to i64
  %17 = getelementptr inbounds [232 x ptr], ptr %12, i64 0, i64 %16
  %18 = load ptr, ptr %17, align 8, !tbaa !23
  call void @Longtail_Free(ptr noundef %18) #3
  %19 = load i32, ptr %10, align 8, !tbaa !22
  %20 = zext i32 %19 to i64
  %21 = getelementptr inbounds [232 x ptr], ptr %12, i64 0, i64 %20
  store ptr null, ptr %21, align 8, !tbaa !23
  %.not = icmp eq i32 %19, 0
  br i1 %.not, label %._crit_edge, label %13, !llvm.loop !24

._crit_edge:                                      ; preds = %13, %1
  %22 = load ptr, ptr %8, align 8, !tbaa !17
  call void @Longtail_UnlockSpinLock(ptr noundef %22) #3
  %23 = load ptr, ptr %8, align 8, !tbaa !17
  call void @Longtail_DeleteSpinLock(ptr noundef %23) #3
  call void @Longtail_Free(ptr noundef nonnull %0) #3
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %3) #3
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %2) #3
  ret void
}

declare void @Longtail_LockSpinLock(ptr noundef) local_unnamed_addr #1

declare void @Longtail_Free(ptr noundef) local_unnamed_addr #1

declare void @Longtail_UnlockSpinLock(ptr noundef) local_unnamed_addr #1

declare void @Longtail_DeleteSpinLock(ptr noundef) local_unnamed_addr #1

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #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 #2 = { 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 #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, !7, i64 0}
!6 = !{!"Longtail_LogFieldFmt_Private", !7, i64 0, !7, i64 8, !7, i64 16}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!6, !7, i64 8}
!11 = !{!6, !7, i64 16}
!12 = !{!13, !7, i64 0}
!13 = !{!"Longtail_LogContextFmt_Private", !7, i64 0, !7, i64 8, !14, i64 16}
!14 = !{!"long", !8, i64 0}
!15 = !{!13, !7, i64 8}
!16 = !{!13, !14, i64 16}
!17 = !{!18, !7, i64 48}
!18 = !{!"Longtail_HPCDCChunkerAPI", !19, i64 0, !7, i64 48, !8, i64 56, !21, i64 1912}
!19 = !{!"Longtail_ChunkerAPI", !20, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !7, i64 32, !7, i64 40}
!20 = !{!"Longtail_API", !7, i64 0}
!21 = !{!"int", !8, i64 0}
!22 = !{!18, !21, i64 1912}
!23 = !{!7, !7, i64 0}
!24 = distinct !{!24, !25}
!25 = !{!"llvm.loop.mustprogress"}


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