; LLVM IR from danginsburg/opengles3-book :: Common/Source (esTransform)

; 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.ESMatrix = type { [4 x [4 x float]] }

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

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

; 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 @esOrtho(ptr noundef %0, float noundef %1, float noundef %2, float noundef %3, float noundef %4, float noundef %5, float noundef %6) #1 {
  %8 = alloca ptr, align 8
  %9 = alloca float, align 4
  %10 = alloca float, align 4
  %11 = alloca float, align 4
  %12 = alloca float, align 4
  %13 = alloca float, align 4
  %14 = alloca float, align 4
  %15 = alloca float, align 4
  %16 = alloca float, align 4
  %17 = alloca float, align 4
  %18 = alloca %struct.ESMatrix, align 4
  %19 = alloca i32, align 4
  store ptr %0, ptr %8, align 8, !tbaa !5
  store float %1, ptr %9, align 4, !tbaa !9
  store float %2, ptr %10, align 4, !tbaa !9
  store float %3, ptr %11, align 4, !tbaa !9
  store float %4, ptr %12, align 4, !tbaa !9
  store float %5, ptr %13, align 4, !tbaa !9
  store float %6, ptr %14, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #2
  %20 = load float, ptr %10, align 4, !tbaa !9
  %21 = load float, ptr %9, align 4, !tbaa !9
  %22 = fsub float %20, %21
  store float %22, ptr %15, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %16) #2
  %23 = load float, ptr %12, align 4, !tbaa !9
  %24 = load float, ptr %11, align 4, !tbaa !9
  %25 = fsub float %23, %24
  store float %25, ptr %16, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %17) #2
  %26 = load float, ptr %14, align 4, !tbaa !9
  %27 = load float, ptr %13, align 4, !tbaa !9
  %28 = fsub float %26, %27
  store float %28, ptr %17, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 64, ptr %18) #2
  %29 = load float, ptr %15, align 4, !tbaa !9
  %30 = fcmp oeq float %29, 0.000000e+00
  br i1 %30, label %37, label %31

31:                                               ; preds = %7
  %32 = load float, ptr %16, align 4, !tbaa !9
  %33 = fcmp oeq float %32, 0.000000e+00
  br i1 %33, label %37, label %34

34:                                               ; preds = %31
  %35 = load float, ptr %17, align 4, !tbaa !9
  %36 = fcmp oeq float %35, 0.000000e+00
  br i1 %36, label %37, label %38

37:                                               ; preds = %34, %31, %7
  store i32 1, ptr %19, align 4
  br label %83

38:                                               ; preds = %34
  call void @esMatrixLoadIdentity(ptr noundef %18)
  %39 = load float, ptr %15, align 4, !tbaa !9
  %40 = fdiv float 2.000000e+00, %39
  %41 = getelementptr inbounds %struct.ESMatrix, ptr %18, i32 0, i32 0
  %42 = getelementptr inbounds [4 x [4 x float]], ptr %41, i64 0, i64 0
  %43 = getelementptr inbounds [4 x float], ptr %42, i64 0, i64 0
  store float %40, ptr %43, align 4, !tbaa !9
  %44 = load float, ptr %10, align 4, !tbaa !9
  %45 = load float, ptr %9, align 4, !tbaa !9
  %46 = fadd float %44, %45
  %47 = fneg float %46
  %48 = load float, ptr %15, align 4, !tbaa !9
  %49 = fdiv float %47, %48
  %50 = getelementptr inbounds %struct.ESMatrix, ptr %18, i32 0, i32 0
  %51 = getelementptr inbounds [4 x [4 x float]], ptr %50, i64 0, i64 3
  %52 = getelementptr inbounds [4 x float], ptr %51, i64 0, i64 0
  store float %49, ptr %52, align 4, !tbaa !9
  %53 = load float, ptr %16, align 4, !tbaa !9
  %54 = fdiv float 2.000000e+00, %53
  %55 = getelementptr inbounds %struct.ESMatrix, ptr %18, i32 0, i32 0
  %56 = getelementptr inbounds [4 x [4 x float]], ptr %55, i64 0, i64 1
  %57 = getelementptr inbounds [4 x float], ptr %56, i64 0, i64 1
  store float %54, ptr %57, align 4, !tbaa !9
  %58 = load float, ptr %12, align 4, !tbaa !9
  %59 = load float, ptr %11, align 4, !tbaa !9
  %60 = fadd float %58, %59
  %61 = fneg float %60
  %62 = load float, ptr %16, align 4, !tbaa !9
  %63 = fdiv float %61, %62
  %64 = getelementptr inbounds %struct.ESMatrix, ptr %18, i32 0, i32 0
  %65 = getelementptr inbounds [4 x [4 x float]], ptr %64, i64 0, i64 3
  %66 = getelementptr inbounds [4 x float], ptr %65, i64 0, i64 1
  store float %63, ptr %66, align 4, !tbaa !9
  %67 = load float, ptr %17, align 4, !tbaa !9
  %68 = fdiv float -2.000000e+00, %67
  %69 = getelementptr inbounds %struct.ESMatrix, ptr %18, i32 0, i32 0
  %70 = getelementptr inbounds [4 x [4 x float]], ptr %69, i64 0, i64 2
  %71 = getelementptr inbounds [4 x float], ptr %70, i64 0, i64 2
  store float %68, ptr %71, align 4, !tbaa !9
  %72 = load float, ptr %13, align 4, !tbaa !9
  %73 = load float, ptr %14, align 4, !tbaa !9
  %74 = fadd float %72, %73
  %75 = fneg float %74
  %76 = load float, ptr %17, align 4, !tbaa !9
  %77 = fdiv float %75, %76
  %78 = getelementptr inbounds %struct.ESMatrix, ptr %18, i32 0, i32 0
  %79 = getelementptr inbounds [4 x [4 x float]], ptr %78, i64 0, i64 3
  %80 = getelementptr inbounds [4 x float], ptr %79, i64 0, i64 2
  store float %77, ptr %80, align 4, !tbaa !9
  %81 = load ptr, ptr %8, align 8, !tbaa !5
  %82 = load ptr, ptr %8, align 8, !tbaa !5
  call void @esMatrixMultiply(ptr noundef %81, ptr noundef %18, ptr noundef %82)
  store i32 0, ptr %19, align 4
  br label %83

83:                                               ; preds = %38, %37
  call void @llvm.lifetime.end.p0(i64 64, ptr %18) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %17) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %16) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #2
  %84 = load i32, ptr %19, align 4
  switch i32 %84, label %86 [
    i32 0, label %85
    i32 1, label %85
  ]

85:                                               ; preds = %83, %83
  ret void

86:                                               ; preds = %83
  unreachable
}

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

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 = !{!"float", !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.ESMatrix = type { [4 x [4 x float]] }

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

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

; Function Attrs: mustprogress 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 @esOrtho(ptr noundef %0, float noundef %1, float noundef %2, float noundef %3, float noundef %4, float noundef %5, float noundef %6) local_unnamed_addr #1 {
  %8 = alloca %struct.ESMatrix, align 4
  %9 = insertelement <2 x float> poison, float %2, i64 0
  %10 = insertelement <2 x float> %9, float %4, i64 1
  %11 = insertelement <2 x float> poison, float %1, i64 0
  %12 = insertelement <2 x float> %11, float %3, i64 1
  %13 = fsub <2 x float> %10, %12
  %14 = fsub float %6, %5
  call void @llvm.lifetime.start.p0(i64 64, ptr nonnull %8) #2
  %15 = extractelement <2 x float> %13, i64 0
  %16 = fcmp oeq float %15, 0.000000e+00
  %17 = extractelement <2 x float> %13, i64 1
  %18 = fcmp oeq float %17, 0.000000e+00
  %or.cond = or i1 %16, %18
  %19 = fcmp oeq float %14, 0.000000e+00
  %or.cond3 = or i1 %or.cond, %19
  br i1 %or.cond3, label %34, label %20

20:                                               ; preds = %7
  call void @esMatrixLoadIdentity(ptr noundef nonnull %8)
  %21 = fdiv float 2.000000e+00, %15
  store float %21, ptr %8, align 4, !tbaa !5
  %22 = fadd <2 x float> %12, %10
  %23 = getelementptr inbounds i8, ptr %8, i64 48
  %24 = fdiv float 2.000000e+00, %17
  %25 = getelementptr inbounds i8, ptr %8, i64 20
  store float %24, ptr %25, align 4, !tbaa !5
  %26 = fneg <2 x float> %22
  %27 = fdiv <2 x float> %26, %13
  store <2 x float> %27, ptr %23, align 4, !tbaa !5
  %28 = fdiv float -2.000000e+00, %14
  %29 = getelementptr inbounds i8, ptr %8, i64 40
  store float %28, ptr %29, align 4, !tbaa !5
  %30 = fadd float %5, %6
  %31 = fneg float %30
  %32 = fdiv float %31, %14
  %33 = getelementptr inbounds i8, ptr %8, i64 56
  store float %32, ptr %33, align 4, !tbaa !5
  call void @esMatrixMultiply(ptr noundef %0, ptr noundef nonnull %8, ptr noundef %0)
  br label %34

34:                                               ; preds = %7, %20
  call void @llvm.lifetime.end.p0(i64 64, ptr nonnull %8) #2
  ret void
}

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

attributes #0 = { mustprogress 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 = !{!"float", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}


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