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

@.str = external hidden unnamed_addr constant [98 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [3 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
@.str.6 = external hidden unnamed_addr constant [12 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [19 x i8], align 1
@__func__.HPCDCChunker_GetMinChunkSize = external hidden unnamed_addr constant [29 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [43 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 i32 @HPCDCChunker_GetMinChunkSize(ptr noundef %0, ptr noundef %1) #2 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca [2 x %struct.Longtail_LogFieldFmt_Private], align 16
  %7 = alloca %struct.Longtail_LogContextFmt_Private, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 48, ptr %6) #3
  %11 = getelementptr inbounds %struct.Longtail_LogFieldFmt_Private, ptr %6, i32 0, i32 0
  store ptr @.str.6, ptr %11, align 8, !tbaa !9
  %12 = getelementptr inbounds %struct.Longtail_LogFieldFmt_Private, ptr %6, i32 0, i32 1
  store ptr @.str.3, ptr %12, align 8, !tbaa !11
  %13 = getelementptr inbounds %struct.Longtail_LogFieldFmt_Private, ptr %6, i32 0, i32 2
  %14 = load ptr, ptr %4, align 8, !tbaa !5
  %15 = ptrtoint ptr %14 to i64
  %16 = inttoptr i64 %15 to ptr
  store ptr %16, ptr %13, align 8, !tbaa !12
  %17 = getelementptr inbounds %struct.Longtail_LogFieldFmt_Private, ptr %6, i64 1
  %18 = getelementptr inbounds %struct.Longtail_LogFieldFmt_Private, ptr %17, i32 0, i32 0
  store ptr @.str.7, ptr %18, align 8, !tbaa !9
  %19 = getelementptr inbounds %struct.Longtail_LogFieldFmt_Private, ptr %17, i32 0, i32 1
  store ptr @.str.3, ptr %19, align 8, !tbaa !11
  %20 = getelementptr inbounds %struct.Longtail_LogFieldFmt_Private, ptr %17, i32 0, i32 2
  %21 = load ptr, ptr %5, align 8, !tbaa !5
  %22 = ptrtoint ptr %21 to i64
  %23 = inttoptr i64 %22 to ptr
  store ptr %23, ptr %20, align 8, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 24, ptr %7) #3
  %24 = getelementptr inbounds %struct.Longtail_LogContextFmt_Private, ptr %7, i32 0, i32 0
  store ptr null, ptr %24, align 8, !tbaa !13
  %25 = getelementptr inbounds %struct.Longtail_LogContextFmt_Private, ptr %7, i32 0, i32 1
  %26 = getelementptr inbounds [2 x %struct.Longtail_LogFieldFmt_Private], ptr %6, i64 0, i64 0
  store ptr %26, ptr %25, align 8, !tbaa !16
  %27 = getelementptr inbounds %struct.Longtail_LogContextFmt_Private, ptr %7, i32 0, i32 2
  store i64 2, ptr %27, align 8, !tbaa !17
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  store ptr %7, ptr %8, align 8, !tbaa !5
  %28 = load ptr, ptr %8, align 8, !tbaa !5
  call void (ptr, ptr, i32, ptr, i32, ptr, ...) @Longtail_CallLogger(ptr noundef @.str, ptr noundef @__func__.HPCDCChunker_GetMinChunkSize, i32 noundef 337, ptr noundef %28, i32 noundef 0, ptr noundef @.str.4, ptr noundef @.str.5)
  %29 = load ptr, ptr %4, align 8, !tbaa !5
  %30 = icmp ne ptr %29, null
  br i1 %30, label %33, label %31

31:                                               ; preds = %2
  %32 = load ptr, ptr %8, align 8, !tbaa !5
  call void (ptr, ptr, i32, ptr, i32, ptr, ...) @Longtail_CallLogger(ptr noundef @.str, ptr noundef @__func__.HPCDCChunker_GetMinChunkSize, i32 noundef 339, ptr noundef %32, i32 noundef 3, ptr noundef @.str.8, ptr noundef @.str.6)
  store i32 22, ptr %3, align 4
  store i32 1, ptr %9, align 4
  br label %41

33:                                               ; preds = %2
  %34 = load ptr, ptr %5, align 8, !tbaa !5
  %35 = icmp ne ptr %34, null
  br i1 %35, label %38, label %36

36:                                               ; preds = %33
  %37 = load ptr, ptr %8, align 8, !tbaa !5
  call void (ptr, ptr, i32, ptr, i32, ptr, ...) @Longtail_CallLogger(ptr noundef @.str, ptr noundef @__func__.HPCDCChunker_GetMinChunkSize, i32 noundef 340, ptr noundef %37, i32 noundef 3, ptr noundef @.str.8, ptr noundef @.str.7)
  store i32 22, ptr %3, align 4
  store i32 1, ptr %9, align 4
  br label %41

38:                                               ; preds = %33
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  %39 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %39, ptr %10, align 8, !tbaa !5
  %40 = load ptr, ptr %5, align 8, !tbaa !5
  store i32 48, ptr %40, align 4, !tbaa !18
  store i32 0, ptr %3, align 4
  store i32 1, ptr %9, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  br label %41

41:                                               ; preds = %38, %36, %31
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 24, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 48, ptr %6) #3
  %42 = load i32, ptr %3, align 4
  ret i32 %42
}

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, !19, i64 0}
!19 = !{!"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"

%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.3 = external hidden unnamed_addr constant [3 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
@.str.6 = external hidden unnamed_addr constant [12 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [19 x i8], align 1
@__func__.HPCDCChunker_GetMinChunkSize = external hidden unnamed_addr constant [29 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [43 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 range(i32 0, 23) i32 @HPCDCChunker_GetMinChunkSize(ptr noundef %0, ptr noundef %1) local_unnamed_addr #2 {
  %3 = alloca [2 x %struct.Longtail_LogFieldFmt_Private], align 16
  %4 = alloca %struct.Longtail_LogContextFmt_Private, align 8
  call void @llvm.lifetime.start.p0(i64 48, ptr nonnull %3) #3
  store ptr @.str.6, ptr %3, align 16, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %3, i64 8
  store ptr @.str.3, ptr %5, align 8, !tbaa !10
  %6 = getelementptr inbounds i8, ptr %3, i64 16
  store ptr %0, ptr %6, align 16, !tbaa !11
  %7 = getelementptr inbounds i8, ptr %3, i64 24
  store ptr @.str.7, ptr %7, align 8, !tbaa !5
  %8 = getelementptr inbounds i8, ptr %3, i64 32
  store ptr @.str.3, ptr %8, align 16, !tbaa !10
  %9 = getelementptr inbounds i8, ptr %3, i64 40
  store ptr %1, ptr %9, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %4) #3
  store ptr null, ptr %4, align 8, !tbaa !12
  %10 = getelementptr inbounds i8, ptr %4, i64 8
  store ptr %3, ptr %10, align 8, !tbaa !15
  %11 = getelementptr inbounds i8, ptr %4, i64 16
  store i64 2, ptr %11, align 8, !tbaa !16
  call void (ptr, ptr, i32, ptr, i32, ptr, ...) @Longtail_CallLogger(ptr noundef nonnull @.str, ptr noundef nonnull @__func__.HPCDCChunker_GetMinChunkSize, i32 noundef 337, ptr noundef nonnull %4, i32 noundef 0, ptr noundef nonnull @.str.4, ptr noundef nonnull @.str.5) #3
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %12, label %13

12:                                               ; preds = %2
  call void (ptr, ptr, i32, ptr, i32, ptr, ...) @Longtail_CallLogger(ptr noundef nonnull @.str, ptr noundef nonnull @__func__.HPCDCChunker_GetMinChunkSize, i32 noundef 339, ptr noundef nonnull %4, i32 noundef 3, ptr noundef nonnull @.str.8, ptr noundef nonnull @.str.6) #3
  br label %16

13:                                               ; preds = %2
  %.not10 = icmp eq ptr %1, null
  br i1 %.not10, label %14, label %15

14:                                               ; preds = %13
  call void (ptr, ptr, i32, ptr, i32, ptr, ...) @Longtail_CallLogger(ptr noundef nonnull @.str, ptr noundef nonnull @__func__.HPCDCChunker_GetMinChunkSize, i32 noundef 340, ptr noundef nonnull %4, i32 noundef 3, ptr noundef nonnull @.str.8, ptr noundef nonnull @.str.7) #3
  br label %16

15:                                               ; preds = %13
  store i32 48, ptr %1, align 4, !tbaa !17
  br label %16

16:                                               ; preds = %15, %14, %12
  %.0 = phi i32 [ 0, %15 ], [ 22, %14 ], [ 22, %12 ]
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %4) #3
  call void @llvm.lifetime.end.p0(i64 48, ptr nonnull %3) #3
  ret i32 %.0
}

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, !18, i64 0}
!18 = !{!"int", !8, i64 0}


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