; LLVM IR from GPUOpen-LibrariesAndSDKs/TAN :: tan/common/fifo.ll (ZN10FifoBuffer5storeEPcj)

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

%class.FifoBuffer = type <{ ptr, i32, i32, i32, [4 x i8] }>

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZN10FifoBuffer8roomLeftEv(ptr noundef nonnull align 8 dereferenceable(20)) #0 align 2

; 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: mustprogress nounwind uwtable
define dso_local noundef zeroext i1 @_ZN10FifoBuffer5storeEPcj(ptr noundef nonnull align 8 dereferenceable(20) %0, ptr noundef %1, i32 noundef %2) #0 align 2 {
  %4 = alloca i1, align 1
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store i32 %2, ptr %7, align 4, !tbaa !9
  %9 = load ptr, ptr %5, align 8
  %10 = load i32, ptr %7, align 4, !tbaa !9
  %11 = call noundef i32 @_ZN10FifoBuffer8roomLeftEv(ptr noundef nonnull align 8 dereferenceable(20) %9)
  %12 = icmp uge i32 %10, %11
  br i1 %12, label %13, label %14

13:                                               ; preds = %3
  store i1 false, ptr %4, align 1
  br label %55

14:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  %15 = getelementptr inbounds %class.FifoBuffer, ptr %9, i32 0, i32 1
  %16 = load i32, ptr %15, align 8, !tbaa !11
  %17 = getelementptr inbounds %class.FifoBuffer, ptr %9, i32 0, i32 3
  %18 = load i32, ptr %17, align 8, !tbaa !13
  %19 = sub i32 %16, %18
  store i32 %19, ptr %8, align 4, !tbaa !9
  %20 = load i32, ptr %7, align 4, !tbaa !9
  %21 = load i32, ptr %8, align 4, !tbaa !9
  %22 = icmp ugt i32 %20, %21
  br i1 %22, label %23, label %41

23:                                               ; preds = %14
  %24 = getelementptr inbounds %class.FifoBuffer, ptr %9, i32 0, i32 0
  %25 = load ptr, ptr %24, align 8, !tbaa !14
  %26 = getelementptr inbounds %class.FifoBuffer, ptr %9, i32 0, i32 3
  %27 = load i32, ptr %26, align 8, !tbaa !13
  %28 = zext i32 %27 to i64
  %29 = getelementptr inbounds i8, ptr %25, i64 %28
  %30 = load ptr, ptr %6, align 8, !tbaa !5
  %31 = load i32, ptr %8, align 4, !tbaa !9
  %32 = zext i32 %31 to i64
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %29, ptr align 1 %30, i64 %32, i1 false)
  %33 = load i32, ptr %8, align 4, !tbaa !9
  %34 = load ptr, ptr %6, align 8, !tbaa !5
  %35 = zext i32 %33 to i64
  %36 = getelementptr inbounds i8, ptr %34, i64 %35
  store ptr %36, ptr %6, align 8, !tbaa !5
  %37 = load i32, ptr %8, align 4, !tbaa !9
  %38 = load i32, ptr %7, align 4, !tbaa !9
  %39 = sub i32 %38, %37
  store i32 %39, ptr %7, align 4, !tbaa !9
  %40 = getelementptr inbounds %class.FifoBuffer, ptr %9, i32 0, i32 3
  store i32 0, ptr %40, align 8, !tbaa !13
  br label %41

41:                                               ; preds = %23, %14
  %42 = getelementptr inbounds %class.FifoBuffer, ptr %9, i32 0, i32 0
  %43 = load ptr, ptr %42, align 8, !tbaa !14
  %44 = getelementptr inbounds %class.FifoBuffer, ptr %9, i32 0, i32 3
  %45 = load i32, ptr %44, align 8, !tbaa !13
  %46 = zext i32 %45 to i64
  %47 = getelementptr inbounds i8, ptr %43, i64 %46
  %48 = load ptr, ptr %6, align 8, !tbaa !5
  %49 = load i32, ptr %7, align 4, !tbaa !9
  %50 = zext i32 %49 to i64
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %47, ptr align 1 %48, i64 %50, i1 false)
  %51 = load i32, ptr %7, align 4, !tbaa !9
  %52 = getelementptr inbounds %class.FifoBuffer, ptr %9, i32 0, i32 3
  %53 = load i32, ptr %52, align 8, !tbaa !13
  %54 = add i32 %53, %51
  store i32 %54, ptr %52, align 8, !tbaa !13
  store i1 true, ptr %4, align 1
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  br label %55

55:                                               ; preds = %41, %13
  %56 = load i1, ptr %4, align 1
  ret i1 %56
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #2

attributes #0 = { 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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 8}
!12 = !{!"_ZTS10FifoBuffer", !6, i64 0, !10, i64 8, !10, i64 12, !10, i64 16}
!13 = !{!12, !10, i64 16}
!14 = !{!12, !6, 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: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZN10FifoBuffer8roomLeftEv(ptr noundef nonnull align 8 dereferenceable(20)) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef zeroext i1 @_ZN10FifoBuffer5storeEPcj(ptr noundef nonnull align 8 dereferenceable(20) %0, ptr nocapture noundef readonly %1, i32 noundef %2) local_unnamed_addr #0 align 2 {
  %4 = tail call noundef i32 @_ZN10FifoBuffer8roomLeftEv(ptr noundef nonnull align 8 dereferenceable(20) %0)
  %.not = icmp ugt i32 %4, %2
  br i1 %.not, label %5, label %27

5:                                                ; preds = %3
  %6 = getelementptr inbounds i8, ptr %0, i64 8
  %7 = load i32, ptr %6, align 8, !tbaa !5
  %8 = getelementptr inbounds i8, ptr %0, i64 16
  %9 = load i32, ptr %8, align 8, !tbaa !11
  %10 = sub i32 %7, %9
  %11 = icmp ult i32 %10, %2
  br i1 %11, label %12, label %19

12:                                               ; preds = %5
  %13 = load ptr, ptr %0, align 8, !tbaa !12
  %14 = zext i32 %9 to i64
  %15 = getelementptr inbounds i8, ptr %13, i64 %14
  %16 = zext i32 %10 to i64
  tail call void @llvm.memcpy.p0.p0.i64(ptr align 1 %15, ptr align 1 %1, i64 %16, i1 false)
  %17 = getelementptr inbounds i8, ptr %1, i64 %16
  %18 = sub i32 %2, %10
  store i32 0, ptr %8, align 8, !tbaa !11
  br label %19

19:                                               ; preds = %12, %5
  %20 = phi i32 [ 0, %12 ], [ %9, %5 ]
  %.014 = phi ptr [ %17, %12 ], [ %1, %5 ]
  %.013 = phi i32 [ %18, %12 ], [ %2, %5 ]
  %21 = load ptr, ptr %0, align 8, !tbaa !12
  %22 = zext i32 %20 to i64
  %23 = getelementptr inbounds i8, ptr %21, i64 %22
  %24 = zext i32 %.013 to i64
  tail call void @llvm.memcpy.p0.p0.i64(ptr align 1 %23, ptr align 1 %.014, i64 %24, i1 false)
  %25 = load i32, ptr %8, align 8, !tbaa !11
  %26 = add i32 %25, %.013
  store i32 %26, ptr %8, align 8, !tbaa !11
  br label %27

27:                                               ; preds = %3, %19
  ret i1 %.not
}

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #1

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

!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, !10, i64 8}
!6 = !{!"_ZTS10FifoBuffer", !7, i64 0, !10, i64 8, !10, i64 12, !10, i64 16}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!6, !10, i64 16}
!12 = !{!6, !7, i64 0}


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