; LLVM IR from afbarnard/go-lbfgsb :: prototype (mainc)

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

%struct.cbdata = type { ptr, i32 }

; Function Attrs: nounwind uwtable
define dso_local i32 @objfunc_sphere(i32 noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3) #0 {
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i64, align 8
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  %14 = alloca ptr, align 8
  %15 = alloca i32, align 4
  store i32 %0, ptr %6, align 4, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !9
  store ptr %2, ptr %8, align 8, !tbaa !9
  store ptr %3, ptr %9, align 8, !tbaa !9
  %16 = load i32, ptr %6, align 4, !tbaa !5
  %17 = zext i32 %16 to i64
  %18 = call ptr @llvm.stacksave.p0()
  store ptr %18, ptr %10, align 8
  %19 = alloca double, i64 %17, align 16
  store i64 %17, ptr %11, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #3
  store i32 0, ptr %12, align 4, !tbaa !5
  br label %20

20:                                               ; preds = %40, %4
  %21 = load i32, ptr %12, align 4, !tbaa !5
  %22 = load i32, ptr %6, align 4, !tbaa !5
  %23 = icmp slt i32 %21, %22
  br i1 %23, label %25, label %24

24:                                               ; preds = %20
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #3
  br label %43

25:                                               ; preds = %20
  %26 = load ptr, ptr %7, align 8, !tbaa !9
  %27 = load i32, ptr %12, align 4, !tbaa !5
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds double, ptr %26, i64 %28
  %30 = load double, ptr %29, align 8, !tbaa !11
  %31 = load ptr, ptr %7, align 8, !tbaa !9
  %32 = load i32, ptr %12, align 4, !tbaa !5
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds double, ptr %31, i64 %33
  %35 = load double, ptr %34, align 8, !tbaa !11
  %36 = fmul double %30, %35
  %37 = load i32, ptr %12, align 4, !tbaa !5
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds double, ptr %19, i64 %38
  store double %36, ptr %39, align 8, !tbaa !11
  br label %40

40:                                               ; preds = %25
  %41 = load i32, ptr %12, align 4, !tbaa !5
  %42 = add nsw i32 %41, 1
  store i32 %42, ptr %12, align 4, !tbaa !5
  br label %20, !llvm.loop !13

43:                                               ; preds = %24
  %44 = load ptr, ptr %8, align 8, !tbaa !9
  store double 0.000000e+00, ptr %44, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #3
  store i32 0, ptr %13, align 4, !tbaa !5
  br label %45

45:                                               ; preds = %58, %43
  %46 = load i32, ptr %13, align 4, !tbaa !5
  %47 = load i32, ptr %6, align 4, !tbaa !5
  %48 = icmp slt i32 %46, %47
  br i1 %48, label %50, label %49

49:                                               ; preds = %45
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #3
  br label %61

50:                                               ; preds = %45
  %51 = load i32, ptr %13, align 4, !tbaa !5
  %52 = sext i32 %51 to i64
  %53 = getelementptr inbounds double, ptr %19, i64 %52
  %54 = load double, ptr %53, align 8, !tbaa !11
  %55 = load ptr, ptr %8, align 8, !tbaa !9
  %56 = load double, ptr %55, align 8, !tbaa !11
  %57 = fadd double %56, %54
  store double %57, ptr %55, align 8, !tbaa !11
  br label %58

58:                                               ; preds = %50
  %59 = load i32, ptr %13, align 4, !tbaa !5
  %60 = add nsw i32 %59, 1
  store i32 %60, ptr %13, align 4, !tbaa !5
  br label %45, !llvm.loop !15

61:                                               ; preds = %49
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #3
  %62 = load ptr, ptr %9, align 8, !tbaa !9
  store ptr %62, ptr %14, align 8, !tbaa !9
  %63 = load ptr, ptr %14, align 8, !tbaa !9
  %64 = getelementptr inbounds %struct.cbdata, ptr %63, i32 0, i32 1
  %65 = load i32, ptr %64, align 8, !tbaa !16
  %66 = icmp ne i32 %65, 987
  br i1 %66, label %67, label %71

67:                                               ; preds = %61
  %68 = load ptr, ptr %14, align 8, !tbaa !9
  %69 = getelementptr inbounds %struct.cbdata, ptr %68, i32 0, i32 1
  %70 = load i32, ptr %69, align 8, !tbaa !16
  store i32 %70, ptr %5, align 4
  store i32 1, ptr %15, align 4
  br label %72

71:                                               ; preds = %61
  store i32 0, ptr %5, align 4
  store i32 1, ptr %15, align 4
  br label %72

72:                                               ; preds = %71, %67
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #3
  %73 = load ptr, ptr %10, align 8
  call void @llvm.stackrestore.p0(ptr %73)
  %74 = load i32, ptr %5, align 4
  ret i32 %74
}

; Function Attrs: nocallback nofree nosync nounwind willreturn
declare ptr @llvm.stacksave.p0() #1

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

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

; Function Attrs: nocallback nofree nosync nounwind willreturn
declare void @llvm.stackrestore.p0(ptr) #1

attributes #0 = { 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 = { nocallback nofree nosync nounwind willreturn }
attributes #2 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"double", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}
!16 = !{!17, !6, i64 8}
!17 = !{!"cbdata", !10, i64 0, !6, i64 8}


; 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: nofree norecurse nosync nounwind memory(argmem: readwrite) uwtable
define dso_local range(i32 988, 987) i32 @objfunc_sphere(i32 noundef %0, ptr nocapture noundef readonly %1, ptr nocapture noundef writeonly %2, ptr nocapture noundef readonly %3) local_unnamed_addr #0 {
  %5 = zext i32 %0 to i64
  %6 = alloca double, i64 %5, align 16
  %7 = icmp sgt i32 %0, 0
  br i1 %7, label %.lr.ph.preheader, label %.sink.split

.lr.ph.preheader:                                 ; preds = %4
  %min.iters.check = icmp ult i32 %0, 4
  br i1 %min.iters.check, label %.lr.ph.preheader35, label %vector.ph

.lr.ph.preheader35:                               ; preds = %middle.block, %.lr.ph.preheader
  %indvars.iv.ph = phi i64 [ 0, %.lr.ph.preheader ], [ %n.vec, %middle.block ]
  br label %.lr.ph

vector.ph:                                        ; preds = %.lr.ph.preheader
  %n.vec = and i64 %5, 2147483644
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %8 = getelementptr inbounds double, ptr %1, i64 %index
  %9 = getelementptr inbounds i8, ptr %8, i64 16
  %wide.load = load <2 x double>, ptr %8, align 8, !tbaa !5
  %wide.load34 = load <2 x double>, ptr %9, align 8, !tbaa !5
  %10 = fmul <2 x double> %wide.load, %wide.load
  %11 = fmul <2 x double> %wide.load34, %wide.load34
  %12 = getelementptr inbounds double, ptr %6, i64 %index
  %13 = getelementptr inbounds i8, ptr %12, i64 16
  store <2 x double> %10, ptr %12, align 16, !tbaa !5
  store <2 x double> %11, ptr %13, align 16, !tbaa !5
  %index.next = add nuw i64 %index, 4
  %14 = icmp eq i64 %index.next, %n.vec
  br i1 %14, label %middle.block, label %vector.body, !llvm.loop !9

middle.block:                                     ; preds = %vector.body
  %cmp.n = icmp eq i64 %n.vec, %5
  br i1 %cmp.n, label %._crit_edge, label %.lr.ph.preheader35

._crit_edge:                                      ; preds = %.lr.ph, %middle.block
  store double 0.000000e+00, ptr %2, align 8, !tbaa !5
  br i1 %7, label %.lr.ph26.preheader, label %24

.lr.ph26.preheader:                               ; preds = %._crit_edge
  %xtraiter = and i64 %5, 7
  %15 = icmp ult i32 %0, 8
  br i1 %15, label %.sink.split.loopexit.unr-lcssa, label %.lr.ph26.preheader.new

.lr.ph26.preheader.new:                           ; preds = %.lr.ph26.preheader
  %unroll_iter = and i64 %5, 2147483640
  br label %.lr.ph26

.lr.ph:                                           ; preds = %.lr.ph.preheader35, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ %indvars.iv.ph, %.lr.ph.preheader35 ]
  %16 = getelementptr inbounds double, ptr %1, i64 %indvars.iv
  %17 = load double, ptr %16, align 8, !tbaa !5
  %18 = fmul double %17, %17
  %19 = getelementptr inbounds double, ptr %6, i64 %indvars.iv
  store double %18, ptr %19, align 8, !tbaa !5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %5
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !13

.sink.split.loopexit.unr-lcssa:                   ; preds = %.lr.ph26, %.lr.ph26.preheader
  %.lcssa.ph = phi double [ poison, %.lr.ph26.preheader ], [ %51, %.lr.ph26 ]
  %indvars.iv29.unr = phi i64 [ 0, %.lr.ph26.preheader ], [ %indvars.iv.next30.7, %.lr.ph26 ]
  %.unr = phi double [ 0.000000e+00, %.lr.ph26.preheader ], [ %51, %.lr.ph26 ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %.sink.split, label %.lr.ph26.epil

.lr.ph26.epil:                                    ; preds = %.sink.split.loopexit.unr-lcssa, %.lr.ph26.epil
  %indvars.iv29.epil = phi i64 [ %indvars.iv.next30.epil, %.lr.ph26.epil ], [ %indvars.iv29.unr, %.sink.split.loopexit.unr-lcssa ]
  %20 = phi double [ %23, %.lr.ph26.epil ], [ %.unr, %.sink.split.loopexit.unr-lcssa ]
  %epil.iter = phi i64 [ %epil.iter.next, %.lr.ph26.epil ], [ 0, %.sink.split.loopexit.unr-lcssa ]
  %21 = getelementptr inbounds double, ptr %6, i64 %indvars.iv29.epil
  %22 = load double, ptr %21, align 8, !tbaa !5
  %23 = fadd double %22, %20
  %indvars.iv.next30.epil = add nuw nsw i64 %indvars.iv29.epil, 1
  %epil.iter.next = add i64 %epil.iter, 1
  %epil.iter.cmp.not = icmp eq i64 %epil.iter.next, %xtraiter
  br i1 %epil.iter.cmp.not, label %.sink.split, label %.lr.ph26.epil, !llvm.loop !14

.sink.split:                                      ; preds = %.sink.split.loopexit.unr-lcssa, %.lr.ph26.epil, %4
  %.sink = phi double [ 0.000000e+00, %4 ], [ %.lcssa.ph, %.sink.split.loopexit.unr-lcssa ], [ %23, %.lr.ph26.epil ]
  store double %.sink, ptr %2, align 8, !tbaa !5
  br label %24

24:                                               ; preds = %.sink.split, %._crit_edge
  %25 = getelementptr inbounds i8, ptr %3, i64 8
  %26 = load i32, ptr %25, align 8, !tbaa !16
  %.not = icmp eq i32 %26, 987
  %. = select i1 %.not, i32 0, i32 %26
  ret i32 %.

.lr.ph26:                                         ; preds = %.lr.ph26, %.lr.ph26.preheader.new
  %indvars.iv29 = phi i64 [ 0, %.lr.ph26.preheader.new ], [ %indvars.iv.next30.7, %.lr.ph26 ]
  %27 = phi double [ 0.000000e+00, %.lr.ph26.preheader.new ], [ %51, %.lr.ph26 ]
  %niter = phi i64 [ 0, %.lr.ph26.preheader.new ], [ %niter.next.7, %.lr.ph26 ]
  %28 = getelementptr inbounds double, ptr %6, i64 %indvars.iv29
  %29 = load double, ptr %28, align 16, !tbaa !5
  %30 = fadd double %29, %27
  %indvars.iv.next30 = or disjoint i64 %indvars.iv29, 1
  %31 = getelementptr inbounds double, ptr %6, i64 %indvars.iv.next30
  %32 = load double, ptr %31, align 8, !tbaa !5
  %33 = fadd double %32, %30
  %indvars.iv.next30.1 = or disjoint i64 %indvars.iv29, 2
  %34 = getelementptr inbounds double, ptr %6, i64 %indvars.iv.next30.1
  %35 = load double, ptr %34, align 16, !tbaa !5
  %36 = fadd double %35, %33
  %indvars.iv.next30.2 = or disjoint i64 %indvars.iv29, 3
  %37 = getelementptr inbounds double, ptr %6, i64 %indvars.iv.next30.2
  %38 = load double, ptr %37, align 8, !tbaa !5
  %39 = fadd double %38, %36
  %indvars.iv.next30.3 = or disjoint i64 %indvars.iv29, 4
  %40 = getelementptr inbounds double, ptr %6, i64 %indvars.iv.next30.3
  %41 = load double, ptr %40, align 16, !tbaa !5
  %42 = fadd double %41, %39
  %indvars.iv.next30.4 = or disjoint i64 %indvars.iv29, 5
  %43 = getelementptr inbounds double, ptr %6, i64 %indvars.iv.next30.4
  %44 = load double, ptr %43, align 8, !tbaa !5
  %45 = fadd double %44, %42
  %indvars.iv.next30.5 = or disjoint i64 %indvars.iv29, 6
  %46 = getelementptr inbounds double, ptr %6, i64 %indvars.iv.next30.5
  %47 = load double, ptr %46, align 16, !tbaa !5
  %48 = fadd double %47, %45
  %indvars.iv.next30.6 = or disjoint i64 %indvars.iv29, 7
  %49 = getelementptr inbounds double, ptr %6, i64 %indvars.iv.next30.6
  %50 = load double, ptr %49, align 8, !tbaa !5
  %51 = fadd double %50, %48
  %indvars.iv.next30.7 = add nuw nsw i64 %indvars.iv29, 8
  %niter.next.7 = add i64 %niter, 8
  %niter.ncmp.7 = icmp eq i64 %niter.next.7, %unroll_iter
  br i1 %niter.ncmp.7, label %.sink.split.loopexit.unr-lcssa, label %.lr.ph26, !llvm.loop !20
}

attributes #0 = { nofree norecurse nosync nounwind memory(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" }

!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 = !{!"double", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = distinct !{!9, !10, !11, !12}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!"llvm.loop.isvectorized", i32 1}
!12 = !{!"llvm.loop.unroll.runtime.disable"}
!13 = distinct !{!13, !10, !12, !11}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.unroll.disable"}
!16 = !{!17, !19, i64 8}
!17 = !{!"cbdata", !18, i64 0, !19, i64 8}
!18 = !{!"any pointer", !7, i64 0}
!19 = !{!"int", !7, i64 0}
!20 = distinct !{!20, !10}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopLoadEliminationPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,LoopVectorizePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass