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

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

@RN_EPSILON = external global double, align 8

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

declare void @_ZN5RNRgbC1Eddd(ptr noundef nonnull align 8 dereferenceable(24), double noundef, double noundef, double noundef) unnamed_addr #1

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

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

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

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

declare noundef nonnull align 8 dereferenceable(24) ptr @_ZN5RNRgbaSERKS_(ptr noundef nonnull align 8 dereferenceable(24), ptr noundef nonnull align 8 dereferenceable(24)) #1

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN6R3Brdf10SetOpacityEd(ptr noundef nonnull align 8 dereferenceable(180) %0, double noundef %1) #4 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca double, align 8
  %5 = alloca double, align 8
  %6 = alloca %class.RNFlags, align 8
  %7 = alloca %class.RNFlags, align 8
  %8 = alloca %class.RNRgb, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store double %1, ptr %4, align 8, !tbaa !9
  %9 = load ptr, ptr %3, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #5
  %10 = load double, ptr %4, align 8, !tbaa !9
  %11 = fsub double 1.000000e+00, %10
  store double %11, ptr %5, align 8, !tbaa !9
  %12 = load double, ptr %5, align 8, !tbaa !9
  %13 = load double, ptr @RN_EPSILON, align 8, !tbaa !9
  %14 = call noundef i32 @_Z9RNIsEqualddd(double noundef %12, double noundef 0.000000e+00, double noundef %13)
  %15 = icmp ne i32 %14, 0
  br i1 %15, label %16, label %17

16:                                               ; preds = %2
  store double 0.000000e+00, ptr %5, align 8, !tbaa !9
  br label %24

17:                                               ; preds = %2
  %18 = load double, ptr %5, align 8, !tbaa !9
  %19 = load double, ptr @RN_EPSILON, align 8, !tbaa !9
  %20 = call noundef i32 @_Z9RNIsEqualddd(double noundef %18, double noundef 1.000000e+00, double noundef %19)
  %21 = icmp ne i32 %20, 0
  br i1 %21, label %22, label %23

22:                                               ; preds = %17
  store double 1.000000e+00, ptr %5, align 8, !tbaa !9
  br label %23

23:                                               ; preds = %22, %17
  br label %24

24:                                               ; preds = %23, %16
  %25 = load double, ptr %5, align 8, !tbaa !9
  %26 = fcmp oeq double %25, 0.000000e+00
  br i1 %26, label %27, label %31

27:                                               ; preds = %24
  %28 = getelementptr inbounds %class.R3Brdf, ptr %9, i32 0, i32 12
  call void @_ZN7RNFlagsC2Em(ptr noundef nonnull align 8 dereferenceable(8) %6, i64 noundef 32)
  %29 = getelementptr inbounds %class.RNFlags, ptr %6, i32 0, i32 0
  %30 = load i64, ptr %29, align 8
  call void @_ZN7RNFlags6RemoveES_(ptr noundef nonnull align 8 dereferenceable(8) %28, i64 %30)
  br label %35

31:                                               ; preds = %24
  %32 = getelementptr inbounds %class.R3Brdf, ptr %9, i32 0, i32 12
  call void @_ZN7RNFlagsC2Em(ptr noundef nonnull align 8 dereferenceable(8) %7, i64 noundef 32)
  %33 = getelementptr inbounds %class.RNFlags, ptr %7, i32 0, i32 0
  %34 = load i64, ptr %33, align 8
  call void @_ZN7RNFlags3AddES_(ptr noundef nonnull align 8 dereferenceable(8) %32, i64 %34)
  br label %35

35:                                               ; preds = %31, %27
  call void @llvm.lifetime.start.p0(i64 24, ptr %8) #5
  %36 = load double, ptr %5, align 8, !tbaa !9
  %37 = load double, ptr %5, align 8, !tbaa !9
  %38 = load double, ptr %5, align 8, !tbaa !9
  call void @_ZN5RNRgbC1Eddd(ptr noundef nonnull align 8 dereferenceable(24) %8, double noundef %36, double noundef %37, double noundef %38)
  %39 = getelementptr inbounds %class.R3Brdf, ptr %9, i32 0, i32 8
  %40 = call noundef nonnull align 8 dereferenceable(24) ptr @_ZN5RNRgbaSERKS_(ptr noundef nonnull align 8 dereferenceable(24) %39, ptr noundef nonnull align 8 dereferenceable(24) %8)
  call void @llvm.lifetime.end.p0(i64 24, ptr %8) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #5
  ret void
}

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef i32 @_Z9RNIsEqualddd(double noundef, double noundef, double noundef) #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { "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 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 #3 = { 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" }
attributes #4 = { 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 #5 = { 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 = !{!"double", !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 }
%class.RNRgb = type { [3 x double] }

@RN_EPSILON = external local_unnamed_addr global double, align 8

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

declare void @_ZN5RNRgbC1Eddd(ptr noundef nonnull align 8 dereferenceable(24), double noundef, double noundef, double noundef) unnamed_addr #1

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

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

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

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

declare noundef nonnull align 8 dereferenceable(24) ptr @_ZN5RNRgbaSERKS_(ptr noundef nonnull align 8 dereferenceable(24), ptr noundef nonnull align 8 dereferenceable(24)) local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN6R3Brdf10SetOpacityEd(ptr noundef nonnull align 8 dereferenceable(180) %0, double noundef %1) local_unnamed_addr #4 align 2 {
  %3 = alloca %class.RNFlags, align 8
  %4 = alloca %class.RNFlags, align 8
  %5 = alloca %class.RNRgb, align 8
  %6 = fsub double 1.000000e+00, %1
  %7 = load double, ptr @RN_EPSILON, align 8, !tbaa !5
  %8 = tail call noundef i32 @_Z9RNIsEqualddd(double noundef %6, double noundef 0.000000e+00, double noundef %7)
  %.not = icmp eq i32 %8, 0
  br i1 %.not, label %9, label %.thread

9:                                                ; preds = %2
  %10 = load double, ptr @RN_EPSILON, align 8, !tbaa !5
  %11 = tail call noundef i32 @_Z9RNIsEqualddd(double noundef %6, double noundef 1.000000e+00, double noundef %10)
  %.not8 = icmp eq i32 %11, 0
  br i1 %.not8, label %12, label %.thread12

12:                                               ; preds = %9
  %13 = fcmp oeq double %6, 0.000000e+00
  br i1 %13, label %.thread, label %.thread12

.thread:                                          ; preds = %2, %12
  %.011 = phi double [ %6, %12 ], [ 0.000000e+00, %2 ]
  %14 = getelementptr inbounds i8, ptr %0, i64 168
  call void @_ZN7RNFlagsC2Em(ptr noundef nonnull align 8 dereferenceable(8) %3, i64 noundef 32)
  %15 = load i64, ptr %3, align 8
  call void @_ZN7RNFlags6RemoveES_(ptr noundef nonnull align 8 dereferenceable(8) %14, i64 %15)
  br label %18

.thread12:                                        ; preds = %9, %12
  %.014 = phi double [ %6, %12 ], [ 1.000000e+00, %9 ]
  %16 = getelementptr inbounds i8, ptr %0, i64 168
  call void @_ZN7RNFlagsC2Em(ptr noundef nonnull align 8 dereferenceable(8) %4, i64 noundef 32)
  %17 = load i64, ptr %4, align 8
  call void @_ZN7RNFlags3AddES_(ptr noundef nonnull align 8 dereferenceable(8) %16, i64 %17)
  br label %18

18:                                               ; preds = %.thread12, %.thread
  %.010 = phi double [ %.014, %.thread12 ], [ %.011, %.thread ]
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %5) #5
  call void @_ZN5RNRgbC1Eddd(ptr noundef nonnull align 8 dereferenceable(24) %5, double noundef %.010, double noundef %.010, double noundef %.010)
  %19 = getelementptr inbounds i8, ptr %0, i64 104
  %20 = call noundef nonnull align 8 dereferenceable(24) ptr @_ZN5RNRgbaSERKS_(ptr noundef nonnull align 8 dereferenceable(24) %19, ptr noundef nonnull align 8 dereferenceable(24) %5)
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %5) #5
  ret void
}

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef i32 @_Z9RNIsEqualddd(double noundef, double noundef, double noundef) local_unnamed_addr #3

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { "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 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 #3 = { 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" }
attributes #4 = { 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 #5 = { 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 = !{!"double", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}


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