; LLVM IR from paroj/gltut :: glsdk/freeglut/progs/demos/spaceball (spaceball)

; 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.vec4_t = type { float, float, float, float }

@rot = external dso_local global %struct.vec4_t, align 4

; Function Attrs: nounwind uwtable
define dso_local void @sbrot(i32 noundef %0, i32 noundef %1, i32 noundef %2) #0 {
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca float, align 4
  %8 = alloca %struct.vec4_t, align 4
  store i32 %0, ptr %4, align 4, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !5
  store i32 %2, ptr %6, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #5
  %9 = load i32, ptr %4, align 4, !tbaa !5
  %10 = load i32, ptr %4, align 4, !tbaa !5
  %11 = mul nsw i32 %9, %10
  %12 = load i32, ptr %5, align 4, !tbaa !5
  %13 = load i32, ptr %5, align 4, !tbaa !5
  %14 = mul nsw i32 %12, %13
  %15 = add nsw i32 %11, %14
  %16 = load i32, ptr %6, align 4, !tbaa !5
  %17 = load i32, ptr %6, align 4, !tbaa !5
  %18 = mul nsw i32 %16, %17
  %19 = add nsw i32 %15, %18
  %20 = sitofp i32 %19 to double
  %21 = call double @sqrt(double noundef %20) #5
  %22 = fptrunc double %21 to float
  store float %22, ptr %7, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 16, ptr %8) #5
  %23 = load float, ptr %7, align 4, !tbaa !9
  %24 = fmul float %23, 0x3F50624DE0000000
  %25 = load i32, ptr %4, align 4, !tbaa !5
  %26 = sub nsw i32 0, %25
  %27 = sitofp i32 %26 to float
  %28 = load float, ptr %7, align 4, !tbaa !9
  %29 = fdiv float %27, %28
  %30 = load i32, ptr %5, align 4, !tbaa !5
  %31 = sub nsw i32 0, %30
  %32 = sitofp i32 %31 to float
  %33 = load float, ptr %7, align 4, !tbaa !9
  %34 = fdiv float %32, %33
  %35 = load i32, ptr %6, align 4, !tbaa !5
  %36 = sitofp i32 %35 to float
  %37 = load float, ptr %7, align 4, !tbaa !9
  %38 = fdiv float %36, %37
  %39 = load <2 x float>, ptr @rot, align 4
  %40 = load <2 x float>, ptr getelementptr inbounds ({ <2 x float>, <2 x float> }, ptr @rot, i32 0, i32 1), align 4
  %41 = call { <2 x float>, <2 x float> } @quat_rotate(<2 x float> %39, <2 x float> %40, float noundef %24, float noundef %29, float noundef %34, float noundef %38)
  %42 = getelementptr inbounds { <2 x float>, <2 x float> }, ptr %8, i32 0, i32 0
  %43 = extractvalue { <2 x float>, <2 x float> } %41, 0
  store <2 x float> %43, ptr %42, align 4
  %44 = getelementptr inbounds { <2 x float>, <2 x float> }, ptr %8, i32 0, i32 1
  %45 = extractvalue { <2 x float>, <2 x float> } %41, 1
  store <2 x float> %45, ptr %44, align 4
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 @rot, ptr align 4 %8, i64 16, i1 false), !tbaa.struct !11
  call void @llvm.lifetime.end.p0(i64 16, ptr %8) #5
  call void @glutPostRedisplay()
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #5
  ret void
}

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

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

; 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 void @glutPostRedisplay() #3

; Function Attrs: nounwind
declare double @sqrt(double noundef) #4

declare { <2 x float>, <2 x float> } @quat_rotate(<2 x float>, <2 x float>, float noundef, float noundef, float noundef, float noundef) #3

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

!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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"float", !7, i64 0}
!11 = !{i64 0, i64 4, !9, i64 4, i64 4, !9, i64 8, i64 4, !9, i64 12, i64 4, !9}


; 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.vec4_t = type { float, float, float, float }

@rot = external dso_local local_unnamed_addr global %struct.vec4_t, align 4

; Function Attrs: nounwind uwtable
define dso_local void @sbrot(i32 noundef %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = mul nsw i32 %0, %0
  %5 = mul nsw i32 %1, %1
  %6 = add nuw nsw i32 %5, %4
  %7 = mul nsw i32 %2, %2
  %8 = add nuw nsw i32 %6, %7
  %9 = uitofp nneg i32 %8 to double
  %sqrt = tail call double @llvm.sqrt.f64(double %9)
  %10 = fptrunc double %sqrt to float
  %11 = fmul float %10, 0x3F50624DE0000000
  %12 = sub nsw i32 0, %0
  %13 = sitofp i32 %12 to float
  %14 = fdiv float %13, %10
  %15 = sub nsw i32 0, %1
  %16 = sitofp i32 %15 to float
  %17 = fdiv float %16, %10
  %18 = sitofp i32 %2 to float
  %19 = fdiv float %18, %10
  %20 = load <2 x float>, ptr @rot, align 4
  %21 = load <2 x float>, ptr getelementptr inbounds (i8, ptr @rot, i64 8), align 4
  %22 = tail call { <2 x float>, <2 x float> } @quat_rotate(<2 x float> %20, <2 x float> %21, float noundef %11, float noundef %14, float noundef %17, float noundef %19) #3
  %23 = extractvalue { <2 x float>, <2 x float> } %22, 0
  %24 = extractvalue { <2 x float>, <2 x float> } %22, 1
  store <2 x float> %23, ptr @rot, align 4
  store <2 x float> %24, ptr getelementptr inbounds (i8, ptr @rot, i64 8), align 4
  tail call void @glutPostRedisplay() #3
  ret void
}

declare void @glutPostRedisplay() local_unnamed_addr #1

declare { <2 x float>, <2 x float> } @quat_rotate(<2 x float>, <2 x float>, float noundef, float noundef, float noundef, float noundef) local_unnamed_addr #1

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.sqrt.f64(double) #2

attributes #0 = { nounwind 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 #1 = { "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 = { 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)"}


; Effective O3 passes: AggressiveInstCombinePass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,ReassociatePass,SROAPass,TailCallElimPass