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

; 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: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

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

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef double @_ZN9CRadTrans5GetKbEv(ptr noundef nonnull align 8 dereferenceable(85)) #2 align 2

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

; Function Attrs: mustprogress uwtable
define dso_local noundef double @_ZN9CRadTrans3QscEv(ptr noundef nonnull align 8 dereferenceable(85) %0) #3 align 2 {
  %2 = alloca double, align 8
  %3 = alloca ptr, align 8
  %4 = alloca double, align 8
  %5 = alloca double, align 8
  %6 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  %7 = load ptr, ptr %3, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  %8 = getelementptr inbounds %class.CRadTrans, ptr %7, i32 0, i32 5
  %9 = load double, ptr %8, align 8, !tbaa !9
  %10 = fcmp oeq double %9, 0.000000e+00
  br i1 %10, label %11, label %12

11:                                               ; preds = %1
  store double 0.000000e+00, ptr %2, align 8
  store i32 1, ptr %6, align 4
  br label %51

12:                                               ; preds = %1
  %13 = getelementptr inbounds %class.CRadTrans, ptr %7, i32 0, i32 3
  %14 = load double, ptr %13, align 8, !tbaa !14
  %15 = getelementptr inbounds %class.CRadTrans, ptr %7, i32 0, i32 0
  %16 = load double, ptr %15, align 8, !tbaa !15
  %17 = call double @sqrt(double noundef %16) #4
  %18 = fneg double %17
  %19 = call noundef double @_ZN9CRadTrans5GetKbEv(ptr noundef nonnull align 8 dereferenceable(85) %7)
  %20 = fmul double %18, %19
  %21 = getelementptr inbounds %class.CRadTrans, ptr %7, i32 0, i32 5
  %22 = load double, ptr %21, align 8, !tbaa !9
  %23 = fmul double %20, %22
  %24 = call double @exp(double noundef %23) #4
  %25 = fsub double 1.000000e+00, %24
  %26 = fmul double %14, %25
  %27 = getelementptr inbounds %class.CRadTrans, ptr %7, i32 0, i32 0
  %28 = load double, ptr %27, align 8, !tbaa !15
  %29 = call double @sqrt(double noundef %28) #4
  %30 = call noundef double @_ZN9CRadTrans5GetKbEv(ptr noundef nonnull align 8 dereferenceable(85) %7)
  %31 = fmul double %29, %30
  %32 = fdiv double %26, %31
  store double %32, ptr %4, align 8, !tbaa !16
  %33 = getelementptr inbounds %class.CRadTrans, ptr %7, i32 0, i32 3
  %34 = load double, ptr %33, align 8, !tbaa !14
  %35 = call noundef double @_ZN9CRadTrans5GetKbEv(ptr noundef nonnull align 8 dereferenceable(85) %7)
  %36 = fneg double %35
  %37 = getelementptr inbounds %class.CRadTrans, ptr %7, i32 0, i32 5
  %38 = load double, ptr %37, align 8, !tbaa !9
  %39 = fmul double %36, %38
  %40 = call double @exp(double noundef %39) #4
  %41 = fsub double 1.000000e+00, %40
  %42 = fmul double %34, %41
  %43 = call noundef double @_ZN9CRadTrans5GetKbEv(ptr noundef nonnull align 8 dereferenceable(85) %7)
  %44 = fdiv double %42, %43
  store double %44, ptr %5, align 8, !tbaa !16
  %45 = load double, ptr %4, align 8, !tbaa !16
  %46 = load double, ptr %5, align 8, !tbaa !16
  %47 = fsub double %45, %46
  %48 = getelementptr inbounds %class.CRadTrans, ptr %7, i32 0, i32 5
  %49 = load double, ptr %48, align 8, !tbaa !9
  %50 = fdiv double %47, %49
  store double %50, ptr %2, align 8
  store i32 1, ptr %6, align 4
  br label %51

51:                                               ; preds = %12, %11
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #4
  %52 = load double, ptr %2, align 8
  ret double %52
}

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

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef double @_ZN9CRadTrans5GetKbEv(ptr noundef nonnull align 8 dereferenceable(85)) local_unnamed_addr #1 align 2

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef double @_ZN9CRadTrans3QscEv(ptr noundef nonnull align 8 dereferenceable(85) %0) local_unnamed_addr #1 align 2 {
  %2 = getelementptr inbounds i8, ptr %0, i64 40
  %3 = load double, ptr %2, align 8, !tbaa !5
  %4 = fcmp oeq double %3, 0.000000e+00
  br i1 %4, label %39, label %5

5:                                                ; preds = %1
  %6 = getelementptr inbounds i8, ptr %0, i64 24
  %7 = load <2 x double>, ptr %6, align 8
  %8 = load double, ptr %0, align 8, !tbaa !12
  %9 = tail call double @sqrt(double noundef %8) #2
  %10 = fneg double %9
  %11 = tail call noundef double @_ZN9CRadTrans5GetKbEv(ptr noundef nonnull align 8 dereferenceable(85) %0)
  %12 = fmul double %11, %10
  %13 = load double, ptr %2, align 8, !tbaa !5
  %14 = fmul double %12, %13
  %15 = tail call double @exp(double noundef %14) #2
  %16 = load double, ptr %0, align 8, !tbaa !12
  %17 = tail call double @sqrt(double noundef %16) #2
  %18 = tail call noundef double @_ZN9CRadTrans5GetKbEv(ptr noundef nonnull align 8 dereferenceable(85) %0)
  %19 = fmul double %17, %18
  %20 = load double, ptr %6, align 8, !tbaa !13
  %21 = tail call noundef double @_ZN9CRadTrans5GetKbEv(ptr noundef nonnull align 8 dereferenceable(85) %0)
  %22 = fneg double %21
  %23 = load double, ptr %2, align 8, !tbaa !5
  %24 = fmul double %23, %22
  %25 = tail call double @exp(double noundef %24) #2
  %26 = tail call noundef double @_ZN9CRadTrans5GetKbEv(ptr noundef nonnull align 8 dereferenceable(85) %0)
  %27 = insertelement <2 x double> poison, double %15, i64 0
  %28 = insertelement <2 x double> %27, double %25, i64 1
  %29 = fsub <2 x double> <double 1.000000e+00, double 1.000000e+00>, %28
  %30 = insertelement <2 x double> %7, double %20, i64 1
  %31 = fmul <2 x double> %30, %29
  %32 = insertelement <2 x double> poison, double %19, i64 0
  %33 = insertelement <2 x double> %32, double %26, i64 1
  %34 = fdiv <2 x double> %31, %33
  %shift = shufflevector <2 x double> %34, <2 x double> poison, <2 x i32> <i32 1, i32 poison>
  %35 = fsub <2 x double> %34, %shift
  %36 = extractelement <2 x double> %35, i64 0
  %37 = load double, ptr %2, align 8, !tbaa !5
  %38 = fdiv double %36, %37
  br label %39

39:                                               ; preds = %1, %5
  %.0 = phi double [ %38, %5 ], [ 0.000000e+00, %1 ]
  ret double %.0
}

attributes #0 = { 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 #1 = { 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 = { 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, !7, i64 40}
!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 0}
!13 = !{!6, !7, i64 24}


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