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

; 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.RNFlags = type { i64 }
%class.R3Material = type { ptr, i32, ptr, ptr, ptr, %class.RNFlags }

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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN10R3Material10SetTextureEPK9R2Texture(ptr noundef nonnull align 8 dereferenceable(48) %0, ptr noundef %1) #1 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca %class.RNFlags, align 8
  %6 = alloca %class.RNFlags, align 8
  %7 = alloca %class.RNFlags, align 8
  %8 = alloca %class.RNFlags, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  %9 = load ptr, ptr %3, align 8
  %10 = getelementptr inbounds %class.R3Material, ptr %9, i32 0, i32 4
  %11 = load ptr, ptr %10, align 8, !tbaa !9
  %12 = icmp ne ptr %11, null
  br i1 %12, label %13, label %20

13:                                               ; preds = %2
  %14 = load ptr, ptr %4, align 8, !tbaa !5
  %15 = icmp ne ptr %14, null
  br i1 %15, label %20, label %16

16:                                               ; preds = %13
  %17 = getelementptr inbounds %class.R3Material, ptr %9, i32 0, i32 5
  call void @_ZN7RNFlagsC2Em(ptr noundef nonnull align 8 dereferenceable(8) %5, i64 noundef 2048)
  %18 = getelementptr inbounds %class.RNFlags, ptr %5, i32 0, i32 0
  %19 = load i64, ptr %18, align 8
  call void @_ZN7RNFlags6RemoveES_(ptr noundef nonnull align 8 dereferenceable(8) %17, i64 %19)
  br label %20

20:                                               ; preds = %16, %13, %2
  %21 = getelementptr inbounds %class.R3Material, ptr %9, i32 0, i32 4
  %22 = load ptr, ptr %21, align 8, !tbaa !9
  %23 = icmp ne ptr %22, null
  br i1 %23, label %31, label %24

24:                                               ; preds = %20
  %25 = load ptr, ptr %4, align 8, !tbaa !5
  %26 = icmp ne ptr %25, null
  br i1 %26, label %27, label %31

27:                                               ; preds = %24
  %28 = getelementptr inbounds %class.R3Material, ptr %9, i32 0, i32 5
  call void @_ZN7RNFlagsC2Em(ptr noundef nonnull align 8 dereferenceable(8) %6, i64 noundef 2048)
  %29 = getelementptr inbounds %class.RNFlags, ptr %6, i32 0, i32 0
  %30 = load i64, ptr %29, align 8
  call void @_ZN7RNFlags3AddES_(ptr noundef nonnull align 8 dereferenceable(8) %28, i64 %30)
  br label %31

31:                                               ; preds = %27, %24, %20
  %32 = getelementptr inbounds %class.R3Material, ptr %9, i32 0, i32 4
  %33 = load ptr, ptr %32, align 8, !tbaa !9
  %34 = icmp ne ptr %33, null
  br i1 %34, label %35, label %43

35:                                               ; preds = %31
  %36 = getelementptr inbounds %class.R3Material, ptr %9, i32 0, i32 5
  %37 = getelementptr inbounds %class.R3Material, ptr %9, i32 0, i32 4
  %38 = load ptr, ptr %37, align 8, !tbaa !9
  %39 = call i64 @_ZNK9R2Texture5FlagsEv(ptr noundef nonnull align 8 dereferenceable(76) %38)
  %40 = getelementptr inbounds %class.RNFlags, ptr %7, i32 0, i32 0
  store i64 %39, ptr %40, align 8
  %41 = getelementptr inbounds %class.RNFlags, ptr %7, i32 0, i32 0
  %42 = load i64, ptr %41, align 8
  call void @_ZN7RNFlags6RemoveES_(ptr noundef nonnull align 8 dereferenceable(8) %36, i64 %42)
  br label %43

43:                                               ; preds = %35, %31
  %44 = load ptr, ptr %4, align 8, !tbaa !5
  %45 = icmp ne ptr %44, null
  br i1 %45, label %46, label %53

46:                                               ; preds = %43
  %47 = getelementptr inbounds %class.R3Material, ptr %9, i32 0, i32 5
  %48 = load ptr, ptr %4, align 8, !tbaa !5
  %49 = call i64 @_ZNK9R2Texture5FlagsEv(ptr noundef nonnull align 8 dereferenceable(76) %48)
  %50 = getelementptr inbounds %class.RNFlags, ptr %8, i32 0, i32 0
  store i64 %49, ptr %50, align 8
  %51 = getelementptr inbounds %class.RNFlags, ptr %8, i32 0, i32 0
  %52 = load i64, ptr %51, align 8
  call void @_ZN7RNFlags3AddES_(ptr noundef nonnull align 8 dereferenceable(8) %47, i64 %52)
  br label %53

53:                                               ; preds = %46, %43
  %54 = load ptr, ptr %4, align 8, !tbaa !5
  %55 = getelementptr inbounds %class.R3Material, ptr %9, i32 0, i32 4
  store ptr %54, ptr %55, align 8, !tbaa !9
  ret void
}

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZN7RNFlags6RemoveES_(ptr noundef nonnull align 8 dereferenceable(8), i64) #2 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZN7RNFlags3AddES_(ptr noundef nonnull align 8 dereferenceable(8), i64) #2 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local i64 @_ZNK9R2Texture5FlagsEv(ptr noundef nonnull align 8 dereferenceable(76)) #0 align 2

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 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 = { inlinehint 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" }

!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 32}
!10 = !{!"_ZTS10R3Material", !6, i64 0, !11, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !12, i64 40}
!11 = !{!"int", !7, i64 0}
!12 = !{!"_ZTS7RNFlags", !13, i64 0}
!13 = !{!"long", !7, i64 0}


; 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.RNFlags = type { i64 }

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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN10R3Material10SetTextureEPK9R2Texture(ptr noundef nonnull align 8 dereferenceable(48) %0, ptr noundef %1) local_unnamed_addr #1 align 2 {
  %3 = alloca %class.RNFlags, align 8
  %4 = alloca %class.RNFlags, align 8
  %5 = getelementptr inbounds i8, ptr %0, i64 32
  %6 = load ptr, ptr %5, align 8, !tbaa !5
  %7 = icmp eq ptr %6, null
  %8 = icmp ne ptr %1, null
  %or.cond = or i1 %8, %7
  br i1 %or.cond, label %11, label %.thread

.thread:                                          ; preds = %2
  %9 = getelementptr inbounds i8, ptr %0, i64 40
  call void @_ZN7RNFlagsC2Em(ptr noundef nonnull align 8 dereferenceable(8) %3, i64 noundef 2048)
  %10 = load i64, ptr %3, align 8
  call void @_ZN7RNFlags6RemoveES_(ptr noundef nonnull align 8 dereferenceable(8) %9, i64 %10)
  br label %thread-pre-split

11:                                               ; preds = %2
  %or.cond3 = and i1 %8, %7
  br i1 %or.cond3, label %12, label %15

12:                                               ; preds = %11
  %13 = getelementptr inbounds i8, ptr %0, i64 40
  call void @_ZN7RNFlagsC2Em(ptr noundef nonnull align 8 dereferenceable(8) %4, i64 noundef 2048)
  %14 = load i64, ptr %4, align 8
  call void @_ZN7RNFlags3AddES_(ptr noundef nonnull align 8 dereferenceable(8) %13, i64 %14)
  br label %thread-pre-split

thread-pre-split:                                 ; preds = %12, %.thread
  %.pr = load ptr, ptr %5, align 8, !tbaa !5
  br label %15

15:                                               ; preds = %thread-pre-split, %11
  %16 = phi ptr [ %.pr, %thread-pre-split ], [ %6, %11 ]
  %.not = icmp eq ptr %16, null
  br i1 %.not, label %20, label %17

17:                                               ; preds = %15
  %18 = getelementptr inbounds i8, ptr %0, i64 40
  %19 = call i64 @_ZNK9R2Texture5FlagsEv(ptr noundef nonnull align 8 dereferenceable(76) %16)
  call void @_ZN7RNFlags6RemoveES_(ptr noundef nonnull align 8 dereferenceable(8) %18, i64 %19)
  br label %20

20:                                               ; preds = %17, %15
  br i1 %8, label %21, label %24

21:                                               ; preds = %20
  %22 = getelementptr inbounds i8, ptr %0, i64 40
  %23 = call i64 @_ZNK9R2Texture5FlagsEv(ptr noundef nonnull align 8 dereferenceable(76) %1)
  call void @_ZN7RNFlags3AddES_(ptr noundef nonnull align 8 dereferenceable(8) %22, i64 %23)
  br label %24

24:                                               ; preds = %21, %20
  store ptr %1, ptr %5, align 8, !tbaa !5
  ret void
}

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZN7RNFlags6RemoveES_(ptr noundef nonnull align 8 dereferenceable(8), i64) local_unnamed_addr #2 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZN7RNFlags3AddES_(ptr noundef nonnull align 8 dereferenceable(8), i64) local_unnamed_addr #2 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local i64 @_ZNK9R2Texture5FlagsEv(ptr noundef nonnull align 8 dereferenceable(76)) local_unnamed_addr #0 align 2

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 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 = { inlinehint 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" }

!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 32}
!6 = !{!"_ZTS10R3Material", !7, i64 0, !10, i64 8, !7, i64 16, !7, i64 24, !7, i64 32, !11, i64 40}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"_ZTS7RNFlags", !12, i64 0}
!12 = !{!"long", !8, i64 0}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InstCombinePass,JumpThreadingPass,ReassociatePass,SROAPass,SimplifyCFGPass