; LLVM IR from AdaptiveCpp/AdaptiveCpp :: src/libkernel/sscp/spirv/atomic.ll_ (acpp_sscp_cmp_exch_strong_i16)

; 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 uwtable
declare dso_local noundef i32 @_Z27get_atomic_memory_semanticsN7hipsycl4sycl12memory_orderE(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
declare dso_local noundef i32 @_Z15get_spirv_scopeN7hipsycl4sycl12memory_scopeE(i32 noundef) #2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef ptr addrspace(1) @_Z9to_globalIsEPU3AS1T_PS0_(ptr noundef) #3

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef ptr addrspace(3) @_Z8to_localIsEPU3AS3T_PS0_(ptr noundef) #3

; Function Attrs: alwaysinline mustprogress uwtable
define dso_local zeroext i1 @__acpp_sscp_cmp_exch_strong_i16(i32 noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, ptr noundef %4, ptr noundef %5, i16 noundef signext %6) #0 {
  %8 = alloca i1, align 1
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca ptr, align 8
  %14 = alloca ptr, align 8
  %15 = alloca i16, align 2
  %16 = alloca i16, align 2
  %17 = alloca i16, align 2
  %18 = alloca i16, align 2
  store i32 %0, ptr %9, align 4, !tbaa !5
  store i32 %1, ptr %10, align 4, !tbaa !9
  store i32 %2, ptr %11, align 4, !tbaa !9
  store i32 %3, ptr %12, align 4, !tbaa !11
  store ptr %4, ptr %13, align 8, !tbaa !13
  store ptr %5, ptr %14, align 8, !tbaa !13
  store i16 %6, ptr %15, align 2, !tbaa !15
  %19 = load i32, ptr %9, align 4, !tbaa !5
  %20 = icmp eq i32 %19, 0
  br i1 %20, label %21, label %43

21:                                               ; preds = %7
  call void @llvm.lifetime.start.p0(i64 2, ptr %16) #5
  %22 = load ptr, ptr %14, align 8, !tbaa !13
  %23 = load i16, ptr %22, align 2, !tbaa !15
  store i16 %23, ptr %16, align 2, !tbaa !15
  %24 = load ptr, ptr %13, align 8, !tbaa !13
  %25 = call noundef ptr addrspace(1) @_Z9to_globalIsEPU3AS1T_PS0_(ptr noundef %24)
  %26 = load i32, ptr %12, align 4, !tbaa !11
  %27 = call noundef i32 @_Z15get_spirv_scopeN7hipsycl4sycl12memory_scopeE(i32 noundef %26)
  %28 = load i32, ptr %10, align 4, !tbaa !9
  %29 = call noundef i32 @_Z27get_atomic_memory_semanticsN7hipsycl4sycl12memory_orderE(i32 noundef %28)
  %30 = load i32, ptr %11, align 4, !tbaa !9
  %31 = call noundef i32 @_Z27get_atomic_memory_semanticsN7hipsycl4sycl12memory_orderE(i32 noundef %30)
  %32 = load i16, ptr %15, align 2, !tbaa !15
  %33 = load ptr, ptr %14, align 8, !tbaa !13
  %34 = load i16, ptr %33, align 2, !tbaa !15
  %35 = call noundef signext i16 @_Z29__spirv_AtomicCompareExchangePU3AS1sN5__spv9ScopeFlagENS1_23MemorySemanticsMaskFlagES3_ss(ptr addrspace(1) noundef %25, i32 noundef %27, i32 noundef %29, i32 noundef %31, i16 noundef signext %32, i16 noundef signext %34)
  %36 = load ptr, ptr %14, align 8, !tbaa !13
  store i16 %35, ptr %36, align 2, !tbaa !15
  %37 = load i16, ptr %16, align 2, !tbaa !15
  %38 = sext i16 %37 to i32
  %39 = load ptr, ptr %14, align 8, !tbaa !13
  %40 = load i16, ptr %39, align 2, !tbaa !15
  %41 = sext i16 %40 to i32
  %42 = icmp eq i32 %38, %41
  store i1 %42, ptr %8, align 1
  call void @llvm.lifetime.end.p0(i64 2, ptr %16) #5
  br label %89

43:                                               ; preds = %7
  %44 = load i32, ptr %9, align 4, !tbaa !5
  %45 = icmp eq i32 %44, 1
  br i1 %45, label %46, label %68

46:                                               ; preds = %43
  call void @llvm.lifetime.start.p0(i64 2, ptr %17) #5
  %47 = load ptr, ptr %14, align 8, !tbaa !13
  %48 = load i16, ptr %47, align 2, !tbaa !15
  store i16 %48, ptr %17, align 2, !tbaa !15
  %49 = load ptr, ptr %13, align 8, !tbaa !13
  %50 = call noundef ptr addrspace(3) @_Z8to_localIsEPU3AS3T_PS0_(ptr noundef %49)
  %51 = load i32, ptr %12, align 4, !tbaa !11
  %52 = call noundef i32 @_Z15get_spirv_scopeN7hipsycl4sycl12memory_scopeE(i32 noundef %51)
  %53 = load i32, ptr %10, align 4, !tbaa !9
  %54 = call noundef i32 @_Z27get_atomic_memory_semanticsN7hipsycl4sycl12memory_orderE(i32 noundef %53)
  %55 = load i32, ptr %11, align 4, !tbaa !9
  %56 = call noundef i32 @_Z27get_atomic_memory_semanticsN7hipsycl4sycl12memory_orderE(i32 noundef %55)
  %57 = load i16, ptr %15, align 2, !tbaa !15
  %58 = load ptr, ptr %14, align 8, !tbaa !13
  %59 = load i16, ptr %58, align 2, !tbaa !15
  %60 = call noundef signext i16 @_Z29__spirv_AtomicCompareExchangePU3AS3sN5__spv9ScopeFlagENS1_23MemorySemanticsMaskFlagES3_ss(ptr addrspace(3) noundef %50, i32 noundef %52, i32 noundef %54, i32 noundef %56, i16 noundef signext %57, i16 noundef signext %59)
  %61 = load ptr, ptr %14, align 8, !tbaa !13
  store i16 %60, ptr %61, align 2, !tbaa !15
  %62 = load i16, ptr %17, align 2, !tbaa !15
  %63 = sext i16 %62 to i32
  %64 = load ptr, ptr %14, align 8, !tbaa !13
  %65 = load i16, ptr %64, align 2, !tbaa !15
  %66 = sext i16 %65 to i32
  %67 = icmp eq i32 %63, %66
  store i1 %67, ptr %8, align 1
  call void @llvm.lifetime.end.p0(i64 2, ptr %17) #5
  br label %89

68:                                               ; preds = %43
  call void @llvm.lifetime.start.p0(i64 2, ptr %18) #5
  %69 = load ptr, ptr %14, align 8, !tbaa !13
  %70 = load i16, ptr %69, align 2, !tbaa !15
  store i16 %70, ptr %18, align 2, !tbaa !15
  %71 = load ptr, ptr %13, align 8, !tbaa !13
  %72 = load i32, ptr %12, align 4, !tbaa !11
  %73 = call noundef i32 @_Z15get_spirv_scopeN7hipsycl4sycl12memory_scopeE(i32 noundef %72)
  %74 = load i32, ptr %10, align 4, !tbaa !9
  %75 = call noundef i32 @_Z27get_atomic_memory_semanticsN7hipsycl4sycl12memory_orderE(i32 noundef %74)
  %76 = load i32, ptr %11, align 4, !tbaa !9
  %77 = call noundef i32 @_Z27get_atomic_memory_semanticsN7hipsycl4sycl12memory_orderE(i32 noundef %76)
  %78 = load i16, ptr %15, align 2, !tbaa !15
  %79 = load ptr, ptr %14, align 8, !tbaa !13
  %80 = load i16, ptr %79, align 2, !tbaa !15
  %81 = call noundef signext i16 @_Z29__spirv_AtomicCompareExchangePsN5__spv9ScopeFlagENS0_23MemorySemanticsMaskFlagES2_ss(ptr noundef %71, i32 noundef %73, i32 noundef %75, i32 noundef %77, i16 noundef signext %78, i16 noundef signext %80)
  %82 = load ptr, ptr %14, align 8, !tbaa !13
  store i16 %81, ptr %82, align 2, !tbaa !15
  %83 = load i16, ptr %18, align 2, !tbaa !15
  %84 = sext i16 %83 to i32
  %85 = load ptr, ptr %14, align 8, !tbaa !13
  %86 = load i16, ptr %85, align 2, !tbaa !15
  %87 = sext i16 %86 to i32
  %88 = icmp eq i32 %84, %87
  store i1 %88, ptr %8, align 1
  call void @llvm.lifetime.end.p0(i64 2, ptr %18) #5
  br label %89

89:                                               ; preds = %68, %46, %21
  %90 = load i1, ptr %8, align 1
  ret i1 %90
}

declare noundef signext i16 @_Z29__spirv_AtomicCompareExchangePU3AS1sN5__spv9ScopeFlagENS1_23MemorySemanticsMaskFlagES3_ss(ptr addrspace(1) noundef, i32 noundef, i32 noundef, i32 noundef, i16 noundef signext, i16 noundef signext) #4

declare noundef signext i16 @_Z29__spirv_AtomicCompareExchangePU3AS3sN5__spv9ScopeFlagENS1_23MemorySemanticsMaskFlagES3_ss(ptr addrspace(3) noundef, i32 noundef, i32 noundef, i32 noundef, i16 noundef signext, i16 noundef signext) #4

declare noundef signext i16 @_Z29__spirv_AtomicCompareExchangePsN5__spv9ScopeFlagENS0_23MemorySemanticsMaskFlagES2_ss(ptr noundef, i32 noundef, i32 noundef, i32 noundef, i16 noundef signext, i16 noundef signext) #4

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

!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 = !{!"short", !7, 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"

; Function Attrs: alwaysinline mustprogress uwtable
declare dso_local noundef i32 @_Z27get_atomic_memory_semanticsN7hipsycl4sycl12memory_orderE(i32 noundef) local_unnamed_addr #0

; Function Attrs: alwaysinline mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z15get_spirv_scopeN7hipsycl4sycl12memory_scopeE(i32 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef ptr addrspace(1) @_Z9to_globalIsEPU3AS1T_PS0_(ptr noundef) local_unnamed_addr #2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef ptr addrspace(3) @_Z8to_localIsEPU3AS3T_PS0_(ptr noundef) local_unnamed_addr #2

; Function Attrs: alwaysinline mustprogress uwtable
define dso_local zeroext i1 @__acpp_sscp_cmp_exch_strong_i16(i32 noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, ptr noundef %4, ptr nocapture noundef %5, i16 noundef signext %6) local_unnamed_addr #0 {
  %8 = load i16, ptr %5, align 2, !tbaa !5
  switch i32 %0, label %23 [
    i32 0, label %9
    i32 1, label %16
  ]

9:                                                ; preds = %7
  %10 = tail call noundef ptr addrspace(1) @_Z9to_globalIsEPU3AS1T_PS0_(ptr noundef %4)
  %11 = tail call noundef i32 @_Z15get_spirv_scopeN7hipsycl4sycl12memory_scopeE(i32 noundef %3)
  %12 = tail call noundef i32 @_Z27get_atomic_memory_semanticsN7hipsycl4sycl12memory_orderE(i32 noundef %1)
  %13 = tail call noundef i32 @_Z27get_atomic_memory_semanticsN7hipsycl4sycl12memory_orderE(i32 noundef %2)
  %14 = load i16, ptr %5, align 2, !tbaa !5
  %15 = tail call noundef signext i16 @_Z29__spirv_AtomicCompareExchangePU3AS1sN5__spv9ScopeFlagENS1_23MemorySemanticsMaskFlagES3_ss(ptr addrspace(1) noundef %10, i32 noundef %11, i32 noundef %12, i32 noundef %13, i16 noundef signext %6, i16 noundef signext %14)
  br label %29

16:                                               ; preds = %7
  %17 = tail call noundef ptr addrspace(3) @_Z8to_localIsEPU3AS3T_PS0_(ptr noundef %4)
  %18 = tail call noundef i32 @_Z15get_spirv_scopeN7hipsycl4sycl12memory_scopeE(i32 noundef %3)
  %19 = tail call noundef i32 @_Z27get_atomic_memory_semanticsN7hipsycl4sycl12memory_orderE(i32 noundef %1)
  %20 = tail call noundef i32 @_Z27get_atomic_memory_semanticsN7hipsycl4sycl12memory_orderE(i32 noundef %2)
  %21 = load i16, ptr %5, align 2, !tbaa !5
  %22 = tail call noundef signext i16 @_Z29__spirv_AtomicCompareExchangePU3AS3sN5__spv9ScopeFlagENS1_23MemorySemanticsMaskFlagES3_ss(ptr addrspace(3) noundef %17, i32 noundef %18, i32 noundef %19, i32 noundef %20, i16 noundef signext %6, i16 noundef signext %21)
  br label %29

23:                                               ; preds = %7
  %24 = tail call noundef i32 @_Z15get_spirv_scopeN7hipsycl4sycl12memory_scopeE(i32 noundef %3)
  %25 = tail call noundef i32 @_Z27get_atomic_memory_semanticsN7hipsycl4sycl12memory_orderE(i32 noundef %1)
  %26 = tail call noundef i32 @_Z27get_atomic_memory_semanticsN7hipsycl4sycl12memory_orderE(i32 noundef %2)
  %27 = load i16, ptr %5, align 2, !tbaa !5
  %28 = tail call noundef signext i16 @_Z29__spirv_AtomicCompareExchangePsN5__spv9ScopeFlagENS0_23MemorySemanticsMaskFlagES2_ss(ptr noundef %4, i32 noundef %24, i32 noundef %25, i32 noundef %26, i16 noundef signext %6, i16 noundef signext %27)
  br label %29

29:                                               ; preds = %23, %16, %9
  %.sink33 = phi i16 [ %28, %23 ], [ %22, %16 ], [ %15, %9 ]
  store i16 %.sink33, ptr %5, align 2, !tbaa !5
  %30 = icmp eq i16 %8, %.sink33
  ret i1 %30
}

declare noundef signext i16 @_Z29__spirv_AtomicCompareExchangePU3AS1sN5__spv9ScopeFlagENS1_23MemorySemanticsMaskFlagES3_ss(ptr addrspace(1) noundef, i32 noundef, i32 noundef, i32 noundef, i16 noundef signext, i16 noundef signext) local_unnamed_addr #3

declare noundef signext i16 @_Z29__spirv_AtomicCompareExchangePU3AS3sN5__spv9ScopeFlagENS1_23MemorySemanticsMaskFlagES3_ss(ptr addrspace(3) noundef, i32 noundef, i32 noundef, i32 noundef, i16 noundef signext, i16 noundef signext) local_unnamed_addr #3

declare noundef signext i16 @_Z29__spirv_AtomicCompareExchangePsN5__spv9ScopeFlagENS0_23MemorySemanticsMaskFlagES2_ss(ptr noundef, i32 noundef, i32 noundef, i32 noundef, i16 noundef signext, i16 noundef signext) local_unnamed_addr #3

attributes #0 = { alwaysinline 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 #1 = { 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 #2 = { 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 #3 = { "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" }

!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 = !{!"short", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}


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