; LLVM IR from GPUOpen-LibrariesAndSDKs/TAN :: amf/public/common (DataStreamMemory)

; 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.amf::AMFDataStreamMemoryImpl" = type { %"class.amf::AMFInterfaceImpl", ptr, i64, i64, i64 }
%"class.amf::AMFInterfaceImpl" = type { %"class.amf::AMFDataStream", %"class.amf::AMFInterfaceBase" }
%"class.amf::AMFDataStream" = type { %"class.amf::AMFInterface" }
%"class.amf::AMFInterface" = type { ptr }
%"class.amf::AMFInterfaceBase" = type { ptr, i64 }

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i32 @_ZN3amf23AMFDataStreamMemoryImpl4SeekENS_15AMF_SEEK_ORIGINElPl(ptr noundef nonnull align 8 dereferenceable(56) %0, i32 noundef %1, i64 noundef %2, ptr noundef %3) unnamed_addr #0 align 2 {
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i64, align 8
  %8 = alloca ptr, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !9
  store i64 %2, ptr %7, align 8, !tbaa !11
  store ptr %3, ptr %8, align 8, !tbaa !5
  %9 = load ptr, ptr %5, align 8
  %10 = load i32, ptr %6, align 4, !tbaa !9
  switch i32 %10, label %25 [
    i32 0, label %11
    i32 1, label %14
    i32 2, label %19
  ]

11:                                               ; preds = %4
  %12 = load i64, ptr %7, align 8, !tbaa !11
  %13 = getelementptr inbounds %"class.amf::AMFDataStreamMemoryImpl", ptr %9, i32 0, i32 4
  store i64 %12, ptr %13, align 8, !tbaa !13
  br label %25

14:                                               ; preds = %4
  %15 = load i64, ptr %7, align 8, !tbaa !11
  %16 = getelementptr inbounds %"class.amf::AMFDataStreamMemoryImpl", ptr %9, i32 0, i32 4
  %17 = load i64, ptr %16, align 8, !tbaa !13
  %18 = add i64 %17, %15
  store i64 %18, ptr %16, align 8, !tbaa !13
  br label %25

19:                                               ; preds = %4
  %20 = getelementptr inbounds %"class.amf::AMFDataStreamMemoryImpl", ptr %9, i32 0, i32 2
  %21 = load i64, ptr %20, align 8, !tbaa !19
  %22 = load i64, ptr %7, align 8, !tbaa !11
  %23 = sub i64 %21, %22
  %24 = getelementptr inbounds %"class.amf::AMFDataStreamMemoryImpl", ptr %9, i32 0, i32 4
  store i64 %23, ptr %24, align 8, !tbaa !13
  br label %25

25:                                               ; preds = %19, %14, %11, %4
  %26 = getelementptr inbounds %"class.amf::AMFDataStreamMemoryImpl", ptr %9, i32 0, i32 4
  %27 = load i64, ptr %26, align 8, !tbaa !13
  %28 = getelementptr inbounds %"class.amf::AMFDataStreamMemoryImpl", ptr %9, i32 0, i32 2
  %29 = load i64, ptr %28, align 8, !tbaa !19
  %30 = icmp ugt i64 %27, %29
  br i1 %30, label %31, label %35

31:                                               ; preds = %25
  %32 = getelementptr inbounds %"class.amf::AMFDataStreamMemoryImpl", ptr %9, i32 0, i32 2
  %33 = load i64, ptr %32, align 8, !tbaa !19
  %34 = getelementptr inbounds %"class.amf::AMFDataStreamMemoryImpl", ptr %9, i32 0, i32 4
  store i64 %33, ptr %34, align 8, !tbaa !13
  br label %35

35:                                               ; preds = %31, %25
  %36 = load ptr, ptr %8, align 8, !tbaa !5
  %37 = icmp ne ptr %36, null
  br i1 %37, label %38, label %42

38:                                               ; preds = %35
  %39 = getelementptr inbounds %"class.amf::AMFDataStreamMemoryImpl", ptr %9, i32 0, i32 4
  %40 = load i64, ptr %39, align 8, !tbaa !13
  %41 = load ptr, ptr %8, align 8, !tbaa !5
  store i64 %40, ptr %41, align 8, !tbaa !11
  br label %42

42:                                               ; preds = %38, %35
  ret i32 0
}

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

!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 = !{!"_ZTSN3amf15AMF_SEEK_ORIGINE", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!14, !12, i64 48}
!14 = !{!"_ZTSN3amf23AMFDataStreamMemoryImplE", !15, i64 0, !6, i64 24, !12, i64 32, !12, i64 40, !12, i64 48}
!15 = !{!"_ZTSN3amf16AMFInterfaceImplINS_13AMFDataStreamEiiiEE", !16, i64 0, !18, i64 8}
!16 = !{!"_ZTSN3amf13AMFDataStreamE", !17, i64 0}
!17 = !{!"_ZTSN3amf12AMFInterfaceE"}
!18 = !{!"_ZTSN3amf16AMFInterfaceBaseE", !12, i64 8}
!19 = !{!14, !12, i64 32}


; 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 nosync nounwind willreturn memory(argmem: readwrite) uwtable
define dso_local noundef i32 @_ZN3amf23AMFDataStreamMemoryImpl4SeekENS_15AMF_SEEK_ORIGINElPl(ptr nocapture noundef nonnull align 8 dereferenceable(56) %0, i32 noundef %1, i64 noundef %2, ptr noundef writeonly %3) unnamed_addr #0 align 2 {
  switch i32 %1, label %._crit_edge [
    i32 0, label %5
    i32 1, label %7
    i32 2, label %11
  ]

._crit_edge:                                      ; preds = %4
  %.phi.trans.insert = getelementptr inbounds i8, ptr %0, i64 48
  %.pre = load i64, ptr %.phi.trans.insert, align 8, !tbaa !5
  br label %16

5:                                                ; preds = %4
  %6 = getelementptr inbounds i8, ptr %0, i64 48
  store i64 %2, ptr %6, align 8, !tbaa !5
  br label %16

7:                                                ; preds = %4
  %8 = getelementptr inbounds i8, ptr %0, i64 48
  %9 = load i64, ptr %8, align 8, !tbaa !5
  %10 = add i64 %9, %2
  store i64 %10, ptr %8, align 8, !tbaa !5
  br label %16

11:                                               ; preds = %4
  %12 = getelementptr inbounds i8, ptr %0, i64 32
  %13 = load i64, ptr %12, align 8, !tbaa !15
  %14 = sub i64 %13, %2
  %15 = getelementptr inbounds i8, ptr %0, i64 48
  store i64 %14, ptr %15, align 8, !tbaa !5
  br label %16

16:                                               ; preds = %._crit_edge, %11, %7, %5
  %17 = phi i64 [ %.pre, %._crit_edge ], [ %14, %11 ], [ %10, %7 ], [ %2, %5 ]
  %18 = getelementptr inbounds i8, ptr %0, i64 32
  %19 = load i64, ptr %18, align 8, !tbaa !15
  %20 = icmp ugt i64 %17, %19
  br i1 %20, label %21, label %23

21:                                               ; preds = %16
  %22 = getelementptr inbounds i8, ptr %0, i64 48
  store i64 %19, ptr %22, align 8, !tbaa !5
  br label %23

23:                                               ; preds = %21, %16
  %24 = phi i64 [ %19, %21 ], [ %17, %16 ]
  %.not = icmp eq ptr %3, null
  br i1 %.not, label %26, label %25

25:                                               ; preds = %23
  store i64 %24, ptr %3, align 8, !tbaa !16
  br label %26

26:                                               ; preds = %25, %23
  ret i32 0
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn 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, !11, i64 48}
!6 = !{!"_ZTSN3amf23AMFDataStreamMemoryImplE", !7, i64 0, !14, i64 24, !11, i64 32, !11, i64 40, !11, i64 48}
!7 = !{!"_ZTSN3amf16AMFInterfaceImplINS_13AMFDataStreamEiiiEE", !8, i64 0, !10, i64 8}
!8 = !{!"_ZTSN3amf13AMFDataStreamE", !9, i64 0}
!9 = !{!"_ZTSN3amf12AMFInterfaceE"}
!10 = !{!"_ZTSN3amf16AMFInterfaceBaseE", !11, i64 8}
!11 = !{!"long", !12, i64 0}
!12 = !{!"omnipotent char", !13, i64 0}
!13 = !{!"Simple C++ TBAA"}
!14 = !{!"any pointer", !12, i64 0}
!15 = !{!6, !11, i64 32}
!16 = !{!11, !11, i64 0}


; Effective O3 passes: EarlyCSEPass,GVNPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass