; LLVM IR from Razakhel/RaZ :: extern/fastgltf/src/io.ll/ZN8fastgltf14MappedGltfFileC2ERKNSt10filesystem7 (cxx114pathE)

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

%struct.stat = type { i64, i64, i64, i32, i32, i32, i32, i64, i64, i64, i64, %struct.timespec, %struct.timespec, %struct.timespec, [3 x i64] }
%struct.timespec = type { i64, i64 }
%"class.fastgltf::MappedGltfFile" = type { %"class.fastgltf::GltfDataGetter", ptr, i64, i64, i64 }
%"class.fastgltf::GltfDataGetter" = type { ptr }

@_ZTVN8fastgltf14MappedGltfFileE = external dso_local unnamed_addr constant { [9 x ptr] }, align 8

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZN8fastgltf14GltfDataGetterC2Ev(ptr noundef nonnull align 8 dereferenceable(8)) unnamed_addr #0 align 2

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

declare i32 @__gxx_personality_v0(...)

; Function Attrs: noinline noreturn nounwind uwtable
declare hidden void @__clang_call_terminate(ptr noundef) #2

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #3

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN8fastgltf14MappedGltfFileC2ERKNSt10filesystem7__cxx114pathE(ptr noundef nonnull align 8 dereferenceable(40) %0, ptr noundef nonnull align 8 dereferenceable(40) %1) unnamed_addr #4 align 2 personality ptr @__gxx_personality_v0 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca %struct.stat, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  %8 = load ptr, ptr %3, align 8
  call void @_ZN8fastgltf14GltfDataGetterC2Ev(ptr noundef nonnull align 8 dereferenceable(8) %8) #7
  store ptr getelementptr inbounds inrange(-16, 56) ({ [9 x ptr] }, ptr @_ZTVN8fastgltf14MappedGltfFileE, i32 0, i32 0, i32 2), ptr %8, align 8, !tbaa !9
  %9 = getelementptr inbounds %"class.fastgltf::MappedGltfFile", ptr %8, i32 0, i32 1
  store ptr inttoptr (i64 -1 to ptr), ptr %9, align 8, !tbaa !11
  %10 = getelementptr inbounds %"class.fastgltf::MappedGltfFile", ptr %8, i32 0, i32 2
  store i64 0, ptr %10, align 8, !tbaa !16
  %11 = getelementptr inbounds %"class.fastgltf::MappedGltfFile", ptr %8, i32 0, i32 3
  store i64 0, ptr %11, align 8, !tbaa !17
  %12 = getelementptr inbounds %"class.fastgltf::MappedGltfFile", ptr %8, i32 0, i32 4
  store i64 0, ptr %12, align 8, !tbaa !18
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #7
  %13 = load ptr, ptr %4, align 8, !tbaa !5
  %14 = call noundef ptr @_ZNKSt10filesystem7__cxx114path5c_strEv(ptr noundef nonnull align 8 dereferenceable(40) %13) #7
  %15 = invoke i32 (ptr, i32, ...) @open(ptr noundef %14, i32 noundef 0, i32 noundef 0)
          to label %16 unwind label %55

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

19:                                               ; preds = %16
  %20 = getelementptr inbounds %"class.fastgltf::MappedGltfFile", ptr %8, i32 0, i32 4
  store i64 1, ptr %20, align 8, !tbaa !18
  store i32 1, ptr %6, align 4
  br label %52

21:                                               ; preds = %16
  call void @llvm.lifetime.start.p0(i64 144, ptr %7) #7
  call void @llvm.memset.p0.i64(ptr align 8 %7, i8 0, i64 144, i1 false)
  %22 = load i32, ptr %5, align 4, !tbaa !19
  %23 = call i32 @fstat(i32 noundef %22, ptr noundef %7) #7
  %24 = icmp ne i32 %23, 0
  br i1 %24, label %25, label %27

25:                                               ; preds = %21
  %26 = getelementptr inbounds %"class.fastgltf::MappedGltfFile", ptr %8, i32 0, i32 4
  store i64 1, ptr %26, align 8, !tbaa !18
  store i32 1, ptr %6, align 4
  br label %51

27:                                               ; preds = %21
  %28 = getelementptr inbounds %struct.stat, ptr %7, i32 0, i32 8
  %29 = load i64, ptr %28, align 8, !tbaa !21
  %30 = load i32, ptr %5, align 4, !tbaa !19
  %31 = call ptr @mmap(ptr noundef null, i64 noundef %29, i32 noundef 1, i32 noundef 2, i32 noundef %30, i64 noundef 0) #7
  %32 = getelementptr inbounds %"class.fastgltf::MappedGltfFile", ptr %8, i32 0, i32 1
  store ptr %31, ptr %32, align 8, !tbaa !11
  %33 = getelementptr inbounds %"class.fastgltf::MappedGltfFile", ptr %8, i32 0, i32 1
  %34 = load ptr, ptr %33, align 8, !tbaa !11
  %35 = icmp ne ptr %34, inttoptr (i64 -1 to ptr)
  br i1 %35, label %36, label %45

36:                                               ; preds = %27
  %37 = getelementptr inbounds %struct.stat, ptr %7, i32 0, i32 8
  %38 = load i64, ptr %37, align 8, !tbaa !21
  %39 = getelementptr inbounds %"class.fastgltf::MappedGltfFile", ptr %8, i32 0, i32 2
  store i64 %38, ptr %39, align 8, !tbaa !16
  %40 = getelementptr inbounds %"class.fastgltf::MappedGltfFile", ptr %8, i32 0, i32 1
  %41 = load ptr, ptr %40, align 8, !tbaa !11
  %42 = getelementptr inbounds %"class.fastgltf::MappedGltfFile", ptr %8, i32 0, i32 2
  %43 = load i64, ptr %42, align 8, !tbaa !16
  %44 = call i32 @madvise(ptr noundef %41, i64 noundef %43, i32 noundef 2) #7
  br label %47

45:                                               ; preds = %27
  %46 = getelementptr inbounds %"class.fastgltf::MappedGltfFile", ptr %8, i32 0, i32 4
  store i64 14, ptr %46, align 8, !tbaa !18
  br label %47

47:                                               ; preds = %45, %36
  %48 = load i32, ptr %5, align 4, !tbaa !19
  %49 = invoke i32 @close(i32 noundef %48)
          to label %50 unwind label %55

50:                                               ; preds = %47
  store i32 0, ptr %6, align 4
  br label %51

51:                                               ; preds = %50, %25
  call void @llvm.lifetime.end.p0(i64 144, ptr %7) #7
  br label %52

52:                                               ; preds = %51, %19
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #7
  %53 = load i32, ptr %6, align 4
  switch i32 %53, label %58 [
    i32 0, label %54
    i32 1, label %54
  ]

54:                                               ; preds = %52, %52
  ret void

55:                                               ; preds = %47, %2
  %56 = landingpad { ptr, i32 }
          catch ptr null
  %57 = extractvalue { ptr, i32 } %56, 0
  call void @__clang_call_terminate(ptr %57) #8
  unreachable

58:                                               ; preds = %52
  unreachable
}

declare i32 @open(ptr noundef, i32 noundef, ...) #5

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZNKSt10filesystem7__cxx114path5c_strEv(ptr noundef nonnull align 8 dereferenceable(40)) #4 align 2

; Function Attrs: nounwind
declare i32 @fstat(i32 noundef, ptr noundef) #6

; Function Attrs: nounwind
declare ptr @mmap(ptr noundef, i64 noundef, i32 noundef, i32 noundef, i32 noundef, i64 noundef) #6

; Function Attrs: nounwind
declare i32 @madvise(ptr noundef, i64 noundef, i32 noundef) #6

declare i32 @close(i32 noundef) #5

attributes #0 = { inlinehint 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 = { noinline noreturn nounwind uwtable "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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #4 = { 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 #5 = { "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 #6 = { 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 #7 = { nounwind }
attributes #8 = { noreturn 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 = !{!"vtable pointer", !8, i64 0}
!11 = !{!12, !6, i64 8}
!12 = !{!"_ZTSN8fastgltf14MappedGltfFileE", !13, i64 0, !6, i64 8, !14, i64 16, !14, i64 24, !15, i64 32}
!13 = !{!"_ZTSN8fastgltf14GltfDataGetterE"}
!14 = !{!"long", !7, i64 0}
!15 = !{!"_ZTSN8fastgltf5ErrorE", !7, i64 0}
!16 = !{!12, !14, i64 16}
!17 = !{!12, !14, i64 24}
!18 = !{!12, !15, i64 32}
!19 = !{!20, !20, i64 0}
!20 = !{!"int", !7, i64 0}
!21 = !{!22, !14, i64 48}
!22 = !{!"_ZTS4stat", !14, i64 0, !14, i64 8, !14, i64 16, !20, i64 24, !20, i64 28, !20, i64 32, !20, i64 36, !14, i64 40, !14, i64 48, !14, i64 56, !14, i64 64, !23, i64 72, !23, i64 88, !23, i64 104, !7, i64 120}
!23 = !{!"_ZTS8timespec", !14, i64 0, !14, i64 8}


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

%struct.stat = type { i64, i64, i64, i32, i32, i32, i32, i64, i64, i64, i64, %struct.timespec, %struct.timespec, %struct.timespec, [3 x i64] }
%struct.timespec = type { i64, i64 }

@_ZTVN8fastgltf14MappedGltfFileE = external dso_local unnamed_addr constant { [9 x ptr] }, align 8

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZN8fastgltf14GltfDataGetterC2Ev(ptr noundef nonnull align 8 dereferenceable(8)) unnamed_addr #0 align 2

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

declare i32 @__gxx_personality_v0(...)

; Function Attrs: noinline noreturn nounwind uwtable
declare hidden void @__clang_call_terminate(ptr noundef) local_unnamed_addr #2

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

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #3

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN8fastgltf14MappedGltfFileC2ERKNSt10filesystem7__cxx114pathE(ptr noundef nonnull align 8 dereferenceable(40) %0, ptr noundef nonnull align 8 dereferenceable(40) %1) unnamed_addr #4 align 2 personality ptr @__gxx_personality_v0 {
  %3 = alloca %struct.stat, align 8
  tail call void @_ZN8fastgltf14GltfDataGetterC2Ev(ptr noundef nonnull align 8 dereferenceable(8) %0) #9
  store ptr getelementptr inbounds inrange(-16, 56) (i8, ptr @_ZTVN8fastgltf14MappedGltfFileE, i64 16), ptr %0, align 8, !tbaa !5
  %4 = getelementptr inbounds i8, ptr %0, i64 8
  store ptr inttoptr (i64 -1 to ptr), ptr %4, align 8, !tbaa !8
  %5 = getelementptr inbounds i8, ptr %0, i64 16
  %6 = getelementptr inbounds i8, ptr %0, i64 32
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(24) %5, i8 0, i64 24, i1 false)
  %7 = tail call noundef ptr @_ZNKSt10filesystem7__cxx114path5c_strEv(ptr noundef nonnull align 8 dereferenceable(40) %1) #9
  %8 = invoke i32 (ptr, i32, ...) @open(ptr noundef %7, i32 noundef 0, i32 noundef 0)
          to label %9 unwind label %26

9:                                                ; preds = %2
  %10 = icmp eq i32 %8, 0
  br i1 %10, label %11, label %12

11:                                               ; preds = %9
  store i64 1, ptr %6, align 8, !tbaa !15
  br label %25

12:                                               ; preds = %9
  call void @llvm.lifetime.start.p0(i64 144, ptr nonnull %3) #9
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(144) %3, i8 0, i64 144, i1 false)
  %13 = call i32 @fstat(i32 noundef %8, ptr noundef nonnull %3) #9
  %.not = icmp eq i32 %13, 0
  br i1 %.not, label %15, label %14

14:                                               ; preds = %12
  store i64 1, ptr %6, align 8, !tbaa !15
  br label %24

15:                                               ; preds = %12
  %16 = getelementptr inbounds i8, ptr %3, i64 48
  %17 = load i64, ptr %16, align 8, !tbaa !16
  %18 = tail call ptr @mmap(ptr noundef null, i64 noundef %17, i32 noundef 1, i32 noundef 2, i32 noundef %8, i64 noundef 0) #9
  store ptr %18, ptr %4, align 8, !tbaa !8
  %.not5 = icmp eq ptr %18, inttoptr (i64 -1 to ptr)
  br i1 %.not5, label %21, label %19

19:                                               ; preds = %15
  store i64 %17, ptr %5, align 8, !tbaa !20
  %20 = tail call i32 @madvise(ptr noundef %18, i64 noundef %17, i32 noundef 2) #9
  br label %22

21:                                               ; preds = %15
  store i64 14, ptr %6, align 8, !tbaa !15
  br label %22

22:                                               ; preds = %21, %19
  %23 = invoke i32 @close(i32 noundef %8)
          to label %24 unwind label %26

24:                                               ; preds = %22, %14
  call void @llvm.lifetime.end.p0(i64 144, ptr nonnull %3) #9
  br label %25

25:                                               ; preds = %24, %11
  ret void

26:                                               ; preds = %22, %2
  %27 = landingpad { ptr, i32 }
          catch ptr null
  %28 = extractvalue { ptr, i32 } %27, 0
  tail call void @__clang_call_terminate(ptr %28) #10
  unreachable
}

; Function Attrs: nofree
declare noundef i32 @open(ptr nocapture noundef readonly, i32 noundef, ...) local_unnamed_addr #5

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZNKSt10filesystem7__cxx114path5c_strEv(ptr noundef nonnull align 8 dereferenceable(40)) local_unnamed_addr #4 align 2

; Function Attrs: nofree nounwind
declare noundef i32 @fstat(i32 noundef, ptr nocapture noundef) local_unnamed_addr #6

; Function Attrs: nounwind
declare ptr @mmap(ptr noundef, i64 noundef, i32 noundef, i32 noundef, i32 noundef, i64 noundef) local_unnamed_addr #7

; Function Attrs: nounwind
declare i32 @madvise(ptr noundef, i64 noundef, i32 noundef) local_unnamed_addr #7

declare i32 @close(i32 noundef) local_unnamed_addr #8

attributes #0 = { inlinehint 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 nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { noinline noreturn nounwind uwtable "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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #4 = { 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 #5 = { nofree "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 #6 = { nofree 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 #7 = { 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 #8 = { "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 #9 = { nounwind }
attributes #10 = { noreturn 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 = !{!"vtable pointer", !7, i64 0}
!7 = !{!"Simple C++ TBAA"}
!8 = !{!9, !11, i64 8}
!9 = !{!"_ZTSN8fastgltf14MappedGltfFileE", !10, i64 0, !11, i64 8, !13, i64 16, !13, i64 24, !14, i64 32}
!10 = !{!"_ZTSN8fastgltf14GltfDataGetterE"}
!11 = !{!"any pointer", !12, i64 0}
!12 = !{!"omnipotent char", !7, i64 0}
!13 = !{!"long", !12, i64 0}
!14 = !{!"_ZTSN8fastgltf5ErrorE", !12, i64 0}
!15 = !{!9, !14, i64 32}
!16 = !{!17, !13, i64 48}
!17 = !{!"_ZTS4stat", !13, i64 0, !13, i64 8, !13, i64 16, !18, i64 24, !18, i64 28, !18, i64 32, !18, i64 36, !13, i64 40, !13, i64 48, !13, i64 56, !13, i64 64, !19, i64 72, !19, i64 88, !19, i64 104, !12, i64 120}
!18 = !{!"int", !12, i64 0}
!19 = !{!"_ZTS8timespec", !13, i64 0, !13, i64 8}
!20 = !{!9, !13, i64 16}


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