; LLVM IR from AdaptiveCpp/AdaptiveCpp :: src/libkernel/sscp/host/atomic.ll_ (acpp_sscp_atomic_fetch_max_f32)

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

; Function Attrs: alwaysinline mustprogress nounwind uwtable
declare dso_local i32 @__acpp_sscp_atomic_load_i32(i32 noundef, i32 noundef, i32 noundef, ptr noundef) #0

; Function Attrs: alwaysinline mustprogress nounwind uwtable
declare dso_local zeroext i1 @__acpp_sscp_cmp_exch_strong_i32(i32 noundef, i32 noundef, i32 noundef, i32 noundef, ptr noundef, ptr noundef, i32 noundef) #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: alwaysinline mustprogress nounwind uwtable
define dso_local float @__acpp_sscp_atomic_fetch_max_f32(i32 noundef %0, i32 noundef %1, i32 noundef %2, ptr noundef %3, float noundef %4) #0 {
  %6 = alloca float, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca ptr, align 8
  %11 = alloca float, align 4
  %12 = alloca i32, align 4
  %13 = alloca float, align 4
  %14 = alloca i32, align 4
  store i32 %0, ptr %7, align 4, !tbaa !5
  store i32 %1, ptr %8, align 4, !tbaa !9
  store i32 %2, ptr %9, align 4, !tbaa !11
  store ptr %3, ptr %10, align 8, !tbaa !13
  store float %4, ptr %11, align 4, !tbaa !15
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #2
  %15 = load i32, ptr %7, align 4, !tbaa !5
  %16 = load i32, ptr %8, align 4, !tbaa !9
  %17 = load i32, ptr %9, align 4, !tbaa !11
  %18 = load ptr, ptr %10, align 8, !tbaa !13
  %19 = call i32 @__acpp_sscp_atomic_load_i32(i32 noundef %15, i32 noundef %16, i32 noundef %17, ptr noundef %18)
  store i32 %19, ptr %12, align 4, !tbaa !17
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #2
  %20 = load float, ptr %12, align 4, !tbaa !15
  store float %20, ptr %13, align 4, !tbaa !15
  br label %21

21:                                               ; preds = %28, %5
  %22 = load float, ptr %13, align 4, !tbaa !15
  %23 = load float, ptr %11, align 4, !tbaa !15
  %24 = fcmp ogt float %22, %23
  br i1 %24, label %25, label %27

25:                                               ; preds = %21
  %26 = load float, ptr %13, align 4, !tbaa !15
  store float %26, ptr %6, align 4
  store i32 1, ptr %14, align 4
  br label %39

27:                                               ; preds = %21
  br label %28

28:                                               ; preds = %27
  %29 = load i32, ptr %7, align 4, !tbaa !5
  %30 = load i32, ptr %8, align 4, !tbaa !9
  %31 = load i32, ptr %8, align 4, !tbaa !9
  %32 = load i32, ptr %9, align 4, !tbaa !11
  %33 = load ptr, ptr %10, align 8, !tbaa !13
  %34 = load i32, ptr %11, align 4, !tbaa !17
  %35 = call zeroext i1 @__acpp_sscp_cmp_exch_strong_i32(i32 noundef %29, i32 noundef %30, i32 noundef %31, i32 noundef %32, ptr noundef %33, ptr noundef %13, i32 noundef %34)
  %36 = xor i1 %35, true
  br i1 %36, label %21, label %37, !llvm.loop !19

37:                                               ; preds = %28
  %38 = load float, ptr %11, align 4, !tbaa !15
  store float %38, ptr %6, align 4
  store i32 1, ptr %14, align 4
  br label %39

39:                                               ; preds = %37, %25
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #2
  %40 = load float, ptr %6, align 4
  ret float %40
}

attributes #0 = { alwaysinline 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 = { 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 = !{!"_ZTSN7hipsycl4sycl6access13address_spaceE", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"_ZTSN7hipsycl4sycl12memory_orderE", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"_ZTSN7hipsycl4sycl12memory_scopeE", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"any pointer", !7, i64 0}
!15 = !{!16, !16, i64 0}
!16 = !{!"float", !7, i64 0}
!17 = !{!18, !18, i64 0}
!18 = !{!"int", !7, i64 0}
!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"

; Function Attrs: alwaysinline mustprogress nounwind uwtable
declare dso_local i32 @__acpp_sscp_atomic_load_i32(i32 noundef, i32 noundef, i32 noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: alwaysinline mustprogress nounwind uwtable
declare dso_local zeroext i1 @__acpp_sscp_cmp_exch_strong_i32(i32 noundef, i32 noundef, i32 noundef, i32 noundef, ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #0

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

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

; Function Attrs: alwaysinline mustprogress nounwind uwtable
define dso_local float @__acpp_sscp_atomic_fetch_max_f32(i32 noundef %0, i32 noundef %1, i32 noundef %2, ptr noundef %3, float noundef %4) local_unnamed_addr #0 {
  %6 = alloca float, align 4
  %7 = tail call i32 @__acpp_sscp_atomic_load_i32(i32 noundef %0, i32 noundef %1, i32 noundef %2, ptr noundef %3)
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %6) #2
  store i32 %7, ptr %6, align 4, !tbaa !5
  %8 = bitcast float %4 to i32
  br label %9

9:                                                ; preds = %12, %5
  %10 = load float, ptr %6, align 4, !tbaa !5
  %11 = fcmp ogt float %10, %4
  br i1 %11, label %14, label %12

12:                                               ; preds = %9
  %13 = call zeroext i1 @__acpp_sscp_cmp_exch_strong_i32(i32 noundef %0, i32 noundef %1, i32 noundef %1, i32 noundef %2, ptr noundef %3, ptr noundef nonnull %6, i32 noundef %8)
  br i1 %13, label %14, label %9, !llvm.loop !9

14:                                               ; preds = %12, %9
  %.0 = phi float [ %10, %9 ], [ %4, %12 ]
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %6) #2
  ret float %.0
}

attributes #0 = { alwaysinline 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 willreturn memory(argmem: readwrite) }
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 = !{!"float", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


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