; LLVM IR from erwincoumans/tiny-differentiable-simulator :: src/visualizer/opengl/utils/tiny_chrome_trace_util.ll (Z22MyLeaveProfileZoneFuncv)

; 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.TinyTimings = type { i32, i32, %"class.std::vector" }
%"class.std::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<TinyTiming, std::allocator<TinyTiming>>::_Vector_impl" }
%"struct.std::_Vector_base<TinyTiming, std::allocator<TinyTiming>>::_Vector_impl" = type { %"struct.std::_Vector_base<TinyTiming, std::allocator<TinyTiming>>::_Vector_impl_data" }
%"struct.std::_Vector_base<TinyTiming, std::allocator<TinyTiming>>::_Vector_impl_data" = type { ptr, ptr, ptr }
%class.TinyClock = type { ptr }

@gTimings = external dso_local global [256 x %struct.TinyTimings], align 16
@gStackDepths = external dso_local global [256 x i32], align 16
@gFuncNames = external dso_local global [256 x [1024 x ptr]], align 16
@gStartTimes = external dso_local global [256 x [1024 x i64]], align 16
@clk = external dso_local global %class.TinyClock, align 8
@_ZL16gProfileDisabled = external hidden global i8, align 1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z26TinyGetCurrentThreadIndex2v() #0

; 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 nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

declare noundef i64 @_ZN9TinyClock20get_time_nanosecondsEv(ptr noundef nonnull align 8 dereferenceable(8)) #2

; Function Attrs: mustprogress uwtable
define dso_local void @_Z22MyLeaveProfileZoneFuncv() #3 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  %4 = alloca i64, align 8
  %5 = alloca i64, align 8
  %6 = load i8, ptr @_ZL16gProfileDisabled, align 1, !tbaa !5, !range !9, !noundef !10
  %7 = trunc i8 %6 to i1
  br i1 %7, label %8, label %9

8:                                                ; preds = %0
  br label %60

9:                                                ; preds = %0
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #4
  %10 = call noundef i32 @_Z26TinyGetCurrentThreadIndex2v()
  store i32 %10, ptr %1, align 4, !tbaa !11
  %11 = load i32, ptr %1, align 4, !tbaa !11
  %12 = icmp slt i32 %11, 0
  br i1 %12, label %16, label %13

13:                                               ; preds = %9
  %14 = load i32, ptr %1, align 4, !tbaa !11
  %15 = icmp sge i32 %14, 256
  br i1 %15, label %16, label %17

16:                                               ; preds = %13, %9
  store i32 1, ptr %2, align 4
  br label %58

17:                                               ; preds = %13
  %18 = load i32, ptr %1, align 4, !tbaa !11
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds [256 x i32], ptr @gStackDepths, i64 0, i64 %19
  %21 = load i32, ptr %20, align 4, !tbaa !11
  %22 = icmp sle i32 %21, 0
  br i1 %22, label %23, label %24

23:                                               ; preds = %17
  store i32 1, ptr %2, align 4
  br label %58

24:                                               ; preds = %17
  %25 = load i32, ptr %1, align 4, !tbaa !11
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds [256 x i32], ptr @gStackDepths, i64 0, i64 %26
  %28 = load i32, ptr %27, align 4, !tbaa !11
  %29 = add nsw i32 %28, -1
  store i32 %29, ptr %27, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #4
  %30 = load i32, ptr %1, align 4, !tbaa !11
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds [256 x [1024 x ptr]], ptr @gFuncNames, i64 0, i64 %31
  %33 = load i32, ptr %1, align 4, !tbaa !11
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds [256 x i32], ptr @gStackDepths, i64 0, i64 %34
  %36 = load i32, ptr %35, align 4, !tbaa !11
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds [1024 x ptr], ptr %32, i64 0, i64 %37
  %39 = load ptr, ptr %38, align 8, !tbaa !13
  store ptr %39, ptr %3, align 8, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #4
  %40 = load i32, ptr %1, align 4, !tbaa !11
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds [256 x [1024 x i64]], ptr @gStartTimes, i64 0, i64 %41
  %43 = load i32, ptr %1, align 4, !tbaa !11
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds [256 x i32], ptr @gStackDepths, i64 0, i64 %44
  %46 = load i32, ptr %45, align 4, !tbaa !11
  %47 = sext i32 %46 to i64
  %48 = getelementptr inbounds [1024 x i64], ptr %42, i64 0, i64 %47
  %49 = load i64, ptr %48, align 8, !tbaa !15
  store i64 %49, ptr %4, align 8, !tbaa !15
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  %50 = call noundef i64 @_ZN9TinyClock20get_time_nanosecondsEv(ptr noundef nonnull align 8 dereferenceable(8) @clk)
  store i64 %50, ptr %5, align 8, !tbaa !15
  %51 = load i32, ptr %1, align 4, !tbaa !11
  %52 = sext i32 %51 to i64
  %53 = getelementptr inbounds [256 x %struct.TinyTimings], ptr @gTimings, i64 0, i64 %52
  %54 = load ptr, ptr %3, align 8, !tbaa !13
  %55 = load i32, ptr %1, align 4, !tbaa !11
  %56 = load i64, ptr %4, align 8, !tbaa !15
  %57 = load i64, ptr %5, align 8, !tbaa !15
  call void @_ZN11TinyTimings9addTimingEPKciyy(ptr noundef nonnull align 8 dereferenceable(32) %53, ptr noundef %54, i32 noundef %55, i64 noundef %56, i64 noundef %57)
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #4
  store i32 0, ptr %2, align 4
  br label %58

58:                                               ; preds = %24, %23, %16
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #4
  %59 = load i32, ptr %2, align 4
  switch i32 %59, label %61 [
    i32 0, label %60
    i32 1, label %60
  ]

60:                                               ; preds = %58, %58, %8
  ret void

61:                                               ; preds = %58
  unreachable
}

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN11TinyTimings9addTimingEPKciyy(ptr noundef nonnull align 8 dereferenceable(32), ptr noundef, i32 noundef, i64 noundef, i64 noundef) #3 align 2

attributes #0 = { mustprogress 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 = { "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 = { 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 #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 = !{!"bool", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{i8 0, i8 2}
!10 = !{}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"any pointer", !7, i64 0}
!15 = !{!16, !16, i64 0}
!16 = !{!"long 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.TinyTimings = type { i32, i32, %"class.std::vector" }
%"class.std::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<TinyTiming, std::allocator<TinyTiming>>::_Vector_impl" }
%"struct.std::_Vector_base<TinyTiming, std::allocator<TinyTiming>>::_Vector_impl" = type { %"struct.std::_Vector_base<TinyTiming, std::allocator<TinyTiming>>::_Vector_impl_data" }
%"struct.std::_Vector_base<TinyTiming, std::allocator<TinyTiming>>::_Vector_impl_data" = type { ptr, ptr, ptr }
%class.TinyClock = type { ptr }

@gTimings = external dso_local global [256 x %struct.TinyTimings], align 16
@gStackDepths = external dso_local local_unnamed_addr global [256 x i32], align 16
@gFuncNames = external dso_local local_unnamed_addr global [256 x [1024 x ptr]], align 16
@gStartTimes = external dso_local local_unnamed_addr global [256 x [1024 x i64]], align 16
@clk = external dso_local global %class.TinyClock, align 8
@_ZL16gProfileDisabled = external hidden local_unnamed_addr global i8, align 1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z26TinyGetCurrentThreadIndex2v() local_unnamed_addr #0

declare noundef i64 @_ZN9TinyClock20get_time_nanosecondsEv(ptr noundef nonnull align 8 dereferenceable(8)) local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
define dso_local void @_Z22MyLeaveProfileZoneFuncv() local_unnamed_addr #2 {
  %1 = load i8, ptr @_ZL16gProfileDisabled, align 1, !tbaa !5, !range !9, !noundef !10
  %2 = trunc nuw i8 %1 to i1
  br i1 %2, label %19, label %3

3:                                                ; preds = %0
  %4 = tail call noundef i32 @_Z26TinyGetCurrentThreadIndex2v()
  %or.cond = icmp ugt i32 %4, 255
  br i1 %or.cond, label %19, label %5

5:                                                ; preds = %3
  %6 = zext nneg i32 %4 to i64
  %7 = getelementptr inbounds [256 x i32], ptr @gStackDepths, i64 0, i64 %6
  %8 = load i32, ptr %7, align 4, !tbaa !11
  %9 = icmp slt i32 %8, 1
  br i1 %9, label %19, label %10

10:                                               ; preds = %5
  %11 = add nsw i32 %8, -1
  store i32 %11, ptr %7, align 4, !tbaa !11
  %12 = zext nneg i32 %11 to i64
  %13 = getelementptr inbounds [256 x [1024 x ptr]], ptr @gFuncNames, i64 0, i64 %6, i64 %12
  %14 = load ptr, ptr %13, align 8, !tbaa !13
  %15 = getelementptr inbounds [256 x [1024 x i64]], ptr @gStartTimes, i64 0, i64 %6, i64 %12
  %16 = load i64, ptr %15, align 8, !tbaa !15
  %17 = tail call noundef i64 @_ZN9TinyClock20get_time_nanosecondsEv(ptr noundef nonnull align 8 dereferenceable(8) @clk)
  %18 = getelementptr inbounds [256 x %struct.TinyTimings], ptr @gTimings, i64 0, i64 %6
  tail call void @_ZN11TinyTimings9addTimingEPKciyy(ptr noundef nonnull align 8 dereferenceable(32) %18, ptr noundef %14, i32 noundef %4, i64 noundef %16, i64 noundef %17)
  br label %19

19:                                               ; preds = %10, %3, %5, %0
  ret void
}

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN11TinyTimings9addTimingEPKciyy(ptr noundef nonnull align 8 dereferenceable(32), ptr noundef, i32 noundef, i64 noundef, i64 noundef) local_unnamed_addr #2 align 2

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

!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 = !{!"bool", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{i8 0, i8 2}
!10 = !{}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"any pointer", !7, i64 0}
!15 = !{!16, !16, i64 0}
!16 = !{!"long long", !7, i64 0}


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