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

; 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, [7000 x float], float }

; 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
declare i32 @rand() #1

; Function Attrs: nounwind uwtable
define dso_local void @Update(ptr noundef %0, float noundef %1) #2 {
  %3 = alloca ptr, align 8
  %4 = alloca float, align 4
  %5 = alloca ptr, align 8
  %6 = alloca [3 x float], align 4
  %7 = alloca [4 x float], align 16
  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
  %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
  %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 7
  %14 = load float, ptr %13, align 4, !tbaa !15
  %15 = fadd float %14, %11
  store float %15, ptr %13, align 4, !tbaa !15
  %16 = load ptr, ptr %5, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.UserData, ptr %16, i32 0, i32 0
  %18 = load i32, ptr %17, align 4, !tbaa !17
  call void @glUseProgram(i32 noundef %18)
  %19 = load ptr, ptr %5, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.UserData, ptr %19, i32 0, i32 7
  %21 = load float, ptr %20, align 4, !tbaa !15
  %22 = fcmp oge float %21, 1.000000e+00
  br i1 %22, label %23, label %71

23:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 12, ptr %6) #4
  call void @llvm.lifetime.start.p0(i64 16, ptr %7) #4
  %24 = load ptr, ptr %5, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.UserData, ptr %24, i32 0, i32 7
  store float 0.000000e+00, ptr %25, align 4, !tbaa !15
  %26 = call i32 @rand() #4
  %27 = srem i32 %26, 10000
  %28 = sitofp i32 %27 to float
  %29 = fdiv float %28, 1.000000e+04
  %30 = fsub float %29, 5.000000e-01
  %31 = getelementptr inbounds [3 x float], ptr %6, i64 0, i64 0
  store float %30, ptr %31, align 4, !tbaa !9
  %32 = call i32 @rand() #4
  %33 = srem i32 %32, 10000
  %34 = sitofp i32 %33 to float
  %35 = fdiv float %34, 1.000000e+04
  %36 = fsub float %35, 5.000000e-01
  %37 = getelementptr inbounds [3 x float], ptr %6, i64 0, i64 1
  store float %36, ptr %37, align 4, !tbaa !9
  %38 = call i32 @rand() #4
  %39 = srem i32 %38, 10000
  %40 = sitofp i32 %39 to float
  %41 = fdiv float %40, 1.000000e+04
  %42 = fsub float %41, 5.000000e-01
  %43 = getelementptr inbounds [3 x float], ptr %6, i64 0, i64 2
  store float %42, ptr %43, align 4, !tbaa !9
  %44 = load ptr, ptr %5, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.UserData, ptr %44, i32 0, i32 3
  %46 = load i32, ptr %45, align 4, !tbaa !18
  %47 = getelementptr inbounds [3 x float], ptr %6, i64 0, i64 0
  call void @glUniform3fv(i32 noundef %46, i32 noundef 1, ptr noundef %47)
  %48 = call i32 @rand() #4
  %49 = srem i32 %48, 10000
  %50 = sitofp i32 %49 to float
  %51 = fdiv float %50, 2.000000e+04
  %52 = fadd float %51, 5.000000e-01
  %53 = getelementptr inbounds [4 x float], ptr %7, i64 0, i64 0
  store float %52, ptr %53, align 16, !tbaa !9
  %54 = call i32 @rand() #4
  %55 = srem i32 %54, 10000
  %56 = sitofp i32 %55 to float
  %57 = fdiv float %56, 2.000000e+04
  %58 = fadd float %57, 5.000000e-01
  %59 = getelementptr inbounds [4 x float], ptr %7, i64 0, i64 1
  store float %58, ptr %59, align 4, !tbaa !9
  %60 = call i32 @rand() #4
  %61 = srem i32 %60, 10000
  %62 = sitofp i32 %61 to float
  %63 = fdiv float %62, 2.000000e+04
  %64 = fadd float %63, 5.000000e-01
  %65 = getelementptr inbounds [4 x float], ptr %7, i64 0, i64 2
  store float %64, ptr %65, align 8, !tbaa !9
  %66 = getelementptr inbounds [4 x float], ptr %7, i64 0, i64 3
  store float 5.000000e-01, ptr %66, align 4, !tbaa !9
  %67 = load ptr, ptr %5, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct.UserData, ptr %67, i32 0, i32 2
  %69 = load i32, ptr %68, align 4, !tbaa !19
  %70 = getelementptr inbounds [4 x float], ptr %7, i64 0, i64 0
  call void @glUniform4fv(i32 noundef %69, i32 noundef 1, ptr noundef %70)
  call void @llvm.lifetime.end.p0(i64 16, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 12, ptr %6) #4
  br label %71

71:                                               ; preds = %23, %2
  %72 = load ptr, ptr %5, align 8, !tbaa !5
  %73 = getelementptr inbounds %struct.UserData, ptr %72, i32 0, i32 1
  %74 = load i32, ptr %73, align 4, !tbaa !20
  %75 = load ptr, ptr %5, align 8, !tbaa !5
  %76 = getelementptr inbounds %struct.UserData, ptr %75, i32 0, i32 7
  %77 = load float, ptr %76, align 4, !tbaa !15
  call void @glUniform1f(i32 noundef %74, float noundef %77)
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  ret void
}

declare void @glUseProgram(i32 noundef) #3

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

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

declare void @glUniform1f(i32 noundef, float noundef) #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nounwind "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 = { "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 28024}
!16 = !{!"", !13, i64 0, !13, i64 4, !13, i64 8, !13, i64 12, !13, i64 16, !13, i64 20, !7, i64 24, !10, i64 28024}
!17 = !{!16, !13, i64 0}
!18 = !{!16, !13, i64 12}
!19 = !{!16, !13, i64 8}
!20 = !{!16, !13, i64 4}


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

; 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
declare i32 @rand() local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local void @Update(ptr nocapture noundef readonly %0, float noundef %1) local_unnamed_addr #2 {
  %3 = alloca [3 x float], align 8
  %4 = alloca [4 x float], align 16
  %5 = getelementptr inbounds i8, ptr %0, i64 8
  %6 = load ptr, ptr %5, align 8, !tbaa !5
  %7 = getelementptr inbounds i8, ptr %6, i64 28024
  %8 = load float, ptr %7, align 4, !tbaa !12
  %9 = fadd float %8, %1
  store float %9, ptr %7, align 4, !tbaa !12
  %10 = load i32, ptr %6, align 4, !tbaa !15
  tail call void @glUseProgram(i32 noundef %10) #4
  %11 = load float, ptr %7, align 4, !tbaa !12
  %12 = fcmp ult float %11, 1.000000e+00
  br i1 %12, label %50, label %13

13:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 12, ptr nonnull %3) #4
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %4) #4
  store float 0.000000e+00, ptr %7, align 4, !tbaa !12
  %14 = tail call i32 @rand() #4
  %15 = tail call i32 @rand() #4
  %16 = insertelement <2 x i32> poison, i32 %14, i64 0
  %17 = insertelement <2 x i32> %16, i32 %15, i64 1
  %18 = srem <2 x i32> %17, <i32 10000, i32 10000>
  %19 = sitofp <2 x i32> %18 to <2 x float>
  %20 = fdiv <2 x float> %19, <float 1.000000e+04, float 1.000000e+04>
  %21 = fadd <2 x float> %20, <float -5.000000e-01, float -5.000000e-01>
  store <2 x float> %21, ptr %3, align 8, !tbaa !16
  %22 = tail call i32 @rand() #4
  %23 = srem i32 %22, 10000
  %24 = sitofp i32 %23 to float
  %25 = fdiv float %24, 1.000000e+04
  %26 = fadd float %25, -5.000000e-01
  %27 = getelementptr inbounds i8, ptr %3, i64 8
  store float %26, ptr %27, align 8, !tbaa !16
  %28 = getelementptr inbounds i8, ptr %6, i64 12
  %29 = load i32, ptr %28, align 4, !tbaa !17
  call void @glUniform3fv(i32 noundef %29, i32 noundef 1, ptr noundef nonnull %3) #4
  %30 = call i32 @rand() #4
  %31 = srem i32 %30, 10000
  %32 = sitofp i32 %31 to float
  %33 = fdiv float %32, 2.000000e+04
  %34 = fadd float %33, 5.000000e-01
  store float %34, ptr %4, align 16, !tbaa !16
  %35 = call i32 @rand() #4
  %36 = srem i32 %35, 10000
  %37 = sitofp i32 %36 to float
  %38 = fdiv float %37, 2.000000e+04
  %39 = fadd float %38, 5.000000e-01
  %40 = getelementptr inbounds i8, ptr %4, i64 4
  store float %39, ptr %40, align 4, !tbaa !16
  %41 = call i32 @rand() #4
  %42 = srem i32 %41, 10000
  %43 = sitofp i32 %42 to float
  %44 = fdiv float %43, 2.000000e+04
  %45 = fadd float %44, 5.000000e-01
  %46 = getelementptr inbounds i8, ptr %4, i64 8
  store float %45, ptr %46, align 8, !tbaa !16
  %47 = getelementptr inbounds i8, ptr %4, i64 12
  store float 5.000000e-01, ptr %47, align 4, !tbaa !16
  %48 = getelementptr inbounds i8, ptr %6, i64 8
  %49 = load i32, ptr %48, align 4, !tbaa !18
  call void @glUniform4fv(i32 noundef %49, i32 noundef 1, ptr noundef nonnull %4) #4
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %4) #4
  call void @llvm.lifetime.end.p0(i64 12, ptr nonnull %3) #4
  %.pre = load float, ptr %7, align 4, !tbaa !12
  br label %50

50:                                               ; preds = %13, %2
  %51 = phi float [ %.pre, %13 ], [ %11, %2 ]
  %52 = getelementptr inbounds i8, ptr %6, i64 4
  %53 = load i32, ptr %52, align 4, !tbaa !19
  call void @glUniform1f(i32 noundef %53, float noundef %51) #4
  ret void
}

declare void @glUseProgram(i32 noundef) local_unnamed_addr #3

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

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

declare void @glUniform1f(i32 noundef, float noundef) local_unnamed_addr #3

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nounwind "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 = { "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 28024}
!13 = !{!"", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20, !8, i64 24, !14, i64 28024}
!14 = !{!"float", !8, i64 0}
!15 = !{!13, !10, i64 0}
!16 = !{!14, !14, i64 0}
!17 = !{!13, !10, i64 12}
!18 = !{!13, !10, i64 8}
!19 = !{!13, !10, i64 4}


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