; 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_translate(ptr noundef %0, ptr noundef %1, i16 noundef zeroext %2) #1 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i16, align 2
  %7 = alloca ptr, align 8
  %8 = alloca i16, align 2
  %9 = alloca ptr, align 8
  %10 = alloca i16, align 2
  %11 = alloca i16, align 2
  %12 = alloca i16, align 2
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store i16 %2, ptr %6, align 2, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #2
  call void @llvm.lifetime.start.p0(i64 2, ptr %8) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #2
  %13 = load ptr, ptr %4, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.Transformation3D, ptr %13, i32 0, i32 1
  %15 = load ptr, ptr %14, align 8, !tbaa !11
  store ptr %15, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 2, ptr %10) #2
  %16 = load ptr, ptr %9, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.Vect3D_f16, ptr %16, i32 0, i32 0
  %18 = load i16, ptr %17, align 2, !tbaa !15
  store i16 %18, ptr %10, align 2, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 2, ptr %11) #2
  %19 = load ptr, ptr %9, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.Vect3D_f16, ptr %19, i32 0, i32 1
  %21 = load i16, ptr %20, align 2, !tbaa !16
  store i16 %21, ptr %11, align 2, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 2, ptr %12) #2
  %22 = load ptr, ptr %9, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.Vect3D_f16, ptr %22, i32 0, i32 2
  %24 = load i16, ptr %23, align 2, !tbaa !17
  store i16 %24, ptr %12, align 2, !tbaa !9
  %25 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %25, ptr %7, align 8, !tbaa !5
  %26 = load i16, ptr %6, align 2, !tbaa !9
  store i16 %26, ptr %8, align 2, !tbaa !9
  br label %27

27:                                               ; preds = %31, %3
  %28 = load i16, ptr %8, align 2, !tbaa !9
  %29 = add i16 %28, -1
  store i16 %29, ptr %8, align 2, !tbaa !9
  %30 = icmp ne i16 %28, 0
  br i1 %30, label %31, label %56

31:                                               ; preds = %27
  %32 = load i16, ptr %10, align 2, !tbaa !9
  %33 = sext i16 %32 to i32
  %34 = load ptr, ptr %7, align 8, !tbaa !5
  %35 = getelementptr inbounds i16, ptr %34, i32 1
  store ptr %35, ptr %7, align 8, !tbaa !5
  %36 = load i16, ptr %34, align 2, !tbaa !9
  %37 = sext i16 %36 to i32
  %38 = add nsw i32 %37, %33
  %39 = trunc i32 %38 to i16
  store i16 %39, ptr %34, align 2, !tbaa !9
  %40 = load i16, ptr %11, align 2, !tbaa !9
  %41 = sext i16 %40 to i32
  %42 = load ptr, ptr %7, align 8, !tbaa !5
  %43 = getelementptr inbounds i16, ptr %42, i32 1
  store ptr %43, ptr %7, align 8, !tbaa !5
  %44 = load i16, ptr %42, align 2, !tbaa !9
  %45 = sext i16 %44 to i32
  %46 = add nsw i32 %45, %41
  %47 = trunc i32 %46 to i16
  store i16 %47, ptr %42, align 2, !tbaa !9
  %48 = load i16, ptr %12, align 2, !tbaa !9
  %49 = sext i16 %48 to i32
  %50 = load ptr, ptr %7, align 8, !tbaa !5
  %51 = getelementptr inbounds i16, ptr %50, i32 1
  store ptr %51, ptr %7, align 8, !tbaa !5
  %52 = load i16, ptr %50, align 2, !tbaa !9
  %53 = sext i16 %52 to i32
  %54 = add nsw i32 %53, %49
  %55 = trunc i32 %54 to i16
  store i16 %55, ptr %50, align 2, !tbaa !9
  br label %27, !llvm.loop !18

56:                                               ; preds = %27
  call void @llvm.lifetime.end.p0(i64 2, ptr %12) #2
  call void @llvm.lifetime.end.p0(i64 2, ptr %11) #2
  call void @llvm.lifetime.end.p0(i64 2, ptr %10) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #2
  call void @llvm.lifetime.end.p0(i64 2, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #2
  ret void
}

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 = { 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, !10, i64 0}
!10 = !{!"short", !7, i64 0}
!11 = !{!12, !6, i64 8}
!12 = !{!"", !10, i64 0, !6, i64 8, !6, i64 16, !13, i64 24, !13, i64 42, !14, i64 60, !14, i64 66}
!13 = !{!"", !14, i64 0, !14, i64 6, !14, i64 12}
!14 = !{!"", !10, i64 0, !10, i64 2, !10, i64 4}
!15 = !{!14, !10, i64 0}
!16 = !{!14, !10, i64 2}
!17 = !{!14, !10, i64 4}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}


; 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: nofree norecurse nosync nounwind memory(readwrite, inaccessiblemem: none) uwtable
define dso_local void @M3D_translate(ptr nocapture noundef readonly %0, ptr nocapture noundef %1, i16 noundef zeroext %2) local_unnamed_addr #0 {
  %4 = getelementptr inbounds i8, ptr %0, i64 8
  %5 = load ptr, ptr %4, align 8, !tbaa !5
  %6 = load <2 x i16>, ptr %5, align 2, !tbaa !13
  %7 = getelementptr inbounds i8, ptr %5, i64 4
  %8 = load i16, ptr %7, align 2, !tbaa !14
  %.not13 = icmp eq i16 %2, 0
  br i1 %.not13, label %._crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %3
  %xtraiter = and i16 %2, 1
  %lcmp.mod.not = icmp eq i16 %xtraiter, 0
  br i1 %lcmp.mod.not, label %.lr.ph.prol.loopexit, label %.lr.ph.prol

.lr.ph.prol:                                      ; preds = %.lr.ph.preheader
  %9 = add nsw i16 %2, -1
  %10 = getelementptr inbounds i8, ptr %1, i64 4
  %11 = load <2 x i16>, ptr %1, align 2, !tbaa !13
  %12 = add <2 x i16> %11, %6
  store <2 x i16> %12, ptr %1, align 2, !tbaa !13
  %13 = getelementptr inbounds i8, ptr %1, i64 6
  %14 = load i16, ptr %10, align 2, !tbaa !13
  %15 = add i16 %14, %8
  store i16 %15, ptr %10, align 2, !tbaa !13
  br label %.lr.ph.prol.loopexit

.lr.ph.prol.loopexit:                             ; preds = %.lr.ph.prol, %.lr.ph.preheader
  %.015.unr = phi ptr [ %1, %.lr.ph.preheader ], [ %13, %.lr.ph.prol ]
  %.01214.unr = phi i16 [ %2, %.lr.ph.preheader ], [ %9, %.lr.ph.prol ]
  %16 = icmp eq i16 %2, 1
  br i1 %16, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.prol.loopexit, %.lr.ph
  %.015 = phi ptr [ %27, %.lr.ph ], [ %.015.unr, %.lr.ph.prol.loopexit ]
  %.01214 = phi i16 [ %23, %.lr.ph ], [ %.01214.unr, %.lr.ph.prol.loopexit ]
  %17 = getelementptr inbounds i8, ptr %.015, i64 4
  %18 = load <2 x i16>, ptr %.015, align 2, !tbaa !13
  %19 = add <2 x i16> %18, %6
  store <2 x i16> %19, ptr %.015, align 2, !tbaa !13
  %20 = getelementptr inbounds i8, ptr %.015, i64 6
  %21 = load i16, ptr %17, align 2, !tbaa !13
  %22 = add i16 %21, %8
  store i16 %22, ptr %17, align 2, !tbaa !13
  %23 = add i16 %.01214, -2
  %24 = getelementptr inbounds i8, ptr %.015, i64 10
  %25 = load <2 x i16>, ptr %20, align 2, !tbaa !13
  %26 = add <2 x i16> %25, %6
  store <2 x i16> %26, ptr %20, align 2, !tbaa !13
  %27 = getelementptr inbounds i8, ptr %.015, i64 12
  %28 = load i16, ptr %24, align 2, !tbaa !13
  %29 = add i16 %28, %8
  store i16 %29, ptr %24, align 2, !tbaa !13
  %.not.1 = icmp eq i16 %23, 0
  br i1 %.not.1, label %._crit_edge, label %.lr.ph, !llvm.loop !15

._crit_edge:                                      ; preds = %.lr.ph.prol.loopexit, %.lr.ph, %3
  ret void
}

attributes #0 = { nofree norecurse nosync nounwind memory(readwrite, inaccessiblemem: none) 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, !10, i64 8}
!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 = !{!7, !7, i64 0}
!14 = !{!12, !7, i64 4}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SLPVectorizerPass,SROAPass,SimplifyCFGPass