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

; 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.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, i32, i32, [200 x %struct.Particle], [2 x i32], i32, float, ptr }
%struct.Particle = type { [2 x float], [2 x float], float, float, float }

@__const.InitEmitParticles.vShaderStr = external hidden unnamed_addr constant [3658 x i8], align 16
@__const.InitEmitParticles.fShaderStr = external hidden unnamed_addr constant [379 x i8], align 16
@__const.InitEmitParticles.feedbackVaryings = external hidden unnamed_addr constant [5 x ptr], align 16
@.str.6 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [15 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [11 x i8], align 1

; 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 @InitEmitParticles(ptr noundef %0) #1 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca [3658 x i8], align 16
  %5 = alloca [379 x i8], align 16
  %6 = alloca [5 x ptr], align 16
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #4
  %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 %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 3658, ptr %4) #4
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %4, ptr align 16 @__const.InitEmitParticles.vShaderStr, i64 3658, i1 false)
  call void @llvm.lifetime.start.p0(i64 379, ptr %5) #4
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %5, ptr align 16 @__const.InitEmitParticles.fShaderStr, i64 379, i1 false)
  %10 = getelementptr inbounds [3658 x i8], ptr %4, i64 0, i64 0
  %11 = getelementptr inbounds [379 x i8], ptr %5, i64 0, i64 0
  %12 = call i32 @esLoadProgram(ptr noundef %10, ptr noundef %11)
  %13 = load ptr, ptr %3, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.UserData, ptr %13, i32 0, i32 0
  store i32 %12, ptr %14, align 8, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 40, ptr %6) #4
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %6, ptr align 16 @__const.InitEmitParticles.feedbackVaryings, i64 40, i1 false)
  %15 = load ptr, ptr %3, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.UserData, ptr %15, i32 0, i32 0
  %17 = load i32, ptr %16, align 8, !tbaa !13
  %18 = getelementptr inbounds [5 x ptr], ptr %6, i64 0, i64 0
  call void @glTransformFeedbackVaryings(i32 noundef %17, i32 noundef 5, ptr noundef %18, i32 noundef 35980)
  %19 = load ptr, ptr %3, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.UserData, ptr %19, i32 0, i32 0
  %21 = load i32, ptr %20, align 8, !tbaa !13
  call void @glLinkProgram(i32 noundef %21)
  %22 = load ptr, ptr %3, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.UserData, ptr %22, i32 0, i32 0
  %24 = load i32, ptr %23, align 8, !tbaa !13
  %25 = call i32 @glGetUniformLocation(i32 noundef %24, ptr noundef @.str.6)
  %26 = load ptr, ptr %3, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.UserData, ptr %26, i32 0, i32 2
  store i32 %25, ptr %27, align 8, !tbaa !16
  %28 = load ptr, ptr %3, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.UserData, ptr %28, i32 0, i32 0
  %30 = load i32, ptr %29, align 8, !tbaa !13
  %31 = call i32 @glGetUniformLocation(i32 noundef %30, ptr noundef @.str.7)
  %32 = load ptr, ptr %3, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.UserData, ptr %32, i32 0, i32 3
  store i32 %31, ptr %33, align 4, !tbaa !17
  %34 = load ptr, ptr %3, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.UserData, ptr %34, i32 0, i32 0
  %36 = load i32, ptr %35, align 8, !tbaa !13
  %37 = call i32 @glGetUniformLocation(i32 noundef %36, ptr noundef @.str.8)
  %38 = load ptr, ptr %3, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.UserData, ptr %38, i32 0, i32 4
  store i32 %37, ptr %39, align 8, !tbaa !18
  call void @llvm.lifetime.end.p0(i64 40, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 379, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 3658, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #4
  ret void
}

; 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) #2

declare i32 @esLoadProgram(ptr noundef, ptr noundef) #3

declare void @glTransformFeedbackVaryings(i32 noundef, i32 noundef, ptr noundef, i32 noundef) #3

declare void @glLinkProgram(i32 noundef) #3

declare i32 @glGetUniformLocation(i32 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 nounwind willreturn memory(argmem: readwrite) }
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, !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 = !{!14, !11, i64 0}
!14 = !{!"", !11, i64 0, !11, i64 4, !11, i64 8, !11, i64 12, !11, i64 16, !11, i64 20, !11, i64 24, !11, i64 28, !11, i64 32, !11, i64 36, !11, i64 40, !7, i64 44, !7, i64 5644, !11, i64 5652, !15, i64 5656, !6, i64 5664}
!15 = !{!"float", !7, i64 0}
!16 = !{!14, !11, i64 8}
!17 = !{!14, !11, i64 12}
!18 = !{!14, !11, i64 16}


; 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.InitEmitParticles.vShaderStr = external hidden unnamed_addr constant [3658 x i8], align 16
@__const.InitEmitParticles.fShaderStr = external hidden unnamed_addr constant [379 x i8], align 16
@__const.InitEmitParticles.feedbackVaryings = external hidden unnamed_addr constant [5 x ptr], align 16
@.str.6 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [15 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [11 x i8], align 1

; 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 @InitEmitParticles(ptr nocapture noundef readonly %0) local_unnamed_addr #1 {
  %2 = alloca [3658 x i8], align 16
  %3 = alloca [379 x i8], align 16
  %4 = alloca [5 x ptr], align 16
  %5 = getelementptr inbounds i8, ptr %0, i64 8
  %6 = load ptr, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 3658, ptr nonnull %2) #4
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 16 dereferenceable(3658) %2, ptr noundef nonnull align 16 dereferenceable(3658) @__const.InitEmitParticles.vShaderStr, i64 3658, i1 false)
  call void @llvm.lifetime.start.p0(i64 379, ptr nonnull %3) #4
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 16 dereferenceable(379) %3, ptr noundef nonnull align 16 dereferenceable(379) @__const.InitEmitParticles.fShaderStr, i64 379, i1 false)
  %7 = call i32 @esLoadProgram(ptr noundef nonnull %2, ptr noundef nonnull %3) #4
  store i32 %7, ptr %6, align 8, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 40, ptr nonnull %4) #4
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 16 dereferenceable(40) %4, ptr noundef nonnull align 16 dereferenceable(40) @__const.InitEmitParticles.feedbackVaryings, i64 40, i1 false)
  call void @glTransformFeedbackVaryings(i32 noundef %7, i32 noundef 5, ptr noundef nonnull %4, i32 noundef 35980) #4
  %8 = load i32, ptr %6, align 8, !tbaa !12
  call void @glLinkProgram(i32 noundef %8) #4
  %9 = load i32, ptr %6, align 8, !tbaa !12
  %10 = call i32 @glGetUniformLocation(i32 noundef %9, ptr noundef nonnull @.str.6) #4
  %11 = getelementptr inbounds i8, ptr %6, i64 8
  store i32 %10, ptr %11, align 8, !tbaa !15
  %12 = load i32, ptr %6, align 8, !tbaa !12
  %13 = call i32 @glGetUniformLocation(i32 noundef %12, ptr noundef nonnull @.str.7) #4
  %14 = getelementptr inbounds i8, ptr %6, i64 12
  store i32 %13, ptr %14, align 4, !tbaa !16
  %15 = load i32, ptr %6, align 8, !tbaa !12
  %16 = call i32 @glGetUniformLocation(i32 noundef %15, ptr noundef nonnull @.str.8) #4
  %17 = getelementptr inbounds i8, ptr %6, i64 16
  store i32 %16, ptr %17, align 8, !tbaa !17
  call void @llvm.lifetime.end.p0(i64 40, ptr nonnull %4) #4
  call void @llvm.lifetime.end.p0(i64 379, ptr nonnull %3) #4
  call void @llvm.lifetime.end.p0(i64 3658, ptr nonnull %2) #4
  ret void
}

; 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

declare i32 @esLoadProgram(ptr noundef, ptr noundef) local_unnamed_addr #3

declare void @glTransformFeedbackVaryings(i32 noundef, i32 noundef, ptr noundef, i32 noundef) local_unnamed_addr #3

declare void @glLinkProgram(i32 noundef) local_unnamed_addr #3

declare i32 @glGetUniformLocation(i32 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 nounwind willreturn memory(argmem: readwrite) }
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, !10, i64 0}
!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, !10, i64 32, !10, i64 36, !10, i64 40, !8, i64 44, !8, i64 5644, !10, i64 5652, !14, i64 5656, !7, i64 5664}
!14 = !{!"float", !8, i64 0}
!15 = !{!13, !10, i64 8}
!16 = !{!13, !10, i64 12}
!17 = !{!13, !10, i64 16}


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