; LLVM IR from aap/librw :: src/matfx.ll (ZN2rw5MatFX22getUVTransformMatricesEPPNS_6MatrixES3_)

; 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.rw::MatFX" = type { [2 x %struct.anon], i32 }
%struct.anon = type { i32, %union.anon }
%union.anon = type { %"struct.rw::MatFX::Bump" }
%"struct.rw::MatFX::Bump" = type { ptr, ptr, ptr, float }
%"struct.rw::MatFX::UVtransform" = type { ptr, ptr }

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

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZN2rw5MatFX14getEffectIndexEj(ptr noundef nonnull align 8 dereferenceable(88), i32 noundef) #1 align 2

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN2rw5MatFX22getUVTransformMatricesEPPNS_6MatrixES3_(ptr noundef nonnull align 8 dereferenceable(88) %0, ptr noundef %1, ptr noundef %2) #1 align 2 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store ptr %2, ptr %6, align 8, !tbaa !5
  %9 = load ptr, ptr %4, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #2
  %10 = call noundef i32 @_ZN2rw5MatFX14getEffectIndexEj(ptr noundef nonnull align 8 dereferenceable(88) %9, i32 noundef 5)
  store i32 %10, ptr %7, align 4, !tbaa !9
  %11 = load i32, ptr %7, align 4, !tbaa !9
  %12 = icmp sge i32 %11, 0
  br i1 %12, label %13, label %38

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

16:                                               ; preds = %13
  %17 = getelementptr inbounds %"struct.rw::MatFX", ptr %9, i32 0, i32 0
  %18 = load i32, ptr %7, align 4, !tbaa !9
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds [2 x %struct.anon], ptr %17, i64 0, i64 %19
  %21 = getelementptr inbounds %struct.anon, ptr %20, i32 0, i32 1
  %22 = getelementptr inbounds %"struct.rw::MatFX::UVtransform", ptr %21, i32 0, i32 0
  %23 = load ptr, ptr %22, align 8, !tbaa !11
  %24 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %23, ptr %24, align 8, !tbaa !5
  br label %25

25:                                               ; preds = %16, %13
  %26 = load ptr, ptr %6, align 8, !tbaa !5
  %27 = icmp ne ptr %26, null
  br i1 %27, label %28, label %37

28:                                               ; preds = %25
  %29 = getelementptr inbounds %"struct.rw::MatFX", ptr %9, i32 0, i32 0
  %30 = load i32, ptr %7, align 4, !tbaa !9
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds [2 x %struct.anon], ptr %29, i64 0, i64 %31
  %33 = getelementptr inbounds %struct.anon, ptr %32, i32 0, i32 1
  %34 = getelementptr inbounds %"struct.rw::MatFX::UVtransform", ptr %33, i32 0, i32 1
  %35 = load ptr, ptr %34, align 8, !tbaa !11
  %36 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %35, ptr %36, align 8, !tbaa !5
  br label %37

37:                                               ; preds = %28, %25
  store i32 1, ptr %8, align 4
  br label %49

38:                                               ; preds = %3
  %39 = load ptr, ptr %5, align 8, !tbaa !5
  %40 = icmp ne ptr %39, null
  br i1 %40, label %41, label %43

41:                                               ; preds = %38
  %42 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr null, ptr %42, align 8, !tbaa !5
  br label %43

43:                                               ; preds = %41, %38
  %44 = load ptr, ptr %6, align 8, !tbaa !5
  %45 = icmp ne ptr %44, null
  br i1 %45, label %46, label %48

46:                                               ; preds = %43
  %47 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr null, ptr %47, align 8, !tbaa !5
  br label %48

48:                                               ; preds = %46, %43
  store i32 0, ptr %8, align 4
  br label %49

49:                                               ; preds = %48, %37
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  %50 = load i32, ptr %8, align 4
  switch i32 %50, label %52 [
    i32 0, label %51
    i32 1, label %51
  ]

51:                                               ; preds = %49, %49
  ret void

52:                                               ; preds = %49
  unreachable
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 = { 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 = !{!"int", !7, i64 0}
!11 = !{!7, !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"

%struct.anon = type { i32, %union.anon }
%union.anon = type { %"struct.rw::MatFX::Bump" }
%"struct.rw::MatFX::Bump" = type { ptr, ptr, ptr, float }

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZN2rw5MatFX14getEffectIndexEj(ptr noundef nonnull align 8 dereferenceable(88), i32 noundef) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN2rw5MatFX22getUVTransformMatricesEPPNS_6MatrixES3_(ptr noundef nonnull align 8 dereferenceable(88) %0, ptr noundef writeonly %1, ptr noundef writeonly %2) local_unnamed_addr #0 align 2 {
  %4 = tail call noundef i32 @_ZN2rw5MatFX14getEffectIndexEj(ptr noundef nonnull align 8 dereferenceable(88) %0, i32 noundef 5)
  %5 = icmp sgt i32 %4, -1
  %.not15 = icmp eq ptr %1, null
  br i1 %5, label %6, label %16

6:                                                ; preds = %3
  br i1 %.not15, label %11, label %7

7:                                                ; preds = %6
  %8 = zext nneg i32 %4 to i64
  %9 = getelementptr inbounds [2 x %struct.anon], ptr %0, i64 0, i64 %8, i32 1
  %10 = load ptr, ptr %9, align 8, !tbaa !5
  store ptr %10, ptr %1, align 8, !tbaa !8
  br label %11

11:                                               ; preds = %7, %6
  %.not16 = icmp eq ptr %2, null
  br i1 %.not16, label %19, label %12

12:                                               ; preds = %11
  %13 = zext nneg i32 %4 to i64
  %14 = getelementptr inbounds [2 x %struct.anon], ptr %0, i64 0, i64 %13, i32 1, i32 0, i32 1
  %15 = load ptr, ptr %14, align 8, !tbaa !5
  br label %.sink.split

16:                                               ; preds = %3
  br i1 %.not15, label %18, label %17

17:                                               ; preds = %16
  store ptr null, ptr %1, align 8, !tbaa !8
  br label %18

18:                                               ; preds = %17, %16
  %.not14 = icmp eq ptr %2, null
  br i1 %.not14, label %19, label %.sink.split

.sink.split:                                      ; preds = %18, %12
  %.sink = phi ptr [ %15, %12 ], [ null, %18 ]
  store ptr %.sink, ptr %2, align 8, !tbaa !8
  br label %19

19:                                               ; preds = %.sink.split, %18, %11
  ret void
}

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

!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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C++ TBAA"}
!8 = !{!9, !9, i64 0}
!9 = !{!"any pointer", !6, i64 0}


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