; LLVM IR from mnovak42/hepemshow :: Simulation/src/Box.ll (ZN3Box13SetHalfLengthEdi)

; 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.Box = type { %"class.std::__cxx11::basic_string", i32, double, double, double, double, double }
%"class.std::__cxx11::basic_string" = type { %"struct.std::__cxx11::basic_string<char>::_Alloc_hider", i64, %union.anon }
%"struct.std::__cxx11::basic_string<char>::_Alloc_hider" = type { ptr }
%union.anon = type { i64, [8 x i8] }

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN3Box13SetHalfLengthEdi(ptr noundef nonnull align 8 dereferenceable(80) %0, double noundef %1, i32 noundef %2) #0 align 2 {
  %4 = alloca ptr, align 8
  %5 = alloca double, align 8
  %6 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store double %1, ptr %5, align 8, !tbaa !9
  store i32 %2, ptr %6, align 4, !tbaa !11
  %7 = load ptr, ptr %4, align 8
  %8 = load double, ptr %5, align 8, !tbaa !9
  %9 = getelementptr inbounds %class.Box, ptr %7, i32 0, i32 5
  %10 = load double, ptr %9, align 8, !tbaa !13
  %11 = fmul double 2.000000e+00, %10
  %12 = fcmp ogt double %8, %11
  br i1 %12, label %13, label %25

13:                                               ; preds = %3
  %14 = load i32, ptr %6, align 4, !tbaa !11
  switch i32 %14, label %24 [
    i32 0, label %15
    i32 1, label %18
    i32 2, label %21
  ]

15:                                               ; preds = %13
  %16 = load double, ptr %5, align 8, !tbaa !9
  %17 = getelementptr inbounds %class.Box, ptr %7, i32 0, i32 2
  store double %16, ptr %17, align 8, !tbaa !18
  br label %24

18:                                               ; preds = %13
  %19 = load double, ptr %5, align 8, !tbaa !9
  %20 = getelementptr inbounds %class.Box, ptr %7, i32 0, i32 3
  store double %19, ptr %20, align 8, !tbaa !19
  br label %24

21:                                               ; preds = %13
  %22 = load double, ptr %5, align 8, !tbaa !9
  %23 = getelementptr inbounds %class.Box, ptr %7, i32 0, i32 4
  store double %22, ptr %23, align 8, !tbaa !20
  br label %24

24:                                               ; preds = %21, %18, %15, %13
  br label %26

25:                                               ; preds = %3
  br label %26

26:                                               ; preds = %25, %24
  ret void
}

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

!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}
!13 = !{!14, !10, i64 64}
!14 = !{!"_ZTS3Box", !15, i64 0, !12, i64 32, !10, i64 40, !10, i64 48, !10, i64 56, !10, i64 64, !10, i64 72}
!15 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE", !16, i64 0, !17, i64 8, !7, i64 16}
!16 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_Alloc_hiderE", !6, i64 0}
!17 = !{!"long", !7, i64 0}
!18 = !{!14, !10, i64 40}
!19 = !{!14, !10, i64 48}
!20 = !{!14, !10, i64 56}


; 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 nofree norecurse nosync nounwind willreturn memory(argmem: readwrite) uwtable
define dso_local void @_ZN3Box13SetHalfLengthEdi(ptr nocapture noundef nonnull align 8 dereferenceable(80) %0, double noundef %1, i32 noundef %2) local_unnamed_addr #0 align 2 {
  %4 = getelementptr inbounds i8, ptr %0, i64 64
  %5 = load double, ptr %4, align 8, !tbaa !5
  %6 = fmul double %5, 2.000000e+00
  %7 = fcmp olt double %6, %1
  %8 = icmp ult i32 %2, 3
  %or.cond = and i1 %7, %8
  br i1 %or.cond, label %switch.lookup, label %13

switch.lookup:                                    ; preds = %3
  %9 = shl nuw nsw i32 %2, 3
  %10 = zext nneg i32 %9 to i64
  %11 = getelementptr inbounds i8, ptr %0, i64 %10
  %12 = getelementptr inbounds i8, ptr %11, i64 40
  store double %1, ptr %12, align 8, !tbaa !15
  br label %13

13:                                               ; preds = %switch.lookup, %3
  ret void
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: readwrite) 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, !14, i64 64}
!6 = !{!"_ZTS3Box", !7, i64 0, !13, i64 32, !14, i64 40, !14, i64 48, !14, i64 56, !14, i64 64, !14, i64 72}
!7 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE", !8, i64 0, !12, i64 8, !10, i64 16}
!8 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_Alloc_hiderE", !9, i64 0}
!9 = !{!"any pointer", !10, i64 0}
!10 = !{!"omnipotent char", !11, i64 0}
!11 = !{!"Simple C++ TBAA"}
!12 = !{!"long", !10, i64 0}
!13 = !{!"int", !10, i64 0}
!14 = !{!"double", !10, i64 0}
!15 = !{!14, !14, i64 0}


; Effective O3 passes: GlobalOptPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass