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

; 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: nounwind uwtable
define dso_local void @M3D_combineTranslationLeft(ptr noundef %0, ptr noundef %1, ptr noundef %2) #1 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  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
  %10 = load ptr, ptr %5, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.Transformation3D, ptr %10, i32 0, i32 0
  %12 = load i16, ptr %11, align 8, !tbaa !9
  %13 = icmp ne i16 %12, 0
  br i1 %13, label %14, label %16

14:                                               ; preds = %3
  %15 = load ptr, ptr %5, align 8, !tbaa !5
  call void @M3D_buildMat3D(ptr noundef %15)
  br label %16

16:                                               ; preds = %14, %3
  %17 = load ptr, ptr %6, align 8, !tbaa !5
  %18 = load ptr, ptr %5, align 8, !tbaa !5
  %19 = icmp ne ptr %17, %18
  br i1 %19, label %20, label %37

20:                                               ; preds = %16
  %21 = load ptr, ptr %6, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.Transformation3D, ptr %21, i32 0, i32 3
  %23 = load ptr, ptr %5, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.Transformation3D, ptr %23, i32 0, i32 3
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %22, ptr align 8 %24, i64 18, i1 false), !tbaa.struct !14
  %25 = load ptr, ptr %6, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.Transformation3D, ptr %25, i32 0, i32 4
  %27 = load ptr, ptr %5, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.Transformation3D, ptr %27, i32 0, i32 4
  call void @llvm.memcpy.p0.p0.i64(ptr align 2 %26, ptr align 2 %28, i64 18, i1 false), !tbaa.struct !14
  %29 = load ptr, ptr %6, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.Transformation3D, ptr %29, i32 0, i32 5
  %31 = load ptr, ptr %5, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.Transformation3D, ptr %31, i32 0, i32 5
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %30, ptr align 4 %32, i64 6, i1 false), !tbaa.struct !16
  %33 = load ptr, ptr %6, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.Transformation3D, ptr %33, i32 0, i32 6
  %35 = load ptr, ptr %5, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.Transformation3D, ptr %35, i32 0, i32 6
  call void @llvm.memcpy.p0.p0.i64(ptr align 2 %34, ptr align 2 %36, i64 6, i1 false), !tbaa.struct !16
  br label %37

37:                                               ; preds = %20, %16
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  %38 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %38, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  %39 = load ptr, ptr %5, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.Transformation3D, ptr %39, i32 0, i32 1
  %41 = load ptr, ptr %40, align 8, !tbaa !17
  store ptr %41, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  %42 = load ptr, ptr %6, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.Transformation3D, ptr %42, i32 0, i32 1
  %44 = load ptr, ptr %43, align 8, !tbaa !17
  store ptr %44, ptr %9, align 8, !tbaa !5
  %45 = load ptr, ptr %7, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.Vect3D_f16, ptr %45, i32 0, i32 0
  %47 = load i16, ptr %46, align 2, !tbaa !18
  %48 = sext i16 %47 to i32
  %49 = load ptr, ptr %8, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.Vect3D_f16, ptr %49, i32 0, i32 0
  %51 = load i16, ptr %50, align 2, !tbaa !18
  %52 = sext i16 %51 to i32
  %53 = add nsw i32 %48, %52
  %54 = trunc i32 %53 to i16
  %55 = load ptr, ptr %9, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.Vect3D_f16, ptr %55, i32 0, i32 0
  store i16 %54, ptr %56, align 2, !tbaa !18
  %57 = load ptr, ptr %7, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.Vect3D_f16, ptr %57, i32 0, i32 1
  %59 = load i16, ptr %58, align 2, !tbaa !19
  %60 = sext i16 %59 to i32
  %61 = load ptr, ptr %8, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.Vect3D_f16, ptr %61, i32 0, i32 1
  %63 = load i16, ptr %62, align 2, !tbaa !19
  %64 = sext i16 %63 to i32
  %65 = add nsw i32 %60, %64
  %66 = trunc i32 %65 to i16
  %67 = load ptr, ptr %9, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct.Vect3D_f16, ptr %67, i32 0, i32 1
  store i16 %66, ptr %68, align 2, !tbaa !19
  %69 = load ptr, ptr %7, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct.Vect3D_f16, ptr %69, i32 0, i32 2
  %71 = load i16, ptr %70, align 2, !tbaa !20
  %72 = sext i16 %71 to i32
  %73 = load ptr, ptr %8, align 8, !tbaa !5
  %74 = getelementptr inbounds %struct.Vect3D_f16, ptr %73, i32 0, i32 2
  %75 = load i16, ptr %74, align 2, !tbaa !20
  %76 = sext i16 %75 to i32
  %77 = add nsw i32 %72, %76
  %78 = trunc i32 %77 to i16
  %79 = load ptr, ptr %9, align 8, !tbaa !5
  %80 = getelementptr inbounds %struct.Vect3D_f16, ptr %79, i32 0, i32 2
  store i16 %78, ptr %80, align 2, !tbaa !20
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  ret void
}

; Function Attrs: nounwind uwtable
declare dso_local void @M3D_buildMat3D(ptr noundef) #1

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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/C++ TBAA"}
!9 = !{!10, !11, i64 0}
!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 = !{i64 0, i64 2, !15, i64 2, i64 2, !15, i64 4, i64 2, !15, i64 6, i64 2, !15, i64 8, i64 2, !15, i64 10, i64 2, !15, i64 12, i64 2, !15, i64 14, i64 2, !15, i64 16, i64 2, !15}
!15 = !{!11, !11, i64 0}
!16 = !{i64 0, i64 2, !15, i64 2, i64 2, !15, i64 4, i64 2, !15}
!17 = !{!10, !6, i64 8}
!18 = !{!13, !11, i64 0}
!19 = !{!13, !11, i64 2}
!20 = !{!13, !11, i64 4}


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

; Function Attrs: nounwind uwtable
define dso_local void @M3D_combineTranslationLeft(ptr nocapture noundef readonly %0, ptr noundef %1, ptr noundef %2) local_unnamed_addr #0 {
  %4 = load i16, ptr %1, align 8, !tbaa !5
  %.not = icmp eq i16 %4, 0
  br i1 %.not, label %6, label %5

5:                                                ; preds = %3
  tail call void @M3D_buildMat3D(ptr noundef nonnull %1)
  br label %6

6:                                                ; preds = %5, %3
  %.not25 = icmp eq ptr %2, %1
  br i1 %.not25, label %16, label %7

7:                                                ; preds = %6
  %8 = getelementptr inbounds i8, ptr %2, i64 24
  %9 = getelementptr inbounds i8, ptr %1, i64 24
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(18) %8, ptr noundef nonnull align 8 dereferenceable(18) %9, i64 18, i1 false), !tbaa.struct !13
  %10 = getelementptr inbounds i8, ptr %2, i64 42
  %11 = getelementptr inbounds i8, ptr %1, i64 42
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 2 dereferenceable(18) %10, ptr noundef nonnull align 2 dereferenceable(18) %11, i64 18, i1 false), !tbaa.struct !13
  %12 = getelementptr inbounds i8, ptr %2, i64 60
  %13 = getelementptr inbounds i8, ptr %1, i64 60
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 4 dereferenceable(6) %12, ptr noundef nonnull align 4 dereferenceable(6) %13, i64 6, i1 false), !tbaa.struct !15
  %14 = getelementptr inbounds i8, ptr %2, i64 66
  %15 = getelementptr inbounds i8, ptr %1, i64 66
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 2 dereferenceable(6) %14, ptr noundef nonnull align 2 dereferenceable(6) %15, i64 6, i1 false), !tbaa.struct !15
  br label %16

16:                                               ; preds = %7, %6
  %17 = getelementptr inbounds i8, ptr %1, i64 8
  %18 = load ptr, ptr %17, align 8, !tbaa !16
  %19 = getelementptr inbounds i8, ptr %2, i64 8
  %20 = load ptr, ptr %19, align 8, !tbaa !16
  %21 = load <2 x i16>, ptr %0, align 2, !tbaa !14
  %22 = load <2 x i16>, ptr %18, align 2, !tbaa !14
  %23 = add <2 x i16> %22, %21
  store <2 x i16> %23, ptr %20, align 2, !tbaa !14
  %24 = getelementptr inbounds i8, ptr %0, i64 4
  %25 = load i16, ptr %24, align 2, !tbaa !17
  %26 = getelementptr inbounds i8, ptr %18, i64 4
  %27 = load i16, ptr %26, align 2, !tbaa !17
  %28 = add i16 %27, %25
  %29 = getelementptr inbounds i8, ptr %20, i64 4
  store i16 %28, ptr %29, align 2, !tbaa !17
  ret void
}

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

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #1

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" }
attributes #1 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }

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


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SLPVectorizerPass,SROAPass,TailCallElimPass