; LLVM IR from Sonryle/JoePhys :: testbed/src (Main)

; 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.WindowManager = type <{ %struct.vec2, i32, i32, ptr, ptr, ptr, i8, i8, i8, i8, [4 x i8] }>
%struct.vec2 = type { float, float }
%struct.Settings = type <{ i32, i32, i32, i32, i8, [3 x i8], float, float, i8, [3 x i8], %struct.vec2, i8, i8, i8, i8, i8, [3 x i8], float, float, float, float, i32, i32, i32, float, i8, [3 x i8] }>
%struct.SceneManager = type <{ ptr, i32, [4 x i8] }>
%struct.Renderer = type { ptr, ptr }
%struct.GUIManager = type { i8, i8, i8, i8 }
%struct.Camera = type { %struct.vec2, float, i32, i32 }

@time_at_last_step = external dso_local global double, align 8
@current_time = external dso_local global double, align 8
@window_mgr = external global %struct.WindowManager, align 8
@settings = external global %struct.Settings, align 4
@scene_manager = external global %struct.SceneManager, align 8
@renderer = external global %struct.Renderer, align 8
@gui_manager = external global %struct.GUIManager, align 1
@camera = external global %struct.Camera, align 4

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

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #1 {
  %1 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  call void @_ZN13WindowManager8InitGLFWEv(ptr noundef nonnull align 8 dereferenceable(44) @window_mgr)
  call void @_ZN13WindowManager8InitGladEv(ptr noundef nonnull align 8 dereferenceable(44) @window_mgr)
  %2 = load ptr, ptr getelementptr inbounds (%struct.WindowManager, ptr @window_mgr, i32 0, i32 3), align 8, !tbaa !5
  call void @_ZN10GUIManager4InitEP10GLFWwindow(ptr noundef nonnull align 1 dereferenceable(4) @gui_manager, ptr noundef %2)
  call void @_ZN12SceneManager11SwitchSceneEi(ptr noundef nonnull align 8 dereferenceable(12) @scene_manager, i32 noundef 0)
  %3 = load i32, ptr @settings, align 4, !tbaa !14
  %4 = load i32, ptr getelementptr inbounds (%struct.Settings, ptr @settings, i32 0, i32 1), align 4, !tbaa !16
  call void @_ZN6Camera6CreateEii(ptr noundef nonnull align 4 dereferenceable(20) @camera, i32 noundef %3, i32 noundef %4)
  call void @_ZN8Renderer6CreateEv(ptr noundef nonnull align 8 dereferenceable(16) @renderer)
  br label %5

5:                                                ; preds = %22, %0
  %6 = load ptr, ptr getelementptr inbounds (%struct.WindowManager, ptr @window_mgr, i32 0, i32 3), align 8, !tbaa !5
  %7 = call i32 @glfwWindowShouldClose(ptr noundef %6)
  %8 = icmp ne i32 %7, 0
  %9 = xor i1 %8, true
  br i1 %9, label %10, label %23

10:                                               ; preds = %5
  %11 = call double @glfwGetTime()
  store double %11, ptr @current_time, align 8, !tbaa !17
  %12 = load double, ptr @current_time, align 8, !tbaa !17
  %13 = load double, ptr @time_at_last_step, align 8, !tbaa !17
  %14 = fsub double %12, %13
  %15 = load i32, ptr getelementptr inbounds (%struct.Settings, ptr @settings, i32 0, i32 3), align 4, !tbaa !19
  %16 = sitofp i32 %15 to float
  %17 = fdiv float 1.000000e+00, %16
  %18 = fpext float %17 to double
  %19 = fcmp ogt double %14, %18
  br i1 %19, label %20, label %22

20:                                               ; preds = %10
  call void @_Z4Stepv()
  %21 = load double, ptr @current_time, align 8, !tbaa !17
  store double %21, ptr @time_at_last_step, align 8, !tbaa !17
  br label %22

22:                                               ; preds = %20, %10
  br label %5, !llvm.loop !20

23:                                               ; preds = %5
  call void @_ZN8Renderer7DestroyEv(ptr noundef nonnull align 8 dereferenceable(16) @renderer)
  call void @glfwTerminate()
  ret i32 1
}

declare void @_ZN13WindowManager8InitGLFWEv(ptr noundef nonnull align 8 dereferenceable(44)) #2

declare void @_ZN13WindowManager8InitGladEv(ptr noundef nonnull align 8 dereferenceable(44)) #2

declare void @_ZN10GUIManager4InitEP10GLFWwindow(ptr noundef nonnull align 1 dereferenceable(4), ptr noundef) #2

declare void @_ZN12SceneManager11SwitchSceneEi(ptr noundef nonnull align 8 dereferenceable(12), i32 noundef) #2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN6Camera6CreateEii(ptr noundef nonnull align 4 dereferenceable(20), i32 noundef, i32 noundef) #0 align 2

declare void @_ZN8Renderer6CreateEv(ptr noundef nonnull align 8 dereferenceable(16)) #2

declare i32 @glfwWindowShouldClose(ptr noundef) #2

declare double @glfwGetTime() #2

declare void @_ZN8Renderer7DestroyEv(ptr noundef nonnull align 8 dereferenceable(16)) #2

declare void @glfwTerminate() #2

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 = { mustprogress norecurse 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 = { "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, !12, i64 16}
!6 = !{!"_ZTS13WindowManager", !7, i64 0, !11, i64 8, !11, i64 12, !12, i64 16, !12, i64 24, !12, i64 32, !13, i64 40, !13, i64 41, !13, i64 42, !13, i64 43}
!7 = !{!"_ZTS4vec2", !8, i64 0, !8, i64 4}
!8 = !{!"float", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C++ TBAA"}
!11 = !{!"int", !9, i64 0}
!12 = !{!"any pointer", !9, i64 0}
!13 = !{!"bool", !9, i64 0}
!14 = !{!15, !11, i64 0}
!15 = !{!"_ZTS8Settings", !11, i64 0, !11, i64 4, !11, i64 8, !11, i64 12, !13, i64 16, !8, i64 20, !8, i64 24, !13, i64 28, !7, i64 32, !13, i64 40, !13, i64 41, !13, i64 42, !13, i64 43, !13, i64 44, !8, i64 48, !8, i64 52, !8, i64 56, !8, i64 60, !11, i64 64, !11, i64 68, !11, i64 72, !8, i64 76, !13, i64 80}
!16 = !{!15, !11, i64 4}
!17 = !{!18, !18, i64 0}
!18 = !{!"double", !9, i64 0}
!19 = !{!15, !11, i64 12}
!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"

%struct.WindowManager = type <{ %struct.vec2, i32, i32, ptr, ptr, ptr, i8, i8, i8, i8, [4 x i8] }>
%struct.vec2 = type { float, float }
%struct.Settings = type <{ i32, i32, i32, i32, i8, [3 x i8], float, float, i8, [3 x i8], %struct.vec2, i8, i8, i8, i8, i8, [3 x i8], float, float, float, float, i32, i32, i32, float, i8, [3 x i8] }>
%struct.SceneManager = type <{ ptr, i32, [4 x i8] }>
%struct.Renderer = type { ptr, ptr }
%struct.GUIManager = type { i8, i8, i8, i8 }
%struct.Camera = type { %struct.vec2, float, i32, i32 }

@time_at_last_step = external dso_local local_unnamed_addr global double, align 8
@current_time = external dso_local local_unnamed_addr global double, align 8
@window_mgr = external global %struct.WindowManager, align 8
@settings = external local_unnamed_addr global %struct.Settings, align 4
@scene_manager = external global %struct.SceneManager, align 8
@renderer = external global %struct.Renderer, align 8
@gui_manager = external global %struct.GUIManager, align 1
@camera = external global %struct.Camera, align 4

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z4Stepv() local_unnamed_addr #0

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() local_unnamed_addr #1 {
  tail call void @_ZN13WindowManager8InitGLFWEv(ptr noundef nonnull align 8 dereferenceable(44) @window_mgr)
  tail call void @_ZN13WindowManager8InitGladEv(ptr noundef nonnull align 8 dereferenceable(44) @window_mgr)
  %1 = load ptr, ptr getelementptr inbounds (i8, ptr @window_mgr, i64 16), align 8, !tbaa !5
  tail call void @_ZN10GUIManager4InitEP10GLFWwindow(ptr noundef nonnull align 1 dereferenceable(4) @gui_manager, ptr noundef %1)
  tail call void @_ZN12SceneManager11SwitchSceneEi(ptr noundef nonnull align 8 dereferenceable(12) @scene_manager, i32 noundef 0)
  %2 = load i32, ptr @settings, align 4, !tbaa !14
  %3 = load i32, ptr getelementptr inbounds (i8, ptr @settings, i64 4), align 4, !tbaa !16
  tail call void @_ZN6Camera6CreateEii(ptr noundef nonnull align 4 dereferenceable(20) @camera, i32 noundef %2, i32 noundef %3)
  tail call void @_ZN8Renderer6CreateEv(ptr noundef nonnull align 8 dereferenceable(16) @renderer)
  %4 = load ptr, ptr getelementptr inbounds (i8, ptr @window_mgr, i64 16), align 8, !tbaa !5
  %5 = tail call i32 @glfwWindowShouldClose(ptr noundef %4)
  %.not1 = icmp eq i32 %5, 0
  br i1 %.not1, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %0, %16
  %6 = tail call double @glfwGetTime()
  store double %6, ptr @current_time, align 8, !tbaa !17
  %7 = load double, ptr @time_at_last_step, align 8, !tbaa !17
  %8 = fsub double %6, %7
  %9 = load i32, ptr getelementptr inbounds (i8, ptr @settings, i64 12), align 4, !tbaa !19
  %10 = sitofp i32 %9 to float
  %11 = fdiv float 1.000000e+00, %10
  %12 = fpext float %11 to double
  %13 = fcmp ogt double %8, %12
  br i1 %13, label %14, label %16

14:                                               ; preds = %.lr.ph
  tail call void @_Z4Stepv()
  %15 = load double, ptr @current_time, align 8, !tbaa !17
  store double %15, ptr @time_at_last_step, align 8, !tbaa !17
  br label %16

16:                                               ; preds = %14, %.lr.ph
  %17 = load ptr, ptr getelementptr inbounds (i8, ptr @window_mgr, i64 16), align 8, !tbaa !5
  %18 = tail call i32 @glfwWindowShouldClose(ptr noundef %17)
  %.not = icmp eq i32 %18, 0
  br i1 %.not, label %.lr.ph, label %._crit_edge, !llvm.loop !20

._crit_edge:                                      ; preds = %16, %0
  tail call void @_ZN8Renderer7DestroyEv(ptr noundef nonnull align 8 dereferenceable(16) @renderer)
  tail call void @glfwTerminate()
  ret i32 1
}

declare void @_ZN13WindowManager8InitGLFWEv(ptr noundef nonnull align 8 dereferenceable(44)) local_unnamed_addr #2

declare void @_ZN13WindowManager8InitGladEv(ptr noundef nonnull align 8 dereferenceable(44)) local_unnamed_addr #2

declare void @_ZN10GUIManager4InitEP10GLFWwindow(ptr noundef nonnull align 1 dereferenceable(4), ptr noundef) local_unnamed_addr #2

declare void @_ZN12SceneManager11SwitchSceneEi(ptr noundef nonnull align 8 dereferenceable(12), i32 noundef) local_unnamed_addr #2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN6Camera6CreateEii(ptr noundef nonnull align 4 dereferenceable(20), i32 noundef, i32 noundef) local_unnamed_addr #0 align 2

declare void @_ZN8Renderer6CreateEv(ptr noundef nonnull align 8 dereferenceable(16)) local_unnamed_addr #2

declare i32 @glfwWindowShouldClose(ptr noundef) local_unnamed_addr #2

declare double @glfwGetTime() local_unnamed_addr #2

declare void @_ZN8Renderer7DestroyEv(ptr noundef nonnull align 8 dereferenceable(16)) local_unnamed_addr #2

declare void @glfwTerminate() local_unnamed_addr #2

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 = { mustprogress norecurse 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 = { "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, !12, i64 16}
!6 = !{!"_ZTS13WindowManager", !7, i64 0, !11, i64 8, !11, i64 12, !12, i64 16, !12, i64 24, !12, i64 32, !13, i64 40, !13, i64 41, !13, i64 42, !13, i64 43}
!7 = !{!"_ZTS4vec2", !8, i64 0, !8, i64 4}
!8 = !{!"float", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C++ TBAA"}
!11 = !{!"int", !9, i64 0}
!12 = !{!"any pointer", !9, i64 0}
!13 = !{!"bool", !9, i64 0}
!14 = !{!15, !11, i64 0}
!15 = !{!"_ZTS8Settings", !11, i64 0, !11, i64 4, !11, i64 8, !11, i64 12, !13, i64 16, !8, i64 20, !8, i64 24, !13, i64 28, !7, i64 32, !13, i64 40, !13, i64 41, !13, i64 42, !13, i64 43, !13, i64 44, !8, i64 48, !8, i64 52, !8, i64 56, !8, i64 60, !11, i64 64, !11, i64 68, !11, i64 72, !8, i64 76, !13, i64 80}
!16 = !{!15, !11, i64 4}
!17 = !{!18, !18, i64 0}
!18 = !{!"double", !9, i64 0}
!19 = !{!15, !11, i64 12}
!20 = distinct !{!20, !21}
!21 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass