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

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

@gTimings = external dso_local global [256 x %struct.TinyTimings], align 16
@_ZL16gProfileDisabled = external hidden global i8, align 1
@_ZZ42TinyChromeUtilsStopTimingsAndWriteJsonFilePKcE11fileCounter = external hidden global i32, align 4
@.str.3 = external hidden unnamed_addr constant [11 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [2 x i8], align 1
@_ZL11gTimingFile = external hidden global ptr, align 8
@.str.5 = external hidden unnamed_addr constant [18 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [34 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [29 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [19 x i8], align 1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z27MyDummyEnterProfileZoneFuncPKc(ptr noundef) #0

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z27MyDummyLeaveProfileZoneFuncv() #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 void @TinySetCustomEnterProfileZoneFunc(ptr noundef) #2

declare void @TinySetCustomLeaveProfileZoneFunc(ptr noundef) #2

; Function Attrs: mustprogress uwtable
define dso_local void @_Z42TinyChromeUtilsStopTimingsAndWriteJsonFilePKc(ptr noundef %0) #3 {
  %2 = alloca ptr, align 8
  %3 = alloca [1024 x i8], align 16
  %4 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @TinySetCustomEnterProfileZoneFunc(ptr noundef @_Z27MyDummyEnterProfileZoneFuncPKc)
  call void @TinySetCustomLeaveProfileZoneFunc(ptr noundef @_Z27MyDummyLeaveProfileZoneFuncv)
  call void @llvm.lifetime.start.p0(i64 1024, ptr %3) #5
  %5 = getelementptr inbounds [1024 x i8], ptr %3, i64 0, i64 0
  %6 = load ptr, ptr %2, align 8, !tbaa !5
  %7 = load i32, ptr @_ZZ42TinyChromeUtilsStopTimingsAndWriteJsonFilePKcE11fileCounter, align 4, !tbaa !9
  %8 = add nsw i32 %7, 1
  store i32 %8, ptr @_ZZ42TinyChromeUtilsStopTimingsAndWriteJsonFilePKcE11fileCounter, align 4, !tbaa !9
  %9 = call i32 (ptr, ptr, ...) @sprintf(ptr noundef %5, ptr noundef @.str.3, ptr noundef %6, i32 noundef %7) #5
  %10 = getelementptr inbounds [1024 x i8], ptr %3, i64 0, i64 0
  %11 = call noalias ptr @fopen(ptr noundef %10, ptr noundef @.str.4)
  store ptr %11, ptr @_ZL11gTimingFile, align 8, !tbaa !5
  %12 = load ptr, ptr @_ZL11gTimingFile, align 8, !tbaa !5
  %13 = icmp ne ptr %12, null
  br i1 %13, label %14, label %48

14:                                               ; preds = %1
  %15 = load ptr, ptr @_ZL11gTimingFile, align 8, !tbaa !5
  %16 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %15, ptr noundef @.str.5) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #5
  store i32 0, ptr %4, align 4, !tbaa !9
  br label %17

17:                                               ; preds = %40, %14
  %18 = load i32, ptr %4, align 4, !tbaa !9
  %19 = icmp slt i32 %18, 256
  br i1 %19, label %21, label %20

20:                                               ; preds = %17
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #5
  br label %43

21:                                               ; preds = %17
  %22 = load i32, ptr %4, align 4, !tbaa !9
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds [256 x %struct.TinyTimings], ptr @gTimings, i64 0, i64 %23
  %25 = getelementptr inbounds %struct.TinyTimings, ptr %24, i32 0, i32 0
  %26 = load i32, ptr %25, align 16, !tbaa !11
  %27 = icmp ne i32 %26, 0
  br i1 %27, label %28, label %39

28:                                               ; preds = %21
  %29 = load i32, ptr %4, align 4, !tbaa !9
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [256 x %struct.TinyTimings], ptr @gTimings, i64 0, i64 %30
  %32 = getelementptr inbounds %struct.TinyTimings, ptr %31, i32 0, i32 0
  %33 = load i32, ptr %32, align 16, !tbaa !11
  %34 = load i32, ptr %4, align 4, !tbaa !9
  %35 = call i32 (ptr, ...) @printf(ptr noundef @.str.6, i32 noundef %33, i32 noundef %34)
  %36 = load i32, ptr %4, align 4, !tbaa !9
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds [256 x %struct.TinyTimings], ptr @gTimings, i64 0, i64 %37
  call void @_ZN11TinyTimings5flushEv(ptr noundef nonnull align 8 dereferenceable(32) %38)
  br label %39

39:                                               ; preds = %28, %21
  br label %40

40:                                               ; preds = %39
  %41 = load i32, ptr %4, align 4, !tbaa !9
  %42 = add nsw i32 %41, 1
  store i32 %42, ptr %4, align 4, !tbaa !9
  br label %17, !llvm.loop !17

43:                                               ; preds = %20
  %44 = load ptr, ptr @_ZL11gTimingFile, align 8, !tbaa !5
  %45 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %44, ptr noundef @.str.7) #5
  %46 = load ptr, ptr @_ZL11gTimingFile, align 8, !tbaa !5
  %47 = call i32 @fclose(ptr noundef %46)
  br label %50

48:                                               ; preds = %1
  call void (ptr, ...) @TinyOutputPrintfVarArgsInternal(ptr noundef @.str.8)
  %49 = getelementptr inbounds [1024 x i8], ptr %3, i64 0, i64 0
  call void (ptr, ...) @TinyOutputPrintfVarArgsInternal(ptr noundef %49)
  br label %50

50:                                               ; preds = %48, %43
  store i8 1, ptr @_ZL16gProfileDisabled, align 1, !tbaa !19
  store ptr null, ptr @_ZL11gTimingFile, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 1024, ptr %3) #5
  ret void
}

; Function Attrs: nounwind
declare i32 @sprintf(ptr noundef, ptr noundef, ...) #4

declare noalias ptr @fopen(ptr noundef, ptr noundef) #2

; Function Attrs: nounwind
declare i32 @fprintf(ptr noundef, ptr noundef, ...) #4

declare i32 @printf(ptr noundef, ...) #2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN11TinyTimings5flushEv(ptr noundef nonnull align 8 dereferenceable(32)) #0 align 2

declare i32 @fclose(ptr noundef) #2

declare void @TinyOutputPrintfVarArgsInternal(ptr noundef, ...) #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 "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 }

!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 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 0}
!12 = !{!"_ZTS11TinyTimings", !10, i64 0, !10, i64 4, !13, i64 8}
!13 = !{!"_ZTSSt6vectorI10TinyTimingSaIS0_EE", !14, i64 0}
!14 = !{!"_ZTSSt12_Vector_baseI10TinyTimingSaIS0_EE", !15, i64 0}
!15 = !{!"_ZTSNSt12_Vector_baseI10TinyTimingSaIS0_EE12_Vector_implE", !16, i64 0}
!16 = !{!"_ZTSNSt12_Vector_baseI10TinyTimingSaIS0_EE17_Vector_impl_dataE", !6, i64 0, !6, i64 8, !6, i64 16}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}
!19 = !{!20, !20, i64 0}
!20 = !{!"bool", !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 }

@gTimings = external dso_local global [256 x %struct.TinyTimings], align 16
@_ZL16gProfileDisabled = external hidden local_unnamed_addr global i8, align 1
@_ZZ42TinyChromeUtilsStopTimingsAndWriteJsonFilePKcE11fileCounter = external hidden local_unnamed_addr global i32, align 4
@.str.3 = external hidden unnamed_addr constant [11 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [2 x i8], align 1
@_ZL11gTimingFile = external hidden local_unnamed_addr global ptr, align 8
@.str.5 = external hidden unnamed_addr constant [18 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [34 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [29 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [19 x i8], align 1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z27MyDummyEnterProfileZoneFuncPKc(ptr noundef) #0

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z27MyDummyLeaveProfileZoneFuncv() #0

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

declare void @TinySetCustomEnterProfileZoneFunc(ptr noundef) local_unnamed_addr #2

declare void @TinySetCustomLeaveProfileZoneFunc(ptr noundef) local_unnamed_addr #2

; Function Attrs: mustprogress uwtable
define dso_local void @_Z42TinyChromeUtilsStopTimingsAndWriteJsonFilePKc(ptr noundef %0) local_unnamed_addr #3 {
  %2 = alloca [1024 x i8], align 16
  tail call void @TinySetCustomEnterProfileZoneFunc(ptr noundef nonnull @_Z27MyDummyEnterProfileZoneFuncPKc)
  tail call void @TinySetCustomLeaveProfileZoneFunc(ptr noundef nonnull @_Z27MyDummyLeaveProfileZoneFuncv)
  call void @llvm.lifetime.start.p0(i64 1024, ptr nonnull %2) #5
  %3 = load i32, ptr @_ZZ42TinyChromeUtilsStopTimingsAndWriteJsonFilePKcE11fileCounter, align 4, !tbaa !5
  %4 = add nsw i32 %3, 1
  store i32 %4, ptr @_ZZ42TinyChromeUtilsStopTimingsAndWriteJsonFilePKcE11fileCounter, align 4, !tbaa !5
  %5 = call i32 (ptr, ptr, ...) @sprintf(ptr noundef nonnull dereferenceable(1) %2, ptr noundef nonnull dereferenceable(1) @.str.3, ptr noundef %0, i32 noundef %3) #5
  %6 = call noalias ptr @fopen(ptr noundef nonnull %2, ptr noundef nonnull @.str.4)
  store ptr %6, ptr @_ZL11gTimingFile, align 8, !tbaa !9
  %.not = icmp eq ptr %6, null
  br i1 %.not, label %21, label %7

7:                                                ; preds = %1
  %8 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef nonnull %6, ptr noundef nonnull @.str.5) #5
  br label %14

9:                                                ; preds = %20
  %10 = load ptr, ptr @_ZL11gTimingFile, align 8, !tbaa !9
  %11 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %10, ptr noundef nonnull @.str.7) #5
  %12 = load ptr, ptr @_ZL11gTimingFile, align 8, !tbaa !9
  %13 = tail call i32 @fclose(ptr noundef %12)
  br label %22

14:                                               ; preds = %7, %20
  %indvars.iv = phi i64 [ 0, %7 ], [ %indvars.iv.next, %20 ]
  %15 = getelementptr inbounds [256 x %struct.TinyTimings], ptr @gTimings, i64 0, i64 %indvars.iv
  %16 = load i32, ptr %15, align 16, !tbaa !11
  %.not8 = icmp eq i32 %16, 0
  br i1 %.not8, label %20, label %17

17:                                               ; preds = %14
  %18 = trunc nuw nsw i64 %indvars.iv to i32
  %19 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.6, i32 noundef %16, i32 noundef %18)
  tail call void @_ZN11TinyTimings5flushEv(ptr noundef nonnull align 8 dereferenceable(32) %15)
  br label %20

20:                                               ; preds = %14, %17
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, 256
  br i1 %exitcond.not, label %9, label %14, !llvm.loop !17

21:                                               ; preds = %1
  tail call void (ptr, ...) @TinyOutputPrintfVarArgsInternal(ptr noundef nonnull @.str.8)
  call void (ptr, ...) @TinyOutputPrintfVarArgsInternal(ptr noundef nonnull %2)
  br label %22

22:                                               ; preds = %21, %9
  store i8 1, ptr @_ZL16gProfileDisabled, align 1, !tbaa !19
  store ptr null, ptr @_ZL11gTimingFile, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 1024, ptr nonnull %2) #5
  ret void
}

; Function Attrs: nofree nounwind
declare noundef i32 @sprintf(ptr noalias nocapture noundef writeonly, ptr nocapture noundef readonly, ...) local_unnamed_addr #4

; Function Attrs: nofree nounwind
declare noalias noundef ptr @fopen(ptr nocapture noundef readonly, ptr nocapture noundef readonly) local_unnamed_addr #4

; Function Attrs: nofree nounwind
declare noundef i32 @fprintf(ptr nocapture noundef, ptr nocapture noundef readonly, ...) local_unnamed_addr #4

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #4

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN11TinyTimings5flushEv(ptr noundef nonnull align 8 dereferenceable(32)) local_unnamed_addr #0 align 2

; Function Attrs: nofree nounwind
declare noundef i32 @fclose(ptr nocapture noundef) local_unnamed_addr #4

declare void @TinyOutputPrintfVarArgsInternal(ptr noundef, ...) local_unnamed_addr #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 = { mustprogress 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 = { nofree 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 #5 = { 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !6, i64 0}
!12 = !{!"_ZTS11TinyTimings", !6, i64 0, !6, i64 4, !13, i64 8}
!13 = !{!"_ZTSSt6vectorI10TinyTimingSaIS0_EE", !14, i64 0}
!14 = !{!"_ZTSSt12_Vector_baseI10TinyTimingSaIS0_EE", !15, i64 0}
!15 = !{!"_ZTSNSt12_Vector_baseI10TinyTimingSaIS0_EE12_Vector_implE", !16, i64 0}
!16 = !{!"_ZTSNSt12_Vector_baseI10TinyTimingSaIS0_EE17_Vector_impl_dataE", !10, i64 0, !10, i64 8, !10, i64 16}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}
!19 = !{!20, !20, i64 0}
!20 = !{!"bool", !7, i64 0}


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