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

; 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] }>

@__const._ZN9CRadTrans2KdEd.gauss3 = external hidden unnamed_addr constant [3 x double], align 16
@__const._ZN9CRadTrans2KdEd.weight3 = external hidden unnamed_addr constant [3 x double], align 16

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN9CRadTrans2KdEd(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 [3 x double], align 16
  %6 = alloca [3 x double], align 16
  %7 = alloca double, align 8
  %8 = alloca double, align 8
  %9 = alloca double, align 8
  %10 = alloca double, align 8
  %11 = alloca double, align 8
  %12 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store double %1, ptr %4, align 8, !tbaa !9
  %13 = load ptr, ptr %3, align 8
  call void @llvm.lifetime.start.p0(i64 24, ptr %5) #6
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %5, ptr align 16 @__const._ZN9CRadTrans2KdEd.gauss3, i64 24, i1 false)
  call void @llvm.lifetime.start.p0(i64 24, ptr %6) #6
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %6, ptr align 16 @__const._ZN9CRadTrans2KdEd.weight3, i64 24, i1 false)
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #6
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #6
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #6
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #6
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #6
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #6
  %14 = getelementptr inbounds %class.CRadTrans, ptr %13, i32 0, i32 11
  %15 = load i8, ptr %14, align 4, !tbaa !11, !range !15, !noundef !16
  %16 = trunc i8 %15 to i1
  %17 = zext i1 %16 to i32
  %18 = icmp eq i32 %17, 1
  br i1 %18, label %19, label %22

19:                                               ; preds = %2
  %20 = getelementptr inbounds %class.CRadTrans, ptr %13, i32 0, i32 7
  %21 = load double, ptr %20, align 8, !tbaa !17
  store double %21, ptr %11, align 8, !tbaa !9
  br label %31

22:                                               ; preds = %2
  %23 = getelementptr inbounds %class.CRadTrans, ptr %13, i32 0, i32 10
  %24 = load i32, ptr %23, align 8, !tbaa !18
  switch i32 %24, label %29 [
    i32 0, label %25
    i32 1, label %26
    i32 2, label %27
    i32 6, label %28
  ]

25:                                               ; preds = %22
  store double 1.000000e+00, ptr %11, align 8, !tbaa !9
  br label %30

26:                                               ; preds = %22
  store double 1.000000e+01, ptr %11, align 8, !tbaa !9
  br label %30

27:                                               ; preds = %22
  store double 0.000000e+00, ptr %11, align 8, !tbaa !9
  br label %30

28:                                               ; preds = %22
  store double 1.370000e+00, ptr %11, align 8, !tbaa !9
  br label %30

29:                                               ; preds = %22
  store double 1.000000e+00, ptr %11, align 8, !tbaa !9
  br label %30

30:                                               ; preds = %29, %28, %27, %26, %25
  br label %31

31:                                               ; preds = %30, %19
  store double 0.000000e+00, ptr %8, align 8, !tbaa !9
  store i32 0, ptr %12, align 4, !tbaa !19
  br label %32

32:                                               ; preds = %73, %31
  %33 = load i32, ptr %12, align 4, !tbaa !19
  %34 = icmp slt i32 %33, 3
  br i1 %34, label %35, label %76

35:                                               ; preds = %32
  %36 = load i32, ptr %12, align 4, !tbaa !19
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds [3 x double], ptr %5, i64 0, i64 %37
  %39 = load double, ptr %38, align 8, !tbaa !9
  %40 = call double @llvm.fmuladd.f64(double 7.853750e-01, double %39, double 7.853750e-01)
  store double %40, ptr %10, align 8, !tbaa !9
  %41 = load double, ptr %11, align 8, !tbaa !9
  %42 = call noundef double @_Z3sqrd(double noundef %41)
  %43 = load double, ptr %10, align 8, !tbaa !9
  %44 = call double @tan(double noundef %43) #6
  %45 = call noundef double @_Z3sqrd(double noundef %44)
  %46 = fadd double %42, %45
  %47 = call double @sqrt(double noundef %46) #6
  %48 = load double, ptr %11, align 8, !tbaa !9
  %49 = load double, ptr %11, align 8, !tbaa !9
  %50 = fadd double %49, 1.182000e+00
  %51 = call double @pow(double noundef %50, double noundef -7.330000e-01) #6
  %52 = call double @llvm.fmuladd.f64(double 1.774000e+00, double %51, double %48)
  %53 = fdiv double %47, %52
  store double %53, ptr %9, align 8, !tbaa !9
  %54 = load double, ptr %8, align 8, !tbaa !9
  %55 = load double, ptr %9, align 8, !tbaa !9
  %56 = fneg double %55
  %57 = load double, ptr %4, align 8, !tbaa !9
  %58 = fmul double %56, %57
  %59 = call double @exp(double noundef %58) #6
  %60 = fmul double 2.000000e+00, %59
  %61 = load double, ptr %10, align 8, !tbaa !9
  %62 = call double @sin(double noundef %61) #6
  %63 = fmul double %60, %62
  %64 = load double, ptr %10, align 8, !tbaa !9
  %65 = call double @cos(double noundef %64) #6
  %66 = fmul double %63, %65
  %67 = fmul double 7.853750e-01, %66
  %68 = load i32, ptr %12, align 4, !tbaa !19
  %69 = sext i32 %68 to i64
  %70 = getelementptr inbounds [3 x double], ptr %6, i64 0, i64 %69
  %71 = load double, ptr %70, align 8, !tbaa !9
  %72 = call double @llvm.fmuladd.f64(double %67, double %71, double %54)
  store double %72, ptr %8, align 8, !tbaa !9
  br label %73

73:                                               ; preds = %35
  %74 = load i32, ptr %12, align 4, !tbaa !19
  %75 = add nsw i32 %74, 1
  store i32 %75, ptr %12, align 4, !tbaa !19
  br label %32, !llvm.loop !21

76:                                               ; preds = %32
  %77 = load double, ptr %4, align 8, !tbaa !9
  %78 = fcmp ole double %77, 0.000000e+00
  br i1 %78, label %79, label %80

79:                                               ; preds = %76
  store double 0.000000e+00, ptr %7, align 8, !tbaa !9
  br label %86

80:                                               ; preds = %76
  %81 = load double, ptr %8, align 8, !tbaa !9
  %82 = call double @log(double noundef %81) #6
  %83 = fneg double %82
  %84 = load double, ptr %4, align 8, !tbaa !9
  %85 = fdiv double %83, %84
  store double %85, ptr %7, align 8, !tbaa !9
  br label %86

86:                                               ; preds = %80, %79
  %87 = load double, ptr %7, align 8, !tbaa !9
  %88 = getelementptr inbounds %class.CRadTrans, ptr %13, i32 0, i32 1
  %89 = load double, ptr %88, align 8, !tbaa !23
  %90 = fmul double %87, %89
  %91 = getelementptr inbounds %class.CRadTrans, ptr %13, i32 0, i32 9
  store double %90, ptr %91, align 8, !tbaa !24
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #6
  call void @llvm.lifetime.end.p0(i64 24, ptr %6) #6
  call void @llvm.lifetime.end.p0(i64 24, ptr %5) #6
  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 @_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

; 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) #5

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

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

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

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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #6 = { 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, !14, i64 84}
!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 = !{i8 0, i8 2}
!16 = !{}
!17 = !{!12, !10, i64 56}
!18 = !{!12, !13, i64 80}
!19 = !{!20, !20, i64 0}
!20 = !{!"int", !7, i64 0}
!21 = distinct !{!21, !22}
!22 = !{!"llvm.loop.mustprogress"}
!23 = !{!12, !10, i64 8}
!24 = !{!12, !10, i64 72}


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

@__const._ZN9CRadTrans2KdEd.gauss3 = external hidden unnamed_addr constant [3 x double], align 16
@__const._ZN9CRadTrans2KdEd.weight3 = external hidden unnamed_addr constant [3 x double], align 16
@switch.table._ZN9CRadTrans2KdEd = 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 @_ZN9CRadTrans2KdEd(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 84
  %4 = load i8, ptr %3, align 4, !tbaa !5, !range !12, !noundef !13
  %5 = trunc nuw i8 %4 to i1
  br i1 %5, label %6, label %8

6:                                                ; preds = %2
  %7 = getelementptr inbounds i8, ptr %0, i64 56
  br label %.sink.split

8:                                                ; preds = %2
  %9 = getelementptr inbounds i8, ptr %0, i64 80
  %10 = load i32, ptr %9, align 8, !tbaa !14
  %switch.tableidx = add i32 %10, -1
  %11 = icmp ult i32 %switch.tableidx, 6
  br i1 %11, label %switch.lookup, label %13

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

.sink.split:                                      ; preds = %6, %switch.lookup
  %switch.gep.sink = phi ptr [ %switch.gep, %switch.lookup ], [ %7, %6 ]
  %switch.load = load double, ptr %switch.gep.sink, align 8
  br label %13

13:                                               ; preds = %.sink.split, %8
  %.017 = phi double [ 1.000000e+00, %8 ], [ %switch.load, %.sink.split ]
  %14 = fadd double %.017, 1.182000e+00
  %15 = load double, ptr @__const._ZN9CRadTrans2KdEd.gauss3, align 16, !tbaa !15
  %16 = tail call double @llvm.fmuladd.f64(double %15, double 7.853750e-01, double 7.853750e-01)
  %17 = tail call noundef double @_Z3sqrd(double noundef %.017)
  %18 = tail call double @tan(double noundef %16) #4
  %19 = tail call noundef double @_Z3sqrd(double noundef %18)
  %20 = fadd double %17, %19
  %21 = tail call double @sqrt(double noundef %20) #4
  %22 = tail call double @pow(double noundef %14, double noundef -7.330000e-01) #4
  %23 = tail call double @llvm.fmuladd.f64(double %22, double 1.774000e+00, double %.017)
  %24 = fneg double %21
  %25 = fdiv double %24, %23
  %26 = fmul double %25, %1
  %27 = tail call double @exp(double noundef %26) #4
  %28 = tail call double @sin(double noundef %16) #4
  %29 = tail call double @cos(double noundef %16) #4
  %30 = load double, ptr @__const._ZN9CRadTrans2KdEd.weight3, align 16, !tbaa !15
  %31 = load double, ptr getelementptr inbounds (i8, ptr @__const._ZN9CRadTrans2KdEd.gauss3, i64 8), align 8, !tbaa !15
  %32 = tail call double @llvm.fmuladd.f64(double %31, double 7.853750e-01, double 7.853750e-01)
  %33 = tail call noundef double @_Z3sqrd(double noundef %.017)
  %34 = tail call double @tan(double noundef %32) #4
  %35 = tail call noundef double @_Z3sqrd(double noundef %34)
  %36 = fadd double %33, %35
  %37 = tail call double @sqrt(double noundef %36) #4
  %38 = tail call double @pow(double noundef %14, double noundef -7.330000e-01) #4
  %39 = tail call double @llvm.fmuladd.f64(double %38, double 1.774000e+00, double %.017)
  %40 = fneg double %37
  %41 = fdiv double %40, %39
  %42 = fmul double %41, %1
  %43 = tail call double @exp(double noundef %42) #4
  %44 = tail call double @sin(double noundef %32) #4
  %45 = tail call double @cos(double noundef %32) #4
  %46 = load double, ptr getelementptr inbounds (i8, ptr @__const._ZN9CRadTrans2KdEd.weight3, i64 8), align 8, !tbaa !15
  %47 = load double, ptr getelementptr inbounds (i8, ptr @__const._ZN9CRadTrans2KdEd.gauss3, i64 16), align 16, !tbaa !15
  %48 = tail call double @llvm.fmuladd.f64(double %47, double 7.853750e-01, double 7.853750e-01)
  %49 = tail call noundef double @_Z3sqrd(double noundef %.017)
  %50 = tail call double @tan(double noundef %48) #4
  %51 = tail call noundef double @_Z3sqrd(double noundef %50)
  %52 = fadd double %49, %51
  %53 = tail call double @sqrt(double noundef %52) #4
  %54 = tail call double @pow(double noundef %14, double noundef -7.330000e-01) #4
  %55 = tail call double @llvm.fmuladd.f64(double %54, double 1.774000e+00, double %.017)
  %56 = fneg double %53
  %57 = fdiv double %56, %55
  %58 = fmul double %57, %1
  %59 = tail call double @exp(double noundef %58) #4
  %60 = tail call double @sin(double noundef %48) #4
  %61 = tail call double @cos(double noundef %48) #4
  %62 = fcmp ugt double %1, 0.000000e+00
  br i1 %62, label %63, label %83

63:                                               ; preds = %13
  %64 = fmul double %59, 2.000000e+00
  %65 = fmul double %64, %60
  %66 = fmul double %65, %61
  %67 = fmul double %66, 7.853750e-01
  %68 = load double, ptr getelementptr inbounds (i8, ptr @__const._ZN9CRadTrans2KdEd.weight3, i64 16), align 16, !tbaa !15
  %69 = fmul double %43, 2.000000e+00
  %70 = fmul double %69, %44
  %71 = fmul double %70, %45
  %72 = fmul double %71, 7.853750e-01
  %73 = fmul double %27, 2.000000e+00
  %74 = fmul double %73, %28
  %75 = fmul double %74, %29
  %76 = fmul double %75, 7.853750e-01
  %77 = tail call double @llvm.fmuladd.f64(double %76, double %30, double 0.000000e+00)
  %78 = tail call double @llvm.fmuladd.f64(double %72, double %46, double %77)
  %79 = tail call double @llvm.fmuladd.f64(double %67, double %68, double %78)
  %80 = tail call double @log(double noundef %79) #4
  %81 = fneg double %80
  %82 = fdiv double %81, %1
  br label %83

83:                                               ; preds = %13, %63
  %.018 = phi double [ %82, %63 ], [ 0.000000e+00, %13 ]
  %84 = getelementptr inbounds i8, ptr %0, i64 8
  %85 = load double, ptr %84, align 8, !tbaa !16
  %86 = fmul double %.018, %85
  %87 = getelementptr inbounds i8, ptr %0, i64 72
  store double %86, ptr %87, align 8, !tbaa !17
  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 @_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: mustprogress nofree nounwind willreturn memory(write)
declare double @exp(double noundef) local_unnamed_addr #1

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

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

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 = { 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, !11, i64 84}
!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 = !{i8 0, i8 2}
!13 = !{}
!14 = !{!6, !10, i64 80}
!15 = !{!7, !7, i64 0}
!16 = !{!6, !7, i64 8}
!17 = !{!6, !7, i64 72}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,LCSSAPass,LICMPass,LoopRotatePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass