; 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 -instsimplify -gvn -S | FileCheck %s; fi
; RUN: %opt < %s %newLoadEnzyme -passes="enzyme,function(mem2reg,instsimplify,gvn)" -enzyme-preopt=false -S | FileCheck %s


define void @addOneMem(double* nocapture %x) {
entry:
  %0 = load double, double* %x, align 8
  %add = fadd double %0, 1.000000e+00
  store double %add, double* %x, align 8
  ret void
}

define void @test_derivative(double* %x, double* %xp1, double* %xp2, double* %xp3) {
entry:
  call void (void (double*)*, ...) @__enzyme_fwddiff(void (double*)* nonnull @addOneMem, metadata !"enzyme_width", i64 3, double* %x, double* %xp1, double* %xp2, double* %xp3)
  ret void
}

declare void @__enzyme_fwddiff(void (double*)*, ...)

; CHECK: define internal void @fwddiffe3addOneMem(double* nocapture %x, [3 x double*] %"x'")
; CHECK-NEXT: entry:
; CHECK-NEXT:   %0 = extractvalue [3 x double*] %"x'", 0
; CHECK-NEXT:   %"'ipl" = load double, double* %0, align 8
; CHECK-NEXT:   %1 = extractvalue [3 x double*] %"x'", 1
; CHECK-NEXT:   %"'ipl1" = load double, double* %1, align 8
; CHECK-NEXT:   %2 = extractvalue [3 x double*] %"x'", 2
; CHECK-NEXT:   %"'ipl2" = load double, double* %2, align 8
; CHECK-NEXT:   %3 = load double, double* %x, align 8
; CHECK-NEXT:   %add = fadd double %3, 1.000000e+00
; CHECK-NEXT:   store double %"'ipl", double* %0, align 8
; CHECK-NEXT:   store double %"'ipl1", double* %1, align 8
; CHECK-NEXT:   store double %"'ipl2", double* %2, align 8
; CHECK-NEXT:   store double %add, double* %x, align 8
; CHECK-NEXT:   ret void
; CHECK-NEXT: }
