; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --function-signature --include-generated-funcs
; RUN: if [ %llvmver -lt 16 ]; then %opt < %s %loadEnzyme -enzyme -enzyme-preopt=false -mem2reg -sroa -instsimplify -simplifycfg -S | FileCheck %s; fi
; RUN: %opt < %s %newLoadEnzyme -passes="enzyme,function(mem2reg,sroa,instsimplify,%simplifycfg)" -enzyme-preopt=false -S | FileCheck %s

%struct.Gradients = type { double, double }

; Function Attrs: nounwind
declare %struct.Gradients @__enzyme_fwddiff(double (double)*, ...)

; Function Attrs: norecurse nounwind readnone uwtable
define double @fun2(double %x) {
entry:
  %cmp.inv = fcmp oge double %x, 0.000000e+00
  %.x = select i1 %cmp.inv, double %x, double 0.000000e+00
  ret double %.x
}

; Function Attrs: nounwind uwtable
define i32 @main() {
entry:
  %call3.4 = tail call %struct.Gradients (double (double)*, ...) @__enzyme_fwddiff(double (double)* nonnull @fun2, metadata !"enzyme_width", i64 2, double 2.0, double 0.000000e+00, double 1.000000e+00)
  ret i32 0
}

; CHECK: define {{[^@]+}}@fwddiffe2fun2(double [[X:%.*]], [2 x double] %"x'")
; CHECK-NEXT:  entry:
; CHECK-NEXT:    [[CMP_INV:%.*]] = fcmp oge double [[X]], 0.000000e+00
; CHECK-NEXT:    [[TMP0:%.*]] = extractvalue [2 x double] %"x'", 0
; CHECK-NEXT:    %".x'ipse" = select {{(fast )?}}i1 [[CMP_INV]], double [[TMP0]], double 0.000000e+00
; CHECK-NEXT:    [[TMP1:%.*]] = insertvalue [2 x double] undef, double %".x'ipse", 0
; CHECK-NEXT:    [[TMP2:%.*]] = extractvalue [2 x double] %"x'", 1
; CHECK-NEXT:    %".x'ipse1" = select {{(fast )?}}i1 [[CMP_INV]], double [[TMP2]], double 0.000000e+00
; CHECK-NEXT:    [[TMP3:%.*]] = insertvalue [2 x double] [[TMP1]], double %".x'ipse1", 1
; CHECK-NEXT:    ret [2 x double] [[TMP3]]
;
