; LLVM IR from DanEngelbrecht/longtail :: test/test.ll (ZN19TestAsyncBlockStore15CompleteRequestEPS_)

; 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 }
%class.TestAsyncBlockStore = type { %struct.Longtail_BlockStoreAPI, ptr, ptr, i32, ptr, ptr, ptr, [8 x ptr], i32, ptr, i64, ptr, i64, ptr, i64, ptr, ptr, ptr }
%struct.Longtail_BlockStoreAPI = type { %struct.Longtail_API, ptr, ptr, ptr, ptr, ptr, ptr, ptr }
%struct.Longtail_API = type { ptr }
%struct.stbds_array_header = type { i64, i64, ptr, i64 }
%struct.Longtail_AsyncFlushAPI = type { %struct.Longtail_API, ptr }

@.str.3 = external hidden unnamed_addr constant [71 x i8], align 1
@.str.585 = external hidden unnamed_addr constant [12 x i8], align 1
@.str.586 = external hidden unnamed_addr constant [3 x i8], align 1
@__func__._ZN19TestAsyncBlockStore15CompleteRequestEPS_ = external hidden unnamed_addr constant [16 x i8], align 1
@.str.587 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.588 = 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

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

; Function Attrs: nounwind
declare void @free(ptr noundef) #1

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN19TestAsyncBlockStore15CompleteRequestEPS_(ptr noundef %0) #2 align 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
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 24, ptr %3) #4
  %9 = getelementptr inbounds %struct.Longtail_LogFieldFmt_Private, ptr %3, i32 0, i32 0
  store ptr @.str.585, ptr %9, align 8, !tbaa !9
  %10 = getelementptr inbounds %struct.Longtail_LogFieldFmt_Private, ptr %3, i32 0, i32 1
  store ptr @.str.586, ptr %10, align 8, !tbaa !11
  %11 = getelementptr inbounds %struct.Longtail_LogFieldFmt_Private, ptr %3, i32 0, i32 2
  %12 = load ptr, ptr %2, align 8, !tbaa !5
  %13 = ptrtoint ptr %12 to i64
  %14 = inttoptr i64 %13 to ptr
  store ptr %14, ptr %11, align 8, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 24, ptr %4) #4
  %15 = getelementptr inbounds %struct.Longtail_LogContextFmt_Private, ptr %4, i32 0, i32 0
  store ptr null, ptr %15, align 8, !tbaa !13
  %16 = getelementptr inbounds %struct.Longtail_LogContextFmt_Private, ptr %4, i32 0, i32 1
  %17 = getelementptr inbounds [1 x %struct.Longtail_LogFieldFmt_Private], ptr %3, i64 0, i64 0
  store ptr %17, ptr %16, align 8, !tbaa !16
  %18 = getelementptr inbounds %struct.Longtail_LogContextFmt_Private, ptr %4, i32 0, i32 2
  store i64 1, ptr %18, align 8, !tbaa !17
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  store ptr %4, ptr %5, align 8, !tbaa !5
  %19 = load ptr, ptr %5, align 8, !tbaa !5
  call void (ptr, ptr, i32, ptr, i32, ptr, ...) @Longtail_CallLogger(ptr noundef @.str.3, ptr noundef @__func__._ZN19TestAsyncBlockStore15CompleteRequestEPS_, i32 noundef 3702, ptr noundef %19, i32 noundef 0, ptr noundef @.str.587, ptr noundef @.str.588)
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  store ptr null, ptr %6, align 8, !tbaa !5
  %20 = load ptr, ptr %2, align 8, !tbaa !5
  %21 = getelementptr inbounds %class.TestAsyncBlockStore, ptr %20, i32 0, i32 4
  %22 = load ptr, ptr %21, align 8, !tbaa !18
  call void @Longtail_LockSpinLock(ptr noundef %22)
  %23 = load ptr, ptr %2, align 8, !tbaa !5
  %24 = getelementptr inbounds %class.TestAsyncBlockStore, ptr %23, i32 0, i32 8
  %25 = call i32 @Longtail_AtomicAdd32(ptr noundef %24, i32 noundef -1)
  %26 = icmp eq i32 0, %25
  br i1 %26, label %27, label %33

27:                                               ; preds = %1
  %28 = load ptr, ptr %2, align 8, !tbaa !5
  %29 = getelementptr inbounds %class.TestAsyncBlockStore, ptr %28, i32 0, i32 9
  %30 = load ptr, ptr %29, align 8, !tbaa !23
  store ptr %30, ptr %6, align 8, !tbaa !5
  %31 = load ptr, ptr %2, align 8, !tbaa !5
  %32 = getelementptr inbounds %class.TestAsyncBlockStore, ptr %31, i32 0, i32 9
  store ptr null, ptr %32, align 8, !tbaa !23
  br label %33

33:                                               ; preds = %27, %1
  %34 = load ptr, ptr %2, align 8, !tbaa !5
  %35 = getelementptr inbounds %class.TestAsyncBlockStore, ptr %34, i32 0, i32 4
  %36 = load ptr, ptr %35, align 8, !tbaa !18
  call void @Longtail_UnlockSpinLock(ptr noundef %36)
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  %37 = load ptr, ptr %6, align 8, !tbaa !5
  %38 = icmp ne ptr %37, null
  br i1 %38, label %39, label %44

39:                                               ; preds = %33
  %40 = load ptr, ptr %6, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.stbds_array_header, ptr %40, i64 -1
  %42 = getelementptr inbounds %struct.stbds_array_header, ptr %41, i32 0, i32 0
  %43 = load i64, ptr %42, align 8, !tbaa !24
  br label %45

44:                                               ; preds = %33
  br label %45

45:                                               ; preds = %44, %39
  %46 = phi i64 [ %43, %39 ], [ 0, %44 ]
  store i64 %46, ptr %7, align 8, !tbaa !26
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  store i64 0, ptr %8, align 8, !tbaa !26
  br label %47

47:                                               ; preds = %63, %45
  %48 = load i64, ptr %8, align 8, !tbaa !26
  %49 = load i64, ptr %7, align 8, !tbaa !26
  %50 = icmp ult i64 %48, %49
  br i1 %50, label %52, label %51

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

52:                                               ; preds = %47
  %53 = load ptr, ptr %6, align 8, !tbaa !5
  %54 = load i64, ptr %8, align 8, !tbaa !26
  %55 = getelementptr inbounds ptr, ptr %53, i64 %54
  %56 = load ptr, ptr %55, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.Longtail_AsyncFlushAPI, ptr %56, i32 0, i32 1
  %58 = load ptr, ptr %57, align 8, !tbaa !27
  %59 = load ptr, ptr %6, align 8, !tbaa !5
  %60 = load i64, ptr %8, align 8, !tbaa !26
  %61 = getelementptr inbounds ptr, ptr %59, i64 %60
  %62 = load ptr, ptr %61, align 8, !tbaa !5
  call void %58(ptr noundef %62, i32 noundef 0)
  br label %63

63:                                               ; preds = %52
  %64 = load i64, ptr %8, align 8, !tbaa !26
  %65 = add i64 %64, 1
  store i64 %65, ptr %8, align 8, !tbaa !26
  br label %47, !llvm.loop !29

66:                                               ; preds = %51
  %67 = load ptr, ptr %6, align 8, !tbaa !5
  %68 = icmp ne ptr %67, null
  br i1 %68, label %69, label %72

69:                                               ; preds = %66
  %70 = load ptr, ptr %6, align 8, !tbaa !5
  %71 = getelementptr inbounds %struct.stbds_array_header, ptr %70, i64 -1
  call void @free(ptr noundef %71) #4
  br label %73

72:                                               ; preds = %66
  br label %73

73:                                               ; preds = %72, %69
  store ptr null, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 24, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 24, ptr %3) #4
  ret void
}

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

declare void @Longtail_LockSpinLock(ptr noundef) #3

declare i32 @Longtail_AtomicAdd32(ptr noundef, i32 noundef) #3

declare void @Longtail_UnlockSpinLock(ptr noundef) #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 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 = { "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++ TBAA"}
!9 = !{!10, !6, i64 0}
!10 = !{!"_ZTS28Longtail_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 = !{!"_ZTS30Longtail_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 88}
!19 = !{!"_ZTS19TestAsyncBlockStore", !20, i64 0, !6, i64 64, !6, i64 72, !22, i64 80, !6, i64 88, !6, i64 96, !6, i64 104, !7, i64 112, !22, i64 176, !6, i64 184, !15, i64 192, !6, i64 200, !15, i64 208, !6, i64 216, !15, i64 224, !6, i64 232, !6, i64 240, !6, i64 248}
!20 = !{!"_ZTS22Longtail_BlockStoreAPI", !21, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56}
!21 = !{!"_ZTS12Longtail_API", !6, i64 0}
!22 = !{!"int", !7, i64 0}
!23 = !{!19, !6, i64 184}
!24 = !{!25, !15, i64 0}
!25 = !{!"_ZTS18stbds_array_header", !15, i64 0, !15, i64 8, !6, i64 16, !15, i64 24}
!26 = !{!15, !15, i64 0}
!27 = !{!28, !6, i64 8}
!28 = !{!"_ZTS22Longtail_AsyncFlushAPI", !21, i64 0, !6, i64 8}
!29 = distinct !{!29, !30}
!30 = !{!"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.3 = external hidden unnamed_addr constant [71 x i8], align 1
@.str.585 = external hidden unnamed_addr constant [12 x i8], align 1
@.str.586 = external hidden unnamed_addr constant [3 x i8], align 1
@__func__._ZN19TestAsyncBlockStore15CompleteRequestEPS_ = external hidden unnamed_addr constant [16 x i8], align 1
@.str.587 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.588 = 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

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

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN19TestAsyncBlockStore15CompleteRequestEPS_(ptr noundef %0) local_unnamed_addr #2 align 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) #4
  store ptr @.str.585, ptr %2, align 16, !tbaa !5
  %4 = getelementptr inbounds i8, ptr %2, i64 8
  store ptr @.str.586, 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) #4
  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.3, ptr noundef nonnull @__func__._ZN19TestAsyncBlockStore15CompleteRequestEPS_, i32 noundef 3702, ptr noundef nonnull %3, i32 noundef 0, ptr noundef nonnull @.str.587, ptr noundef nonnull @.str.588)
  %8 = getelementptr inbounds i8, ptr %0, i64 88
  %9 = load ptr, ptr %8, align 8, !tbaa !17
  call void @Longtail_LockSpinLock(ptr noundef %9)
  %10 = getelementptr inbounds i8, ptr %0, i64 176
  %11 = call i32 @Longtail_AtomicAdd32(ptr noundef nonnull %10, i32 noundef -1)
  %12 = icmp eq i32 %11, 0
  br i1 %12, label %14, label %.thread

.thread:                                          ; preds = %1
  %13 = load ptr, ptr %8, align 8, !tbaa !17
  call void @Longtail_UnlockSpinLock(ptr noundef %13)
  br label %._crit_edge

14:                                               ; preds = %1
  %15 = getelementptr inbounds i8, ptr %0, i64 184
  %16 = load ptr, ptr %15, align 8, !tbaa !22
  store ptr null, ptr %15, align 8, !tbaa !22
  %17 = load ptr, ptr %8, align 8, !tbaa !17
  call void @Longtail_UnlockSpinLock(ptr noundef %17)
  %.not = icmp eq ptr %16, null
  br i1 %.not, label %._crit_edge, label %18

18:                                               ; preds = %14
  %19 = getelementptr inbounds i8, ptr %16, i64 -32
  %20 = load i64, ptr %19, align 8, !tbaa !23
  %.not23 = icmp eq i64 %20, 0
  br i1 %.not23, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %18, %.lr.ph
  %.022 = phi i64 [ %25, %.lr.ph ], [ 0, %18 ]
  %21 = getelementptr inbounds ptr, ptr %16, i64 %.022
  %22 = load ptr, ptr %21, align 8, !tbaa !25
  %23 = getelementptr inbounds i8, ptr %22, i64 8
  %24 = load ptr, ptr %23, align 8, !tbaa !26
  call void %24(ptr noundef %22, i32 noundef 0)
  %25 = add nuw i64 %.022, 1
  %exitcond.not = icmp eq i64 %25, %20
  br i1 %exitcond.not, label %.loopexit, label %.lr.ph, !llvm.loop !28

.loopexit:                                        ; preds = %.lr.ph, %18
  %26 = getelementptr inbounds i8, ptr %16, i64 -32
  call void @free(ptr noundef nonnull %26) #4
  br label %._crit_edge

._crit_edge:                                      ; preds = %.thread, %14, %.loopexit
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %3) #4
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %2) #4
  ret void
}

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

declare void @Longtail_LockSpinLock(ptr noundef) local_unnamed_addr #3

declare i32 @Longtail_AtomicAdd32(ptr noundef, i32 noundef) local_unnamed_addr #3

declare void @Longtail_UnlockSpinLock(ptr noundef) local_unnamed_addr #3

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress nounwind willreturn allockind("free") 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 #2 = { mustprogress 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 = { "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 0}
!6 = !{!"_ZTS28Longtail_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++ TBAA"}
!10 = !{!6, !7, i64 8}
!11 = !{!6, !7, i64 16}
!12 = !{!13, !7, i64 0}
!13 = !{!"_ZTS30Longtail_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 88}
!18 = !{!"_ZTS19TestAsyncBlockStore", !19, i64 0, !7, i64 64, !7, i64 72, !21, i64 80, !7, i64 88, !7, i64 96, !7, i64 104, !8, i64 112, !21, i64 176, !7, i64 184, !14, i64 192, !7, i64 200, !14, i64 208, !7, i64 216, !14, i64 224, !7, i64 232, !7, i64 240, !7, i64 248}
!19 = !{!"_ZTS22Longtail_BlockStoreAPI", !20, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !7, i64 32, !7, i64 40, !7, i64 48, !7, i64 56}
!20 = !{!"_ZTS12Longtail_API", !7, i64 0}
!21 = !{!"int", !8, i64 0}
!22 = !{!18, !7, i64 184}
!23 = !{!24, !14, i64 0}
!24 = !{!"_ZTS18stbds_array_header", !14, i64 0, !14, i64 8, !7, i64 16, !14, i64 24}
!25 = !{!7, !7, i64 0}
!26 = !{!27, !7, i64 8}
!27 = !{!"_ZTS22Longtail_AsyncFlushAPI", !20, i64 0, !7, i64 8}
!28 = distinct !{!28, !29}
!29 = !{!"llvm.loop.mustprogress"}


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