; LLVM IR from danginsburg/opengles3-book :: Chapter_14/TerrainRendering (TerrainRendering)

; 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]] }
%struct.ESContext = type { ptr, ptr, i32, i32, ptr, i64, ptr, ptr, ptr, ptr, ptr, ptr, ptr }
%struct.UserData = type { i32, i32, i32, i32, i32, i32, i32, i32, i32, %struct.ESMatrix }

; 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 i32 @InitMVP(ptr noundef %0) #1 {
  %2 = alloca ptr, align 8
  %3 = alloca %struct.ESMatrix, align 4
  %4 = alloca %struct.ESMatrix, align 4
  %5 = alloca float, align 4
  %6 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 64, ptr %3) #3
  call void @llvm.lifetime.start.p0(i64 64, ptr %4) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %7 = load ptr, ptr %2, align 8, !tbaa !5
  %8 = getelementptr inbounds %struct.ESContext, ptr %7, i32 0, i32 1
  %9 = load ptr, ptr %8, align 8, !tbaa !9
  store ptr %9, ptr %6, align 8, !tbaa !5
  %10 = load ptr, ptr %2, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.ESContext, ptr %10, i32 0, i32 2
  %12 = load i32, ptr %11, align 8, !tbaa !13
  %13 = sitofp i32 %12 to float
  %14 = load ptr, ptr %2, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.ESContext, ptr %14, i32 0, i32 3
  %16 = load i32, ptr %15, align 4, !tbaa !14
  %17 = sitofp i32 %16 to float
  %18 = fdiv float %13, %17
  store float %18, ptr %5, align 4, !tbaa !15
  call void @esMatrixLoadIdentity(ptr noundef %3)
  %19 = load float, ptr %5, align 4, !tbaa !15
  call void @esPerspective(ptr noundef %3, float noundef 6.000000e+01, float noundef %19, float noundef 0x3FB99999A0000000, float noundef 2.000000e+01)
  call void @esMatrixLoadIdentity(ptr noundef %4)
  call void @esTranslate(ptr noundef %4, float noundef -5.000000e-01, float noundef -5.000000e-01, float noundef 0xBFE6666660000000)
  call void @esRotate(ptr noundef %4, float noundef 4.500000e+01, float noundef 1.000000e+00, float noundef 0.000000e+00, float noundef 0.000000e+00)
  %20 = load ptr, ptr %6, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.UserData, ptr %20, i32 0, i32 9
  call void @esMatrixMultiply(ptr noundef %21, ptr noundef %4, ptr noundef %3)
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 64, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 64, ptr %3) #3
  ret i32 1
}

declare void @esMatrixLoadIdentity(ptr noundef) #2

declare void @esPerspective(ptr noundef, float noundef, float noundef, float noundef, float noundef) #2

declare void @esTranslate(ptr noundef, float noundef, float noundef, float noundef) #2

declare void @esRotate(ptr noundef, float noundef, float noundef, float noundef, float noundef) #2

declare void @esMatrixMultiply(ptr noundef, ptr noundef, ptr noundef) #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 = { "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 = { 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, !6, i64 8}
!10 = !{!"ESContext", !6, i64 0, !6, i64 8, !11, i64 16, !11, i64 20, !6, i64 24, !12, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !6, i64 64, !6, i64 72, !6, i64 80, !6, i64 88}
!11 = !{!"int", !7, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!10, !11, i64 16}
!14 = !{!10, !11, i64 20}
!15 = !{!16, !16, i64 0}
!16 = !{!"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: 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 noundef i32 @InitMVP(ptr nocapture noundef readonly %0) local_unnamed_addr #1 {
  %2 = alloca %struct.ESMatrix, align 4
  %3 = alloca %struct.ESMatrix, align 4
  call void @llvm.lifetime.start.p0(i64 64, ptr nonnull %2) #3
  call void @llvm.lifetime.start.p0(i64 64, ptr nonnull %3) #3
  %4 = getelementptr inbounds i8, ptr %0, i64 8
  %5 = load ptr, ptr %4, align 8, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %0, i64 16
  %7 = load <2 x i32>, ptr %6, align 8, !tbaa !12
  %8 = sitofp <2 x i32> %7 to <2 x float>
  %9 = extractelement <2 x float> %8, i64 0
  %10 = extractelement <2 x float> %8, i64 1
  %11 = fdiv float %9, %10
  call void @esMatrixLoadIdentity(ptr noundef nonnull %2) #3
  call void @esPerspective(ptr noundef nonnull %2, float noundef 6.000000e+01, float noundef %11, float noundef 0x3FB99999A0000000, float noundef 2.000000e+01) #3
  call void @esMatrixLoadIdentity(ptr noundef nonnull %3) #3
  call void @esTranslate(ptr noundef nonnull %3, float noundef -5.000000e-01, float noundef -5.000000e-01, float noundef 0xBFE6666660000000) #3
  call void @esRotate(ptr noundef nonnull %3, float noundef 4.500000e+01, float noundef 1.000000e+00, float noundef 0.000000e+00, float noundef 0.000000e+00) #3
  %12 = getelementptr inbounds i8, ptr %5, i64 36
  call void @esMatrixMultiply(ptr noundef nonnull %12, ptr noundef nonnull %3, ptr noundef nonnull %2) #3
  call void @llvm.lifetime.end.p0(i64 64, ptr nonnull %3) #3
  call void @llvm.lifetime.end.p0(i64 64, ptr nonnull %2) #3
  ret i32 1
}

declare void @esMatrixLoadIdentity(ptr noundef) local_unnamed_addr #2

declare void @esPerspective(ptr noundef, float noundef, float noundef, float noundef, float noundef) local_unnamed_addr #2

declare void @esTranslate(ptr noundef, float noundef, float noundef, float noundef) local_unnamed_addr #2

declare void @esRotate(ptr noundef, float noundef, float noundef, float noundef, float noundef) local_unnamed_addr #2

declare void @esMatrixMultiply(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

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 = { "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 = { 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, !7, i64 8}
!6 = !{!"ESContext", !7, i64 0, !7, i64 8, !10, i64 16, !10, i64 20, !7, i64 24, !11, i64 32, !7, i64 40, !7, i64 48, !7, i64 56, !7, i64 64, !7, i64 72, !7, i64 80, !7, i64 88}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"long", !8, i64 0}
!12 = !{!10, !10, i64 0}


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