; LLVM IR from Razakhel/RaZ :: extern/tracy/libbacktrace (dwarf)

; 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.tracy::backtrace_state" = type { ptr, i32, ptr, ptr, ptr, ptr, ptr, i32, i32, ptr, ptr }
%"struct.tracy::dwarf_data" = type { ptr, ptr, i64, ptr, i64, ptr, i64, %"struct.tracy::dwarf_sections", i32, %"struct.tracy::function_vector" }
%"struct.tracy::dwarf_sections" = type { [9 x ptr], [9 x i64] }
%"struct.tracy::function_vector" = type { %"struct.tracy::backtrace_vector", i64 }
%"struct.tracy::backtrace_vector" = type { ptr, i64, i64 }

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN5tracy45dwarf_fileline_dwarf_lookup_pc_in_all_entriesEPNS_15backtrace_stateEmPFiPvmmPKciS4_EPFvS2_S4_iES2_Rii(ptr noundef %0, i64 noundef %1, ptr noundef %2, ptr noundef %3, ptr noundef %4, ptr noundef nonnull align 4 dereferenceable(4) %5, i32 noundef %6) #0 {
  %8 = alloca i1, align 1
  %9 = alloca ptr, align 8
  %10 = alloca i64, align 8
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca ptr, align 8
  %14 = alloca ptr, align 8
  %15 = alloca i32, align 4
  %16 = alloca ptr, align 8
  %17 = alloca i32, align 4
  store ptr %0, ptr %9, align 8, !tbaa !5
  store i64 %1, ptr %10, align 8, !tbaa !9
  store ptr %2, ptr %11, align 8, !tbaa !5
  store ptr %3, ptr %12, align 8, !tbaa !5
  store ptr %4, ptr %13, align 8, !tbaa !5
  store ptr %5, ptr %14, align 8, !tbaa !5
  store i32 %6, ptr %15, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #2
  %18 = load ptr, ptr %9, align 8, !tbaa !5
  %19 = getelementptr inbounds %"struct.tracy::backtrace_state", ptr %18, i32 0, i32 4
  %20 = load ptr, ptr %19, align 8, !tbaa !13
  store ptr %20, ptr %16, align 8, !tbaa !5
  br label %21

21:                                               ; preds = %42, %7
  %22 = load ptr, ptr %16, align 8, !tbaa !5
  %23 = icmp ne ptr %22, null
  br i1 %23, label %25, label %24

24:                                               ; preds = %21
  store i32 2, ptr %17, align 4
  br label %46

25:                                               ; preds = %21
  %26 = load ptr, ptr %9, align 8, !tbaa !5
  %27 = load ptr, ptr %16, align 8, !tbaa !5
  %28 = load i64, ptr %10, align 8, !tbaa !9
  %29 = load ptr, ptr %11, align 8, !tbaa !5
  %30 = load ptr, ptr %12, align 8, !tbaa !5
  %31 = load ptr, ptr %13, align 8, !tbaa !5
  %32 = load ptr, ptr %14, align 8, !tbaa !5
  %33 = call noundef i32 @_ZN5tracyL15dwarf_lookup_pcEPNS_15backtrace_stateEPNS_10dwarf_dataEmPFiPvmmPKciS6_EPFvS4_S6_iES4_Pi(ptr noundef %26, ptr noundef %27, i64 noundef %28, ptr noundef %29, ptr noundef %30, ptr noundef %31, ptr noundef %32)
  store i32 %33, ptr %15, align 4, !tbaa !11
  %34 = load i32, ptr %15, align 4, !tbaa !11
  %35 = icmp ne i32 %34, 0
  br i1 %35, label %40, label %36

36:                                               ; preds = %25
  %37 = load ptr, ptr %14, align 8, !tbaa !5
  %38 = load i32, ptr %37, align 4, !tbaa !11
  %39 = icmp ne i32 %38, 0
  br i1 %39, label %40, label %41

40:                                               ; preds = %36, %25
  store i1 true, ptr %8, align 1
  store i32 1, ptr %17, align 4
  br label %46

41:                                               ; preds = %36
  br label %42

42:                                               ; preds = %41
  %43 = load ptr, ptr %16, align 8, !tbaa !5
  %44 = getelementptr inbounds %"struct.tracy::dwarf_data", ptr %43, i32 0, i32 0
  %45 = load ptr, ptr %44, align 8, !tbaa !15
  store ptr %45, ptr %16, align 8, !tbaa !5
  br label %21, !llvm.loop !20

46:                                               ; preds = %40, %24
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #2
  %47 = load i32, ptr %17, align 4
  switch i32 %47, label %51 [
    i32 2, label %48
    i32 1, label %49
  ]

48:                                               ; preds = %46
  store i1 false, ptr %8, align 1
  br label %49

49:                                               ; preds = %48, %46
  %50 = load i1, ptr %8, align 1
  ret i1 %50

51:                                               ; preds = %46
  unreachable
}

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

; Function Attrs: mustprogress uwtable
declare hidden noundef i32 @_ZN5tracyL15dwarf_lookup_pcEPNS_15backtrace_stateEPNS_10dwarf_dataEmPFiPvmmPKciS6_EPFvS4_S6_iES4_Pi(ptr noundef, ptr noundef, i64 noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef) #0

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

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !6, i64 32}
!14 = !{!"_ZTSN5tracy15backtrace_stateE", !6, i64 0, !12, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !12, i64 56, !12, i64 60, !6, i64 64, !6, i64 72}
!15 = !{!16, !6, i64 0}
!16 = !{!"_ZTSN5tracy10dwarf_dataE", !6, i64 0, !6, i64 8, !10, i64 16, !6, i64 24, !10, i64 32, !6, i64 40, !10, i64 48, !17, i64 56, !12, i64 200, !18, i64 208}
!17 = !{!"_ZTSN5tracy14dwarf_sectionsE", !7, i64 0, !7, i64 72}
!18 = !{!"_ZTSN5tracy15function_vectorE", !19, i64 0, !10, i64 24}
!19 = !{!"_ZTSN5tracy16backtrace_vectorE", !6, i64 0, !10, i64 8, !10, i64 16}
!20 = distinct !{!20, !21}
!21 = !{!"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"

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN5tracy45dwarf_fileline_dwarf_lookup_pc_in_all_entriesEPNS_15backtrace_stateEmPFiPvmmPKciS4_EPFvS2_S4_iES2_Rii(ptr noundef %0, i64 noundef %1, ptr noundef %2, ptr noundef %3, ptr noundef %4, ptr noundef nonnull align 4 dereferenceable(4) %5, i32 noundef %6) local_unnamed_addr #0 {
  %8 = getelementptr inbounds i8, ptr %0, i64 32
  br label %9

9:                                                ; preds = %10, %7
  %.013.in = phi ptr [ %8, %7 ], [ %.013, %10 ]
  %.013 = load ptr, ptr %.013.in, align 8, !tbaa !5
  %.not.not = icmp ne ptr %.013, null
  br i1 %.not.not, label %10, label %13

10:                                               ; preds = %9
  %11 = tail call noundef i32 @_ZN5tracyL15dwarf_lookup_pcEPNS_15backtrace_stateEPNS_10dwarf_dataEmPFiPvmmPKciS6_EPFvS4_S6_iES4_Pi(ptr noundef %0, ptr noundef nonnull %.013, i64 noundef %1, ptr noundef %2, ptr noundef %3, ptr noundef %4, ptr noundef nonnull %5)
  %.not15 = icmp eq i32 %11, 0
  %12 = load i32, ptr %5, align 4
  %.not16 = icmp eq i32 %12, 0
  %or.cond = select i1 %.not15, i1 %.not16, i1 false
  br i1 %or.cond, label %9, label %13, !llvm.loop !9

13:                                               ; preds = %10, %9
  ret i1 %.not.not
}

; Function Attrs: mustprogress uwtable
declare hidden noundef i32 @_ZN5tracyL15dwarf_lookup_pcEPNS_15backtrace_stateEPNS_10dwarf_dataEmPFiPvmmPKciS6_EPFvS4_S6_iES4_Pi(ptr noundef, ptr noundef, i64 noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #0

attributes #0 = { 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" }

!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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass