; LLVM IR from libxsmm/libxsmm :: src (libxsmm_timer)

; 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.libxsmm_timer_info = type { i32 }

@libxsmm_timer_scale = external global double, align 8
@libxsmm_ninit = external global i32, align 4
@libxsmm_get_timer_info.error_once = external hidden global i32, align 4
@libxsmm_verbosity = external global i32, align 4
@stderr = external global ptr, align 8
@.str = external hidden unnamed_addr constant [71 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i32 @libxsmm_get_timer_info(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) #4
  %4 = load ptr, ptr %2, align 8, !tbaa !5
  %5 = icmp ne ptr null, %4
  br i1 %5, label %6, label %30

6:                                                ; preds = %1
  %7 = load double, ptr @libxsmm_timer_scale, align 8, !tbaa !9
  %8 = fcmp olt double 0.000000e+00, %7
  br i1 %8, label %9, label %12

9:                                                ; preds = %6
  %10 = load ptr, ptr %2, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.libxsmm_timer_info, ptr %10, i32 0, i32 0
  store i32 1, ptr %11, align 4, !tbaa !11
  br label %29

12:                                               ; preds = %6
  %13 = load i32, ptr @libxsmm_ninit, align 4, !tbaa !14
  %14 = icmp ugt i32 2, %13
  br i1 %14, label %15, label %25

15:                                               ; preds = %12
  call void @libxsmm_init()
  %16 = load double, ptr @libxsmm_timer_scale, align 8, !tbaa !9
  %17 = fcmp olt double 0.000000e+00, %16
  br i1 %17, label %18, label %21

18:                                               ; preds = %15
  %19 = load ptr, ptr %2, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.libxsmm_timer_info, ptr %19, i32 0, i32 0
  store i32 1, ptr %20, align 4, !tbaa !11
  br label %24

21:                                               ; preds = %15
  %22 = load ptr, ptr %2, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.libxsmm_timer_info, ptr %22, i32 0, i32 0
  store i32 0, ptr %23, align 4, !tbaa !11
  br label %24

24:                                               ; preds = %21, %18
  br label %28

25:                                               ; preds = %12
  %26 = load ptr, ptr %2, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.libxsmm_timer_info, ptr %26, i32 0, i32 0
  store i32 0, ptr %27, align 4, !tbaa !11
  br label %28

28:                                               ; preds = %25, %24
  br label %29

29:                                               ; preds = %28, %9
  store i32 0, ptr %3, align 4, !tbaa !14
  br label %41

30:                                               ; preds = %1
  %31 = load i32, ptr @libxsmm_verbosity, align 4, !tbaa !14
  %32 = icmp ne i32 0, %31
  br i1 %32, label %33, label %40

33:                                               ; preds = %30
  %34 = atomicrmw add ptr @libxsmm_get_timer_info.error_once, i32 1 seq_cst, align 4
  %35 = add i32 %34, 1
  %36 = icmp eq i32 1, %35
  br i1 %36, label %37, label %40

37:                                               ; preds = %33
  %38 = load ptr, ptr @stderr, align 8, !tbaa !5
  %39 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %38, ptr noundef @.str) #4
  br label %40

40:                                               ; preds = %37, %33, %30
  store i32 1, ptr %3, align 4, !tbaa !14
  br label %41

41:                                               ; preds = %40, %29
  %42 = load i32, ptr %3, align 4, !tbaa !14
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #4
  ret i32 %42
}

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

declare void @libxsmm_init() #2

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

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

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 = { "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 = { 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 = !{!"double", !7, i64 0}
!11 = !{!12, !13, i64 0}
!12 = !{!"libxsmm_timer_info", !13, i64 0}
!13 = !{!"int", !7, i64 0}
!14 = !{!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"

@libxsmm_timer_scale = external local_unnamed_addr global double, align 8
@libxsmm_ninit = external local_unnamed_addr global i32, align 4
@libxsmm_get_timer_info.error_once = external hidden global i32, align 4
@libxsmm_verbosity = external local_unnamed_addr global i32, align 4
@stderr = external local_unnamed_addr global ptr, align 8
@.str = external hidden unnamed_addr constant [71 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 2) i32 @libxsmm_get_timer_info(ptr noundef writeonly %0) local_unnamed_addr #0 {
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %15, label %2

2:                                                ; preds = %1
  %3 = load double, ptr @libxsmm_timer_scale, align 8, !tbaa !5
  %4 = fcmp ogt double %3, 0.000000e+00
  br i1 %4, label %5, label %6

5:                                                ; preds = %2
  store i32 1, ptr %0, align 4, !tbaa !9
  br label %23

6:                                                ; preds = %2
  %7 = load i32, ptr @libxsmm_ninit, align 4, !tbaa !12
  %8 = icmp ult i32 %7, 2
  br i1 %8, label %9, label %14

9:                                                ; preds = %6
  tail call void @libxsmm_init() #3
  %10 = load double, ptr @libxsmm_timer_scale, align 8, !tbaa !5
  %11 = fcmp ogt double %10, 0.000000e+00
  br i1 %11, label %12, label %13

12:                                               ; preds = %9
  store i32 1, ptr %0, align 4, !tbaa !9
  br label %23

13:                                               ; preds = %9
  store i32 0, ptr %0, align 4, !tbaa !9
  br label %23

14:                                               ; preds = %6
  store i32 0, ptr %0, align 4, !tbaa !9
  br label %23

15:                                               ; preds = %1
  %16 = load i32, ptr @libxsmm_verbosity, align 4, !tbaa !12
  %.not6 = icmp eq i32 %16, 0
  br i1 %.not6, label %23, label %17

17:                                               ; preds = %15
  %18 = atomicrmw add ptr @libxsmm_get_timer_info.error_once, i32 1 seq_cst, align 4
  %19 = icmp eq i32 %18, 0
  br i1 %19, label %20, label %23

20:                                               ; preds = %17
  %21 = load ptr, ptr @stderr, align 8, !tbaa !13
  %22 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %21, ptr noundef nonnull @.str) #4
  br label %23

23:                                               ; preds = %15, %17, %20, %5, %12, %13, %14
  %.0 = phi i32 [ 0, %14 ], [ 0, %13 ], [ 0, %12 ], [ 0, %5 ], [ 1, %20 ], [ 1, %17 ], [ 1, %15 ]
  ret i32 %.0
}

declare void @libxsmm_init() local_unnamed_addr #1

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

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 = { "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 = { nounwind }
attributes #4 = { cold 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 = !{!"double", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !11, i64 0}
!10 = !{!"libxsmm_timer_info", !11, i64 0}
!11 = !{!"int", !7, i64 0}
!12 = !{!11, !11, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"any pointer", !7, i64 0}


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