; LLVM IR from DanEngelbrecht/longtail :: lib/concurrentchunkwrite (longtail_concurrentchunkwrite)

; 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_LogContextFmt_Private = type { ptr, ptr, i64 }
%struct.Longtail_VersionIndex = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, i32, ptr, ptr }

@.str = external hidden unnamed_addr constant [114 x i8], align 1
@__func__.Longtail_CreateConcurrentChunkWriteAPI = external hidden unnamed_addr constant [39 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [43 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [16 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [24 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [32 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [46 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local ptr @Longtail_CreateConcurrentChunkWriteAPI(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3) #0 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca %struct.Longtail_LogContextFmt_Private, align 8
  %11 = alloca ptr, align 8
  %12 = alloca i32, align 4
  %13 = alloca i64, align 8
  %14 = alloca ptr, align 8
  %15 = alloca ptr, align 8
  %16 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store ptr %2, ptr %8, align 8, !tbaa !5
  store ptr %3, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 24, ptr %10) #4
  call void @llvm.memset.p0.i64(ptr align 8 %10, i8 0, i64 24, i1 false)
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  store ptr %10, ptr %11, align 8, !tbaa !5
  %17 = load ptr, ptr %11, align 8, !tbaa !5
  call void (ptr, ptr, i32, ptr, i32, ptr, ...) @Longtail_CallLogger(ptr noundef @.str, ptr noundef @__func__.Longtail_CreateConcurrentChunkWriteAPI, i32 noundef 488, ptr noundef %17, i32 noundef 0, ptr noundef @.str.1, ptr noundef @.str.2)
  %18 = load ptr, ptr %6, align 8, !tbaa !5
  %19 = icmp ne ptr %18, null
  br i1 %19, label %22, label %20

20:                                               ; preds = %4
  %21 = load ptr, ptr %11, align 8, !tbaa !5
  call void (ptr, ptr, i32, ptr, i32, ptr, ...) @Longtail_CallLogger(ptr noundef @.str, ptr noundef @__func__.Longtail_CreateConcurrentChunkWriteAPI, i32 noundef 489, ptr noundef %21, i32 noundef 3, ptr noundef @.str.3, ptr noundef @.str.4)
  store ptr null, ptr %5, align 8
  store i32 1, ptr %12, align 4
  br label %53

22:                                               ; preds = %4
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #4
  %23 = load ptr, ptr %7, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.Longtail_VersionIndex, ptr %23, i32 0, i32 3
  %25 = load ptr, ptr %24, align 8, !tbaa !9
  %26 = load i32, ptr %25, align 4, !tbaa !12
  %27 = zext i32 %26 to i64
  %28 = mul i64 8, %27
  %29 = add i64 80, %28
  store i64 %29, ptr %13, align 8, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #4
  %30 = load i64, ptr %13, align 8, !tbaa !13
  %31 = call ptr @Longtail_Alloc(ptr noundef @.str.5, i64 noundef %30)
  store ptr %31, ptr %14, align 8, !tbaa !5
  %32 = load ptr, ptr %14, align 8, !tbaa !5
  %33 = icmp ne ptr %32, null
  br i1 %33, label %36, label %34

34:                                               ; preds = %22
  %35 = load ptr, ptr %11, align 8, !tbaa !5
  call void (ptr, ptr, i32, ptr, i32, ptr, ...) @Longtail_CallLogger(ptr noundef @.str, ptr noundef @__func__.Longtail_CreateConcurrentChunkWriteAPI, i32 noundef 495, ptr noundef %35, i32 noundef 3, ptr noundef @.str.6, i32 noundef 12)
  store ptr null, ptr %5, align 8
  store i32 1, ptr %12, align 4
  br label %52

36:                                               ; preds = %22
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %16) #4
  %37 = load ptr, ptr %14, align 8, !tbaa !5
  %38 = load ptr, ptr %6, align 8, !tbaa !5
  %39 = load ptr, ptr %7, align 8, !tbaa !5
  %40 = load ptr, ptr %8, align 8, !tbaa !5
  %41 = load ptr, ptr %9, align 8, !tbaa !5
  %42 = call i32 @ConcurrentChunkWriteAPI_Init(ptr noundef %37, ptr noundef %38, ptr noundef %39, ptr noundef %40, ptr noundef %41, ptr noundef %15)
  store i32 %42, ptr %16, align 4, !tbaa !12
  %43 = load i32, ptr %16, align 4, !tbaa !12
  %44 = icmp ne i32 %43, 0
  br i1 %44, label %45, label %49

45:                                               ; preds = %36
  %46 = load ptr, ptr %11, align 8, !tbaa !5
  %47 = load i32, ptr %16, align 4, !tbaa !12
  call void (ptr, ptr, i32, ptr, i32, ptr, ...) @Longtail_CallLogger(ptr noundef @.str, ptr noundef @__func__.Longtail_CreateConcurrentChunkWriteAPI, i32 noundef 502, ptr noundef %46, i32 noundef 3, ptr noundef @.str.7, i32 noundef %47)
  %48 = load ptr, ptr %14, align 8, !tbaa !5
  call void @Longtail_Free(ptr noundef %48)
  store ptr null, ptr %5, align 8
  store i32 1, ptr %12, align 4
  br label %51

49:                                               ; preds = %36
  %50 = load ptr, ptr %15, align 8, !tbaa !5
  store ptr %50, ptr %5, align 8
  store i32 1, ptr %12, align 4
  br label %51

51:                                               ; preds = %49, %45
  call void @llvm.lifetime.end.p0(i64 4, ptr %16) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #4
  br label %52

52:                                               ; preds = %51, %34
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #4
  br label %53

53:                                               ; preds = %52, %20
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 24, ptr %10) #4
  %54 = load ptr, ptr %5, align 8
  ret ptr %54
}

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

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

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

; Function Attrs: nounwind uwtable
declare hidden i32 @ConcurrentChunkWriteAPI_Init(ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef) #0

declare void @Longtail_Free(ptr noundef) #3

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nocallback nofree nounwind willreturn memory(argmem: write) }
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, !6, i64 24}
!10 = !{!"Longtail_VersionIndex", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !6, i64 64, !6, i64 72, !6, i64 80, !6, i64 88, !6, i64 96, !6, i64 104, !6, i64 112, !6, i64 120, !11, i64 128, !6, i64 136, !6, i64 144}
!11 = !{!"int", !7, i64 0}
!12 = !{!11, !11, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"long", !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_LogContextFmt_Private = type { ptr, ptr, i64 }

@.str = external hidden unnamed_addr constant [114 x i8], align 1
@__func__.Longtail_CreateConcurrentChunkWriteAPI = external hidden unnamed_addr constant [39 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [43 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [16 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [24 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [32 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [46 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local ptr @Longtail_CreateConcurrentChunkWriteAPI(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3) local_unnamed_addr #0 {
  %5 = alloca %struct.Longtail_LogContextFmt_Private, align 8
  %6 = alloca ptr, align 8
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %5) #4
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(24) %5, i8 0, i64 24, i1 false)
  call void (ptr, ptr, i32, ptr, i32, ptr, ...) @Longtail_CallLogger(ptr noundef nonnull @.str, ptr noundef nonnull @__func__.Longtail_CreateConcurrentChunkWriteAPI, i32 noundef 488, ptr noundef nonnull %5, i32 noundef 0, ptr noundef nonnull @.str.1, ptr noundef nonnull @.str.2) #4
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %7, label %8

7:                                                ; preds = %4
  call void (ptr, ptr, i32, ptr, i32, ptr, ...) @Longtail_CallLogger(ptr noundef nonnull @.str, ptr noundef nonnull @__func__.Longtail_CreateConcurrentChunkWriteAPI, i32 noundef 489, ptr noundef nonnull %5, i32 noundef 3, ptr noundef nonnull @.str.3, ptr noundef nonnull @.str.4) #4
  br label %23

8:                                                ; preds = %4
  %9 = getelementptr inbounds i8, ptr %1, i64 24
  %10 = load ptr, ptr %9, align 8, !tbaa !5
  %11 = load i32, ptr %10, align 4, !tbaa !11
  %12 = zext i32 %11 to i64
  %13 = shl nuw nsw i64 %12, 3
  %14 = add nuw nsw i64 %13, 80
  %15 = call ptr @Longtail_Alloc(ptr noundef nonnull @.str.5, i64 noundef %14) #4
  %.not19 = icmp eq ptr %15, null
  br i1 %.not19, label %16, label %17

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

17:                                               ; preds = %8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %6) #4
  %18 = call i32 @ConcurrentChunkWriteAPI_Init(ptr noundef nonnull %15, ptr noundef nonnull %0, ptr noundef nonnull %1, ptr noundef %2, ptr noundef %3, ptr noundef nonnull %6)
  %.not20 = icmp eq i32 %18, 0
  br i1 %.not20, label %20, label %19

19:                                               ; preds = %17
  call void (ptr, ptr, i32, ptr, i32, ptr, ...) @Longtail_CallLogger(ptr noundef nonnull @.str, ptr noundef nonnull @__func__.Longtail_CreateConcurrentChunkWriteAPI, i32 noundef 502, ptr noundef nonnull %5, i32 noundef 3, ptr noundef nonnull @.str.7, i32 noundef %18) #4
  call void @Longtail_Free(ptr noundef nonnull %15) #4
  br label %22

20:                                               ; preds = %17
  %21 = load ptr, ptr %6, align 8, !tbaa !12
  br label %22

22:                                               ; preds = %20, %19
  %.0 = phi ptr [ null, %19 ], [ %21, %20 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %6) #4
  br label %23

23:                                               ; preds = %16, %22, %7
  %.2 = phi ptr [ null, %7 ], [ %.0, %22 ], [ null, %16 ]
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %5) #4
  ret ptr %.2
}

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

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

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

declare ptr @Longtail_Alloc(ptr noundef, i64 noundef) local_unnamed_addr #3

; Function Attrs: nounwind uwtable
declare hidden i32 @ConcurrentChunkWriteAPI_Init(ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #0

declare void @Longtail_Free(ptr noundef) local_unnamed_addr #3

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
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, !7, i64 24}
!6 = !{!"Longtail_VersionIndex", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !7, i64 32, !7, i64 40, !7, i64 48, !7, i64 56, !7, i64 64, !7, i64 72, !7, i64 80, !7, i64 88, !7, i64 96, !7, i64 104, !7, i64 112, !7, i64 120, !10, i64 128, !7, i64 136, !7, i64 144}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!10, !10, i64 0}
!12 = !{!7, !7, i64 0}


; Effective O3 passes: CorrelatedValuePropagationPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,ReassociatePass,SROAPass,SimplifyCFGPass