; LLVM IR from taichi-dev/taichi :: taichi/runtime/llvm/runtime_module (runtime)

; 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: 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: mustprogress nounwind uwtable
define dso_local void @atomic_set_mask_b16(ptr noundef %0, i64 noundef %1, i16 noundef zeroext %2) #1 {
  %4 = alloca ptr, align 8
  %5 = alloca i64, align 8
  %6 = alloca i16, align 2
  %7 = alloca i16, align 2
  %8 = alloca i16, align 2
  %9 = alloca i16, align 2
  %10 = alloca i8, align 1
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i64 %1, ptr %5, align 8, !tbaa !9
  store i16 %2, ptr %6, align 2, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 2, ptr %7) #2
  %11 = load i64, ptr %5, align 8, !tbaa !9
  %12 = trunc i64 %11 to i16
  store i16 %12, ptr %7, align 2, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 2, ptr %8) #2
  store i16 0, ptr %8, align 2, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 2, ptr %9) #2
  %13 = load ptr, ptr %4, align 8, !tbaa !5
  %14 = load i16, ptr %13, align 2, !tbaa !11
  store i16 %14, ptr %9, align 2, !tbaa !11
  br label %15

15:                                               ; preds = %39, %3
  %16 = load ptr, ptr %4, align 8, !tbaa !5
  %17 = load i16, ptr %16, align 2, !tbaa !11
  store i16 %17, ptr %9, align 2, !tbaa !11
  %18 = load i16, ptr %9, align 2, !tbaa !11
  %19 = zext i16 %18 to i32
  %20 = load i16, ptr %7, align 2, !tbaa !11
  %21 = zext i16 %20 to i32
  %22 = xor i32 %21, -1
  %23 = and i32 %19, %22
  %24 = sext i32 %23 to i64
  %25 = load i16, ptr %6, align 2, !tbaa !11
  %26 = zext i16 %25 to i64
  %27 = load i64, ptr %5, align 8, !tbaa !9
  %28 = and i64 %26, %27
  %29 = or i64 %24, %28
  %30 = trunc i64 %29 to i16
  store i16 %30, ptr %8, align 2, !tbaa !11
  br label %31

31:                                               ; preds = %15
  %32 = load ptr, ptr %4, align 8, !tbaa !5
  %33 = load i16, ptr %9, align 2
  %34 = load i16, ptr %8, align 2
  %35 = cmpxchg weak ptr %32, i16 %33, i16 %34 seq_cst seq_cst, align 2
  %36 = extractvalue { i16, i1 } %35, 0
  %37 = extractvalue { i16, i1 } %35, 1
  br i1 %37, label %39, label %38

38:                                               ; preds = %31
  store i16 %36, ptr %9, align 2
  br label %39

39:                                               ; preds = %38, %31
  %40 = zext i1 %37 to i8
  store i8 %40, ptr %10, align 1, !tbaa !13
  %41 = load i8, ptr %10, align 1, !tbaa !13, !range !15, !noundef !16
  %42 = trunc i8 %41 to i1
  %43 = xor i1 %42, true
  br i1 %43, label %15, label %44, !llvm.loop !17

44:                                               ; preds = %39
  call void @llvm.lifetime.end.p0(i64 2, ptr %9) #2
  call void @llvm.lifetime.end.p0(i64 2, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 2, ptr %7) #2
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 = { 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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"short", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"bool", !7, i64 0}
!15 = !{i8 0, i8 2}
!16 = !{}
!17 = distinct !{!17, !18}
!18 = !{!"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: mustprogress nofree norecurse nounwind memory(argmem: readwrite) uwtable
define dso_local void @atomic_set_mask_b16(ptr nocapture noundef %0, i64 noundef %1, i16 noundef zeroext %2) local_unnamed_addr #0 {
  %4 = xor i64 %1, -1
  %5 = zext i16 %2 to i64
  %6 = and i64 %5, %1
  br label %7

7:                                                ; preds = %7, %3
  %8 = load i16, ptr %0, align 2, !tbaa !5
  %9 = zext i16 %8 to i64
  %10 = and i64 %9, %4
  %11 = or disjoint i64 %10, %6
  %12 = trunc nuw i64 %11 to i16
  %13 = cmpxchg weak ptr %0, i16 %8, i16 %12 seq_cst seq_cst, align 2
  %14 = extractvalue { i16, i1 } %13, 1
  br i1 %14, label %15, label %7, !llvm.loop !9

15:                                               ; preds = %7
  ret void
}

attributes #0 = { mustprogress nofree norecurse nounwind memory(argmem: readwrite) 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" }

!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"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


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