; LLVM IR from Stephane-D/SGDK :: src (maths3D)

; 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.Context3D = type { %struct.Vect2D_u16, i16, %struct.Vect3D_f16, i16 }
%struct.Vect2D_u16 = type { i16, i16 }
%struct.Vect3D_f16 = type { i16, i16, i16 }
%struct.Transformation3D = type { i16, ptr, ptr, %struct.Mat3D_f16, %struct.Mat3D_f16, %struct.Vect3D_f16, %struct.Vect3D_f16 }
%struct.Mat3D_f16 = type { %struct.Vect3D_f16, %struct.Vect3D_f16, %struct.Vect3D_f16 }

@context3D = external dso_local global %struct.Context3D, align 2

; Function Attrs: nounwind uwtable
declare dso_local void @M3D_rotateInv(ptr noundef, ptr noundef, ptr noundef) #0

; Function Attrs: nounwind uwtable
define dso_local void @M3D_buildMat3DExtras(ptr noundef %0) #0 {
  %2 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  %3 = load ptr, ptr %2, align 8, !tbaa !5
  %4 = getelementptr inbounds %struct.Transformation3D, ptr %3, i32 0, i32 3
  %5 = getelementptr inbounds %struct.Mat3D_f16, ptr %4, i32 0, i32 0
  %6 = getelementptr inbounds %struct.Vect3D_f16, ptr %5, i32 0, i32 0
  %7 = load i16, ptr %6, align 8, !tbaa !9
  %8 = load ptr, ptr %2, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct.Transformation3D, ptr %8, i32 0, i32 4
  %10 = getelementptr inbounds %struct.Mat3D_f16, ptr %9, i32 0, i32 0
  %11 = getelementptr inbounds %struct.Vect3D_f16, ptr %10, i32 0, i32 0
  store i16 %7, ptr %11, align 2, !tbaa !14
  %12 = load ptr, ptr %2, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.Transformation3D, ptr %12, i32 0, i32 3
  %14 = getelementptr inbounds %struct.Mat3D_f16, ptr %13, i32 0, i32 0
  %15 = getelementptr inbounds %struct.Vect3D_f16, ptr %14, i32 0, i32 1
  %16 = load i16, ptr %15, align 2, !tbaa !15
  %17 = load ptr, ptr %2, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.Transformation3D, ptr %17, i32 0, i32 4
  %19 = getelementptr inbounds %struct.Mat3D_f16, ptr %18, i32 0, i32 1
  %20 = getelementptr inbounds %struct.Vect3D_f16, ptr %19, i32 0, i32 0
  store i16 %16, ptr %20, align 2, !tbaa !16
  %21 = load ptr, ptr %2, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.Transformation3D, ptr %21, i32 0, i32 3
  %23 = getelementptr inbounds %struct.Mat3D_f16, ptr %22, i32 0, i32 0
  %24 = getelementptr inbounds %struct.Vect3D_f16, ptr %23, i32 0, i32 2
  %25 = load i16, ptr %24, align 4, !tbaa !17
  %26 = load ptr, ptr %2, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.Transformation3D, ptr %26, i32 0, i32 4
  %28 = getelementptr inbounds %struct.Mat3D_f16, ptr %27, i32 0, i32 2
  %29 = getelementptr inbounds %struct.Vect3D_f16, ptr %28, i32 0, i32 0
  store i16 %25, ptr %29, align 2, !tbaa !18
  %30 = load ptr, ptr %2, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.Transformation3D, ptr %30, i32 0, i32 3
  %32 = getelementptr inbounds %struct.Mat3D_f16, ptr %31, i32 0, i32 1
  %33 = getelementptr inbounds %struct.Vect3D_f16, ptr %32, i32 0, i32 0
  %34 = load i16, ptr %33, align 2, !tbaa !19
  %35 = load ptr, ptr %2, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.Transformation3D, ptr %35, i32 0, i32 4
  %37 = getelementptr inbounds %struct.Mat3D_f16, ptr %36, i32 0, i32 0
  %38 = getelementptr inbounds %struct.Vect3D_f16, ptr %37, i32 0, i32 1
  store i16 %34, ptr %38, align 2, !tbaa !20
  %39 = load ptr, ptr %2, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.Transformation3D, ptr %39, i32 0, i32 3
  %41 = getelementptr inbounds %struct.Mat3D_f16, ptr %40, i32 0, i32 1
  %42 = getelementptr inbounds %struct.Vect3D_f16, ptr %41, i32 0, i32 1
  %43 = load i16, ptr %42, align 2, !tbaa !21
  %44 = load ptr, ptr %2, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.Transformation3D, ptr %44, i32 0, i32 4
  %46 = getelementptr inbounds %struct.Mat3D_f16, ptr %45, i32 0, i32 1
  %47 = getelementptr inbounds %struct.Vect3D_f16, ptr %46, i32 0, i32 1
  store i16 %43, ptr %47, align 2, !tbaa !22
  %48 = load ptr, ptr %2, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.Transformation3D, ptr %48, i32 0, i32 3
  %50 = getelementptr inbounds %struct.Mat3D_f16, ptr %49, i32 0, i32 1
  %51 = getelementptr inbounds %struct.Vect3D_f16, ptr %50, i32 0, i32 2
  %52 = load i16, ptr %51, align 2, !tbaa !23
  %53 = load ptr, ptr %2, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.Transformation3D, ptr %53, i32 0, i32 4
  %55 = getelementptr inbounds %struct.Mat3D_f16, ptr %54, i32 0, i32 2
  %56 = getelementptr inbounds %struct.Vect3D_f16, ptr %55, i32 0, i32 1
  store i16 %52, ptr %56, align 2, !tbaa !24
  %57 = load ptr, ptr %2, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.Transformation3D, ptr %57, i32 0, i32 3
  %59 = getelementptr inbounds %struct.Mat3D_f16, ptr %58, i32 0, i32 2
  %60 = getelementptr inbounds %struct.Vect3D_f16, ptr %59, i32 0, i32 0
  %61 = load i16, ptr %60, align 4, !tbaa !25
  %62 = load ptr, ptr %2, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.Transformation3D, ptr %62, i32 0, i32 4
  %64 = getelementptr inbounds %struct.Mat3D_f16, ptr %63, i32 0, i32 0
  %65 = getelementptr inbounds %struct.Vect3D_f16, ptr %64, i32 0, i32 2
  store i16 %61, ptr %65, align 2, !tbaa !26
  %66 = load ptr, ptr %2, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.Transformation3D, ptr %66, i32 0, i32 3
  %68 = getelementptr inbounds %struct.Mat3D_f16, ptr %67, i32 0, i32 2
  %69 = getelementptr inbounds %struct.Vect3D_f16, ptr %68, i32 0, i32 1
  %70 = load i16, ptr %69, align 2, !tbaa !27
  %71 = load ptr, ptr %2, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct.Transformation3D, ptr %71, i32 0, i32 4
  %73 = getelementptr inbounds %struct.Mat3D_f16, ptr %72, i32 0, i32 1
  %74 = getelementptr inbounds %struct.Vect3D_f16, ptr %73, i32 0, i32 2
  store i16 %70, ptr %74, align 2, !tbaa !28
  %75 = load ptr, ptr %2, align 8, !tbaa !5
  %76 = getelementptr inbounds %struct.Transformation3D, ptr %75, i32 0, i32 3
  %77 = getelementptr inbounds %struct.Mat3D_f16, ptr %76, i32 0, i32 2
  %78 = getelementptr inbounds %struct.Vect3D_f16, ptr %77, i32 0, i32 2
  %79 = load i16, ptr %78, align 4, !tbaa !29
  %80 = load ptr, ptr %2, align 8, !tbaa !5
  %81 = getelementptr inbounds %struct.Transformation3D, ptr %80, i32 0, i32 4
  %82 = getelementptr inbounds %struct.Mat3D_f16, ptr %81, i32 0, i32 2
  %83 = getelementptr inbounds %struct.Vect3D_f16, ptr %82, i32 0, i32 2
  store i16 %79, ptr %83, align 2, !tbaa !30
  %84 = load ptr, ptr %2, align 8, !tbaa !5
  %85 = getelementptr inbounds %struct.Transformation3D, ptr %84, i32 0, i32 4
  %86 = getelementptr inbounds %struct.Mat3D_f16, ptr %85, i32 0, i32 0
  %87 = getelementptr inbounds %struct.Vect3D_f16, ptr %86, i32 0, i32 2
  %88 = load i16, ptr %87, align 2, !tbaa !26
  %89 = load ptr, ptr %2, align 8, !tbaa !5
  %90 = getelementptr inbounds %struct.Transformation3D, ptr %89, i32 0, i32 5
  %91 = getelementptr inbounds %struct.Vect3D_f16, ptr %90, i32 0, i32 0
  store i16 %88, ptr %91, align 4, !tbaa !31
  %92 = load ptr, ptr %2, align 8, !tbaa !5
  %93 = getelementptr inbounds %struct.Transformation3D, ptr %92, i32 0, i32 4
  %94 = getelementptr inbounds %struct.Mat3D_f16, ptr %93, i32 0, i32 1
  %95 = getelementptr inbounds %struct.Vect3D_f16, ptr %94, i32 0, i32 2
  %96 = load i16, ptr %95, align 2, !tbaa !28
  %97 = load ptr, ptr %2, align 8, !tbaa !5
  %98 = getelementptr inbounds %struct.Transformation3D, ptr %97, i32 0, i32 5
  %99 = getelementptr inbounds %struct.Vect3D_f16, ptr %98, i32 0, i32 1
  store i16 %96, ptr %99, align 2, !tbaa !32
  %100 = load ptr, ptr %2, align 8, !tbaa !5
  %101 = getelementptr inbounds %struct.Transformation3D, ptr %100, i32 0, i32 4
  %102 = getelementptr inbounds %struct.Mat3D_f16, ptr %101, i32 0, i32 2
  %103 = getelementptr inbounds %struct.Vect3D_f16, ptr %102, i32 0, i32 2
  %104 = load i16, ptr %103, align 2, !tbaa !30
  %105 = load ptr, ptr %2, align 8, !tbaa !5
  %106 = getelementptr inbounds %struct.Transformation3D, ptr %105, i32 0, i32 5
  %107 = getelementptr inbounds %struct.Vect3D_f16, ptr %106, i32 0, i32 2
  store i16 %104, ptr %107, align 4, !tbaa !33
  %108 = load i16, ptr getelementptr inbounds (%struct.Context3D, ptr @context3D, i32 0, i32 3), align 2, !tbaa !34
  %109 = icmp ne i16 %108, 0
  br i1 %109, label %110, label %114

110:                                              ; preds = %1
  %111 = load ptr, ptr %2, align 8, !tbaa !5
  %112 = load ptr, ptr %2, align 8, !tbaa !5
  %113 = getelementptr inbounds %struct.Transformation3D, ptr %112, i32 0, i32 6
  call void @M3D_rotateInv(ptr noundef %111, ptr noundef getelementptr inbounds (%struct.Context3D, ptr @context3D, i32 0, i32 2), ptr noundef %113)
  br label %114

114:                                              ; preds = %110, %1
  ret void
}

attributes #0 = { 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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !11, i64 24}
!10 = !{!"", !11, i64 0, !6, i64 8, !6, i64 16, !12, i64 24, !12, i64 42, !13, i64 60, !13, i64 66}
!11 = !{!"short", !7, i64 0}
!12 = !{!"", !13, i64 0, !13, i64 6, !13, i64 12}
!13 = !{!"", !11, i64 0, !11, i64 2, !11, i64 4}
!14 = !{!10, !11, i64 42}
!15 = !{!10, !11, i64 26}
!16 = !{!10, !11, i64 48}
!17 = !{!10, !11, i64 28}
!18 = !{!10, !11, i64 54}
!19 = !{!10, !11, i64 30}
!20 = !{!10, !11, i64 44}
!21 = !{!10, !11, i64 32}
!22 = !{!10, !11, i64 50}
!23 = !{!10, !11, i64 34}
!24 = !{!10, !11, i64 56}
!25 = !{!10, !11, i64 36}
!26 = !{!10, !11, i64 46}
!27 = !{!10, !11, i64 38}
!28 = !{!10, !11, i64 52}
!29 = !{!10, !11, i64 40}
!30 = !{!10, !11, i64 58}
!31 = !{!10, !11, i64 60}
!32 = !{!10, !11, i64 62}
!33 = !{!10, !11, i64 64}
!34 = !{!35, !11, i64 12}
!35 = !{!"", !36, i64 0, !11, i64 4, !13, i64 6, !11, i64 12}
!36 = !{!"", !11, i64 0, !11, i64 2}


; 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.Context3D = type { %struct.Vect2D_u16, i16, %struct.Vect3D_f16, i16 }
%struct.Vect2D_u16 = type { i16, i16 }
%struct.Vect3D_f16 = type { i16, i16, i16 }

@context3D = external dso_local global %struct.Context3D, align 2

; Function Attrs: nounwind uwtable
declare dso_local void @M3D_rotateInv(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @M3D_buildMat3DExtras(ptr noundef %0) local_unnamed_addr #0 {
  %2 = getelementptr inbounds i8, ptr %0, i64 24
  %3 = getelementptr inbounds i8, ptr %0, i64 42
  %4 = load <8 x i16>, ptr %2, align 8, !tbaa !5
  %5 = shufflevector <8 x i16> %4, <8 x i16> poison, <8 x i32> <i32 0, i32 3, i32 6, i32 1, i32 4, i32 7, i32 2, i32 5>
  store <8 x i16> %5, ptr %3, align 2, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %0, i64 40
  %7 = load i16, ptr %6, align 4, !tbaa !9
  %8 = getelementptr inbounds i8, ptr %0, i64 58
  store i16 %7, ptr %8, align 2, !tbaa !14
  %9 = getelementptr inbounds i8, ptr %0, i64 60
  %10 = shufflevector <8 x i16> %4, <8 x i16> poison, <2 x i32> <i32 6, i32 7>
  store <2 x i16> %10, ptr %9, align 4, !tbaa !5
  %11 = getelementptr inbounds i8, ptr %0, i64 64
  store i16 %7, ptr %11, align 4, !tbaa !15
  %12 = load i16, ptr getelementptr inbounds (i8, ptr @context3D, i64 12), align 2, !tbaa !16
  %.not = icmp eq i16 %12, 0
  br i1 %.not, label %15, label %13

13:                                               ; preds = %1
  %14 = getelementptr inbounds i8, ptr %0, i64 66
  tail call void @M3D_rotateInv(ptr noundef nonnull %0, ptr noundef nonnull getelementptr inbounds (i8, ptr @context3D, i64 6), ptr noundef nonnull %14)
  br label %15

15:                                               ; preds = %13, %1
  ret void
}

attributes #0 = { 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 = !{!"short", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !6, i64 40}
!10 = !{!"", !6, i64 0, !11, i64 8, !11, i64 16, !12, i64 24, !12, i64 42, !13, i64 60, !13, i64 66}
!11 = !{!"any pointer", !7, i64 0}
!12 = !{!"", !13, i64 0, !13, i64 6, !13, i64 12}
!13 = !{!"", !6, i64 0, !6, i64 2, !6, i64 4}
!14 = !{!10, !6, i64 58}
!15 = !{!10, !6, i64 64}
!16 = !{!17, !6, i64 12}
!17 = !{!"", !18, i64 0, !6, i64 4, !13, i64 6, !6, i64 12}
!18 = !{!"", !6, i64 0, !6, i64 2}


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