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

; 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"

@__const.esGenCube.cubeVerts = external hidden unnamed_addr constant [72 x float], align 16
@__const.esGenCube.cubeNormals = external hidden unnamed_addr constant [72 x float], align 16
@__const.esGenCube.cubeTex = external hidden unnamed_addr constant [48 x float], align 16
@__const.esGenCube.cubeIndices = external hidden unnamed_addr constant [36 x i32], align 16

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

; Function Attrs: nounwind allocsize(0)
declare noalias ptr @malloc(i64 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 i32 @esGenCube(float noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3, ptr noundef %4) #2 {
  %6 = alloca float, align 4
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  %14 = alloca [72 x float], align 16
  %15 = alloca [72 x float], align 16
  %16 = alloca [48 x float], align 16
  %17 = alloca [36 x i32], align 16
  store float %0, ptr %6, align 4, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !9
  store ptr %2, ptr %8, align 8, !tbaa !9
  store ptr %3, ptr %9, align 8, !tbaa !9
  store ptr %4, ptr %10, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #4
  store i32 24, ptr %12, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #4
  store i32 36, ptr %13, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 288, ptr %14) #4
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %14, ptr align 16 @__const.esGenCube.cubeVerts, i64 288, i1 false)
  call void @llvm.lifetime.start.p0(i64 288, ptr %15) #4
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %15, ptr align 16 @__const.esGenCube.cubeNormals, i64 288, i1 false)
  call void @llvm.lifetime.start.p0(i64 192, ptr %16) #4
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %16, ptr align 16 @__const.esGenCube.cubeTex, i64 192, i1 false)
  %18 = load ptr, ptr %7, align 8, !tbaa !9
  %19 = icmp ne ptr %18, null
  br i1 %19, label %20, label %47

20:                                               ; preds = %5
  %21 = load i32, ptr %12, align 4, !tbaa !11
  %22 = sext i32 %21 to i64
  %23 = mul i64 12, %22
  %24 = call noalias ptr @malloc(i64 noundef %23) #5
  %25 = load ptr, ptr %7, align 8, !tbaa !9
  store ptr %24, ptr %25, align 8, !tbaa !9
  %26 = load ptr, ptr %7, align 8, !tbaa !9
  %27 = load ptr, ptr %26, align 8, !tbaa !9
  %28 = getelementptr inbounds [72 x float], ptr %14, i64 0, i64 0
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %27, ptr align 16 %28, i64 288, i1 false)
  store i32 0, ptr %11, align 4, !tbaa !11
  br label %29

29:                                               ; preds = %43, %20
  %30 = load i32, ptr %11, align 4, !tbaa !11
  %31 = load i32, ptr %12, align 4, !tbaa !11
  %32 = mul nsw i32 %31, 3
  %33 = icmp slt i32 %30, %32
  br i1 %33, label %34, label %46

34:                                               ; preds = %29
  %35 = load float, ptr %6, align 4, !tbaa !5
  %36 = load ptr, ptr %7, align 8, !tbaa !9
  %37 = load ptr, ptr %36, align 8, !tbaa !9
  %38 = load i32, ptr %11, align 4, !tbaa !11
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds float, ptr %37, i64 %39
  %41 = load float, ptr %40, align 4, !tbaa !5
  %42 = fmul float %41, %35
  store float %42, ptr %40, align 4, !tbaa !5
  br label %43

43:                                               ; preds = %34
  %44 = load i32, ptr %11, align 4, !tbaa !11
  %45 = add nsw i32 %44, 1
  store i32 %45, ptr %11, align 4, !tbaa !11
  br label %29, !llvm.loop !13

46:                                               ; preds = %29
  br label %47

47:                                               ; preds = %46, %5
  %48 = load ptr, ptr %8, align 8, !tbaa !9
  %49 = icmp ne ptr %48, null
  br i1 %49, label %50, label %59

50:                                               ; preds = %47
  %51 = load i32, ptr %12, align 4, !tbaa !11
  %52 = sext i32 %51 to i64
  %53 = mul i64 12, %52
  %54 = call noalias ptr @malloc(i64 noundef %53) #5
  %55 = load ptr, ptr %8, align 8, !tbaa !9
  store ptr %54, ptr %55, align 8, !tbaa !9
  %56 = load ptr, ptr %8, align 8, !tbaa !9
  %57 = load ptr, ptr %56, align 8, !tbaa !9
  %58 = getelementptr inbounds [72 x float], ptr %15, i64 0, i64 0
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %57, ptr align 16 %58, i64 288, i1 false)
  br label %59

59:                                               ; preds = %50, %47
  %60 = load ptr, ptr %9, align 8, !tbaa !9
  %61 = icmp ne ptr %60, null
  br i1 %61, label %62, label %71

62:                                               ; preds = %59
  %63 = load i32, ptr %12, align 4, !tbaa !11
  %64 = sext i32 %63 to i64
  %65 = mul i64 8, %64
  %66 = call noalias ptr @malloc(i64 noundef %65) #5
  %67 = load ptr, ptr %9, align 8, !tbaa !9
  store ptr %66, ptr %67, align 8, !tbaa !9
  %68 = load ptr, ptr %9, align 8, !tbaa !9
  %69 = load ptr, ptr %68, align 8, !tbaa !9
  %70 = getelementptr inbounds [48 x float], ptr %16, i64 0, i64 0
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %69, ptr align 16 %70, i64 192, i1 false)
  br label %71

71:                                               ; preds = %62, %59
  %72 = load ptr, ptr %10, align 8, !tbaa !9
  %73 = icmp ne ptr %72, null
  br i1 %73, label %74, label %83

74:                                               ; preds = %71
  call void @llvm.lifetime.start.p0(i64 144, ptr %17) #4
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %17, ptr align 16 @__const.esGenCube.cubeIndices, i64 144, i1 false)
  %75 = load i32, ptr %13, align 4, !tbaa !11
  %76 = sext i32 %75 to i64
  %77 = mul i64 4, %76
  %78 = call noalias ptr @malloc(i64 noundef %77) #5
  %79 = load ptr, ptr %10, align 8, !tbaa !9
  store ptr %78, ptr %79, align 8, !tbaa !9
  %80 = load ptr, ptr %10, align 8, !tbaa !9
  %81 = load ptr, ptr %80, align 8, !tbaa !9
  %82 = getelementptr inbounds [36 x i32], ptr %17, i64 0, i64 0
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %81, ptr align 16 %82, i64 144, i1 false)
  call void @llvm.lifetime.end.p0(i64 144, ptr %17) #4
  br label %83

83:                                               ; preds = %74, %71
  %84 = load i32, ptr %13, align 4, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 192, ptr %16) #4
  call void @llvm.lifetime.end.p0(i64 288, ptr %15) #4
  call void @llvm.lifetime.end.p0(i64 288, ptr %14) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #4
  ret i32 %84
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nounwind allocsize(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 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 #3 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { nounwind }
attributes #5 = { nounwind allocsize(0) }

!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"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"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"

@__const.esGenCube.cubeVerts = external hidden unnamed_addr constant [72 x float], align 16
@__const.esGenCube.cubeNormals = external hidden unnamed_addr constant [72 x float], align 16
@__const.esGenCube.cubeTex = external hidden unnamed_addr constant [48 x float], align 16
@__const.esGenCube.cubeIndices = external hidden unnamed_addr constant [36 x i32], align 16

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #0

; Function Attrs: nofree nounwind memory(readwrite, argmem: write) uwtable
define dso_local noundef i32 @esGenCube(float noundef %0, ptr noundef writeonly %1, ptr noundef writeonly %2, ptr noundef writeonly %3, ptr noundef writeonly %4) local_unnamed_addr #1 {
  %.not = icmp eq ptr %1, null
  br i1 %.not, label %.loopexit, label %vector.ph

vector.ph:                                        ; preds = %5
  %6 = tail call noalias dereferenceable_or_null(288) ptr @malloc(i64 noundef 288) #3
  store ptr %6, ptr %1, align 8, !tbaa !5
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 4 dereferenceable(288) %6, ptr noundef nonnull align 16 dereferenceable(288) @__const.esGenCube.cubeVerts, i64 288, i1 false)
  %broadcast.splatinsert = insertelement <4 x float> poison, float %0, i64 0
  %broadcast.splat = shufflevector <4 x float> %broadcast.splatinsert, <4 x float> poison, <4 x i32> zeroinitializer
  %7 = getelementptr inbounds i8, ptr %6, i64 16
  %wide.load = load <4 x float>, ptr %6, align 4, !tbaa !9
  %wide.load31 = load <4 x float>, ptr %7, align 4, !tbaa !9
  %8 = fmul <4 x float> %wide.load, %broadcast.splat
  %9 = fmul <4 x float> %wide.load31, %broadcast.splat
  store <4 x float> %8, ptr %6, align 4, !tbaa !9
  store <4 x float> %9, ptr %7, align 4, !tbaa !9
  %10 = getelementptr inbounds i8, ptr %6, i64 32
  %11 = getelementptr inbounds i8, ptr %6, i64 48
  %wide.load.1 = load <4 x float>, ptr %10, align 4, !tbaa !9
  %wide.load31.1 = load <4 x float>, ptr %11, align 4, !tbaa !9
  %12 = fmul <4 x float> %wide.load.1, %broadcast.splat
  %13 = fmul <4 x float> %wide.load31.1, %broadcast.splat
  store <4 x float> %12, ptr %10, align 4, !tbaa !9
  store <4 x float> %13, ptr %11, align 4, !tbaa !9
  %14 = getelementptr inbounds i8, ptr %6, i64 64
  %15 = getelementptr inbounds i8, ptr %6, i64 80
  %wide.load.2 = load <4 x float>, ptr %14, align 4, !tbaa !9
  %wide.load31.2 = load <4 x float>, ptr %15, align 4, !tbaa !9
  %16 = fmul <4 x float> %wide.load.2, %broadcast.splat
  %17 = fmul <4 x float> %wide.load31.2, %broadcast.splat
  store <4 x float> %16, ptr %14, align 4, !tbaa !9
  store <4 x float> %17, ptr %15, align 4, !tbaa !9
  %18 = getelementptr inbounds i8, ptr %6, i64 96
  %19 = getelementptr inbounds i8, ptr %6, i64 112
  %wide.load.3 = load <4 x float>, ptr %18, align 4, !tbaa !9
  %wide.load31.3 = load <4 x float>, ptr %19, align 4, !tbaa !9
  %20 = fmul <4 x float> %wide.load.3, %broadcast.splat
  %21 = fmul <4 x float> %wide.load31.3, %broadcast.splat
  store <4 x float> %20, ptr %18, align 4, !tbaa !9
  store <4 x float> %21, ptr %19, align 4, !tbaa !9
  %22 = getelementptr inbounds i8, ptr %6, i64 128
  %23 = getelementptr inbounds i8, ptr %6, i64 144
  %wide.load.4 = load <4 x float>, ptr %22, align 4, !tbaa !9
  %wide.load31.4 = load <4 x float>, ptr %23, align 4, !tbaa !9
  %24 = fmul <4 x float> %wide.load.4, %broadcast.splat
  %25 = fmul <4 x float> %wide.load31.4, %broadcast.splat
  store <4 x float> %24, ptr %22, align 4, !tbaa !9
  store <4 x float> %25, ptr %23, align 4, !tbaa !9
  %26 = getelementptr inbounds i8, ptr %6, i64 160
  %27 = getelementptr inbounds i8, ptr %6, i64 176
  %wide.load.5 = load <4 x float>, ptr %26, align 4, !tbaa !9
  %wide.load31.5 = load <4 x float>, ptr %27, align 4, !tbaa !9
  %28 = fmul <4 x float> %wide.load.5, %broadcast.splat
  %29 = fmul <4 x float> %wide.load31.5, %broadcast.splat
  store <4 x float> %28, ptr %26, align 4, !tbaa !9
  store <4 x float> %29, ptr %27, align 4, !tbaa !9
  %30 = getelementptr inbounds i8, ptr %6, i64 192
  %31 = getelementptr inbounds i8, ptr %6, i64 208
  %wide.load.6 = load <4 x float>, ptr %30, align 4, !tbaa !9
  %wide.load31.6 = load <4 x float>, ptr %31, align 4, !tbaa !9
  %32 = fmul <4 x float> %wide.load.6, %broadcast.splat
  %33 = fmul <4 x float> %wide.load31.6, %broadcast.splat
  store <4 x float> %32, ptr %30, align 4, !tbaa !9
  store <4 x float> %33, ptr %31, align 4, !tbaa !9
  %34 = getelementptr inbounds i8, ptr %6, i64 224
  %35 = getelementptr inbounds i8, ptr %6, i64 240
  %wide.load.7 = load <4 x float>, ptr %34, align 4, !tbaa !9
  %wide.load31.7 = load <4 x float>, ptr %35, align 4, !tbaa !9
  %36 = fmul <4 x float> %wide.load.7, %broadcast.splat
  %37 = fmul <4 x float> %wide.load31.7, %broadcast.splat
  store <4 x float> %36, ptr %34, align 4, !tbaa !9
  store <4 x float> %37, ptr %35, align 4, !tbaa !9
  %38 = getelementptr inbounds i8, ptr %6, i64 256
  %39 = getelementptr inbounds i8, ptr %6, i64 272
  %wide.load.8 = load <4 x float>, ptr %38, align 4, !tbaa !9
  %wide.load31.8 = load <4 x float>, ptr %39, align 4, !tbaa !9
  %40 = fmul <4 x float> %wide.load.8, %broadcast.splat
  %41 = fmul <4 x float> %wide.load31.8, %broadcast.splat
  store <4 x float> %40, ptr %38, align 4, !tbaa !9
  store <4 x float> %41, ptr %39, align 4, !tbaa !9
  br label %.loopexit

.loopexit:                                        ; preds = %vector.ph, %5
  %.not26 = icmp eq ptr %2, null
  br i1 %.not26, label %44, label %42

42:                                               ; preds = %.loopexit
  %43 = tail call noalias dereferenceable_or_null(288) ptr @malloc(i64 noundef 288) #3
  store ptr %43, ptr %2, align 8, !tbaa !5
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 4 dereferenceable(288) %43, ptr noundef nonnull align 16 dereferenceable(288) @__const.esGenCube.cubeNormals, i64 288, i1 false)
  br label %44

44:                                               ; preds = %42, %.loopexit
  %.not27 = icmp eq ptr %3, null
  br i1 %.not27, label %47, label %45

45:                                               ; preds = %44
  %46 = tail call noalias dereferenceable_or_null(192) ptr @malloc(i64 noundef 192) #3
  store ptr %46, ptr %3, align 8, !tbaa !5
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 4 dereferenceable(192) %46, ptr noundef nonnull align 16 dereferenceable(192) @__const.esGenCube.cubeTex, i64 192, i1 false)
  br label %47

47:                                               ; preds = %45, %44
  %.not28 = icmp eq ptr %4, null
  br i1 %.not28, label %50, label %48

48:                                               ; preds = %47
  %49 = tail call noalias dereferenceable_or_null(144) ptr @malloc(i64 noundef 144) #3
  store ptr %49, ptr %4, align 8, !tbaa !5
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 4 dereferenceable(144) %49, ptr noundef nonnull align 16 dereferenceable(144) @__const.esGenCube.cubeIndices, i64 144, i1 false)
  br label %50

50:                                               ; preds = %48, %47
  ret i32 36
}

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #2

attributes #0 = { mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" "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 #1 = { nofree nounwind memory(readwrite, argmem: write) 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 nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { nounwind allocsize(0) }

!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}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopLoadEliminationPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,LoopVectorizePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass