; LLVM IR from stfc/PSycloneBench :: benchmarks/nemo/nemolite2d/manual_versions/psykal_c_opencl (timing)

; 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.TimerStruct = type { [64 x i8], i64, double }
%struct.TimerStackStruct = type { double, ptr }

@num_active_timers = external hidden global i32, align 4
@timer_list = external hidden global [40 x %struct.TimerStruct], align 16
@timer_stack = external hidden global [40 x %struct.TimerStackStruct], align 16
@next_free_timer = external hidden global i32, align 4

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

; Function Attrs: nounwind uwtable
define dso_local void @TimerInit() #1 {
  %1 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #2
  store i32 0, ptr @num_active_timers, align 4, !tbaa !5
  store i32 0, ptr %1, align 4, !tbaa !5
  br label %2

2:                                                ; preds = %27, %0
  %3 = load i32, ptr %1, align 4, !tbaa !5
  %4 = icmp slt i32 %3, 40
  br i1 %4, label %5, label %30

5:                                                ; preds = %2
  %6 = load i32, ptr %1, align 4, !tbaa !5
  %7 = sext i32 %6 to i64
  %8 = getelementptr inbounds [40 x %struct.TimerStruct], ptr @timer_list, i64 0, i64 %7
  %9 = getelementptr inbounds %struct.TimerStruct, ptr %8, i32 0, i32 0
  %10 = getelementptr inbounds [64 x i8], ptr %9, i64 0, i64 0
  store i8 0, ptr %10, align 16, !tbaa !9
  %11 = load i32, ptr %1, align 4, !tbaa !5
  %12 = sext i32 %11 to i64
  %13 = getelementptr inbounds [40 x %struct.TimerStruct], ptr @timer_list, i64 0, i64 %12
  %14 = getelementptr inbounds %struct.TimerStruct, ptr %13, i32 0, i32 1
  store i64 0, ptr %14, align 16, !tbaa !10
  %15 = load i32, ptr %1, align 4, !tbaa !5
  %16 = sext i32 %15 to i64
  %17 = getelementptr inbounds [40 x %struct.TimerStruct], ptr @timer_list, i64 0, i64 %16
  %18 = getelementptr inbounds %struct.TimerStruct, ptr %17, i32 0, i32 2
  store double 0.000000e+00, ptr %18, align 8, !tbaa !14
  %19 = load i32, ptr %1, align 4, !tbaa !5
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds [40 x %struct.TimerStackStruct], ptr @timer_stack, i64 0, i64 %20
  %22 = getelementptr inbounds %struct.TimerStackStruct, ptr %21, i32 0, i32 0
  store double 0.000000e+00, ptr %22, align 16, !tbaa !15
  %23 = load i32, ptr %1, align 4, !tbaa !5
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds [40 x %struct.TimerStackStruct], ptr @timer_stack, i64 0, i64 %24
  %26 = getelementptr inbounds %struct.TimerStackStruct, ptr %25, i32 0, i32 1
  store ptr null, ptr %26, align 8, !tbaa !18
  br label %27

27:                                               ; preds = %5
  %28 = load i32, ptr %1, align 4, !tbaa !5
  %29 = add nsw i32 %28, 1
  store i32 %29, ptr %1, align 4, !tbaa !5
  br label %2, !llvm.loop !19

30:                                               ; preds = %2
  store i32 0, ptr @next_free_timer, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #2
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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, !6, i64 0}
!6 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!7, !7, i64 0}
!10 = !{!11, !12, i64 64}
!11 = !{!"TimerStruct", !7, i64 0, !12, i64 64, !13, i64 72}
!12 = !{!"long", !7, i64 0}
!13 = !{!"double", !7, i64 0}
!14 = !{!11, !13, i64 72}
!15 = !{!16, !13, i64 0}
!16 = !{!"TimerStackStruct", !13, i64 0, !17, i64 8}
!17 = !{!"any pointer", !7, i64 0}
!18 = !{!16, !17, i64 8}
!19 = distinct !{!19, !20}
!20 = !{!"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.TimerStruct = type { [64 x i8], i64, double }
%struct.TimerStackStruct = type { double, ptr }

@num_active_timers = external hidden local_unnamed_addr global i32, align 4
@timer_list = external hidden local_unnamed_addr global [40 x %struct.TimerStruct], align 16
@timer_stack = external hidden local_unnamed_addr global [40 x %struct.TimerStackStruct], align 16
@next_free_timer = external hidden local_unnamed_addr global i32, align 4

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(write, argmem: none, inaccessiblemem: none) uwtable
define dso_local void @TimerInit() local_unnamed_addr #0 {
  store i32 0, ptr @num_active_timers, align 4, !tbaa !5
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(640) @timer_stack, i8 0, i64 640, i1 false), !tbaa !9
  store i8 0, ptr @timer_list, align 16, !tbaa !9
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(17) getelementptr inbounds (i8, ptr @timer_list, i64 64), i8 0, i64 17, i1 false)
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(17) getelementptr inbounds (i8, ptr @timer_list, i64 144), i8 0, i64 17, i1 false)
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(17) getelementptr inbounds (i8, ptr @timer_list, i64 224), i8 0, i64 17, i1 false)
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(17) getelementptr inbounds (i8, ptr @timer_list, i64 304), i8 0, i64 17, i1 false)
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(17) getelementptr inbounds (i8, ptr @timer_list, i64 384), i8 0, i64 17, i1 false)
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(17) getelementptr inbounds (i8, ptr @timer_list, i64 464), i8 0, i64 17, i1 false)
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(17) getelementptr inbounds (i8, ptr @timer_list, i64 544), i8 0, i64 17, i1 false)
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(17) getelementptr inbounds (i8, ptr @timer_list, i64 624), i8 0, i64 17, i1 false)
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(17) getelementptr inbounds (i8, ptr @timer_list, i64 704), i8 0, i64 17, i1 false)
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(17) getelementptr inbounds (i8, ptr @timer_list, i64 784), i8 0, i64 17, i1 false)
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(17) getelementptr inbounds (i8, ptr @timer_list, i64 864), i8 0, i64 17, i1 false)
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(17) getelementptr inbounds (i8, ptr @timer_list, i64 944), i8 0, i64 17, i1 false)
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(17) getelementptr inbounds (i8, ptr @timer_list, i64 1024), i8 0, i64 17, i1 false)
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(17) getelementptr inbounds (i8, ptr @timer_list, i64 1104), i8 0, i64 17, i1 false)
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(17) getelementptr inbounds (i8, ptr @timer_list, i64 1184), i8 0, i64 17, i1 false)
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(17) getelementptr inbounds (i8, ptr @timer_list, i64 1264), i8 0, i64 17, i1 false)
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(17) getelementptr inbounds (i8, ptr @timer_list, i64 1344), i8 0, i64 17, i1 false)
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(17) getelementptr inbounds (i8, ptr @timer_list, i64 1424), i8 0, i64 17, i1 false)
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(17) getelementptr inbounds (i8, ptr @timer_list, i64 1504), i8 0, i64 17, i1 false)
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(17) getelementptr inbounds (i8, ptr @timer_list, i64 1584), i8 0, i64 17, i1 false)
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(17) getelementptr inbounds (i8, ptr @timer_list, i64 1664), i8 0, i64 17, i1 false)
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(17) getelementptr inbounds (i8, ptr @timer_list, i64 1744), i8 0, i64 17, i1 false)
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(17) getelementptr inbounds (i8, ptr @timer_list, i64 1824), i8 0, i64 17, i1 false)
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(17) getelementptr inbounds (i8, ptr @timer_list, i64 1904), i8 0, i64 17, i1 false)
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(17) getelementptr inbounds (i8, ptr @timer_list, i64 1984), i8 0, i64 17, i1 false)
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(17) getelementptr inbounds (i8, ptr @timer_list, i64 2064), i8 0, i64 17, i1 false)
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(17) getelementptr inbounds (i8, ptr @timer_list, i64 2144), i8 0, i64 17, i1 false)
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(17) getelementptr inbounds (i8, ptr @timer_list, i64 2224), i8 0, i64 17, i1 false)
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(17) getelementptr inbounds (i8, ptr @timer_list, i64 2304), i8 0, i64 17, i1 false)
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(17) getelementptr inbounds (i8, ptr @timer_list, i64 2384), i8 0, i64 17, i1 false)
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(17) getelementptr inbounds (i8, ptr @timer_list, i64 2464), i8 0, i64 17, i1 false)
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(17) getelementptr inbounds (i8, ptr @timer_list, i64 2544), i8 0, i64 17, i1 false)
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(17) getelementptr inbounds (i8, ptr @timer_list, i64 2624), i8 0, i64 17, i1 false)
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(17) getelementptr inbounds (i8, ptr @timer_list, i64 2704), i8 0, i64 17, i1 false)
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(17) getelementptr inbounds (i8, ptr @timer_list, i64 2784), i8 0, i64 17, i1 false)
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(17) getelementptr inbounds (i8, ptr @timer_list, i64 2864), i8 0, i64 17, i1 false)
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(17) getelementptr inbounds (i8, ptr @timer_list, i64 2944), i8 0, i64 17, i1 false)
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(17) getelementptr inbounds (i8, ptr @timer_list, i64 3024), i8 0, i64 17, i1 false)
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(17) getelementptr inbounds (i8, ptr @timer_list, i64 3104), i8 0, i64 17, i1 false)
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(16) getelementptr inbounds (i8, ptr @timer_list, i64 3184), i8 0, i64 16, i1 false)
  store i32 0, ptr @next_free_timer, align 4, !tbaa !5
  ret void
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #1

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(write, argmem: none, inaccessiblemem: none) 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 nounwind willreturn memory(argmem: write) }

!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/C++ TBAA"}
!9 = !{!7, !7, i64 0}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LoopIdiomRecognizePass,LoopRotatePass,MemCpyOptPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass