; LLVM IR from USDA-ARS-ACSL/MAIZSIM :: Crop source/radtrans.ll (ZN9CRadTrans2KbEd)

; 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.CRadTrans = type <{ double, double, double, double, double, double, double, double, double, double, i32, i8, [3 x i8] }>

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN9CRadTrans2KbEd(ptr noundef nonnull align 8 dereferenceable(85) %0, double noundef %1) #0 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca double, align 8
  %5 = alloca double, align 8
  %6 = alloca double, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store double %1, ptr %4, align 8, !tbaa !9
  %7 = load ptr, ptr %3, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #5
  store double 5.000000e-01, ptr %6, align 8, !tbaa !9
  %8 = getelementptr inbounds %class.CRadTrans, ptr %7, i32 0, i32 10
  %9 = load i32, ptr %8, align 8, !tbaa !11
  switch i32 %9, label %28 [
    i32 0, label %10
    i32 1, label %15
    i32 2, label %20
    i32 3, label %26
    i32 4, label %27
  ]

10:                                               ; preds = %2
  %11 = getelementptr inbounds %class.CRadTrans, ptr %7, i32 0, i32 6
  %12 = load double, ptr %11, align 8, !tbaa !15
  %13 = call double @sin(double noundef %12) #5
  %14 = fdiv double 5.000000e-01, %13
  store double %14, ptr %6, align 8, !tbaa !9
  br label %33

15:                                               ; preds = %2
  %16 = getelementptr inbounds %class.CRadTrans, ptr %7, i32 0, i32 6
  %17 = load double, ptr %16, align 8, !tbaa !15
  %18 = call double @sin(double noundef %17) #5
  %19 = fdiv double 1.000000e+00, %18
  store double %19, ptr %6, align 8, !tbaa !9
  br label %33

20:                                               ; preds = %2
  %21 = getelementptr inbounds %class.CRadTrans, ptr %7, i32 0, i32 6
  %22 = load double, ptr %21, align 8, !tbaa !15
  %23 = call noundef double @_Z3cotd(double noundef %22)
  %24 = fdiv double 2.000000e+00, %23
  %25 = fdiv double %24, 3.141500e+00
  store double %25, ptr %6, align 8, !tbaa !9
  br label %33

26:                                               ; preds = %2
  store double 1.000000e+00, ptr %6, align 8, !tbaa !9
  br label %33

27:                                               ; preds = %2
  store double 6.670000e-01, ptr %6, align 8, !tbaa !9
  br label %33

28:                                               ; preds = %2
  %29 = getelementptr inbounds %class.CRadTrans, ptr %7, i32 0, i32 6
  %30 = load double, ptr %29, align 8, !tbaa !15
  %31 = call double @sin(double noundef %30) #5
  %32 = fdiv double 5.000000e-01, %31
  store double %32, ptr %6, align 8, !tbaa !9
  br label %33

33:                                               ; preds = %28, %27, %26, %20, %15, %10
  %34 = getelementptr inbounds %class.CRadTrans, ptr %7, i32 0, i32 11
  %35 = load i8, ptr %34, align 4, !tbaa !16, !range !17, !noundef !18
  %36 = trunc i8 %35 to i1
  %37 = zext i1 %36 to i32
  %38 = icmp eq i32 %37, 1
  br i1 %38, label %39, label %42

39:                                               ; preds = %33
  %40 = getelementptr inbounds %class.CRadTrans, ptr %7, i32 0, i32 7
  %41 = load double, ptr %40, align 8, !tbaa !19
  store double %41, ptr %5, align 8, !tbaa !9
  br label %51

42:                                               ; preds = %33
  %43 = getelementptr inbounds %class.CRadTrans, ptr %7, i32 0, i32 10
  %44 = load i32, ptr %43, align 8, !tbaa !11
  switch i32 %44, label %49 [
    i32 0, label %45
    i32 1, label %46
    i32 2, label %47
    i32 6, label %48
  ]

45:                                               ; preds = %42
  store double 1.000000e+00, ptr %5, align 8, !tbaa !9
  br label %50

46:                                               ; preds = %42
  store double 1.000000e+01, ptr %5, align 8, !tbaa !9
  br label %50

47:                                               ; preds = %42
  store double 0.000000e+00, ptr %5, align 8, !tbaa !9
  br label %50

48:                                               ; preds = %42
  store double 1.370000e+00, ptr %5, align 8, !tbaa !9
  br label %50

49:                                               ; preds = %42
  store double 1.000000e+00, ptr %5, align 8, !tbaa !9
  br label %50

50:                                               ; preds = %49, %48, %47, %46, %45
  br label %51

51:                                               ; preds = %50, %39
  %52 = load double, ptr %5, align 8, !tbaa !9
  %53 = call noundef double @_Z3sqrd(double noundef %52)
  %54 = load double, ptr %4, align 8, !tbaa !9
  %55 = call double @tan(double noundef %54) #5
  %56 = call noundef double @_Z3sqrd(double noundef %55)
  %57 = fadd double %53, %56
  %58 = call double @sqrt(double noundef %57) #5
  %59 = load double, ptr %5, align 8, !tbaa !9
  %60 = load double, ptr %5, align 8, !tbaa !9
  %61 = fadd double %60, 1.182000e+00
  %62 = call double @pow(double noundef %61, double noundef -7.330000e-01) #5
  %63 = call double @llvm.fmuladd.f64(double 1.774000e+00, double %62, double %59)
  %64 = fdiv double %58, %63
  store double %64, ptr %6, align 8, !tbaa !9
  %65 = load double, ptr %6, align 8, !tbaa !9
  %66 = getelementptr inbounds %class.CRadTrans, ptr %7, i32 0, i32 1
  %67 = load double, ptr %66, align 8, !tbaa !20
  %68 = fmul double %65, %67
  %69 = getelementptr inbounds %class.CRadTrans, ptr %7, i32 0, i32 8
  store double %68, ptr %69, align 8, !tbaa !21
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #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: nounwind
declare double @sqrt(double noundef) #2

; Function Attrs: nounwind
declare double @sin(double noundef) #2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef double @_Z3cotd(double noundef) #3

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef double @_Z3sqrd(double noundef) #3

; Function Attrs: nounwind
declare double @tan(double noundef) #2

; Function Attrs: nounwind
declare double @pow(double noundef, double noundef) #2

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

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #3 = { 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 #4 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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 = !{!"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, !13, i64 80}
!12 = !{!"_ZTS9CRadTrans", !10, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !10, i64 32, !10, i64 40, !10, i64 48, !10, i64 56, !10, i64 64, !10, i64 72, !13, i64 80, !14, i64 84}
!13 = !{!"_ZTSN9CRadTrans10CLeafAngleE", !7, i64 0}
!14 = !{!"bool", !7, i64 0}
!15 = !{!12, !10, i64 48}
!16 = !{!12, !14, i64 84}
!17 = !{i8 0, i8 2}
!18 = !{}
!19 = !{!12, !10, i64 56}
!20 = !{!12, !10, i64 8}
!21 = !{!12, !10, i64 64}


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

@switch.table._ZN9CRadTrans2KbEd = private unnamed_addr constant [6 x double] [double 1.000000e+01, double 0.000000e+00, double 1.000000e+00, double 1.000000e+00, double 1.000000e+00, double 1.370000e+00], align 8

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN9CRadTrans2KbEd(ptr nocapture noundef nonnull align 8 dereferenceable(85) %0, double noundef %1) local_unnamed_addr #0 align 2 {
  %3 = getelementptr inbounds i8, ptr %0, i64 80
  %4 = load i32, ptr %3, align 8, !tbaa !5
  switch i32 %4, label %21 [
    i32 0, label %5
    i32 1, label %11
    i32 2, label %17
    i32 3, label %cdce.end
    i32 4, label %cdce.end
  ]

5:                                                ; preds = %2
  %6 = getelementptr inbounds i8, ptr %0, i64 48
  %7 = load double, ptr %6, align 8, !tbaa !12
  %8 = tail call double @llvm.fabs.f64(double %7)
  %9 = fcmp oeq double %8, 0x7FF0000000000000
  br i1 %9, label %cdce.call, label %cdce.end, !prof !13

cdce.call:                                        ; preds = %5
  %10 = tail call double @sin(double noundef %7) #5
  br label %cdce.end

11:                                               ; preds = %2
  %12 = getelementptr inbounds i8, ptr %0, i64 48
  %13 = load double, ptr %12, align 8, !tbaa !12
  %14 = tail call double @llvm.fabs.f64(double %13)
  %15 = fcmp oeq double %14, 0x7FF0000000000000
  br i1 %15, label %cdce.call6, label %cdce.end, !prof !13

cdce.call6:                                       ; preds = %11
  %16 = tail call double @sin(double noundef %13) #5
  br label %cdce.end

17:                                               ; preds = %2
  %18 = getelementptr inbounds i8, ptr %0, i64 48
  %19 = load double, ptr %18, align 8, !tbaa !12
  %20 = tail call noundef double @_Z3cotd(double noundef %19)
  br label %cdce.end

21:                                               ; preds = %2
  %22 = getelementptr inbounds i8, ptr %0, i64 48
  %23 = load double, ptr %22, align 8, !tbaa !12
  %24 = tail call double @llvm.fabs.f64(double %23)
  %25 = fcmp oeq double %24, 0x7FF0000000000000
  br i1 %25, label %cdce.call8, label %cdce.end, !prof !13

cdce.call8:                                       ; preds = %21
  %26 = tail call double @sin(double noundef %23) #5
  br label %cdce.end

cdce.end:                                         ; preds = %cdce.call8, %21, %cdce.call6, %11, %cdce.call, %5, %2, %2, %17
  %27 = getelementptr inbounds i8, ptr %0, i64 84
  %28 = load i8, ptr %27, align 4, !tbaa !14, !range !15, !noundef !16
  %29 = trunc nuw i8 %28 to i1
  br i1 %29, label %30, label %32

30:                                               ; preds = %cdce.end
  %31 = getelementptr inbounds i8, ptr %0, i64 56
  br label %.sink.split

32:                                               ; preds = %cdce.end
  %33 = load i32, ptr %3, align 8, !tbaa !5
  %switch.tableidx = add i32 %33, -1
  %34 = icmp ult i32 %switch.tableidx, 6
  br i1 %34, label %switch.lookup, label %36

switch.lookup:                                    ; preds = %32
  %35 = zext nneg i32 %switch.tableidx to i64
  %switch.gep = getelementptr inbounds [6 x double], ptr @switch.table._ZN9CRadTrans2KbEd, i64 0, i64 %35
  br label %.sink.split

.sink.split:                                      ; preds = %30, %switch.lookup
  %switch.gep.sink = phi ptr [ %switch.gep, %switch.lookup ], [ %31, %30 ]
  %switch.load = load double, ptr %switch.gep.sink, align 8
  br label %36

36:                                               ; preds = %.sink.split, %32
  %.0 = phi double [ 1.000000e+00, %32 ], [ %switch.load, %.sink.split ]
  %37 = tail call noundef double @_Z3sqrd(double noundef %.0)
  %38 = tail call double @tan(double noundef %1) #5
  %39 = tail call noundef double @_Z3sqrd(double noundef %38)
  %40 = fadd double %37, %39
  %41 = tail call double @sqrt(double noundef %40) #5
  %42 = fadd double %.0, 1.182000e+00
  %43 = tail call double @pow(double noundef %42, double noundef -7.330000e-01) #5
  %44 = tail call double @llvm.fmuladd.f64(double %43, double 1.774000e+00, double %.0)
  %45 = fdiv double %41, %44
  %46 = getelementptr inbounds i8, ptr %0, i64 8
  %47 = load double, ptr %46, align 8, !tbaa !17
  %48 = fmul double %47, %45
  %49 = getelementptr inbounds i8, ptr %0, i64 64
  store double %48, ptr %49, align 8, !tbaa !18
  ret void
}

; Function Attrs: mustprogress nofree nounwind willreturn memory(write)
declare double @sqrt(double noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nofree nounwind willreturn memory(write)
declare double @sin(double noundef) local_unnamed_addr #1

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef double @_Z3cotd(double noundef) local_unnamed_addr #2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef double @_Z3sqrd(double noundef) local_unnamed_addr #2

; Function Attrs: mustprogress nofree nounwind willreturn memory(write)
declare double @tan(double noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nofree nounwind willreturn memory(write)
declare double @pow(double noundef, double noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #3

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

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" }
attributes #1 = { mustprogress nofree nounwind willreturn memory(write) "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 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 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #4 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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, !10, i64 80}
!6 = !{!"_ZTS9CRadTrans", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !7, i64 32, !7, i64 40, !7, i64 48, !7, i64 56, !7, i64 64, !7, i64 72, !10, i64 80, !11, i64 84}
!7 = !{!"double", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"_ZTSN9CRadTrans10CLeafAngleE", !8, i64 0}
!11 = !{!"bool", !8, i64 0}
!12 = !{!6, !7, i64 48}
!13 = !{!"branch_weights", i32 1, i32 1048575}
!14 = !{!6, !11, i64 84}
!15 = !{i8 0, i8 2}
!16 = !{}
!17 = !{!6, !7, i64 8}
!18 = !{!6, !7, i64 64}


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