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

; 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::MatFXGlobals" = type { i32, i32, [13 x ptr], ptr }
%"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 }

@_ZN2rw12matFXGlobalsE = external dso_local global %"struct.rw::MatFXGlobals", align 8
@.str = external hidden unnamed_addr constant [73 x i8], align 1

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN2rw5MatFX10setEffectsEPNS_8MaterialEj(ptr noundef %0, i32 noundef %1) #0 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #5
  %6 = load ptr, ptr %3, align 8, !tbaa !5
  %7 = call noundef ptr @_ZN2rw5MatFX3getEPKNS_8MaterialE(ptr noundef %6)
  store ptr %7, ptr %5, align 8, !tbaa !5
  %8 = load ptr, ptr %5, align 8, !tbaa !5
  %9 = icmp eq ptr %8, null
  br i1 %9, label %10, label %18

10:                                               ; preds = %2
  %11 = call noundef ptr @_ZN2rw14mustmalloc_LOCEmjPKc(i64 noundef 88, i32 noundef 196896, ptr noundef @.str)
  store ptr %11, ptr %5, align 8, !tbaa !5
  %12 = load ptr, ptr %5, align 8, !tbaa !5
  call void @llvm.memset.p0.i64(ptr align 8 %12, i8 0, i64 88, i1 false)
  %13 = load ptr, ptr %5, align 8, !tbaa !5
  %14 = load ptr, ptr %3, align 8, !tbaa !5
  %15 = load i32, ptr getelementptr inbounds (%"struct.rw::MatFXGlobals", ptr @_ZN2rw12matFXGlobalsE, i32 0, i32 1), align 4, !tbaa !11
  %16 = sext i32 %15 to i64
  %17 = getelementptr inbounds i8, ptr %14, i64 %16
  store ptr %13, ptr %17, align 8, !tbaa !5
  br label %18

18:                                               ; preds = %10, %2
  %19 = load ptr, ptr %5, align 8, !tbaa !5
  %20 = getelementptr inbounds %"struct.rw::MatFX", ptr %19, i32 0, i32 1
  %21 = load i32, ptr %20, align 8, !tbaa !13
  %22 = icmp ne i32 %21, 0
  br i1 %22, label %23, label %31

23:                                               ; preds = %18
  %24 = load ptr, ptr %5, align 8, !tbaa !5
  %25 = getelementptr inbounds %"struct.rw::MatFX", ptr %24, i32 0, i32 1
  %26 = load i32, ptr %25, align 8, !tbaa !13
  %27 = load i32, ptr %4, align 4, !tbaa !9
  %28 = icmp ne i32 %26, %27
  br i1 %28, label %29, label %31

29:                                               ; preds = %23
  %30 = load ptr, ptr %5, align 8, !tbaa !5
  call void @_ZN2rwL10clearMatFXEPNS_5MatFXE(ptr noundef %30)
  br label %31

31:                                               ; preds = %29, %23, %18
  %32 = load i32, ptr %4, align 4, !tbaa !9
  %33 = load ptr, ptr %5, align 8, !tbaa !5
  %34 = getelementptr inbounds %"struct.rw::MatFX", ptr %33, i32 0, i32 1
  store i32 %32, ptr %34, align 8, !tbaa !13
  %35 = load i32, ptr %4, align 4, !tbaa !9
  switch i32 %35, label %64 [
    i32 1, label %36
    i32 2, label %36
    i32 4, label %36
    i32 5, label %36
    i32 3, label %46
    i32 6, label %55
  ]

36:                                               ; preds = %31, %31, %31, %31
  %37 = load i32, ptr %4, align 4, !tbaa !9
  %38 = load ptr, ptr %5, align 8, !tbaa !5
  %39 = getelementptr inbounds %"struct.rw::MatFX", ptr %38, i32 0, i32 0
  %40 = getelementptr inbounds [2 x %struct.anon], ptr %39, i64 0, i64 0
  %41 = getelementptr inbounds %struct.anon, ptr %40, i32 0, i32 0
  store i32 %37, ptr %41, align 8, !tbaa !15
  %42 = load ptr, ptr %5, align 8, !tbaa !5
  %43 = getelementptr inbounds %"struct.rw::MatFX", ptr %42, i32 0, i32 0
  %44 = getelementptr inbounds [2 x %struct.anon], ptr %43, i64 0, i64 1
  %45 = getelementptr inbounds %struct.anon, ptr %44, i32 0, i32 0
  store i32 0, ptr %45, align 8, !tbaa !15
  br label %64

46:                                               ; preds = %31
  %47 = load ptr, ptr %5, align 8, !tbaa !5
  %48 = getelementptr inbounds %"struct.rw::MatFX", ptr %47, i32 0, i32 0
  %49 = getelementptr inbounds [2 x %struct.anon], ptr %48, i64 0, i64 0
  %50 = getelementptr inbounds %struct.anon, ptr %49, i32 0, i32 0
  store i32 1, ptr %50, align 8, !tbaa !15
  %51 = load ptr, ptr %5, align 8, !tbaa !5
  %52 = getelementptr inbounds %"struct.rw::MatFX", ptr %51, i32 0, i32 0
  %53 = getelementptr inbounds [2 x %struct.anon], ptr %52, i64 0, i64 1
  %54 = getelementptr inbounds %struct.anon, ptr %53, i32 0, i32 0
  store i32 2, ptr %54, align 8, !tbaa !15
  br label %64

55:                                               ; preds = %31
  %56 = load ptr, ptr %5, align 8, !tbaa !5
  %57 = getelementptr inbounds %"struct.rw::MatFX", ptr %56, i32 0, i32 0
  %58 = getelementptr inbounds [2 x %struct.anon], ptr %57, i64 0, i64 0
  %59 = getelementptr inbounds %struct.anon, ptr %58, i32 0, i32 0
  store i32 5, ptr %59, align 8, !tbaa !15
  %60 = load ptr, ptr %5, align 8, !tbaa !5
  %61 = getelementptr inbounds %"struct.rw::MatFX", ptr %60, i32 0, i32 0
  %62 = getelementptr inbounds [2 x %struct.anon], ptr %61, i64 0, i64 1
  %63 = getelementptr inbounds %struct.anon, ptr %62, i32 0, i32 0
  store i32 4, ptr %63, align 8, !tbaa !15
  br label %64

64:                                               ; preds = %55, %46, %36, %31
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #5
  ret void
}

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZN2rw5MatFX3getEPKNS_8MaterialE(ptr noundef) #2 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef ptr @_ZN2rw14mustmalloc_LOCEmjPKc(i64 noundef, i32 noundef, ptr noundef) #3

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

; Function Attrs: mustprogress uwtable
declare hidden void @_ZN2rwL10clearMatFXEPNS_5MatFXE(ptr noundef) #0

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

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
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 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 4}
!12 = !{!"_ZTSN2rw12MatFXGlobalsE", !10, i64 0, !10, i64 4, !7, i64 8, !6, i64 112}
!13 = !{!14, !10, i64 80}
!14 = !{!"_ZTSN2rw5MatFXE", !7, i64 0, !10, i64 80}
!15 = !{!16, !10, i64 0}
!16 = !{!"_ZTSN2rw5MatFXUt0_E", !10, i64 0, !7, 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.rw::MatFXGlobals" = type { i32, i32, [13 x ptr], ptr }

@_ZN2rw12matFXGlobalsE = external dso_local local_unnamed_addr global %"struct.rw::MatFXGlobals", align 8
@.str = external hidden unnamed_addr constant [73 x i8], align 1
@switch.table._ZN2rw5MatFX10setEffectsEPNS_8MaterialEj = private unnamed_addr constant [6 x i32] [i32 1, i32 2, i32 1, i32 4, i32 5, i32 5], align 4
@switch.table._ZN2rw5MatFX10setEffectsEPNS_8MaterialEj.1 = private unnamed_addr constant [6 x i32] [i32 0, i32 0, i32 2, i32 0, i32 0, i32 4], align 4

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN2rw5MatFX10setEffectsEPNS_8MaterialEj(ptr noundef %0, i32 noundef %1) local_unnamed_addr #0 align 2 {
  %3 = tail call noundef ptr @_ZN2rw5MatFX3getEPKNS_8MaterialE(ptr noundef %0)
  %4 = icmp eq ptr %3, null
  br i1 %4, label %5, label %10

5:                                                ; preds = %2
  %6 = tail call noundef ptr @_ZN2rw14mustmalloc_LOCEmjPKc(i64 noundef 88, i32 noundef 196896, ptr noundef nonnull @.str)
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(88) %6, i8 0, i64 88, i1 false)
  %7 = load i32, ptr getelementptr inbounds (i8, ptr @_ZN2rw12matFXGlobalsE, i64 4), align 4, !tbaa !5
  %8 = sext i32 %7 to i64
  %9 = getelementptr inbounds i8, ptr %0, i64 %8
  store ptr %6, ptr %9, align 8, !tbaa !11
  br label %10

10:                                               ; preds = %5, %2
  %.0 = phi ptr [ %6, %5 ], [ %3, %2 ]
  %11 = getelementptr inbounds i8, ptr %.0, i64 80
  %12 = load i32, ptr %11, align 8, !tbaa !12
  %.not = icmp eq i32 %12, 0
  %.not20 = icmp eq i32 %12, %1
  %or.cond = or i1 %.not, %.not20
  br i1 %or.cond, label %14, label %13

13:                                               ; preds = %10
  tail call void @_ZN2rwL10clearMatFXEPNS_5MatFXE(ptr noundef nonnull %.0)
  br label %14

14:                                               ; preds = %13, %10
  store i32 %1, ptr %11, align 8, !tbaa !12
  %switch.tableidx = add i32 %1, -1
  %15 = icmp ult i32 %switch.tableidx, 6
  br i1 %15, label %switch.lookup, label %19

switch.lookup:                                    ; preds = %14
  %16 = zext nneg i32 %switch.tableidx to i64
  %switch.gep = getelementptr inbounds [6 x i32], ptr @switch.table._ZN2rw5MatFX10setEffectsEPNS_8MaterialEj, i64 0, i64 %16
  %switch.load = load i32, ptr %switch.gep, align 4
  %17 = zext nneg i32 %switch.tableidx to i64
  %switch.gep23 = getelementptr inbounds [6 x i32], ptr @switch.table._ZN2rw5MatFX10setEffectsEPNS_8MaterialEj.1, i64 0, i64 %17
  %switch.load24 = load i32, ptr %switch.gep23, align 4
  store i32 %switch.load, ptr %.0, align 8, !tbaa !14
  %18 = getelementptr inbounds i8, ptr %.0, i64 40
  store i32 %switch.load24, ptr %18, align 8, !tbaa !14
  br label %19

19:                                               ; preds = %14, %switch.lookup
  ret void
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZN2rw5MatFX3getEPKNS_8MaterialE(ptr noundef) local_unnamed_addr #1 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef ptr @_ZN2rw14mustmalloc_LOCEmjPKc(i64 noundef, i32 noundef, ptr noundef) local_unnamed_addr #2

; 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 uwtable
declare hidden void @_ZN2rwL10clearMatFXEPNS_5MatFXE(ptr noundef) local_unnamed_addr #0

attributes #0 = { 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 #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 = { 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 #3 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }

!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 4}
!6 = !{!"_ZTSN2rw12MatFXGlobalsE", !7, i64 0, !7, i64 4, !8, i64 8, !10, i64 112}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!10, !10, i64 0}
!12 = !{!13, !7, i64 80}
!13 = !{!"_ZTSN2rw5MatFXE", !8, i64 0, !7, i64 80}
!14 = !{!15, !7, i64 0}
!15 = !{!"_ZTSN2rw5MatFXUt0_E", !7, i64 0, !8, i64 8}


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