; LLVM IR from aap/librw :: src/base.ll (ZN2rw12StreamMemory4seekEii)

; 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.rw::StreamMemory" = type <{ %"class.rw::Stream", ptr, i32, i32, i32, [4 x i8] }>
%"class.rw::Stream" = type { ptr }

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN2rw12StreamMemory4seekEii(ptr noundef nonnull align 8 dereferenceable(28) %0, i32 noundef %1, i32 noundef %2) unnamed_addr #0 align 2 {
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  store i32 %2, ptr %6, align 4, !tbaa !9
  %7 = load ptr, ptr %4, align 8
  %8 = load i32, ptr %6, align 4, !tbaa !9
  %9 = icmp eq i32 %8, 0
  br i1 %9, label %10, label %13

10:                                               ; preds = %3
  %11 = load i32, ptr %5, align 4, !tbaa !9
  %12 = getelementptr inbounds %"class.rw::StreamMemory", ptr %7, i32 0, i32 4
  store i32 %11, ptr %12, align 8, !tbaa !11
  br label %28

13:                                               ; preds = %3
  %14 = load i32, ptr %6, align 4, !tbaa !9
  %15 = icmp eq i32 %14, 1
  br i1 %15, label %16, label %21

16:                                               ; preds = %13
  %17 = load i32, ptr %5, align 4, !tbaa !9
  %18 = getelementptr inbounds %"class.rw::StreamMemory", ptr %7, i32 0, i32 4
  %19 = load i32, ptr %18, align 8, !tbaa !11
  %20 = add i32 %19, %17
  store i32 %20, ptr %18, align 8, !tbaa !11
  br label %27

21:                                               ; preds = %13
  %22 = getelementptr inbounds %"class.rw::StreamMemory", ptr %7, i32 0, i32 2
  %23 = load i32, ptr %22, align 8, !tbaa !14
  %24 = load i32, ptr %5, align 4, !tbaa !9
  %25 = sub i32 %23, %24
  %26 = getelementptr inbounds %"class.rw::StreamMemory", ptr %7, i32 0, i32 4
  store i32 %25, ptr %26, align 8, !tbaa !11
  br label %27

27:                                               ; preds = %21, %16
  br label %28

28:                                               ; preds = %27, %10
  %29 = getelementptr inbounds %"class.rw::StreamMemory", ptr %7, i32 0, i32 4
  %30 = load i32, ptr %29, align 8, !tbaa !11
  %31 = getelementptr inbounds %"class.rw::StreamMemory", ptr %7, i32 0, i32 2
  %32 = load i32, ptr %31, align 8, !tbaa !14
  %33 = icmp ugt i32 %30, %32
  br i1 %33, label %34, label %47

34:                                               ; preds = %28
  %35 = getelementptr inbounds %"class.rw::StreamMemory", ptr %7, i32 0, i32 4
  %36 = load i32, ptr %35, align 8, !tbaa !11
  %37 = getelementptr inbounds %"class.rw::StreamMemory", ptr %7, i32 0, i32 3
  %38 = load i32, ptr %37, align 4, !tbaa !15
  %39 = icmp ugt i32 %36, %38
  br i1 %39, label %40, label %42

40:                                               ; preds = %34
  %41 = getelementptr inbounds %"class.rw::StreamMemory", ptr %7, i32 0, i32 4
  store i32 -1, ptr %41, align 8, !tbaa !11
  br label %46

42:                                               ; preds = %34
  %43 = getelementptr inbounds %"class.rw::StreamMemory", ptr %7, i32 0, i32 4
  %44 = load i32, ptr %43, align 8, !tbaa !11
  %45 = getelementptr inbounds %"class.rw::StreamMemory", ptr %7, i32 0, i32 2
  store i32 %44, ptr %45, align 8, !tbaa !14
  br label %46

46:                                               ; preds = %42, %40
  br label %47

47:                                               ; preds = %46, %28
  ret void
}

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 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 24}
!12 = !{!"_ZTSN2rw12StreamMemoryE", !13, i64 0, !6, i64 8, !10, i64 16, !10, i64 20, !10, i64 24}
!13 = !{!"_ZTSN2rw6StreamE"}
!14 = !{!12, !10, i64 16}
!15 = !{!12, !10, i64 20}


; 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 void @_ZN2rw12StreamMemory4seekEii(ptr nocapture noundef nonnull align 8 dereferenceable(28) %0, i32 noundef %1, i32 noundef %2) unnamed_addr #0 align 2 {
  switch i32 %2, label %10 [
    i32 0, label %4
    i32 1, label %6
  ]

4:                                                ; preds = %3
  %5 = getelementptr inbounds i8, ptr %0, i64 24
  store i32 %1, ptr %5, align 8, !tbaa !5
  br label %15

6:                                                ; preds = %3
  %7 = getelementptr inbounds i8, ptr %0, i64 24
  %8 = load i32, ptr %7, align 8, !tbaa !5
  %9 = add i32 %8, %1
  store i32 %9, ptr %7, align 8, !tbaa !5
  br label %15

10:                                               ; preds = %3
  %11 = getelementptr inbounds i8, ptr %0, i64 16
  %12 = load i32, ptr %11, align 8, !tbaa !12
  %13 = sub i32 %12, %1
  %14 = getelementptr inbounds i8, ptr %0, i64 24
  store i32 %13, ptr %14, align 8, !tbaa !5
  br label %15

15:                                               ; preds = %6, %10, %4
  %16 = phi i32 [ %9, %6 ], [ %13, %10 ], [ %1, %4 ]
  %17 = getelementptr inbounds i8, ptr %0, i64 24
  %18 = getelementptr inbounds i8, ptr %0, i64 16
  %19 = load i32, ptr %18, align 8, !tbaa !12
  %20 = icmp ugt i32 %16, %19
  br i1 %20, label %21, label %27

21:                                               ; preds = %15
  %22 = getelementptr inbounds i8, ptr %0, i64 20
  %23 = load i32, ptr %22, align 4, !tbaa !13
  %24 = icmp ugt i32 %16, %23
  br i1 %24, label %25, label %26

25:                                               ; preds = %21
  store i32 -1, ptr %17, align 8, !tbaa !5
  br label %27

26:                                               ; preds = %21
  store i32 %16, ptr %18, align 8, !tbaa !12
  br label %27

27:                                               ; preds = %25, %26, %15
  ret void
}

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


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