; LLVM IR from niessner/Matterport :: code/gaps/pkgs/R3Graphics/R3Viewer.ll (ZN8R3Viewer15RotateCameraYawEdiiii)

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

%class.R3Viewer = type { ptr, %class.R3Camera, %class.R2Viewport }
%class.R3Camera = type { %class.R3CoordSystem, double, double, double, double, double, ptr }
%class.R3CoordSystem = type { %class.R3Point, %class.R3Triad }
%class.R3Point = type { [3 x double] }
%class.R3Triad = type { [3 x %class.R3Vector] }
%class.R3Vector = type { [3 x double] }
%class.R2Viewport = type { i32, i32, i32, i32 }

@RN_PI = external constant double, align 8

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNK10R2Viewport6HeightEv(ptr noundef nonnull align 4 dereferenceable(16)) #1 align 2

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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN8R3Viewer15RotateCameraYawEdiiii(ptr noundef nonnull align 8 dereferenceable(168) %0, double noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4, i32 noundef %5) unnamed_addr #2 align 2 {
  %7 = alloca ptr, align 8
  %8 = alloca double, align 8
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca double, align 8
  %14 = alloca double, align 8
  store ptr %0, ptr %7, align 8, !tbaa !5
  store double %1, ptr %8, align 8, !tbaa !9
  store i32 %2, ptr %9, align 4, !tbaa !11
  store i32 %3, ptr %10, align 4, !tbaa !11
  store i32 %4, ptr %11, align 4, !tbaa !11
  store i32 %5, ptr %12, align 4, !tbaa !11
  %15 = load ptr, ptr %7, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #4
  %16 = load i32, ptr %10, align 4, !tbaa !11
  %17 = mul nsw i32 2, %16
  %18 = getelementptr inbounds %class.R3Viewer, ptr %15, i32 0, i32 2
  %19 = call noundef i32 @_ZNK10R2Viewport6HeightEv(ptr noundef nonnull align 4 dereferenceable(16) %18)
  %20 = sub nsw i32 %17, %19
  %21 = sitofp i32 %20 to double
  %22 = getelementptr inbounds %class.R3Viewer, ptr %15, i32 0, i32 2
  %23 = call noundef i32 @_ZNK10R2Viewport6HeightEv(ptr noundef nonnull align 4 dereferenceable(16) %22)
  %24 = sitofp i32 %23 to double
  %25 = fdiv double %21, %24
  store double %25, ptr %13, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #4
  %26 = load double, ptr %8, align 8, !tbaa !9
  %27 = load double, ptr @RN_PI, align 8, !tbaa !9
  %28 = fdiv double %27, 6.400000e+01
  %29 = fmul double %26, %28
  %30 = load double, ptr %13, align 8, !tbaa !9
  %31 = fmul double %29, %30
  %32 = load double, ptr %13, align 8, !tbaa !9
  %33 = fcmp olt double %32, 0.000000e+00
  br i1 %33, label %34, label %37

34:                                               ; preds = %6
  %35 = load double, ptr %13, align 8, !tbaa !9
  %36 = fneg double %35
  br label %39

37:                                               ; preds = %6
  %38 = load double, ptr %13, align 8, !tbaa !9
  br label %39

39:                                               ; preds = %37, %34
  %40 = phi double [ %36, %34 ], [ %38, %37 ]
  %41 = fmul double %31, %40
  store double %41, ptr %14, align 8, !tbaa !9
  %42 = getelementptr inbounds %class.R3Viewer, ptr %15, i32 0, i32 1
  %43 = load double, ptr %14, align 8, !tbaa !9
  call void @_ZN8R3Camera9RotateYawEd(ptr noundef nonnull align 8 dereferenceable(144) %42, double noundef %43)
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #4
  ret void
}

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZN8R3Camera9RotateYawEd(ptr noundef nonnull align 8 dereferenceable(144), double noundef) #3 align 2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { inlinehint mustprogress 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 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 = { 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 #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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"double", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}


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

@RN_PI = external local_unnamed_addr constant double, align 8

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNK10R2Viewport6HeightEv(ptr noundef nonnull align 4 dereferenceable(16)) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN8R3Viewer15RotateCameraYawEdiiii(ptr noundef nonnull align 8 dereferenceable(168) %0, double noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4, i32 noundef %5) unnamed_addr #1 align 2 {
  %7 = shl nsw i32 %3, 1
  %8 = getelementptr inbounds i8, ptr %0, i64 152
  %9 = tail call noundef i32 @_ZNK10R2Viewport6HeightEv(ptr noundef nonnull align 4 dereferenceable(16) %8)
  %10 = sub nsw i32 %7, %9
  %11 = sitofp i32 %10 to double
  %12 = tail call noundef i32 @_ZNK10R2Viewport6HeightEv(ptr noundef nonnull align 4 dereferenceable(16) %8)
  %13 = sitofp i32 %12 to double
  %14 = fdiv double %11, %13
  %15 = load double, ptr @RN_PI, align 8, !tbaa !5
  %16 = fmul double %15, 1.562500e-02
  %17 = fmul double %16, %1
  %18 = fmul double %14, %17
  %19 = fcmp olt double %14, 0.000000e+00
  %20 = fneg double %14
  %21 = select i1 %19, double %20, double %14
  %22 = fmul double %18, %21
  %23 = getelementptr inbounds i8, ptr %0, i64 8
  tail call void @_ZN8R3Camera9RotateYawEd(ptr noundef nonnull align 8 dereferenceable(144) %23, double noundef %22)
  ret void
}

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZN8R3Camera9RotateYawEd(ptr noundef nonnull align 8 dereferenceable(144), double noundef) local_unnamed_addr #2 align 2

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

!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 = !{!"double", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}


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