; LLVM IR from danginsburg/opengles3-book :: Chapter_8/Simple_VertexShader (Simple_VertexShader)

; 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, ptr, ptr, i32, float, %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 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 %struct.ESMatrix, align 4
  %8 = 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) #4
  %9 = load ptr, ptr %3, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct.ESContext, ptr %9, i32 0, i32 1
  %11 = load ptr, ptr %10, align 8, !tbaa !11
  store ptr %11, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 64, ptr %6) #4
  call void @llvm.lifetime.start.p0(i64 64, ptr %7) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  %12 = load float, ptr %4, align 4, !tbaa !9
  %13 = load ptr, ptr %5, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.UserData, ptr %13, i32 0, i32 5
  %15 = load float, ptr %14, align 4, !tbaa !15
  %16 = call float @llvm.fmuladd.f32(float %12, float 4.000000e+01, float %15)
  store float %16, ptr %14, align 4, !tbaa !15
  %17 = load ptr, ptr %5, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.UserData, ptr %17, i32 0, i32 5
  %19 = load float, ptr %18, align 4, !tbaa !15
  %20 = fcmp oge float %19, 3.600000e+02
  br i1 %20, label %21, label %26

21:                                               ; preds = %2
  %22 = load ptr, ptr %5, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.UserData, ptr %22, i32 0, i32 5
  %24 = load float, ptr %23, align 4, !tbaa !15
  %25 = fsub float %24, 3.600000e+02
  store float %25, ptr %23, align 4, !tbaa !15
  br label %26

26:                                               ; preds = %21, %2
  %27 = load ptr, ptr %3, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.ESContext, ptr %27, i32 0, i32 2
  %29 = load i32, ptr %28, align 8, !tbaa !18
  %30 = sitofp i32 %29 to float
  %31 = load ptr, ptr %3, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.ESContext, ptr %31, i32 0, i32 3
  %33 = load i32, ptr %32, align 4, !tbaa !19
  %34 = sitofp i32 %33 to float
  %35 = fdiv float %30, %34
  store float %35, ptr %8, align 4, !tbaa !9
  call void @esMatrixLoadIdentity(ptr noundef %6)
  %36 = load float, ptr %8, align 4, !tbaa !9
  call void @esPerspective(ptr noundef %6, float noundef 6.000000e+01, float noundef %36, float noundef 1.000000e+00, float noundef 2.000000e+01)
  call void @esMatrixLoadIdentity(ptr noundef %7)
  call void @esTranslate(ptr noundef %7, float noundef 0.000000e+00, float noundef 0.000000e+00, float noundef -2.000000e+00)
  %37 = load ptr, ptr %5, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.UserData, ptr %37, i32 0, i32 5
  %39 = load float, ptr %38, align 4, !tbaa !15
  call void @esRotate(ptr noundef %7, float noundef %39, float noundef 1.000000e+00, float noundef 0.000000e+00, float noundef 1.000000e+00)
  %40 = load ptr, ptr %5, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.UserData, ptr %40, i32 0, i32 6
  call void @esMatrixMultiply(ptr noundef %41, ptr noundef %7, ptr noundef %6)
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 64, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 64, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  ret void
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare float @llvm.fmuladd.f32(float, float, float) #2

declare void @esMatrixLoadIdentity(ptr noundef) #3

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

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

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

declare void @esMatrixMultiply(ptr noundef, ptr noundef, ptr noundef) #3

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 nosync nounwind speculatable willreturn memory(none) }
attributes #3 = { "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 #4 = { 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 28}
!16 = !{!"", !13, i64 0, !13, i64 4, !6, i64 8, !6, i64 16, !13, i64 24, !10, i64 28, !17, i64 32}
!17 = !{!"", !7, i64 0}
!18 = !{!12, !13, i64 16}
!19 = !{!12, !13, i64 20}


; 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 = alloca %struct.ESMatrix, align 4
  %5 = getelementptr inbounds i8, ptr %0, i64 8
  %6 = load ptr, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 64, ptr nonnull %3) #4
  call void @llvm.lifetime.start.p0(i64 64, ptr nonnull %4) #4
  %7 = getelementptr inbounds i8, ptr %6, i64 28
  %8 = load float, ptr %7, align 4, !tbaa !12
  %9 = tail call float @llvm.fmuladd.f32(float %1, float 4.000000e+01, float %8)
  %10 = fcmp ult float %9, 3.600000e+02
  %11 = fadd float %9, -3.600000e+02
  %storemerge = select i1 %10, float %9, float %11
  store float %storemerge, ptr %7, align 4, !tbaa !12
  %12 = getelementptr inbounds i8, ptr %0, i64 16
  %13 = load <2 x i32>, ptr %12, align 8, !tbaa !16
  %14 = sitofp <2 x i32> %13 to <2 x float>
  %15 = extractelement <2 x float> %14, i64 0
  %16 = extractelement <2 x float> %14, i64 1
  %17 = fdiv float %15, %16
  call void @esMatrixLoadIdentity(ptr noundef nonnull %3) #4
  call void @esPerspective(ptr noundef nonnull %3, float noundef 6.000000e+01, float noundef %17, float noundef 1.000000e+00, float noundef 2.000000e+01) #4
  call void @esMatrixLoadIdentity(ptr noundef nonnull %4) #4
  call void @esTranslate(ptr noundef nonnull %4, float noundef 0.000000e+00, float noundef 0.000000e+00, float noundef -2.000000e+00) #4
  %18 = load float, ptr %7, align 4, !tbaa !12
  call void @esRotate(ptr noundef nonnull %4, float noundef %18, float noundef 1.000000e+00, float noundef 0.000000e+00, float noundef 1.000000e+00) #4
  %19 = getelementptr inbounds i8, ptr %6, i64 32
  call void @esMatrixMultiply(ptr noundef nonnull %19, ptr noundef nonnull %4, ptr noundef nonnull %3) #4
  call void @llvm.lifetime.end.p0(i64 64, ptr nonnull %4) #4
  call void @llvm.lifetime.end.p0(i64 64, ptr nonnull %3) #4
  ret void
}

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare float @llvm.fmuladd.f32(float, float, float) #2

declare void @esMatrixLoadIdentity(ptr noundef) local_unnamed_addr #3

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

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

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

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

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 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #3 = { "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 #4 = { 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 28}
!13 = !{!"", !10, i64 0, !10, i64 4, !7, i64 8, !7, i64 16, !10, i64 24, !14, i64 28, !15, i64 32}
!14 = !{!"float", !8, i64 0}
!15 = !{!"", !8, i64 0}
!16 = !{!10, !10, i64 0}


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