; LLVM IR from niessner/Matterport :: code/gaps/pkgs/R3Graphics/R2Texture.ll (ZN9R2TextureD2Ev)

; 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.R2Texture = type <{ ptr, i32, [4 x i8], ptr, ptr, ptr, i32, i32, i32, i32, i32, [4 x i8], %class.RNFlags, i32, [4 x i8] }>
%class.RNFlags = type { i64 }

declare i32 @__gxx_personality_v0(...)

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN9R2TextureD2Ev(ptr noundef nonnull align 8 dereferenceable(76) %0) unnamed_addr #0 align 2 personality ptr @__gxx_personality_v0 {
  %2 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  %3 = load ptr, ptr %2, align 8
  %4 = invoke noundef i32 @_ZNK9R2Texture8IsLoadedEv(ptr noundef nonnull align 8 dereferenceable(76) %3)
          to label %5 unwind label %32

5:                                                ; preds = %1
  %6 = icmp sgt i32 %4, 0
  br i1 %6, label %7, label %9

7:                                                ; preds = %5
  invoke void @_ZNK9R2Texture6UnloadEv(ptr noundef nonnull align 8 dereferenceable(76) %3)
          to label %8 unwind label %32

8:                                                ; preds = %7
  br label %9

9:                                                ; preds = %8, %5
  %10 = getelementptr inbounds %class.R2Texture, ptr %3, i32 0, i32 0
  %11 = load ptr, ptr %10, align 8, !tbaa !9
  %12 = icmp ne ptr %11, null
  br i1 %12, label %13, label %17

13:                                               ; preds = %9
  %14 = getelementptr inbounds %class.R2Texture, ptr %3, i32 0, i32 0
  %15 = load ptr, ptr %14, align 8, !tbaa !9
  invoke void @_ZN7R3Scene13RemoveTextureEP9R2Texture(ptr noundef nonnull align 8 dereferenceable(352) %15, ptr noundef %3)
          to label %16 unwind label %32

16:                                               ; preds = %13
  br label %17

17:                                               ; preds = %16, %9
  %18 = getelementptr inbounds %class.R2Texture, ptr %3, i32 0, i32 3
  %19 = load ptr, ptr %18, align 8, !tbaa !17
  %20 = icmp ne ptr %19, null
  br i1 %20, label %21, label %24

21:                                               ; preds = %17
  %22 = getelementptr inbounds %class.R2Texture, ptr %3, i32 0, i32 3
  %23 = load ptr, ptr %22, align 8, !tbaa !17
  call void @free(ptr noundef %23) #6
  br label %24

24:                                               ; preds = %21, %17
  %25 = getelementptr inbounds %class.R2Texture, ptr %3, i32 0, i32 4
  %26 = load ptr, ptr %25, align 8, !tbaa !18
  %27 = icmp ne ptr %26, null
  br i1 %27, label %28, label %31

28:                                               ; preds = %24
  %29 = getelementptr inbounds %class.R2Texture, ptr %3, i32 0, i32 4
  %30 = load ptr, ptr %29, align 8, !tbaa !18
  call void @free(ptr noundef %30) #6
  br label %31

31:                                               ; preds = %28, %24
  ret void

32:                                               ; preds = %13, %7, %1
  %33 = landingpad { ptr, i32 }
          catch ptr null
  %34 = extractvalue { ptr, i32 } %33, 0
  call void @__clang_call_terminate(ptr %34) #7
  unreachable
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNK9R2Texture8IsLoadedEv(ptr noundef nonnull align 8 dereferenceable(76)) #1 align 2

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZNK9R2Texture6UnloadEv(ptr noundef nonnull align 8 dereferenceable(76)) #3 align 2

declare void @_ZN7R3Scene13RemoveTextureEP9R2Texture(ptr noundef nonnull align 8 dereferenceable(352), ptr noundef) #4

; Function Attrs: nounwind
declare void @free(ptr noundef) #5

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" }
attributes #1 = { 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 #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 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 #4 = { "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 = { 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 #6 = { nounwind }
attributes #7 = { 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, !6, i64 0}
!10 = !{!"_ZTS9R2Texture", !6, i64 0, !11, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !12, i64 40, !12, i64 44, !13, i64 48, !13, i64 52, !14, i64 56, !15, i64 64, !11, i64 72}
!11 = !{!"int", !7, i64 0}
!12 = !{!"_ZTS13R2TextureWrap", !7, i64 0}
!13 = !{!"_ZTS15R2TextureFilter", !7, i64 0}
!14 = !{!"_ZTS14R2TextureBlend", !7, i64 0}
!15 = !{!"_ZTS7RNFlags", !16, i64 0}
!16 = !{!"long", !7, i64 0}
!17 = !{!10, !6, i64 16}
!18 = !{!10, !6, i64 24}


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

declare i32 @__gxx_personality_v0(...)

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN9R2TextureD2Ev(ptr noundef nonnull align 8 dereferenceable(76) %0) unnamed_addr #0 align 2 personality ptr @__gxx_personality_v0 {
  %2 = tail call noundef i32 @_ZNK9R2Texture8IsLoadedEv(ptr noundef nonnull align 8 dereferenceable(76) %0)
  %3 = icmp sgt i32 %2, 0
  br i1 %3, label %4, label %5

4:                                                ; preds = %1
  invoke void @_ZNK9R2Texture6UnloadEv(ptr noundef nonnull align 8 dereferenceable(76) %0)
          to label %5 unwind label %17

5:                                                ; preds = %4, %1
  %6 = load ptr, ptr %0, align 8, !tbaa !5
  %.not = icmp eq ptr %6, null
  br i1 %.not, label %8, label %7

7:                                                ; preds = %5
  invoke void @_ZN7R3Scene13RemoveTextureEP9R2Texture(ptr noundef nonnull align 8 dereferenceable(352) %6, ptr noundef nonnull %0)
          to label %8 unwind label %17

8:                                                ; preds = %7, %5
  %9 = getelementptr inbounds i8, ptr %0, i64 16
  %10 = load ptr, ptr %9, align 8, !tbaa !16
  %.not3 = icmp eq ptr %10, null
  br i1 %.not3, label %12, label %11

11:                                               ; preds = %8
  tail call void @free(ptr noundef nonnull %10) #6
  br label %12

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

15:                                               ; preds = %12
  tail call void @free(ptr noundef nonnull %14) #6
  br label %16

16:                                               ; preds = %15, %12
  ret void

17:                                               ; preds = %7, %4
  %18 = landingpad { ptr, i32 }
          catch ptr null
  %19 = extractvalue { ptr, i32 } %18, 0
  tail call void @__clang_call_terminate(ptr %19) #7
  unreachable
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNK9R2Texture8IsLoadedEv(ptr noundef nonnull align 8 dereferenceable(76)) local_unnamed_addr #1 align 2

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZNK9R2Texture6UnloadEv(ptr noundef nonnull align 8 dereferenceable(76)) local_unnamed_addr #3 align 2

declare void @_ZN7R3Scene13RemoveTextureEP9R2Texture(ptr noundef nonnull align 8 dereferenceable(352), ptr noundef) local_unnamed_addr #4

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #5

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" }
attributes #1 = { 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 #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 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 #4 = { "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 = { mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite) "alloc-family"="malloc" "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 }
attributes #7 = { 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, !7, i64 0}
!6 = !{!"_ZTS9R2Texture", !7, i64 0, !10, i64 8, !7, i64 16, !7, i64 24, !7, i64 32, !11, i64 40, !11, i64 44, !12, i64 48, !12, i64 52, !13, i64 56, !14, i64 64, !10, i64 72}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"_ZTS13R2TextureWrap", !8, i64 0}
!12 = !{!"_ZTS15R2TextureFilter", !8, i64 0}
!13 = !{!"_ZTS14R2TextureBlend", !8, i64 0}
!14 = !{!"_ZTS7RNFlags", !15, i64 0}
!15 = !{!"long", !8, i64 0}
!16 = !{!6, !7, i64 16}
!17 = !{!6, !7, i64 24}


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