; LLVM IR from idmillington/cyclone-physics :: src/demos/timing.ll (ZN10TimingData6updateEv)

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

@_ZL10timingData = external hidden global ptr, align 8

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z10systemTimev() #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 nounwind uwtable
declare dso_local noundef i64 @_ZN10TimingData8getClockEv() #0 align 2

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN10TimingData6updateEv() #0 align 2 {
  %1 = alloca i32, align 4
  %2 = alloca i64, align 8
  %3 = load ptr, ptr @_ZL10timingData, align 8, !tbaa !5
  %4 = icmp ne ptr %3, null
  br i1 %4, label %6, label %5

5:                                                ; preds = %0
  br label %77

6:                                                ; preds = %0
  %7 = load ptr, ptr @_ZL10timingData, align 8, !tbaa !5
  %8 = getelementptr inbounds %struct.TimingData, ptr %7, i32 0, i32 6
  %9 = load i8, ptr %8, align 8, !tbaa !9, !range !16, !noundef !17
  %10 = trunc i8 %9 to i1
  br i1 %10, label %16, label %11

11:                                               ; preds = %6
  %12 = load ptr, ptr @_ZL10timingData, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.TimingData, ptr %12, i32 0, i32 0
  %14 = load i32, ptr %13, align 8, !tbaa !18
  %15 = add i32 %14, 1
  store i32 %15, ptr %13, align 8, !tbaa !18
  br label %16

16:                                               ; preds = %11, %6
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #3
  %17 = call noundef i32 @_Z10systemTimev()
  store i32 %17, ptr %1, align 4, !tbaa !19
  %18 = load i32, ptr %1, align 4, !tbaa !19
  %19 = load ptr, ptr @_ZL10timingData, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.TimingData, ptr %19, i32 0, i32 1
  %21 = load i32, ptr %20, align 4, !tbaa !20
  %22 = sub i32 %18, %21
  %23 = load ptr, ptr @_ZL10timingData, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.TimingData, ptr %23, i32 0, i32 2
  store i32 %22, ptr %24, align 8, !tbaa !21
  %25 = load i32, ptr %1, align 4, !tbaa !19
  %26 = load ptr, ptr @_ZL10timingData, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.TimingData, ptr %26, i32 0, i32 1
  store i32 %25, ptr %27, align 4, !tbaa !20
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #3
  %28 = call noundef i64 @_ZN10TimingData8getClockEv()
  store i64 %28, ptr %2, align 8, !tbaa !22
  %29 = load i64, ptr %2, align 8, !tbaa !22
  %30 = load ptr, ptr @_ZL10timingData, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.TimingData, ptr %30, i32 0, i32 4
  %32 = load i64, ptr %31, align 8, !tbaa !23
  %33 = sub i64 %29, %32
  %34 = load ptr, ptr @_ZL10timingData, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.TimingData, ptr %34, i32 0, i32 5
  store i64 %33, ptr %35, align 8, !tbaa !24
  %36 = load i64, ptr %2, align 8, !tbaa !22
  %37 = load ptr, ptr @_ZL10timingData, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.TimingData, ptr %37, i32 0, i32 4
  store i64 %36, ptr %38, align 8, !tbaa !23
  %39 = load ptr, ptr @_ZL10timingData, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.TimingData, ptr %39, i32 0, i32 0
  %41 = load i32, ptr %40, align 8, !tbaa !18
  %42 = icmp ugt i32 %41, 1
  br i1 %42, label %43, label %76

43:                                               ; preds = %16
  %44 = load ptr, ptr @_ZL10timingData, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.TimingData, ptr %44, i32 0, i32 8
  %46 = load double, ptr %45, align 8, !tbaa !25
  %47 = fcmp ole double %46, 0.000000e+00
  br i1 %47, label %48, label %55

48:                                               ; preds = %43
  %49 = load ptr, ptr @_ZL10timingData, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.TimingData, ptr %49, i32 0, i32 2
  %51 = load i32, ptr %50, align 8, !tbaa !21
  %52 = uitofp i32 %51 to double
  %53 = load ptr, ptr @_ZL10timingData, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.TimingData, ptr %53, i32 0, i32 8
  store double %52, ptr %54, align 8, !tbaa !25
  br label %75

55:                                               ; preds = %43
  %56 = load ptr, ptr @_ZL10timingData, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.TimingData, ptr %56, i32 0, i32 8
  %58 = load double, ptr %57, align 8, !tbaa !25
  %59 = fmul double %58, 0x3FEFAE147AE147AE
  store double %59, ptr %57, align 8, !tbaa !25
  %60 = load ptr, ptr @_ZL10timingData, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.TimingData, ptr %60, i32 0, i32 2
  %62 = load i32, ptr %61, align 8, !tbaa !21
  %63 = uitofp i32 %62 to double
  %64 = load ptr, ptr @_ZL10timingData, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.TimingData, ptr %64, i32 0, i32 8
  %66 = load double, ptr %65, align 8, !tbaa !25
  %67 = call double @llvm.fmuladd.f64(double 1.000000e-02, double %63, double %66)
  store double %67, ptr %65, align 8, !tbaa !25
  %68 = load ptr, ptr @_ZL10timingData, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.TimingData, ptr %68, i32 0, i32 8
  %70 = load double, ptr %69, align 8, !tbaa !25
  %71 = fdiv double 1.000000e+03, %70
  %72 = fptrunc double %71 to float
  %73 = load ptr, ptr @_ZL10timingData, align 8, !tbaa !5
  %74 = getelementptr inbounds %struct.TimingData, ptr %73, i32 0, i32 9
  store float %72, ptr %74, align 8, !tbaa !26
  br label %75

75:                                               ; preds = %55, %48
  br label %76

76:                                               ; preds = %75, %16
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #3
  br label %77

77:                                               ; preds = %76, %5
  ret void
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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, !13, i64 32}
!10 = !{!"_ZTS10TimingData", !11, i64 0, !11, i64 4, !11, i64 8, !12, i64 16, !12, i64 24, !13, i64 32, !14, i64 40, !15, i64 48}
!11 = !{!"int", !7, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!"bool", !7, i64 0}
!14 = !{!"double", !7, i64 0}
!15 = !{!"float", !7, i64 0}
!16 = !{i8 0, i8 2}
!17 = !{}
!18 = !{!10, !11, i64 0}
!19 = !{!11, !11, i64 0}
!20 = !{!10, !11, i64 4}
!21 = !{!10, !11, i64 8}
!22 = !{!12, !12, i64 0}
!23 = !{!10, !12, i64 16}
!24 = !{!10, !12, i64 24}
!25 = !{!10, !14, i64 40}
!26 = !{!10, !15, i64 48}


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

@_ZL10timingData = external hidden local_unnamed_addr global ptr, align 8

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZN10TimingData8getClockEv() local_unnamed_addr #0 align 2

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN10TimingData6updateEv() local_unnamed_addr #0 align 2 {
  %1 = load ptr, ptr @_ZL10timingData, align 8, !tbaa !5
  %.not = icmp eq ptr %1, null
  br i1 %.not, label %41, label %2

2:                                                ; preds = %0
  %3 = getelementptr inbounds i8, ptr %1, i64 32
  %4 = load i8, ptr %3, align 8, !tbaa !9, !range !16, !noundef !17
  %5 = trunc nuw i8 %4 to i1
  br i1 %5, label %9, label %6

6:                                                ; preds = %2
  %7 = load i32, ptr %1, align 8, !tbaa !18
  %8 = add i32 %7, 1
  store i32 %8, ptr %1, align 8, !tbaa !18
  br label %9

9:                                                ; preds = %6, %2
  %10 = tail call noundef i32 @_Z10systemTimev()
  %11 = load ptr, ptr @_ZL10timingData, align 8, !tbaa !5
  %12 = getelementptr inbounds i8, ptr %11, i64 4
  %13 = load i32, ptr %12, align 4, !tbaa !19
  %14 = sub i32 %10, %13
  %15 = getelementptr inbounds i8, ptr %11, i64 8
  store i32 %14, ptr %15, align 8, !tbaa !20
  store i32 %10, ptr %12, align 4, !tbaa !19
  %16 = tail call noundef i64 @_ZN10TimingData8getClockEv()
  %17 = load ptr, ptr @_ZL10timingData, align 8, !tbaa !5
  %18 = getelementptr inbounds i8, ptr %17, i64 16
  %19 = load i64, ptr %18, align 8, !tbaa !21
  %20 = sub i64 %16, %19
  %21 = getelementptr inbounds i8, ptr %17, i64 24
  store i64 %20, ptr %21, align 8, !tbaa !22
  store i64 %16, ptr %18, align 8, !tbaa !21
  %22 = load i32, ptr %17, align 8, !tbaa !18
  %23 = icmp ugt i32 %22, 1
  br i1 %23, label %24, label %41

24:                                               ; preds = %9
  %25 = getelementptr inbounds i8, ptr %17, i64 40
  %26 = load double, ptr %25, align 8, !tbaa !23
  %27 = fcmp ugt double %26, 0.000000e+00
  br i1 %27, label %32, label %28

28:                                               ; preds = %24
  %29 = getelementptr inbounds i8, ptr %17, i64 8
  %30 = load i32, ptr %29, align 8, !tbaa !20
  %31 = uitofp i32 %30 to double
  store double %31, ptr %25, align 8, !tbaa !23
  br label %41

32:                                               ; preds = %24
  %33 = fmul double %26, 0x3FEFAE147AE147AE
  %34 = getelementptr inbounds i8, ptr %17, i64 8
  %35 = load i32, ptr %34, align 8, !tbaa !20
  %36 = uitofp i32 %35 to double
  %37 = tail call double @llvm.fmuladd.f64(double %36, double 1.000000e-02, double %33)
  store double %37, ptr %25, align 8, !tbaa !23
  %38 = fdiv double 1.000000e+03, %37
  %39 = fptrunc double %38 to float
  %40 = getelementptr inbounds i8, ptr %17, i64 48
  store float %39, ptr %40, align 8, !tbaa !24
  br label %41

41:                                               ; preds = %9, %32, %28, %0
  ret void
}

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #1

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 speculatable willreturn memory(none) }

!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, !13, i64 32}
!10 = !{!"_ZTS10TimingData", !11, i64 0, !11, i64 4, !11, i64 8, !12, i64 16, !12, i64 24, !13, i64 32, !14, i64 40, !15, i64 48}
!11 = !{!"int", !7, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!"bool", !7, i64 0}
!14 = !{!"double", !7, i64 0}
!15 = !{!"float", !7, i64 0}
!16 = !{i8 0, i8 2}
!17 = !{}
!18 = !{!10, !11, i64 0}
!19 = !{!10, !11, i64 4}
!20 = !{!10, !11, i64 8}
!21 = !{!10, !12, i64 16}
!22 = !{!10, !12, i64 24}
!23 = !{!10, !14, i64 40}
!24 = !{!10, !15, i64 48}


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