; 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
@stderr = external global ptr, align 8
@.str = external hidden unnamed_addr constant [105 x i8], align 1
@top_of_stack = external hidden global i32, align 4
@.str.1 = external hidden unnamed_addr constant [113 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local double @CurrentTimeSeconds() #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: nounwind uwtable
define dso_local void @TimerStart(ptr noundef %0) #0 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #5
  store i32 0, ptr %3, align 4, !tbaa !9
  br label %4

4:                                                ; preds = %19, %1
  %5 = load i32, ptr %3, align 4, !tbaa !9
  %6 = load i32, ptr @num_active_timers, align 4, !tbaa !9
  %7 = icmp slt i32 %5, %6
  br i1 %7, label %8, label %22

8:                                                ; preds = %4
  %9 = load i32, ptr %3, align 4, !tbaa !9
  %10 = sext i32 %9 to i64
  %11 = getelementptr inbounds [40 x %struct.TimerStruct], ptr @timer_list, i64 0, i64 %10
  %12 = getelementptr inbounds %struct.TimerStruct, ptr %11, i32 0, i32 0
  %13 = getelementptr inbounds [64 x i8], ptr %12, i64 0, i64 0
  %14 = load ptr, ptr %2, align 8, !tbaa !5
  %15 = call i32 @strcmp(ptr noundef %13, ptr noundef %14) #6
  %16 = icmp eq i32 %15, 0
  br i1 %16, label %17, label %18

17:                                               ; preds = %8
  br label %22

18:                                               ; preds = %8
  br label %19

19:                                               ; preds = %18
  %20 = load i32, ptr %3, align 4, !tbaa !9
  %21 = add nsw i32 %20, 1
  store i32 %21, ptr %3, align 4, !tbaa !9
  br label %4, !llvm.loop !11

22:                                               ; preds = %17, %4
  %23 = load i32, ptr %3, align 4, !tbaa !9
  %24 = load i32, ptr @num_active_timers, align 4, !tbaa !9
  %25 = icmp eq i32 %23, %24
  br i1 %25, label %26, label %46

26:                                               ; preds = %22
  %27 = load i32, ptr @next_free_timer, align 4, !tbaa !9
  store i32 %27, ptr %3, align 4, !tbaa !9
  %28 = load i32, ptr @next_free_timer, align 4, !tbaa !9
  %29 = add nsw i32 %28, 1
  store i32 %29, ptr @next_free_timer, align 4, !tbaa !9
  %30 = load i32, ptr @num_active_timers, align 4, !tbaa !9
  %31 = add nsw i32 %30, 1
  store i32 %31, ptr @num_active_timers, align 4, !tbaa !9
  %32 = load i32, ptr %3, align 4, !tbaa !9
  %33 = icmp eq i32 %32, 40
  br i1 %33, label %34, label %38

34:                                               ; preds = %26
  %35 = load ptr, ptr @stderr, align 8, !tbaa !5
  %36 = load ptr, ptr %2, align 8, !tbaa !5
  %37 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %35, ptr noundef @.str, i32 noundef 40, ptr noundef %36) #5
  call void @exit(i32 noundef 1) #7
  unreachable

38:                                               ; preds = %26
  %39 = load i32, ptr %3, align 4, !tbaa !9
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds [40 x %struct.TimerStruct], ptr @timer_list, i64 0, i64 %40
  %42 = getelementptr inbounds %struct.TimerStruct, ptr %41, i32 0, i32 0
  %43 = getelementptr inbounds [64 x i8], ptr %42, i64 0, i64 0
  %44 = load ptr, ptr %2, align 8, !tbaa !5
  %45 = call ptr @strncpy(ptr noundef %43, ptr noundef %44, i64 noundef 64) #5
  br label %46

46:                                               ; preds = %38, %22
  %47 = load i32, ptr %3, align 4, !tbaa !9
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds [40 x %struct.TimerStruct], ptr @timer_list, i64 0, i64 %48
  %50 = getelementptr inbounds %struct.TimerStruct, ptr %49, i32 0, i32 1
  %51 = load i64, ptr %50, align 16, !tbaa !13
  %52 = add nsw i64 %51, 1
  store i64 %52, ptr %50, align 16, !tbaa !13
  %53 = load i32, ptr @top_of_stack, align 4, !tbaa !9
  %54 = icmp sgt i32 %53, 40
  br i1 %54, label %55, label %59

55:                                               ; preds = %46
  %56 = load ptr, ptr @stderr, align 8, !tbaa !5
  %57 = load ptr, ptr %2, align 8, !tbaa !5
  %58 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %56, ptr noundef @.str.1, i32 noundef 40, ptr noundef %57) #5
  call void @exit(i32 noundef 1) #7
  unreachable

59:                                               ; preds = %46
  %60 = load i32, ptr %3, align 4, !tbaa !9
  %61 = sext i32 %60 to i64
  %62 = getelementptr inbounds [40 x %struct.TimerStruct], ptr @timer_list, i64 0, i64 %61
  %63 = load i32, ptr @top_of_stack, align 4, !tbaa !9
  %64 = sext i32 %63 to i64
  %65 = getelementptr inbounds [40 x %struct.TimerStackStruct], ptr @timer_stack, i64 0, i64 %64
  %66 = getelementptr inbounds %struct.TimerStackStruct, ptr %65, i32 0, i32 1
  store ptr %62, ptr %66, align 8, !tbaa !17
  %67 = call double @CurrentTimeSeconds()
  %68 = load i32, ptr @top_of_stack, align 4, !tbaa !9
  %69 = sext i32 %68 to i64
  %70 = getelementptr inbounds [40 x %struct.TimerStackStruct], ptr @timer_stack, i64 0, i64 %69
  %71 = getelementptr inbounds %struct.TimerStackStruct, ptr %70, i32 0, i32 0
  store double %67, ptr %71, align 16, !tbaa !19
  %72 = load i32, ptr @top_of_stack, align 4, !tbaa !9
  %73 = add nsw i32 %72, 1
  store i32 %73, ptr @top_of_stack, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #5
  ret void
}

; Function Attrs: nounwind willreturn memory(read)
declare i32 @strcmp(ptr noundef, ptr noundef) #2

; Function Attrs: nounwind
declare i32 @fprintf(ptr noundef, ptr noundef, ...) #3

; Function Attrs: noreturn nounwind
declare void @exit(i32 noundef) #4

; Function Attrs: nounwind
declare ptr @strncpy(ptr noundef, ptr noundef, i64 noundef) #3

attributes #0 = { 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 = { nounwind willreturn memory(read) "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 "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 = { noreturn 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 #5 = { nounwind }
attributes #6 = { nounwind willreturn memory(read) }
attributes #7 = { noreturn 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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{!14, !15, i64 64}
!14 = !{!"TimerStruct", !7, i64 0, !15, i64 64, !16, i64 72}
!15 = !{!"long", !7, i64 0}
!16 = !{!"double", !7, i64 0}
!17 = !{!18, !6, i64 8}
!18 = !{!"TimerStackStruct", !16, i64 0, !6, i64 8}
!19 = !{!18, !16, 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.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 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
@stderr = external local_unnamed_addr global ptr, align 8
@.str = external hidden unnamed_addr constant [105 x i8], align 1
@top_of_stack = external hidden local_unnamed_addr global i32, align 4
@.str.1 = external hidden unnamed_addr constant [113 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local double @CurrentTimeSeconds() local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @TimerStart(ptr noundef %0) local_unnamed_addr #0 {
  %2 = load i32, ptr @num_active_timers, align 4, !tbaa !5
  %3 = icmp sgt i32 %2, 0
  br i1 %3, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %1
  %wide.trip.count = zext nneg i32 %2 to i64
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %7
  %indvars.iv = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next, %7 ]
  %4 = getelementptr inbounds [40 x %struct.TimerStruct], ptr @timer_list, i64 0, i64 %indvars.iv
  %5 = tail call i32 @strcmp(ptr noundef nonnull dereferenceable(1) %4, ptr noundef nonnull dereferenceable(1) %0) #5
  %6 = icmp eq i32 %5, 0
  br i1 %6, label %._crit_edge.loopexit, label %7

7:                                                ; preds = %.lr.ph
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge.thread, label %.lr.ph, !llvm.loop !9

._crit_edge.loopexit:                             ; preds = %.lr.ph
  %8 = trunc nuw nsw i64 %indvars.iv to i32
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %1
  %.0.lcssa = phi i32 [ 0, %1 ], [ %8, %._crit_edge.loopexit ]
  %9 = icmp eq i32 %.0.lcssa, %2
  br i1 %9, label %._crit_edge.thread, label %._crit_edge._crit_edge

._crit_edge._crit_edge:                           ; preds = %._crit_edge
  %.pre = sext i32 %.0.lcssa to i64
  br label %21

._crit_edge.thread:                               ; preds = %7, %._crit_edge
  %10 = load i32, ptr @next_free_timer, align 4, !tbaa !5
  %11 = add nsw i32 %10, 1
  store i32 %11, ptr @next_free_timer, align 4, !tbaa !5
  %12 = add nsw i32 %2, 1
  store i32 %12, ptr @num_active_timers, align 4, !tbaa !5
  %13 = icmp eq i32 %10, 40
  br i1 %13, label %14, label %17

14:                                               ; preds = %._crit_edge.thread
  %15 = load ptr, ptr @stderr, align 8, !tbaa !11
  %16 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %15, ptr noundef nonnull @.str, i32 noundef 40, ptr noundef %0) #6
  tail call void @exit(i32 noundef 1) #7
  unreachable

17:                                               ; preds = %._crit_edge.thread
  %18 = sext i32 %10 to i64
  %19 = getelementptr inbounds [40 x %struct.TimerStruct], ptr @timer_list, i64 0, i64 %18
  %20 = tail call ptr @strncpy(ptr noundef nonnull dereferenceable(1) %19, ptr noundef nonnull dereferenceable(1) %0, i64 noundef 64) #8
  br label %21

21:                                               ; preds = %._crit_edge._crit_edge, %17
  %.pre-phi = phi i64 [ %.pre, %._crit_edge._crit_edge ], [ %18, %17 ]
  %22 = getelementptr inbounds [40 x %struct.TimerStruct], ptr @timer_list, i64 0, i64 %.pre-phi
  %23 = getelementptr inbounds i8, ptr %22, i64 64
  %24 = load i64, ptr %23, align 16, !tbaa !13
  %25 = add nsw i64 %24, 1
  store i64 %25, ptr %23, align 16, !tbaa !13
  %26 = load i32, ptr @top_of_stack, align 4, !tbaa !5
  %27 = icmp sgt i32 %26, 40
  br i1 %27, label %28, label %31

28:                                               ; preds = %21
  %29 = load ptr, ptr @stderr, align 8, !tbaa !11
  %30 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %29, ptr noundef nonnull @.str.1, i32 noundef 40, ptr noundef %0) #6
  tail call void @exit(i32 noundef 1) #7
  unreachable

31:                                               ; preds = %21
  %32 = sext i32 %26 to i64
  %33 = getelementptr inbounds [40 x %struct.TimerStackStruct], ptr @timer_stack, i64 0, i64 %32, i32 1
  store ptr %22, ptr %33, align 8, !tbaa !17
  %34 = tail call double @CurrentTimeSeconds()
  %35 = load i32, ptr @top_of_stack, align 4, !tbaa !5
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds [40 x %struct.TimerStackStruct], ptr @timer_stack, i64 0, i64 %36
  store double %34, ptr %37, align 16, !tbaa !19
  %38 = add nsw i32 %35, 1
  store i32 %38, ptr @top_of_stack, align 4, !tbaa !5
  ret void
}

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare i32 @strcmp(ptr nocapture noundef, ptr nocapture noundef) local_unnamed_addr #1

; Function Attrs: nofree nounwind
declare noundef i32 @fprintf(ptr nocapture noundef, ptr nocapture noundef readonly, ...) local_unnamed_addr #2

; Function Attrs: noreturn nounwind
declare void @exit(i32 noundef) local_unnamed_addr #3

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: readwrite)
declare ptr @strncpy(ptr noalias noundef returned writeonly, ptr noalias nocapture noundef readonly, i64 noundef) local_unnamed_addr #4

attributes #0 = { 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 nofree nounwind willreturn memory(argmem: read) "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 = { nofree 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 #3 = { noreturn 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 #4 = { mustprogress nofree nounwind willreturn memory(argmem: readwrite) "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 #5 = { nounwind willreturn memory(read) }
attributes #6 = { cold nounwind }
attributes #7 = { noreturn nounwind }
attributes #8 = { 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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!12, !12, i64 0}
!12 = !{!"any pointer", !7, i64 0}
!13 = !{!14, !15, i64 64}
!14 = !{!"TimerStruct", !7, i64 0, !15, i64 64, !16, i64 72}
!15 = !{!"long", !7, i64 0}
!16 = !{!"double", !7, i64 0}
!17 = !{!18, !12, i64 8}
!18 = !{!"TimerStackStruct", !16, i64 0, !12, i64 8}
!19 = !{!18, !16, i64 0}


; Effective O3 passes: BDCEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass