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

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

; 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) #0

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

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN6SoLoud10MemoryFile7openMemEPKhjbb(ptr noundef nonnull align 8 dereferenceable(25) %0, ptr noundef %1, i32 noundef %2, i1 noundef zeroext %3, i1 noundef zeroext %4) #2 align 2 {
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca i8, align 1
  %11 = alloca i8, align 1
  store ptr %0, ptr %7, align 8, !tbaa !5
  store ptr %1, ptr %8, align 8, !tbaa !5
  store i32 %2, ptr %9, align 4, !tbaa !9
  %12 = zext i1 %3 to i8
  store i8 %12, ptr %10, align 1, !tbaa !11
  %13 = zext i1 %4 to i8
  store i8 %13, ptr %11, align 1, !tbaa !11
  %14 = load ptr, ptr %7, align 8
  %15 = load ptr, ptr %8, align 8, !tbaa !5
  %16 = icmp eq ptr %15, null
  br i1 %16, label %20, label %17

17:                                               ; preds = %5
  %18 = load i32, ptr %9, align 4, !tbaa !9
  %19 = icmp eq i32 %18, 0
  br i1 %19, label %20, label %21

20:                                               ; preds = %17, %5
  store i32 1, ptr %6, align 4
  br label %61

21:                                               ; preds = %17
  %22 = getelementptr inbounds %"class.SoLoud::MemoryFile", ptr %14, i32 0, i32 4
  %23 = load i8, ptr %22, align 8, !tbaa !13, !range !16, !noundef !17
  %24 = trunc i8 %23 to i1
  br i1 %24, label %25, label %31

25:                                               ; preds = %21
  %26 = getelementptr inbounds %"class.SoLoud::MemoryFile", ptr %14, i32 0, i32 1
  %27 = load ptr, ptr %26, align 8, !tbaa !18
  %28 = icmp eq ptr %27, null
  br i1 %28, label %30, label %29

29:                                               ; preds = %25
  call void @_ZdaPv(ptr noundef %27) #4
  br label %30

30:                                               ; preds = %29, %25
  br label %31

31:                                               ; preds = %30, %21
  %32 = getelementptr inbounds %"class.SoLoud::MemoryFile", ptr %14, i32 0, i32 1
  store ptr null, ptr %32, align 8, !tbaa !18
  %33 = getelementptr inbounds %"class.SoLoud::MemoryFile", ptr %14, i32 0, i32 3
  store i32 0, ptr %33, align 4, !tbaa !19
  %34 = load i32, ptr %9, align 4, !tbaa !9
  %35 = getelementptr inbounds %"class.SoLoud::MemoryFile", ptr %14, i32 0, i32 2
  store i32 %34, ptr %35, align 8, !tbaa !20
  %36 = load i8, ptr %10, align 1, !tbaa !11, !range !16, !noundef !17
  %37 = trunc i8 %36 to i1
  br i1 %37, label %38, label %54

38:                                               ; preds = %31
  %39 = getelementptr inbounds %"class.SoLoud::MemoryFile", ptr %14, i32 0, i32 4
  store i8 1, ptr %39, align 8, !tbaa !13
  %40 = load i32, ptr %9, align 4, !tbaa !9
  %41 = zext i32 %40 to i64
  %42 = call noalias noundef nonnull ptr @_Znam(i64 noundef %41) #5
  %43 = getelementptr inbounds %"class.SoLoud::MemoryFile", ptr %14, i32 0, i32 1
  store ptr %42, ptr %43, align 8, !tbaa !18
  %44 = getelementptr inbounds %"class.SoLoud::MemoryFile", ptr %14, i32 0, i32 1
  %45 = load ptr, ptr %44, align 8, !tbaa !18
  %46 = icmp eq ptr %45, null
  br i1 %46, label %47, label %48

47:                                               ; preds = %38
  store i32 5, ptr %6, align 4
  br label %61

48:                                               ; preds = %38
  %49 = getelementptr inbounds %"class.SoLoud::MemoryFile", ptr %14, i32 0, i32 1
  %50 = load ptr, ptr %49, align 8, !tbaa !18
  %51 = load ptr, ptr %8, align 8, !tbaa !5
  %52 = load i32, ptr %9, align 4, !tbaa !9
  %53 = zext i32 %52 to i64
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %50, ptr align 1 %51, i64 %53, i1 false)
  store i32 0, ptr %6, align 4
  br label %61

54:                                               ; preds = %31
  %55 = load ptr, ptr %8, align 8, !tbaa !5
  %56 = getelementptr inbounds %"class.SoLoud::MemoryFile", ptr %14, i32 0, i32 1
  store ptr %55, ptr %56, align 8, !tbaa !18
  %57 = load i8, ptr %11, align 1, !tbaa !11, !range !16, !noundef !17
  %58 = trunc i8 %57 to i1
  %59 = getelementptr inbounds %"class.SoLoud::MemoryFile", ptr %14, i32 0, i32 4
  %60 = zext i1 %58 to i8
  store i8 %60, ptr %59, align 8, !tbaa !13
  store i32 0, ptr %6, align 4
  br label %61

61:                                               ; preds = %54, %48, %47, %20
  %62 = load i32, ptr %6, align 4
  ret i32 %62
}

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

attributes #0 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { 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 #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 = { 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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"bool", !7, i64 0}
!13 = !{!14, !12, i64 24}
!14 = !{!"_ZTSN6SoLoud10MemoryFileE", !15, i64 0, !6, i64 8, !10, i64 16, !10, i64 20, !12, i64 24}
!15 = !{!"_ZTSN6SoLoud4FileE"}
!16 = !{i8 0, i8 2}
!17 = !{}
!18 = !{!14, !6, i64 8}
!19 = !{!14, !10, i64 20}
!20 = !{!14, !10, 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"

; 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) #0

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

; Function Attrs: mustprogress uwtable
define dso_local noundef range(i32 0, 2) i32 @_ZN6SoLoud10MemoryFile7openMemEPKhjbb(ptr nocapture noundef nonnull align 8 dereferenceable(25) %0, ptr noundef %1, i32 noundef %2, i1 noundef zeroext %3, i1 noundef zeroext %4) local_unnamed_addr #2 align 2 {
  %6 = zext i1 %4 to i8
  %7 = icmp eq ptr %1, null
  %8 = icmp eq i32 %2, 0
  %or.cond = or i1 %7, %8
  br i1 %or.cond, label %26, label %9

9:                                                ; preds = %5
  %10 = getelementptr inbounds i8, ptr %0, i64 24
  %11 = load i8, ptr %10, align 8, !tbaa !5, !range !13, !noundef !14
  %12 = trunc nuw i8 %11 to i1
  br i1 %12, label %13, label %18

13:                                               ; preds = %9
  %14 = getelementptr inbounds i8, ptr %0, i64 8
  %15 = load ptr, ptr %14, align 8, !tbaa !15
  %16 = icmp eq ptr %15, null
  br i1 %16, label %18, label %17

17:                                               ; preds = %13
  tail call void @_ZdaPv(ptr noundef nonnull %15) #4
  br label %18

18:                                               ; preds = %13, %17, %9
  %19 = getelementptr inbounds i8, ptr %0, i64 8
  store ptr null, ptr %19, align 8, !tbaa !15
  %20 = getelementptr inbounds i8, ptr %0, i64 20
  store i32 0, ptr %20, align 4, !tbaa !16
  %21 = getelementptr inbounds i8, ptr %0, i64 16
  store i32 %2, ptr %21, align 8, !tbaa !17
  br i1 %3, label %22, label %25

22:                                               ; preds = %18
  store i8 1, ptr %10, align 8, !tbaa !5
  %23 = zext i32 %2 to i64
  %24 = tail call noalias noundef nonnull ptr @_Znam(i64 noundef %23) #5
  store ptr %24, ptr %19, align 8, !tbaa !15
  tail call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 1 %24, ptr nonnull align 1 %1, i64 %23, i1 false)
  br label %26

25:                                               ; preds = %18
  store ptr %1, ptr %19, align 8, !tbaa !15
  store i8 %6, ptr %10, align 8, !tbaa !5
  br label %26

26:                                               ; preds = %5, %25, %22
  %.0 = phi i32 [ 0, %22 ], [ 0, %25 ], [ 1, %5 ]
  ret i32 %.0
}

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

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