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

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

%class.TinyClock = type { ptr }

@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
@.str = external hidden unnamed_addr constant [2 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [131 x i8], align 1
@__PRETTY_FUNCTION__._Z22MyEnterProfileZoneFuncPKc = external hidden unnamed_addr constant [42 x 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

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

7:                                                ; preds = %1
  br label %96

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

12:                                               ; preds = %8
  %13 = load i32, ptr %3, align 4, !tbaa !13
  %14 = icmp sge i32 %13, 256
  br i1 %14, label %15, label %16

15:                                               ; preds = %12, %8
  store i32 1, ptr %4, align 4
  br label %94

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

22:                                               ; preds = %16
  call void @__assert_fail(ptr noundef @.str, ptr noundef @.str.2, i32 noundef 211, ptr noundef @__PRETTY_FUNCTION__._Z22MyEnterProfileZoneFuncPKc) #6
  unreachable

23:                                               ; preds = %16
  %24 = load ptr, ptr %2, align 8, !tbaa !5
  %25 = load i32, ptr %3, align 4, !tbaa !13
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds [256 x [1024 x ptr]], ptr @gFuncNames, i64 0, i64 %26
  %28 = load i32, ptr %3, align 4, !tbaa !13
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds [256 x i32], ptr @gStackDepths, i64 0, i64 %29
  %31 = load i32, ptr %30, align 4, !tbaa !13
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds [1024 x ptr], ptr %27, i64 0, i64 %32
  store ptr %24, ptr %33, align 8, !tbaa !5
  %34 = call noundef i64 @_ZN9TinyClock20get_time_nanosecondsEv(ptr noundef nonnull align 8 dereferenceable(8) @clk)
  %35 = load i32, ptr %3, align 4, !tbaa !13
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds [256 x [1024 x i64]], ptr @gStartTimes, i64 0, i64 %36
  %38 = load i32, ptr %3, align 4, !tbaa !13
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds [256 x i32], ptr @gStackDepths, i64 0, i64 %39
  %41 = load i32, ptr %40, align 4, !tbaa !13
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds [1024 x i64], ptr %37, i64 0, i64 %42
  store i64 %34, ptr %43, align 8, !tbaa !15
  %44 = load i32, ptr %3, align 4, !tbaa !13
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds [256 x [1024 x i64]], ptr @gStartTimes, i64 0, i64 %45
  %47 = load i32, ptr %3, align 4, !tbaa !13
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds [256 x i32], ptr @gStackDepths, i64 0, i64 %48
  %50 = load i32, ptr %49, align 4, !tbaa !13
  %51 = sext i32 %50 to i64
  %52 = getelementptr inbounds [1024 x i64], ptr %46, i64 0, i64 %51
  %53 = load i64, ptr %52, align 8, !tbaa !15
  %54 = load i32, ptr %3, align 4, !tbaa !13
  %55 = sext i32 %54 to i64
  %56 = getelementptr inbounds [256 x [1024 x i64]], ptr @gStartTimes, i64 0, i64 %55
  %57 = load i32, ptr %3, align 4, !tbaa !13
  %58 = sext i32 %57 to i64
  %59 = getelementptr inbounds [256 x i32], ptr @gStackDepths, i64 0, i64 %58
  %60 = load i32, ptr %59, align 4, !tbaa !13
  %61 = sub nsw i32 %60, 1
  %62 = sext i32 %61 to i64
  %63 = getelementptr inbounds [1024 x i64], ptr %56, i64 0, i64 %62
  %64 = load i64, ptr %63, align 8, !tbaa !15
  %65 = icmp ule i64 %53, %64
  br i1 %65, label %66, label %88

66:                                               ; preds = %23
  %67 = load i32, ptr %3, align 4, !tbaa !13
  %68 = sext i32 %67 to i64
  %69 = getelementptr inbounds [256 x [1024 x i64]], ptr @gStartTimes, i64 0, i64 %68
  %70 = load i32, ptr %3, align 4, !tbaa !13
  %71 = sext i32 %70 to i64
  %72 = getelementptr inbounds [256 x i32], ptr @gStackDepths, i64 0, i64 %71
  %73 = load i32, ptr %72, align 4, !tbaa !13
  %74 = sub nsw i32 %73, 1
  %75 = sext i32 %74 to i64
  %76 = getelementptr inbounds [1024 x i64], ptr %69, i64 0, i64 %75
  %77 = load i64, ptr %76, align 8, !tbaa !15
  %78 = add i64 1, %77
  %79 = load i32, ptr %3, align 4, !tbaa !13
  %80 = sext i32 %79 to i64
  %81 = getelementptr inbounds [256 x [1024 x i64]], ptr @gStartTimes, i64 0, i64 %80
  %82 = load i32, ptr %3, align 4, !tbaa !13
  %83 = sext i32 %82 to i64
  %84 = getelementptr inbounds [256 x i32], ptr @gStackDepths, i64 0, i64 %83
  %85 = load i32, ptr %84, align 4, !tbaa !13
  %86 = sext i32 %85 to i64
  %87 = getelementptr inbounds [1024 x i64], ptr %81, i64 0, i64 %86
  store i64 %78, ptr %87, align 8, !tbaa !15
  br label %88

88:                                               ; preds = %66, %23
  %89 = load i32, ptr %3, align 4, !tbaa !13
  %90 = sext i32 %89 to i64
  %91 = getelementptr inbounds [256 x i32], ptr @gStackDepths, i64 0, i64 %90
  %92 = load i32, ptr %91, align 4, !tbaa !13
  %93 = add nsw i32 %92, 1
  store i32 %93, ptr %91, align 4, !tbaa !13
  store i32 0, ptr %4, align 4
  br label %94

94:                                               ; preds = %88, %15
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #5
  %95 = load i32, ptr %4, align 4
  switch i32 %95, label %97 [
    i32 0, label %96
    i32 1, label %96
  ]

96:                                               ; preds = %94, %94, %7
  ret void

97:                                               ; preds = %94
  unreachable
}

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #3

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

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 = { 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 = { noreturn 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 #4 = { "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 #5 = { nounwind }
attributes #6 = { noreturn 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 = !{!"bool", !7, i64 0}
!11 = !{i8 0, i8 2}
!12 = !{}
!13 = !{!14, !14, i64 0}
!14 = !{!"int", !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"

%class.TinyClock = type { ptr }

@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
@.str = external hidden unnamed_addr constant [2 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [131 x i8], align 1
@__PRETTY_FUNCTION__._Z22MyEnterProfileZoneFuncPKc = external hidden unnamed_addr constant [42 x i8], align 1

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

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

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

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

11:                                               ; preds = %6
  tail call void @__assert_fail(ptr noundef nonnull @.str, ptr noundef nonnull @.str.2, i32 noundef 211, ptr noundef nonnull @__PRETTY_FUNCTION__._Z22MyEnterProfileZoneFuncPKc) #4
  unreachable

12:                                               ; preds = %6
  %13 = sext i32 %9 to i64
  %14 = getelementptr inbounds [256 x [1024 x ptr]], ptr @gFuncNames, i64 0, i64 %7, i64 %13
  store ptr %0, ptr %14, align 8, !tbaa !13
  %15 = tail call noundef i64 @_ZN9TinyClock20get_time_nanosecondsEv(ptr noundef nonnull align 8 dereferenceable(8) @clk)
  %16 = load i32, ptr %8, align 4, !tbaa !11
  %17 = sext i32 %16 to i64
  %18 = getelementptr inbounds [256 x [1024 x i64]], ptr @gStartTimes, i64 0, i64 %7, i64 %17
  store i64 %15, ptr %18, align 8, !tbaa !15
  %19 = add nsw i32 %16, -1
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds [256 x [1024 x i64]], ptr @gStartTimes, i64 0, i64 %7, i64 %20
  %22 = load i64, ptr %21, align 8, !tbaa !15
  %.not = icmp ugt i64 %15, %22
  br i1 %.not, label %25, label %23

23:                                               ; preds = %12
  %24 = add i64 %22, 1
  store i64 %24, ptr %18, align 8, !tbaa !15
  br label %25

25:                                               ; preds = %23, %12
  %26 = add nsw i32 %16, 1
  store i32 %26, ptr %8, align 4, !tbaa !11
  br label %27

27:                                               ; preds = %25, %4, %1
  ret void
}

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #2

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

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 = { 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 #2 = { noreturn 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 #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 = { noreturn 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}


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