; LLVM IR from Compaile/ctrack :: examples/basic_singlethreaded.ll (Z9factoriali)

; 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.ctrack::vCTRACK_VERSION_MAJOR_CTRACK_VERSION_MINOR_CTRACK_VERSION_PATCH::EventHandler" = type <{ %"class.std::chrono::time_point", i32, i32, %"class.std::basic_string_view", %"class.std::basic_string_view", i32, i32, i32, [4 x i8] }>
%"class.std::chrono::time_point" = type { %"class.std::chrono::duration" }
%"class.std::chrono::duration" = type { i64 }
%"class.std::basic_string_view" = type { i64, ptr }

@.str.19 = external hidden unnamed_addr constant [83 x i8], align 1
@.str.21 = external hidden unnamed_addr constant [10 x i8], align 1

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

declare i32 @__gxx_personality_v0(...)

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

; Function Attrs: nounwind
declare i64 @_ZNSt6chrono3_V212system_clock3nowEv() #1

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN6ctrack63vCTRACK_VERSION_MAJOR_CTRACK_VERSION_MINOR_CTRACK_VERSION_PATCH12EventHandlerC2EiPKcS3_NSt6chrono10time_pointINS4_3_V212system_clockENS4_8durationIlSt5ratioILl1ELl1000000000EEEEEE(ptr noundef nonnull align 8 dereferenceable(60), i32 noundef, ptr noundef, ptr noundef, i64) unnamed_addr #2 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN6ctrack63vCTRACK_VERSION_MAJOR_CTRACK_VERSION_MINOR_CTRACK_VERSION_PATCH12EventHandlerD2Ev(ptr noundef nonnull align 8 dereferenceable(60)) unnamed_addr #3 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef i64 @_Z9factoriali(i32 noundef %0) #2 personality ptr @__gxx_personality_v0 {
  %2 = alloca i64, align 8
  %3 = alloca i32, align 4
  %4 = alloca %"class.ctrack::vCTRACK_VERSION_MAJOR_CTRACK_VERSION_MINOR_CTRACK_VERSION_PATCH::EventHandler", align 8
  %5 = alloca %"class.std::chrono::time_point", align 8
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  store i32 %0, ptr %3, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 64, ptr %4) #4
  %9 = call i64 @_ZNSt6chrono3_V212system_clock3nowEv() #4
  %10 = getelementptr inbounds %"class.std::chrono::time_point", ptr %5, i32 0, i32 0
  %11 = getelementptr inbounds %"class.std::chrono::duration", ptr %10, i32 0, i32 0
  store i64 %9, ptr %11, align 8
  %12 = getelementptr inbounds %"class.std::chrono::time_point", ptr %5, i32 0, i32 0
  %13 = getelementptr inbounds %"class.std::chrono::duration", ptr %12, i32 0, i32 0
  %14 = load i64, ptr %13, align 8
  call void @_ZN6ctrack63vCTRACK_VERSION_MAJOR_CTRACK_VERSION_MINOR_CTRACK_VERSION_PATCH12EventHandlerC2EiPKcS3_NSt6chrono10time_pointINS4_3_V212system_clockENS4_8durationIlSt5ratioILl1ELl1000000000EEEEEE(ptr noundef nonnull align 8 dereferenceable(60) %4, i32 noundef 17, ptr noundef @.str.19, ptr noundef @.str.21, i64 %14)
  %15 = load i32, ptr %3, align 4, !tbaa !5
  %16 = icmp sle i32 %15, 1
  br i1 %16, label %17, label %18

17:                                               ; preds = %1
  store i64 1, ptr %2, align 8
  store i32 1, ptr %6, align 4
  br label %30

18:                                               ; preds = %1
  %19 = load i32, ptr %3, align 4, !tbaa !5
  %20 = sext i32 %19 to i64
  %21 = load i32, ptr %3, align 4, !tbaa !5
  %22 = sub nsw i32 %21, 1
  %23 = invoke noundef i64 @_Z9factoriali(i32 noundef %22)
          to label %24 unwind label %26

24:                                               ; preds = %18
  %25 = mul i64 %20, %23
  store i64 %25, ptr %2, align 8
  store i32 1, ptr %6, align 4
  br label %30

26:                                               ; preds = %18
  %27 = landingpad { ptr, i32 }
          cleanup
  %28 = extractvalue { ptr, i32 } %27, 0
  store ptr %28, ptr %7, align 8
  %29 = extractvalue { ptr, i32 } %27, 1
  store i32 %29, ptr %8, align 4
  call void @_ZN6ctrack63vCTRACK_VERSION_MAJOR_CTRACK_VERSION_MINOR_CTRACK_VERSION_PATCH12EventHandlerD2Ev(ptr noundef nonnull align 8 dereferenceable(60) %4) #4
  call void @llvm.lifetime.end.p0(i64 64, ptr %4) #4
  br label %32

30:                                               ; preds = %24, %17
  call void @_ZN6ctrack63vCTRACK_VERSION_MAJOR_CTRACK_VERSION_MINOR_CTRACK_VERSION_PATCH12EventHandlerD2Ev(ptr noundef nonnull align 8 dereferenceable(60) %4) #4
  call void @llvm.lifetime.end.p0(i64 64, ptr %4) #4
  %31 = load i64, ptr %2, align 8
  ret i64 %31

32:                                               ; preds = %26
  %33 = load ptr, ptr %7, align 8
  %34 = load i32, ptr %8, align 4
  %35 = insertvalue { ptr, i32 } poison, ptr %33, 0
  %36 = insertvalue { ptr, i32 } %35, i32 %34, 1
  resume { ptr, i32 } %36
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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 = { 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 #4 = { 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"}


; 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.ctrack::vCTRACK_VERSION_MAJOR_CTRACK_VERSION_MINOR_CTRACK_VERSION_PATCH::EventHandler" = type <{ %"class.std::chrono::time_point", i32, i32, %"class.std::basic_string_view", %"class.std::basic_string_view", i32, i32, i32, [4 x i8] }>
%"class.std::chrono::time_point" = type { %"class.std::chrono::duration" }
%"class.std::chrono::duration" = type { i64 }
%"class.std::basic_string_view" = type { i64, ptr }

@.str.19 = external hidden unnamed_addr constant [83 x i8], align 1
@.str.21 = external hidden unnamed_addr constant [10 x i8], align 1

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

declare i32 @__gxx_personality_v0(...)

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

; Function Attrs: nounwind
declare i64 @_ZNSt6chrono3_V212system_clock3nowEv() local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN6ctrack63vCTRACK_VERSION_MAJOR_CTRACK_VERSION_MINOR_CTRACK_VERSION_PATCH12EventHandlerC2EiPKcS3_NSt6chrono10time_pointINS4_3_V212system_clockENS4_8durationIlSt5ratioILl1ELl1000000000EEEEEE(ptr noundef nonnull align 8 dereferenceable(60), i32 noundef, ptr noundef, ptr noundef, i64) unnamed_addr #2 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN6ctrack63vCTRACK_VERSION_MAJOR_CTRACK_VERSION_MINOR_CTRACK_VERSION_PATCH12EventHandlerD2Ev(ptr noundef nonnull align 8 dereferenceable(60)) unnamed_addr #3 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef i64 @_Z9factoriali(i32 noundef %0) local_unnamed_addr #2 personality ptr @__gxx_personality_v0 {
  %2 = alloca %"class.ctrack::vCTRACK_VERSION_MAJOR_CTRACK_VERSION_MINOR_CTRACK_VERSION_PATCH::EventHandler", align 8
  call void @llvm.lifetime.start.p0(i64 64, ptr nonnull %2) #4
  %3 = tail call i64 @_ZNSt6chrono3_V212system_clock3nowEv() #4
  call void @_ZN6ctrack63vCTRACK_VERSION_MAJOR_CTRACK_VERSION_MINOR_CTRACK_VERSION_PATCH12EventHandlerC2EiPKcS3_NSt6chrono10time_pointINS4_3_V212system_clockENS4_8durationIlSt5ratioILl1ELl1000000000EEEEEE(ptr noundef nonnull align 8 dereferenceable(60) %2, i32 noundef 17, ptr noundef nonnull @.str.19, ptr noundef nonnull @.str.21, i64 %3)
  %4 = icmp slt i32 %0, 2
  br i1 %4, label %13, label %5

5:                                                ; preds = %1
  %6 = add nsw i32 %0, -1
  %7 = invoke noundef i64 @_Z9factoriali(i32 noundef %6)
          to label %8 unwind label %11

8:                                                ; preds = %5
  %9 = zext nneg i32 %0 to i64
  %10 = mul i64 %7, %9
  br label %13

11:                                               ; preds = %5
  %12 = landingpad { ptr, i32 }
          cleanup
  call void @_ZN6ctrack63vCTRACK_VERSION_MAJOR_CTRACK_VERSION_MINOR_CTRACK_VERSION_PATCH12EventHandlerD2Ev(ptr noundef nonnull align 8 dereferenceable(60) %2) #4
  call void @llvm.lifetime.end.p0(i64 64, ptr nonnull %2) #4
  resume { ptr, i32 } %12

13:                                               ; preds = %1, %8
  %.0 = phi i64 [ %10, %8 ], [ 1, %1 ]
  call void @_ZN6ctrack63vCTRACK_VERSION_MAJOR_CTRACK_VERSION_MINOR_CTRACK_VERSION_PATCH12EventHandlerD2Ev(ptr noundef nonnull align 8 dereferenceable(60) %2) #4
  call void @llvm.lifetime.end.p0(i64 64, ptr nonnull %2) #4
  ret i64 %.0
}

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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 = { 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 #4 = { 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)"}


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