; LLVM IR from Overload-Technologies/Overload :: Dependencies/soloud/src/core/soloud_file.ll (ZN6SoLoud10MemoryFile9openToMemEPKc)

; 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.SoLoud::DiskFile" = type { %"class.SoLoud::File", ptr }
%"class.SoLoud::File" = type { ptr }
%"class.SoLoud::MemoryFile" = type <{ %"class.SoLoud::File", ptr, i32, i32, i8, [7 x i8] }>

; 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 uwtable
declare dso_local noundef i32 @_ZN6SoLoud8DiskFile4readEPhj(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef, i32 noundef) unnamed_addr #1 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_ZN6SoLoud8DiskFile6lengthEv(ptr noundef nonnull align 8 dereferenceable(16)) unnamed_addr #1 align 2

declare i32 @__gxx_personality_v0(...)

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_ZN6SoLoud8DiskFile4openEPKc(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef) #1 align 2

; Function Attrs: nobuiltin nounwind
declare void @_ZdaPv(ptr noundef) #2

; Function Attrs: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znam(i64 noundef) #3

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN6SoLoud10MemoryFile9openToMemEPKc(ptr noundef nonnull align 8 dereferenceable(25) %0, ptr noundef %1) #1 align 2 personality ptr @__gxx_personality_v0 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca %"class.SoLoud::DiskFile", align 8
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  %11 = load ptr, ptr %4, align 8
  %12 = load ptr, ptr %5, align 8, !tbaa !5
  %13 = icmp ne ptr %12, null
  br i1 %13, label %15, label %14

14:                                               ; preds = %2
  store i32 1, ptr %3, align 4
  br label %62

15:                                               ; preds = %2
  %16 = getelementptr inbounds %"class.SoLoud::MemoryFile", ptr %11, i32 0, i32 4
  %17 = load i8, ptr %16, align 8, !tbaa !9, !range !14, !noundef !15
  %18 = trunc i8 %17 to i1
  br i1 %18, label %19, label %25

19:                                               ; preds = %15
  %20 = getelementptr inbounds %"class.SoLoud::MemoryFile", ptr %11, i32 0, i32 1
  %21 = load ptr, ptr %20, align 8, !tbaa !16
  %22 = icmp eq ptr %21, null
  br i1 %22, label %24, label %23

23:                                               ; preds = %19
  call void @_ZdaPv(ptr noundef %21) #4
  br label %24

24:                                               ; preds = %23, %19
  br label %25

25:                                               ; preds = %24, %15
  %26 = getelementptr inbounds %"class.SoLoud::MemoryFile", ptr %11, i32 0, i32 1
  store ptr null, ptr %26, align 8, !tbaa !16
  %27 = getelementptr inbounds %"class.SoLoud::MemoryFile", ptr %11, i32 0, i32 3
  store i32 0, ptr %27, align 4, !tbaa !17
  call void @llvm.lifetime.start.p0(i64 16, ptr %6) #5
  call void @_ZN6SoLoud8DiskFileC1Ev(ptr noundef nonnull align 8 dereferenceable(16) %6)
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #5
  %28 = load ptr, ptr %5, align 8, !tbaa !5
  %29 = invoke noundef i32 @_ZN6SoLoud8DiskFile4openEPKc(ptr noundef nonnull align 8 dereferenceable(16) %6, ptr noundef %28)
          to label %30 unwind label %35

30:                                               ; preds = %25
  store i32 %29, ptr %7, align 4, !tbaa !18
  %31 = load i32, ptr %7, align 4, !tbaa !18
  %32 = icmp ne i32 %31, 0
  br i1 %32, label %33, label %39

33:                                               ; preds = %30
  %34 = load i32, ptr %7, align 4, !tbaa !18
  store i32 %34, ptr %3, align 4
  store i32 1, ptr %10, align 4
  br label %61

35:                                               ; preds = %53, %41, %39, %25
  %36 = landingpad { ptr, i32 }
          cleanup
  %37 = extractvalue { ptr, i32 } %36, 0
  store ptr %37, ptr %8, align 8
  %38 = extractvalue { ptr, i32 } %36, 1
  store i32 %38, ptr %9, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #5
  call void @_ZN6SoLoud8DiskFileD1Ev(ptr noundef nonnull align 8 dereferenceable(16) %6) #5
  call void @llvm.lifetime.end.p0(i64 16, ptr %6) #5
  br label %64

39:                                               ; preds = %30
  %40 = invoke noundef i32 @_ZN6SoLoud8DiskFile6lengthEv(ptr noundef nonnull align 8 dereferenceable(16) %6)
          to label %41 unwind label %35

41:                                               ; preds = %39
  %42 = getelementptr inbounds %"class.SoLoud::MemoryFile", ptr %11, i32 0, i32 2
  store i32 %40, ptr %42, align 8, !tbaa !19
  %43 = getelementptr inbounds %"class.SoLoud::MemoryFile", ptr %11, i32 0, i32 2
  %44 = load i32, ptr %43, align 8, !tbaa !19
  %45 = zext i32 %44 to i64
  %46 = invoke noalias noundef nonnull ptr @_Znam(i64 noundef %45) #6
          to label %47 unwind label %35

47:                                               ; preds = %41
  %48 = getelementptr inbounds %"class.SoLoud::MemoryFile", ptr %11, i32 0, i32 1
  store ptr %46, ptr %48, align 8, !tbaa !16
  %49 = getelementptr inbounds %"class.SoLoud::MemoryFile", ptr %11, i32 0, i32 1
  %50 = load ptr, ptr %49, align 8, !tbaa !16
  %51 = icmp eq ptr %50, null
  br i1 %51, label %52, label %53

52:                                               ; preds = %47
  store i32 5, ptr %3, align 4
  store i32 1, ptr %10, align 4
  br label %61

53:                                               ; preds = %47
  %54 = getelementptr inbounds %"class.SoLoud::MemoryFile", ptr %11, i32 0, i32 1
  %55 = load ptr, ptr %54, align 8, !tbaa !16
  %56 = getelementptr inbounds %"class.SoLoud::MemoryFile", ptr %11, i32 0, i32 2
  %57 = load i32, ptr %56, align 8, !tbaa !19
  %58 = invoke noundef i32 @_ZN6SoLoud8DiskFile4readEPhj(ptr noundef nonnull align 8 dereferenceable(16) %6, ptr noundef %55, i32 noundef %57)
          to label %59 unwind label %35

59:                                               ; preds = %53
  %60 = getelementptr inbounds %"class.SoLoud::MemoryFile", ptr %11, i32 0, i32 4
  store i8 1, ptr %60, align 8, !tbaa !9
  store i32 0, ptr %3, align 4
  store i32 1, ptr %10, align 4
  br label %61

61:                                               ; preds = %59, %52, %33
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #5
  call void @_ZN6SoLoud8DiskFileD1Ev(ptr noundef nonnull align 8 dereferenceable(16) %6) #5
  call void @llvm.lifetime.end.p0(i64 16, ptr %6) #5
  br label %62

62:                                               ; preds = %61, %14
  %63 = load i32, ptr %3, align 4
  ret i32 %63

64:                                               ; preds = %35
  %65 = load ptr, ptr %8, align 8
  %66 = load i32, ptr %9, align 4
  %67 = insertvalue { ptr, i32 } poison, ptr %65, 0
  %68 = insertvalue { ptr, i32 } %67, i32 %66, 1
  resume { ptr, i32 } %68
}

declare void @_ZN6SoLoud8DiskFileD1Ev(ptr)

declare void @_ZN6SoLoud8DiskFileC1Ev(ptr)

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

!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, !13, i64 24}
!10 = !{!"_ZTSN6SoLoud10MemoryFileE", !11, i64 0, !6, i64 8, !12, i64 16, !12, i64 20, !13, i64 24}
!11 = !{!"_ZTSN6SoLoud4FileE"}
!12 = !{!"int", !7, i64 0}
!13 = !{!"bool", !7, i64 0}
!14 = !{i8 0, i8 2}
!15 = !{}
!16 = !{!10, !6, i64 8}
!17 = !{!10, !12, i64 20}
!18 = !{!12, !12, i64 0}
!19 = !{!10, !12, i64 16}


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

%"class.SoLoud::DiskFile" = type { %"class.SoLoud::File", ptr }
%"class.SoLoud::File" = type { ptr }

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_ZN6SoLoud8DiskFile4readEPhj(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef, i32 noundef) unnamed_addr #1 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_ZN6SoLoud8DiskFile6lengthEv(ptr noundef nonnull align 8 dereferenceable(16)) unnamed_addr #1 align 2

declare i32 @__gxx_personality_v0(...)

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_ZN6SoLoud8DiskFile4openEPKc(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef) local_unnamed_addr #1 align 2

; Function Attrs: nobuiltin nounwind
declare void @_ZdaPv(ptr noundef) local_unnamed_addr #2

; Function Attrs: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znam(i64 noundef) local_unnamed_addr #3

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN6SoLoud10MemoryFile9openToMemEPKc(ptr nocapture noundef nonnull align 8 dereferenceable(25) %0, ptr noundef %1) local_unnamed_addr #1 align 2 personality ptr @__gxx_personality_v0 {
  %3 = alloca %"class.SoLoud::DiskFile", align 8
  %.not = icmp eq ptr %1, null
  br i1 %.not, label %30, label %4

4:                                                ; preds = %2
  %5 = getelementptr inbounds i8, ptr %0, i64 24
  %6 = load i8, ptr %5, align 8, !tbaa !5, !range !13, !noundef !14
  %7 = trunc nuw i8 %6 to i1
  br i1 %7, label %8, label %13

8:                                                ; preds = %4
  %9 = getelementptr inbounds i8, ptr %0, i64 8
  %10 = load ptr, ptr %9, align 8, !tbaa !15
  %11 = icmp eq ptr %10, null
  br i1 %11, label %13, label %12

12:                                               ; preds = %8
  tail call void @_ZdaPv(ptr noundef nonnull %10) #4
  br label %13

13:                                               ; preds = %8, %12, %4
  %14 = getelementptr inbounds i8, ptr %0, i64 8
  store ptr null, ptr %14, align 8, !tbaa !15
  %15 = getelementptr inbounds i8, ptr %0, i64 20
  store i32 0, ptr %15, align 4, !tbaa !16
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %3) #5
  call void @_ZN6SoLoud8DiskFileC1Ev(ptr noundef nonnull align 8 dereferenceable(16) %3)
  %16 = invoke noundef i32 @_ZN6SoLoud8DiskFile4openEPKc(ptr noundef nonnull align 8 dereferenceable(16) %3, ptr noundef nonnull %1)
          to label %17 unwind label %18

17:                                               ; preds = %13
  %.not10 = icmp eq i32 %16, 0
  br i1 %.not10, label %20, label %29

18:                                               ; preds = %26, %22, %20, %13
  %19 = landingpad { ptr, i32 }
          cleanup
  call void @_ZN6SoLoud8DiskFileD1Ev(ptr noundef nonnull align 8 dereferenceable(16) %3) #5
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %3) #5
  resume { ptr, i32 } %19

20:                                               ; preds = %17
  %21 = invoke noundef i32 @_ZN6SoLoud8DiskFile6lengthEv(ptr noundef nonnull align 8 dereferenceable(16) %3)
          to label %22 unwind label %18

22:                                               ; preds = %20
  %23 = getelementptr inbounds i8, ptr %0, i64 16
  store i32 %21, ptr %23, align 8, !tbaa !17
  %24 = zext i32 %21 to i64
  %25 = invoke noalias noundef nonnull ptr @_Znam(i64 noundef %24) #6
          to label %26 unwind label %18

26:                                               ; preds = %22
  store ptr %25, ptr %14, align 8, !tbaa !15
  %27 = invoke noundef i32 @_ZN6SoLoud8DiskFile4readEPhj(ptr noundef nonnull align 8 dereferenceable(16) %3, ptr noundef nonnull %25, i32 noundef %21)
          to label %28 unwind label %18

28:                                               ; preds = %26
  store i8 1, ptr %5, align 8, !tbaa !5
  br label %29

29:                                               ; preds = %17, %28
  call void @_ZN6SoLoud8DiskFileD1Ev(ptr noundef nonnull align 8 dereferenceable(16) %3) #5
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %3) #5
  br label %30

30:                                               ; preds = %2, %29
  %.1 = phi i32 [ %16, %29 ], [ 1, %2 ]
  ret i32 %.1
}

declare void @_ZN6SoLoud8DiskFileD1Ev(ptr) local_unnamed_addr

declare void @_ZN6SoLoud8DiskFileC1Ev(ptr) local_unnamed_addr

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

!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, !12, i64 24}
!6 = !{!"_ZTSN6SoLoud10MemoryFileE", !7, i64 0, !8, i64 8, !11, i64 16, !11, i64 20, !12, i64 24}
!7 = !{!"_ZTSN6SoLoud4FileE"}
!8 = !{!"any pointer", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C++ TBAA"}
!11 = !{!"int", !9, i64 0}
!12 = !{!"bool", !9, i64 0}
!13 = !{i8 0, i8 2}
!14 = !{}
!15 = !{!6, !8, i64 8}
!16 = !{!6, !11, i64 20}
!17 = !{!6, !11, i64 16}


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