; LLVM IR from Samson-Mano/EM_Propogation_simulation :: EM_Propogation_simulation/src/ImGui/implot.ll (ZN6ImPlot9RoundTimeERK10ImPlotTimei)

; 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.ImPlotTime = type <{ i64, i32, [4 x i8] }>

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #1

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

; Function Attrs: mustprogress uwtable
declare dso_local { i64, i32 } @_ZN6ImPlot7AddTimeERK10ImPlotTimeii(ptr noundef nonnull align 8 dereferenceable(12), i32 noundef, i32 noundef) #2

; Function Attrs: mustprogress uwtable
declare dso_local { i64, i32 } @_ZN6ImPlot9FloorTimeERK10ImPlotTimei(ptr noundef nonnull align 8 dereferenceable(12), i32 noundef) #2

; Function Attrs: mustprogress uwtable
define dso_local { i64, i32 } @_ZN6ImPlot9RoundTimeERK10ImPlotTimei(ptr noundef nonnull align 8 dereferenceable(12) %0, i32 noundef %1) #2 {
  %3 = alloca %struct.ImPlotTime, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca %struct.ImPlotTime, align 8
  %7 = alloca { i64, i32 }, align 8
  %8 = alloca %struct.ImPlotTime, align 8
  %9 = alloca { i64, i32 }, align 8
  %10 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 16, ptr %6) #3
  %11 = load ptr, ptr %4, align 8, !tbaa !5
  %12 = load i32, ptr %5, align 4, !tbaa !9
  %13 = call { i64, i32 } @_ZN6ImPlot9FloorTimeERK10ImPlotTimei(ptr noundef nonnull align 8 dereferenceable(12) %11, i32 noundef %12)
  store { i64, i32 } %13, ptr %7, align 8
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %6, ptr align 8 %7, i64 12, i1 false)
  call void @llvm.lifetime.start.p0(i64 16, ptr %8) #3
  %14 = load i32, ptr %5, align 4, !tbaa !9
  %15 = call { i64, i32 } @_ZN6ImPlot7AddTimeERK10ImPlotTimeii(ptr noundef nonnull align 8 dereferenceable(12) %6, i32 noundef %14, i32 noundef 1)
  store { i64, i32 } %15, ptr %9, align 8
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %8, ptr align 8 %9, i64 12, i1 false)
  %16 = getelementptr inbounds %struct.ImPlotTime, ptr %6, i32 0, i32 0
  %17 = load i64, ptr %16, align 8, !tbaa !11
  %18 = getelementptr inbounds %struct.ImPlotTime, ptr %8, i32 0, i32 0
  %19 = load i64, ptr %18, align 8, !tbaa !11
  %20 = icmp eq i64 %17, %19
  br i1 %20, label %21, label %39

21:                                               ; preds = %2
  %22 = load ptr, ptr %4, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.ImPlotTime, ptr %22, i32 0, i32 1
  %24 = load i32, ptr %23, align 8, !tbaa !14
  %25 = getelementptr inbounds %struct.ImPlotTime, ptr %6, i32 0, i32 1
  %26 = load i32, ptr %25, align 8, !tbaa !14
  %27 = sub nsw i32 %24, %26
  %28 = getelementptr inbounds %struct.ImPlotTime, ptr %8, i32 0, i32 1
  %29 = load i32, ptr %28, align 8, !tbaa !14
  %30 = load ptr, ptr %4, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.ImPlotTime, ptr %30, i32 0, i32 1
  %32 = load i32, ptr %31, align 8, !tbaa !14
  %33 = sub nsw i32 %29, %32
  %34 = icmp slt i32 %27, %33
  br i1 %34, label %35, label %36

35:                                               ; preds = %21
  br label %37

36:                                               ; preds = %21
  br label %37

37:                                               ; preds = %36, %35
  %38 = phi ptr [ %6, %35 ], [ %8, %36 ]
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %3, ptr align 8 %38, i64 16, i1 false), !tbaa.struct !15
  store i32 1, ptr %10, align 4
  br label %57

39:                                               ; preds = %2
  %40 = load ptr, ptr %4, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.ImPlotTime, ptr %40, i32 0, i32 0
  %42 = load i64, ptr %41, align 8, !tbaa !11
  %43 = getelementptr inbounds %struct.ImPlotTime, ptr %6, i32 0, i32 0
  %44 = load i64, ptr %43, align 8, !tbaa !11
  %45 = sub nsw i64 %42, %44
  %46 = getelementptr inbounds %struct.ImPlotTime, ptr %8, i32 0, i32 0
  %47 = load i64, ptr %46, align 8, !tbaa !11
  %48 = load ptr, ptr %4, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.ImPlotTime, ptr %48, i32 0, i32 0
  %50 = load i64, ptr %49, align 8, !tbaa !11
  %51 = sub nsw i64 %47, %50
  %52 = icmp slt i64 %45, %51
  br i1 %52, label %53, label %54

53:                                               ; preds = %39
  br label %55

54:                                               ; preds = %39
  br label %55

55:                                               ; preds = %54, %53
  %56 = phi ptr [ %6, %53 ], [ %8, %54 ]
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %3, ptr align 8 %56, i64 16, i1 false), !tbaa.struct !15
  store i32 1, ptr %10, align 4
  br label %57

57:                                               ; preds = %55, %37
  call void @llvm.lifetime.end.p0(i64 16, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 16, ptr %6) #3
  %58 = load { i64, i32 }, ptr %3, align 8
  ret { i64, i32 } %58
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree 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 = { 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, !13, i64 0}
!12 = !{!"_ZTS10ImPlotTime", !13, i64 0, !10, i64 8}
!13 = !{!"long", !7, i64 0}
!14 = !{!12, !10, i64 8}
!15 = !{i64 0, i64 8, !16, i64 8, i64 4, !9}
!16 = !{!13, !13, 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.ImPlotTime = type <{ i64, i32, [4 x i8] }>

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

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

; Function Attrs: mustprogress uwtable
declare dso_local { i64, i32 } @_ZN6ImPlot7AddTimeERK10ImPlotTimeii(ptr noundef nonnull align 8 dereferenceable(12), i32 noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
declare dso_local { i64, i32 } @_ZN6ImPlot9FloorTimeERK10ImPlotTimei(ptr noundef nonnull align 8 dereferenceable(12), i32 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
define dso_local { i64, i32 } @_ZN6ImPlot9RoundTimeERK10ImPlotTimei(ptr noundef nonnull align 8 dereferenceable(12) %0, i32 noundef %1) local_unnamed_addr #1 {
  %3 = alloca %struct.ImPlotTime, align 8
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %3) #2
  %4 = tail call { i64, i32 } @_ZN6ImPlot9FloorTimeERK10ImPlotTimei(ptr noundef nonnull align 8 dereferenceable(12) %0, i32 noundef %1)
  %.fca.0.extract2 = extractvalue { i64, i32 } %4, 0
  %.fca.1.extract3 = extractvalue { i64, i32 } %4, 1
  store i64 %.fca.0.extract2, ptr %3, align 8
  %.sroa.25.0..sroa_idx = getelementptr inbounds i8, ptr %3, i64 8
  store i32 %.fca.1.extract3, ptr %.sroa.25.0..sroa_idx, align 8
  %5 = call { i64, i32 } @_ZN6ImPlot7AddTimeERK10ImPlotTimeii(ptr noundef nonnull align 8 dereferenceable(12) %3, i32 noundef %1, i32 noundef 1)
  %.fca.0.extract = extractvalue { i64, i32 } %5, 0
  %.fca.1.extract = extractvalue { i64, i32 } %5, 1
  %6 = load i64, ptr %3, align 8, !tbaa !5
  %7 = icmp eq i64 %6, %.fca.0.extract
  br i1 %7, label %8, label %15

8:                                                ; preds = %2
  %9 = getelementptr inbounds i8, ptr %0, i64 8
  %10 = load i32, ptr %9, align 8, !tbaa !11
  %11 = load i32, ptr %.sroa.25.0..sroa_idx, align 8, !tbaa !11
  %12 = sub nsw i32 %10, %11
  %13 = sub nsw i32 %.fca.1.extract, %10
  %14 = icmp slt i32 %12, %13
  br label %20

15:                                               ; preds = %2
  %16 = load i64, ptr %0, align 8, !tbaa !5
  %17 = sub nsw i64 %16, %6
  %18 = sub nsw i64 %.fca.0.extract, %16
  %19 = icmp slt i64 %17, %18
  br label %20

20:                                               ; preds = %15, %8
  %.sink = phi i1 [ %19, %15 ], [ %14, %8 ]
  %.sroa.gep = getelementptr inbounds i8, ptr %3, i64 8
  %.sroa.3.0.sroa.speculate.load.true = load i32, ptr %.sroa.gep, align 8, !tbaa !12
  %.sroa.3.0.sroa.speculated = select i1 %.sink, i32 %.sroa.3.0.sroa.speculate.load.true, i32 %.fca.1.extract
  %.sroa.011.0.sroa.speculate.load.true = load i64, ptr %3, align 8, !tbaa !13
  %.sroa.011.0.sroa.speculated = select i1 %.sink, i64 %.sroa.011.0.sroa.speculate.load.true, i64 %.fca.0.extract
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %3) #2
  %.fca.0.insert = insertvalue { i64, i32 } poison, i64 %.sroa.011.0.sroa.speculated, 0
  %.fca.1.insert = insertvalue { i64, i32 } %.fca.0.insert, i32 %.sroa.3.0.sroa.speculated, 1
  ret { i64, i32 } %.fca.1.insert
}

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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, !7, i64 0}
!6 = !{!"_ZTS10ImPlotTime", !7, i64 0, !10, i64 8}
!7 = !{!"long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!6, !10, i64 8}
!12 = !{!10, !10, i64 0}
!13 = !{!7, !7, i64 0}


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