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

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN6CSolar10SetAzimuthEv(ptr noundef nonnull align 8 dereferenceable(418) %0) #0 align 2 {
  %2 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  %3 = load ptr, ptr %2, align 8
  %4 = getelementptr inbounds %class.CSolar, ptr %3, i32 0, i32 2
  %5 = load double, ptr %4, align 8, !tbaa !9
  %6 = getelementptr inbounds %class.CSolar, ptr %3, i32 0, i32 9
  %7 = load double, ptr %6, align 8, !tbaa !14
  %8 = fcmp olt double %5, %7
  br i1 %8, label %9, label %30

9:                                                ; preds = %1
  %10 = getelementptr inbounds %class.CSolar, ptr %3, i32 0, i32 10
  %11 = load double, ptr %10, align 8, !tbaa !15
  %12 = getelementptr inbounds %class.CSolar, ptr %3, i32 0, i32 3
  %13 = load double, ptr %12, align 8, !tbaa !16
  %14 = call double @sin(double noundef %13) #3
  %15 = getelementptr inbounds %class.CSolar, ptr %3, i32 0, i32 8
  %16 = load double, ptr %15, align 8, !tbaa !17
  %17 = call double @sin(double noundef %16) #3
  %18 = fneg double %17
  %19 = call double @llvm.fmuladd.f64(double %11, double %14, double %18)
  %20 = getelementptr inbounds %class.CSolar, ptr %3, i32 0, i32 3
  %21 = load double, ptr %20, align 8, !tbaa !16
  %22 = call double @cos(double noundef %21) #3
  %23 = getelementptr inbounds %class.CSolar, ptr %3, i32 0, i32 16
  %24 = load double, ptr %23, align 8, !tbaa !18
  %25 = fmul double %22, %24
  %26 = fdiv double %19, %25
  %27 = call double @acos(double noundef %26) #3
  %28 = fneg double %27
  %29 = getelementptr inbounds %class.CSolar, ptr %3, i32 0, i32 11
  store double %28, ptr %29, align 8, !tbaa !19
  br label %59

30:                                               ; preds = %1
  %31 = getelementptr inbounds %class.CSolar, ptr %3, i32 0, i32 2
  %32 = load double, ptr %31, align 8, !tbaa !9
  %33 = getelementptr inbounds %class.CSolar, ptr %3, i32 0, i32 9
  %34 = load double, ptr %33, align 8, !tbaa !14
  %35 = fcmp ogt double %32, %34
  br i1 %35, label %36, label %56

36:                                               ; preds = %30
  %37 = getelementptr inbounds %class.CSolar, ptr %3, i32 0, i32 10
  %38 = load double, ptr %37, align 8, !tbaa !15
  %39 = getelementptr inbounds %class.CSolar, ptr %3, i32 0, i32 3
  %40 = load double, ptr %39, align 8, !tbaa !16
  %41 = call double @sin(double noundef %40) #3
  %42 = getelementptr inbounds %class.CSolar, ptr %3, i32 0, i32 8
  %43 = load double, ptr %42, align 8, !tbaa !17
  %44 = call double @sin(double noundef %43) #3
  %45 = fneg double %44
  %46 = call double @llvm.fmuladd.f64(double %38, double %41, double %45)
  %47 = getelementptr inbounds %class.CSolar, ptr %3, i32 0, i32 3
  %48 = load double, ptr %47, align 8, !tbaa !16
  %49 = call double @cos(double noundef %48) #3
  %50 = getelementptr inbounds %class.CSolar, ptr %3, i32 0, i32 16
  %51 = load double, ptr %50, align 8, !tbaa !18
  %52 = fmul double %49, %51
  %53 = fdiv double %46, %52
  %54 = call double @acos(double noundef %53) #3
  %55 = getelementptr inbounds %class.CSolar, ptr %3, i32 0, i32 11
  store double %54, ptr %55, align 8, !tbaa !19
  br label %58

56:                                               ; preds = %30
  %57 = getelementptr inbounds %class.CSolar, ptr %3, i32 0, i32 11
  store double 0.000000e+00, ptr %57, align 8, !tbaa !19
  br label %58

58:                                               ; preds = %56, %36
  br label %59

59:                                               ; preds = %58, %9
  ret void
}

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

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

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

; Function Attrs: nounwind
declare double @acos(double noundef) #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 = { 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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #3 = { 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, !12, i64 8}
!10 = !{!"_ZTS6CSolar", !11, i64 0, !12, i64 8, !12, i64 16, !12, i64 24, !12, i64 32, !12, i64 40, !12, i64 48, !12, i64 56, !12, i64 64, !12, i64 72, !12, i64 80, !12, i64 88, !12, i64 96, !12, i64 104, !12, i64 112, !12, i64 120, !12, i64 128, !12, i64 136, !12, i64 144, !12, i64 152, !12, i64 160, !12, i64 168, !12, i64 176, !12, i64 184, !12, i64 192, !12, i64 200, !12, i64 208, !12, i64 216, !12, i64 224, !12, i64 232, !12, i64 240, !12, i64 248, !12, i64 256, !12, i64 264, !12, i64 272, !12, i64 280, !12, i64 288, !12, i64 296, !12, i64 304, !12, i64 312, !12, i64 320, !12, i64 328, !12, i64 336, !12, i64 344, !12, i64 352, !12, i64 360, !12, i64 368, !12, i64 376, !12, i64 384, !12, i64 392, !12, i64 400, !12, i64 408, !13, i64 416, !13, i64 417}
!11 = !{!"int", !7, i64 0}
!12 = !{!"double", !7, i64 0}
!13 = !{!"bool", !7, i64 0}
!14 = !{!10, !12, i64 64}
!15 = !{!10, !12, i64 72}
!16 = !{!10, !12, i64 16}
!17 = !{!10, !12, i64 56}
!18 = !{!10, !12, i64 120}
!19 = !{!10, !12, i64 80}


; 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, argmem: readwrite) uwtable
define dso_local void @_ZN6CSolar10SetAzimuthEv(ptr nocapture noundef nonnull align 8 dereferenceable(418) %0) local_unnamed_addr #0 align 2 {
  %2 = getelementptr inbounds i8, ptr %0, i64 8
  %3 = load double, ptr %2, align 8, !tbaa !5
  %4 = getelementptr inbounds i8, ptr %0, i64 64
  %5 = load double, ptr %4, align 8, !tbaa !12
  %6 = fcmp olt double %3, %5
  br i1 %6, label %7, label %26

7:                                                ; preds = %1
  %8 = getelementptr inbounds i8, ptr %0, i64 72
  %9 = load double, ptr %8, align 8, !tbaa !13
  %10 = getelementptr inbounds i8, ptr %0, i64 16
  %11 = load double, ptr %10, align 8, !tbaa !14
  %12 = tail call double @sin(double noundef %11) #3
  %13 = getelementptr inbounds i8, ptr %0, i64 56
  %14 = load double, ptr %13, align 8, !tbaa !15
  %15 = tail call double @sin(double noundef %14) #3
  %16 = fneg double %15
  %17 = tail call double @llvm.fmuladd.f64(double %9, double %12, double %16)
  %18 = load double, ptr %10, align 8, !tbaa !14
  %19 = tail call double @cos(double noundef %18) #3
  %20 = getelementptr inbounds i8, ptr %0, i64 120
  %21 = load double, ptr %20, align 8, !tbaa !16
  %22 = fmul double %19, %21
  %23 = fdiv double %17, %22
  %24 = tail call double @acos(double noundef %23) #3
  %25 = fneg double %24
  br label %46

26:                                               ; preds = %1
  %27 = fcmp ogt double %3, %5
  br i1 %27, label %28, label %46

28:                                               ; preds = %26
  %29 = getelementptr inbounds i8, ptr %0, i64 72
  %30 = load double, ptr %29, align 8, !tbaa !13
  %31 = getelementptr inbounds i8, ptr %0, i64 16
  %32 = load double, ptr %31, align 8, !tbaa !14
  %33 = tail call double @sin(double noundef %32) #3
  %34 = getelementptr inbounds i8, ptr %0, i64 56
  %35 = load double, ptr %34, align 8, !tbaa !15
  %36 = tail call double @sin(double noundef %35) #3
  %37 = fneg double %36
  %38 = tail call double @llvm.fmuladd.f64(double %30, double %33, double %37)
  %39 = load double, ptr %31, align 8, !tbaa !14
  %40 = tail call double @cos(double noundef %39) #3
  %41 = getelementptr inbounds i8, ptr %0, i64 120
  %42 = load double, ptr %41, align 8, !tbaa !16
  %43 = fmul double %40, %42
  %44 = fdiv double %38, %43
  %45 = tail call double @acos(double noundef %44) #3
  br label %46

46:                                               ; preds = %26, %28, %7
  %.sink = phi double [ %45, %28 ], [ %25, %7 ], [ 0.000000e+00, %26 ]
  %47 = getelementptr inbounds i8, ptr %0, i64 80
  store double %.sink, ptr %47, align 8, !tbaa !17
  ret void
}

; Function Attrs: mustprogress nofree nounwind willreturn memory(write)
declare double @sin(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) #2

; 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 @acos(double noundef) local_unnamed_addr #1

attributes #0 = { mustprogress nofree nounwind willreturn memory(write, 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" }
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 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #3 = { 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 8}
!6 = !{!"_ZTS6CSolar", !7, 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, !10, i64 80, !10, i64 88, !10, i64 96, !10, i64 104, !10, i64 112, !10, i64 120, !10, i64 128, !10, i64 136, !10, i64 144, !10, i64 152, !10, i64 160, !10, i64 168, !10, i64 176, !10, i64 184, !10, i64 192, !10, i64 200, !10, i64 208, !10, i64 216, !10, i64 224, !10, i64 232, !10, i64 240, !10, i64 248, !10, i64 256, !10, i64 264, !10, i64 272, !10, i64 280, !10, i64 288, !10, i64 296, !10, i64 304, !10, i64 312, !10, i64 320, !10, i64 328, !10, i64 336, !10, i64 344, !10, i64 352, !10, i64 360, !10, i64 368, !10, i64 376, !10, i64 384, !10, i64 392, !10, i64 400, !10, i64 408, !11, i64 416, !11, i64 417}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"double", !8, i64 0}
!11 = !{!"bool", !8, i64 0}
!12 = !{!6, !10, i64 64}
!13 = !{!6, !10, i64 72}
!14 = !{!6, !10, i64 16}
!15 = !{!6, !10, i64 56}
!16 = !{!6, !10, i64 120}
!17 = !{!6, !10, i64 80}


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