; LLVM IR from Dovyski/opengl-demos :: libs/glm-0.9.9.3/test/gtc/gtc_random.ll (Z13test_ballRandv)

; 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.glm::vec.52" = type { %union.anon.53 }
%union.anon.53 = type { %"struct.glm::detail::storage<3, float, true>::type" }
%"struct.glm::detail::storage<3, float, true>::type" = type { [4 x float] }
%"struct.glm::vec.57" = type { %union.anon.58 }
%union.anon.58 = type { %"struct.glm::detail::storage<3, double, true>::type" }
%"struct.glm::detail::storage<3, double, true>::type" = type { [4 x double] }

@.str = external hidden unnamed_addr constant [7 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [95 x i8], align 1
@__PRETTY_FUNCTION__._Z13test_ballRandv = external hidden unnamed_addr constant [20 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: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #1

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef float @_ZN3glm6lengthILi3EfLNS_9qualifierE3EEET0_RKNS_3vecIXT_ES2_XT1_EEE(ptr noundef nonnull align 16 dereferenceable(16)) #2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef double @_ZN3glm6lengthILi3EdLNS_9qualifierE3EEET0_RKNS_3vecIXT_ES2_XT1_EEE(ptr noundef nonnull align 32 dereferenceable(32)) #2

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_Z13test_ballRandv() #3 {
  %1 = alloca i32, align 4
  %2 = alloca float, align 4
  %3 = alloca double, align 8
  %4 = alloca i64, align 8
  %5 = alloca %"struct.glm::vec.52", align 16
  %6 = alloca %"struct.glm::vec.57", align 32
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #5
  store i32 0, ptr %1, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #5
  store float 0.000000e+00, ptr %2, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #5
  store double 0.000000e+00, ptr %3, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #5
  store i64 0, ptr %4, align 8, !tbaa !13
  br label %7

7:                                                ; preds = %26, %0
  %8 = load i64, ptr %4, align 8, !tbaa !13
  %9 = icmp ult i64 %8, 10000
  br i1 %9, label %11, label %10

10:                                               ; preds = %7
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #5
  br label %29

11:                                               ; preds = %7
  call void @llvm.lifetime.start.p0(i64 16, ptr %5) #5
  %12 = call { <2 x float>, <2 x float> } @_ZN3glm8ballRandIfEENS_3vecILi3ET_LNS_9qualifierE3EEES2_(float noundef 2.000000e+00)
  %13 = getelementptr inbounds %"struct.glm::vec.52", ptr %5, i32 0, i32 0
  %14 = getelementptr inbounds %union.anon.53, ptr %13, i32 0, i32 0
  %15 = getelementptr inbounds %"struct.glm::detail::storage<3, float, true>::type", ptr %14, i32 0, i32 0
  %16 = getelementptr inbounds { <2 x float>, <2 x float> }, ptr %15, i32 0, i32 0
  %17 = extractvalue { <2 x float>, <2 x float> } %12, 0
  store <2 x float> %17, ptr %16, align 16
  %18 = getelementptr inbounds { <2 x float>, <2 x float> }, ptr %15, i32 0, i32 1
  %19 = extractvalue { <2 x float>, <2 x float> } %12, 1
  store <2 x float> %19, ptr %18, align 8
  %20 = call noundef float @_ZN3glm6lengthILi3EfLNS_9qualifierE3EEET0_RKNS_3vecIXT_ES2_XT1_EEE(ptr noundef nonnull align 16 dereferenceable(16) %5)
  %21 = load float, ptr %2, align 4, !tbaa !9
  %22 = fadd float %21, %20
  store float %22, ptr %2, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 16, ptr %5) #5
  call void @llvm.lifetime.start.p0(i64 32, ptr %6) #5
  call void @_ZN3glm8ballRandIdEENS_3vecILi3ET_LNS_9qualifierE3EEES2_(ptr dead_on_unwind writable sret(%"struct.glm::vec.57") align 32 %6, double noundef 2.000000e+00)
  %23 = call noundef double @_ZN3glm6lengthILi3EdLNS_9qualifierE3EEET0_RKNS_3vecIXT_ES2_XT1_EEE(ptr noundef nonnull align 32 dereferenceable(32) %6)
  %24 = load double, ptr %3, align 8, !tbaa !11
  %25 = fadd double %24, %23
  store double %25, ptr %3, align 8, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 32, ptr %6) #5
  br label %26

26:                                               ; preds = %11
  %27 = load i64, ptr %4, align 8, !tbaa !13
  %28 = add i64 %27, 1
  store i64 %28, ptr %4, align 8, !tbaa !13
  br label %7, !llvm.loop !15

29:                                               ; preds = %10
  %30 = load float, ptr %2, align 4, !tbaa !9
  %31 = fcmp olt float %30, 2.000000e+04
  %32 = zext i1 %31 to i64
  %33 = select i1 %31, i32 0, i32 1
  %34 = load i32, ptr %1, align 4, !tbaa !5
  %35 = add nsw i32 %34, %33
  store i32 %35, ptr %1, align 4, !tbaa !5
  %36 = load double, ptr %3, align 8, !tbaa !11
  %37 = fcmp olt double %36, 2.000000e+04
  %38 = zext i1 %37 to i64
  %39 = select i1 %37, i32 0, i32 1
  %40 = load i32, ptr %1, align 4, !tbaa !5
  %41 = add nsw i32 %40, %39
  store i32 %41, ptr %1, align 4, !tbaa !5
  %42 = load i32, ptr %1, align 4, !tbaa !5
  %43 = icmp ne i32 %42, 0
  %44 = xor i1 %43, true
  br i1 %44, label %45, label %46

45:                                               ; preds = %29
  br label %48

46:                                               ; preds = %29
  call void @__assert_fail(ptr noundef @.str, ptr noundef @.str.1, i32 noundef 320, ptr noundef @__PRETTY_FUNCTION__._Z13test_ballRandv) #6
  unreachable

47:                                               ; No predecessors!
  br label %48

48:                                               ; preds = %47, %45
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #5
  %49 = load i32, ptr %1, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #5
  ret i32 %49
}

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local { <2 x float>, <2 x float> } @_ZN3glm8ballRandIfEENS_3vecILi3ET_LNS_9qualifierE3EEES2_(float noundef) #4

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZN3glm8ballRandIdEENS_3vecILi3ET_LNS_9qualifierE3EEES2_(ptr dead_on_unwind noalias writable sret(%"struct.glm::vec.57") align 32, double noundef) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { noreturn 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 = { inlinehint mustprogress 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 = { mustprogress uwtable "min-legal-vector-width"="64" "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 = { inlinehint mustprogress uwtable "min-legal-vector-width"="64" "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 #5 = { nounwind }
attributes #6 = { noreturn 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"float", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"double", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"long", !7, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"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"

%"struct.glm::vec.52" = type { %union.anon.53 }
%union.anon.53 = type { %"struct.glm::detail::storage<3, float, true>::type" }
%"struct.glm::detail::storage<3, float, true>::type" = type { [4 x float] }
%"struct.glm::vec.57" = type { %union.anon.58 }
%union.anon.58 = type { %"struct.glm::detail::storage<3, double, true>::type" }
%"struct.glm::detail::storage<3, double, true>::type" = type { [4 x double] }

@.str = external hidden unnamed_addr constant [7 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [95 x i8], align 1
@__PRETTY_FUNCTION__._Z13test_ballRandv = external hidden unnamed_addr constant [20 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: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef float @_ZN3glm6lengthILi3EfLNS_9qualifierE3EEET0_RKNS_3vecIXT_ES2_XT1_EEE(ptr noundef nonnull align 16 dereferenceable(16)) local_unnamed_addr #2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef double @_ZN3glm6lengthILi3EdLNS_9qualifierE3EEET0_RKNS_3vecIXT_ES2_XT1_EEE(ptr noundef nonnull align 32 dereferenceable(32)) local_unnamed_addr #2

; Function Attrs: mustprogress uwtable
define dso_local noundef range(i32 0, 3) i32 @_Z13test_ballRandv() local_unnamed_addr #3 {
  %1 = alloca %"struct.glm::vec.52", align 16
  %2 = alloca %"struct.glm::vec.57", align 32
  %3 = getelementptr inbounds i8, ptr %1, i64 8
  br label %7

4:                                                ; preds = %7
  %5 = fcmp olt float %12, 2.000000e+04
  %6 = fcmp olt double %14, 2.000000e+04
  %.not13 = and i1 %5, %6
  br i1 %.not13, label %17, label %16

7:                                                ; preds = %0, %7
  %.016 = phi i64 [ 0, %0 ], [ %15, %7 ]
  %.0915 = phi double [ 0.000000e+00, %0 ], [ %14, %7 ]
  %.01014 = phi float [ 0.000000e+00, %0 ], [ %12, %7 ]
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %1) #5
  %8 = call { <2 x float>, <2 x float> } @_ZN3glm8ballRandIfEENS_3vecILi3ET_LNS_9qualifierE3EEES2_(float noundef 2.000000e+00)
  %9 = extractvalue { <2 x float>, <2 x float> } %8, 0
  store <2 x float> %9, ptr %1, align 16
  %10 = extractvalue { <2 x float>, <2 x float> } %8, 1
  store <2 x float> %10, ptr %3, align 8
  %11 = call noundef float @_ZN3glm6lengthILi3EfLNS_9qualifierE3EEET0_RKNS_3vecIXT_ES2_XT1_EEE(ptr noundef nonnull align 16 dereferenceable(16) %1)
  %12 = fadd float %.01014, %11
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %1) #5
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %2) #5
  call void @_ZN3glm8ballRandIdEENS_3vecILi3ET_LNS_9qualifierE3EEES2_(ptr dead_on_unwind nonnull writable sret(%"struct.glm::vec.57") align 32 %2, double noundef 2.000000e+00)
  %13 = call noundef double @_ZN3glm6lengthILi3EdLNS_9qualifierE3EEET0_RKNS_3vecIXT_ES2_XT1_EEE(ptr noundef nonnull align 32 dereferenceable(32) %2)
  %14 = fadd double %.0915, %13
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %2) #5
  %15 = add nuw nsw i64 %.016, 1
  %exitcond.not = icmp eq i64 %15, 10000
  br i1 %exitcond.not, label %4, label %7, !llvm.loop !5

16:                                               ; preds = %4
  call void @__assert_fail(ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 320, ptr noundef nonnull @__PRETTY_FUNCTION__._Z13test_ballRandv) #6
  unreachable

17:                                               ; preds = %4
  ret i32 0
}

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local { <2 x float>, <2 x float> } @_ZN3glm8ballRandIfEENS_3vecILi3ET_LNS_9qualifierE3EEES2_(float noundef) local_unnamed_addr #4

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZN3glm8ballRandIdEENS_3vecILi3ET_LNS_9qualifierE3EEES2_(ptr dead_on_unwind noalias writable sret(%"struct.glm::vec.57") align 32, double noundef) local_unnamed_addr #2

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { noreturn 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 = { inlinehint mustprogress 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 = { mustprogress uwtable "min-legal-vector-width"="64" "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 = { inlinehint mustprogress uwtable "min-legal-vector-width"="64" "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 #5 = { nounwind }
attributes #6 = { noreturn 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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LICMPass,LoopRotatePass,LoopUnrollPass,SROAPass,SimplifyCFGPass