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

; 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, ptr, ptr, ptr, i32, float, %struct.ESMatrix, %struct.ESMatrix, float, i32 }

; 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 @Update(ptr noundef %0, float noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca float, align 4
  %5 = alloca ptr, align 8
  %6 = alloca %struct.ESMatrix, align 4
  %7 = alloca float, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store float %1, ptr %4, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  %8 = load ptr, ptr %3, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct.ESContext, ptr %8, i32 0, i32 1
  %10 = load ptr, ptr %9, align 8, !tbaa !11
  store ptr %10, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 64, ptr %6) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  %11 = load float, ptr %4, align 4, !tbaa !9
  %12 = load ptr, ptr %5, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.UserData, ptr %12, i32 0, i32 15
  %14 = load float, ptr %13, align 8, !tbaa !15
  %15 = fadd float %14, %11
  store float %15, ptr %13, align 8, !tbaa !15
  %16 = load ptr, ptr %3, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.ESContext, ptr %16, i32 0, i32 2
  %18 = load i32, ptr %17, align 8, !tbaa !18
  %19 = sitofp i32 %18 to float
  %20 = load ptr, ptr %3, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.ESContext, ptr %20, i32 0, i32 3
  %22 = load i32, ptr %21, align 4, !tbaa !19
  %23 = sitofp i32 %22 to float
  %24 = fdiv float %19, %23
  store float %24, ptr %7, align 4, !tbaa !9
  call void @esMatrixLoadIdentity(ptr noundef %6)
  %25 = load float, ptr %7, align 4, !tbaa !9
  call void @esPerspective(ptr noundef %6, float noundef 6.000000e+01, float noundef %25, float noundef 1.000000e+00, float noundef 2.000000e+01)
  %26 = load ptr, ptr %5, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.UserData, ptr %26, i32 0, i32 13
  call void @esMatrixLoadIdentity(ptr noundef %27)
  %28 = load ptr, ptr %5, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.UserData, ptr %28, i32 0, i32 13
  call void @esTranslate(ptr noundef %29, float noundef 0.000000e+00, float noundef -2.500000e+00, float noundef -2.500000e+00)
  %30 = load ptr, ptr %5, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.UserData, ptr %30, i32 0, i32 13
  %32 = load ptr, ptr %5, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.UserData, ptr %32, i32 0, i32 12
  %34 = load float, ptr %33, align 4, !tbaa !20
  call void @esRotate(ptr noundef %31, float noundef %34, float noundef 1.000000e+00, float noundef 0.000000e+00, float noundef 1.000000e+00)
  %35 = load ptr, ptr %5, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.UserData, ptr %35, i32 0, i32 14
  %37 = load ptr, ptr %5, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.UserData, ptr %37, i32 0, i32 13
  call void @esMatrixMultiply(ptr noundef %36, ptr noundef %38, ptr noundef %6)
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 64, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  ret void
}

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, !10, i64 0}
!10 = !{!"float", !7, i64 0}
!11 = !{!12, !6, i64 8}
!12 = !{!"ESContext", !6, i64 0, !6, i64 8, !13, i64 16, !13, i64 20, !6, i64 24, !14, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !6, i64 64, !6, i64 72, !6, i64 80, !6, i64 88}
!13 = !{!"int", !7, i64 0}
!14 = !{!"long", !7, i64 0}
!15 = !{!16, !10, i64 192}
!16 = !{!"", !13, i64 0, !13, i64 4, !13, i64 8, !13, i64 12, !13, i64 16, !13, i64 20, !13, i64 24, !13, i64 28, !6, i64 32, !6, i64 40, !6, i64 48, !13, i64 56, !10, i64 60, !17, i64 64, !17, i64 128, !10, i64 192, !13, i64 196}
!17 = !{!"", !7, i64 0}
!18 = !{!12, !13, i64 16}
!19 = !{!12, !13, i64 20}
!20 = !{!16, !10, i64 60}


; 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 void @Update(ptr nocapture noundef readonly %0, float noundef %1) local_unnamed_addr #1 {
  %3 = alloca %struct.ESMatrix, align 4
  %4 = getelementptr inbounds i8, ptr %0, i64 8
  %5 = load ptr, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 64, ptr nonnull %3) #3
  %6 = getelementptr inbounds i8, ptr %5, i64 192
  %7 = load float, ptr %6, align 8, !tbaa !12
  %8 = fadd float %7, %1
  store float %8, ptr %6, align 8, !tbaa !12
  %9 = getelementptr inbounds i8, ptr %0, i64 16
  %10 = load <2 x i32>, ptr %9, align 8, !tbaa !16
  %11 = sitofp <2 x i32> %10 to <2 x float>
  %12 = extractelement <2 x float> %11, i64 0
  %13 = extractelement <2 x float> %11, i64 1
  %14 = fdiv float %12, %13
  call void @esMatrixLoadIdentity(ptr noundef nonnull %3) #3
  call void @esPerspective(ptr noundef nonnull %3, float noundef 6.000000e+01, float noundef %14, float noundef 1.000000e+00, float noundef 2.000000e+01) #3
  %15 = getelementptr inbounds i8, ptr %5, i64 64
  call void @esMatrixLoadIdentity(ptr noundef nonnull %15) #3
  call void @esTranslate(ptr noundef nonnull %15, float noundef 0.000000e+00, float noundef -2.500000e+00, float noundef -2.500000e+00) #3
  %16 = getelementptr inbounds i8, ptr %5, i64 60
  %17 = load float, ptr %16, align 4, !tbaa !17
  call void @esRotate(ptr noundef nonnull %15, float noundef %17, float noundef 1.000000e+00, float noundef 0.000000e+00, float noundef 1.000000e+00) #3
  %18 = getelementptr inbounds i8, ptr %5, i64 128
  call void @esMatrixMultiply(ptr noundef nonnull %18, ptr noundef nonnull %15, ptr noundef nonnull %3) #3
  call void @llvm.lifetime.end.p0(i64 64, ptr nonnull %3) #3
  ret void
}

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 = !{!13, !14, i64 192}
!13 = !{!"", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20, !10, i64 24, !10, i64 28, !7, i64 32, !7, i64 40, !7, i64 48, !10, i64 56, !14, i64 60, !15, i64 64, !15, i64 128, !14, i64 192, !10, i64 196}
!14 = !{!"float", !8, i64 0}
!15 = !{!"", !8, i64 0}
!16 = !{!10, !10, i64 0}
!17 = !{!13, !14, i64 60}


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