; LLVM IR from mkobos/lbfgsb_wrapper :: raw_wrapper (lbfgsb_wrapper)

; 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.lbfgsb = type { i32, i32, ptr, ptr, ptr, ptr, double, ptr, double, double, ptr, ptr, [61 x i8], i32, [60 x i8], [4 x i32], [44 x i32], [29 x double] }

; Function Attrs: nounwind uwtable
define dso_local ptr @lbfgsb_create(i32 noundef %0, i32 noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  store i32 %0, ptr %3, align 4, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  %8 = call noalias ptr @malloc(i64 noundef 640) #4
  store ptr %8, ptr %5, align 8, !tbaa !9
  %9 = load i32, ptr %3, align 4, !tbaa !5
  %10 = load ptr, ptr %5, align 8, !tbaa !9
  %11 = getelementptr inbounds %struct.lbfgsb, ptr %10, i32 0, i32 0
  store i32 %9, ptr %11, align 8, !tbaa !11
  %12 = load i32, ptr %4, align 4, !tbaa !5
  %13 = load ptr, ptr %5, align 8, !tbaa !9
  %14 = getelementptr inbounds %struct.lbfgsb, ptr %13, i32 0, i32 1
  store i32 %12, ptr %14, align 4, !tbaa !14
  %15 = load i32, ptr %3, align 4, !tbaa !5
  %16 = sext i32 %15 to i64
  %17 = mul i64 %16, 8
  %18 = call noalias ptr @malloc(i64 noundef %17) #4
  %19 = load ptr, ptr %5, align 8, !tbaa !9
  %20 = getelementptr inbounds %struct.lbfgsb, ptr %19, i32 0, i32 2
  store ptr %18, ptr %20, align 8, !tbaa !15
  %21 = load i32, ptr %3, align 4, !tbaa !5
  %22 = sext i32 %21 to i64
  %23 = mul i64 %22, 8
  %24 = call noalias ptr @malloc(i64 noundef %23) #4
  %25 = load ptr, ptr %5, align 8, !tbaa !9
  %26 = getelementptr inbounds %struct.lbfgsb, ptr %25, i32 0, i32 3
  store ptr %24, ptr %26, align 8, !tbaa !16
  %27 = load i32, ptr %3, align 4, !tbaa !5
  %28 = sext i32 %27 to i64
  %29 = mul i64 %28, 8
  %30 = call noalias ptr @malloc(i64 noundef %29) #4
  %31 = load ptr, ptr %5, align 8, !tbaa !9
  %32 = getelementptr inbounds %struct.lbfgsb, ptr %31, i32 0, i32 4
  store ptr %30, ptr %32, align 8, !tbaa !17
  %33 = load i32, ptr %3, align 4, !tbaa !5
  %34 = sext i32 %33 to i64
  %35 = mul i64 %34, 4
  %36 = call noalias ptr @malloc(i64 noundef %35) #4
  %37 = load ptr, ptr %5, align 8, !tbaa !9
  %38 = getelementptr inbounds %struct.lbfgsb, ptr %37, i32 0, i32 5
  store ptr %36, ptr %38, align 8, !tbaa !18
  %39 = load ptr, ptr %5, align 8, !tbaa !9
  %40 = getelementptr inbounds %struct.lbfgsb, ptr %39, i32 0, i32 6
  store double 0.000000e+00, ptr %40, align 8, !tbaa !19
  %41 = load i32, ptr %3, align 4, !tbaa !5
  %42 = sext i32 %41 to i64
  %43 = mul i64 %42, 8
  %44 = call noalias ptr @malloc(i64 noundef %43) #4
  %45 = load ptr, ptr %5, align 8, !tbaa !9
  %46 = getelementptr inbounds %struct.lbfgsb, ptr %45, i32 0, i32 7
  store ptr %44, ptr %46, align 8, !tbaa !20
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  store i32 0, ptr %6, align 4, !tbaa !5
  br label %47

47:                                               ; preds = %58, %2
  %48 = load i32, ptr %6, align 4, !tbaa !5
  %49 = load i32, ptr %3, align 4, !tbaa !5
  %50 = icmp slt i32 %48, %49
  br i1 %50, label %51, label %61

51:                                               ; preds = %47
  %52 = load ptr, ptr %5, align 8, !tbaa !9
  %53 = getelementptr inbounds %struct.lbfgsb, ptr %52, i32 0, i32 7
  %54 = load ptr, ptr %53, align 8, !tbaa !20
  %55 = load i32, ptr %6, align 4, !tbaa !5
  %56 = sext i32 %55 to i64
  %57 = getelementptr inbounds double, ptr %54, i64 %56
  store double 0.000000e+00, ptr %57, align 8, !tbaa !21
  br label %58

58:                                               ; preds = %51
  %59 = load i32, ptr %6, align 4, !tbaa !5
  %60 = add nsw i32 %59, 1
  store i32 %60, ptr %6, align 4, !tbaa !5
  br label %47, !llvm.loop !22

61:                                               ; preds = %47
  %62 = load ptr, ptr %5, align 8, !tbaa !9
  %63 = getelementptr inbounds %struct.lbfgsb, ptr %62, i32 0, i32 8
  store double 1.000000e+07, ptr %63, align 8, !tbaa !24
  %64 = load ptr, ptr %5, align 8, !tbaa !9
  %65 = getelementptr inbounds %struct.lbfgsb, ptr %64, i32 0, i32 9
  store double 1.000000e-05, ptr %65, align 8, !tbaa !25
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  %66 = load i32, ptr %4, align 4, !tbaa !5
  %67 = mul nsw i32 2, %66
  %68 = load i32, ptr %3, align 4, !tbaa !5
  %69 = mul nsw i32 %67, %68
  %70 = load i32, ptr %3, align 4, !tbaa !5
  %71 = mul nsw i32 5, %70
  %72 = add nsw i32 %69, %71
  %73 = load i32, ptr %4, align 4, !tbaa !5
  %74 = mul nsw i32 11, %73
  %75 = load i32, ptr %4, align 4, !tbaa !5
  %76 = mul nsw i32 %74, %75
  %77 = add nsw i32 %72, %76
  %78 = load i32, ptr %4, align 4, !tbaa !5
  %79 = mul nsw i32 8, %78
  %80 = add nsw i32 %77, %79
  store i32 %80, ptr %7, align 4, !tbaa !5
  %81 = load i32, ptr %7, align 4, !tbaa !5
  %82 = sext i32 %81 to i64
  %83 = mul i64 %82, 8
  %84 = call noalias ptr @malloc(i64 noundef %83) #4
  %85 = load ptr, ptr %5, align 8, !tbaa !9
  %86 = getelementptr inbounds %struct.lbfgsb, ptr %85, i32 0, i32 10
  store ptr %84, ptr %86, align 8, !tbaa !26
  %87 = load i32, ptr %3, align 4, !tbaa !5
  %88 = mul nsw i32 3, %87
  %89 = sext i32 %88 to i64
  %90 = mul i64 %89, 4
  %91 = call noalias ptr @malloc(i64 noundef %90) #4
  %92 = load ptr, ptr %5, align 8, !tbaa !9
  %93 = getelementptr inbounds %struct.lbfgsb, ptr %92, i32 0, i32 11
  store ptr %91, ptr %93, align 8, !tbaa !27
  %94 = load ptr, ptr %5, align 8, !tbaa !9
  %95 = getelementptr inbounds %struct.lbfgsb, ptr %94, i32 0, i32 12
  %96 = getelementptr inbounds [61 x i8], ptr %95, i64 0, i64 60
  store i8 0, ptr %96, align 4, !tbaa !28
  %97 = load ptr, ptr %5, align 8, !tbaa !9
  %98 = getelementptr inbounds %struct.lbfgsb, ptr %97, i32 0, i32 13
  store i32 -1, ptr %98, align 8, !tbaa !29
  %99 = load ptr, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  ret ptr %99
}

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

; Function Attrs: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #2

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 memory(argmem: readwrite) }
attributes #2 = { nounwind allocsize(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 = { nounwind }
attributes #4 = { nounwind allocsize(0) }

!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, !6, i64 0}
!12 = !{!"lbfgsb", !6, i64 0, !6, i64 4, !10, i64 8, !10, i64 16, !10, i64 24, !10, i64 32, !13, i64 40, !10, i64 48, !13, i64 56, !13, i64 64, !10, i64 72, !10, i64 80, !7, i64 88, !6, i64 152, !7, i64 156, !7, i64 216, !7, i64 232, !7, i64 408}
!13 = !{!"double", !7, i64 0}
!14 = !{!12, !6, i64 4}
!15 = !{!12, !10, i64 8}
!16 = !{!12, !10, i64 16}
!17 = !{!12, !10, i64 24}
!18 = !{!12, !10, i64 32}
!19 = !{!12, !13, i64 40}
!20 = !{!12, !10, i64 48}
!21 = !{!13, !13, i64 0}
!22 = distinct !{!22, !23}
!23 = !{!"llvm.loop.mustprogress"}
!24 = !{!12, !13, i64 56}
!25 = !{!12, !13, i64 64}
!26 = !{!12, !10, i64 72}
!27 = !{!12, !10, i64 80}
!28 = !{!7, !7, i64 0}
!29 = !{!12, !6, i64 152}


; 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: none, inaccessiblemem: readwrite) uwtable
define dso_local noalias noundef ptr @lbfgsb_create(i32 noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = tail call noalias dereferenceable_or_null(640) ptr @malloc(i64 noundef 640) #3
  store i32 %0, ptr %3, align 8, !tbaa !5
  %4 = getelementptr inbounds i8, ptr %3, i64 4
  store i32 %1, ptr %4, align 4, !tbaa !12
  %5 = sext i32 %0 to i64
  %6 = shl nsw i64 %5, 3
  %7 = tail call noalias ptr @malloc(i64 noundef %6) #3
  %8 = getelementptr inbounds i8, ptr %3, i64 8
  store ptr %7, ptr %8, align 8, !tbaa !13
  %9 = tail call noalias ptr @malloc(i64 noundef %6) #3
  %10 = getelementptr inbounds i8, ptr %3, i64 16
  store ptr %9, ptr %10, align 8, !tbaa !14
  %11 = tail call noalias ptr @malloc(i64 noundef %6) #3
  %12 = getelementptr inbounds i8, ptr %3, i64 24
  store ptr %11, ptr %12, align 8, !tbaa !15
  %13 = shl nsw i64 %5, 2
  %14 = tail call noalias ptr @malloc(i64 noundef %13) #3
  %15 = getelementptr inbounds i8, ptr %3, i64 32
  store ptr %14, ptr %15, align 8, !tbaa !16
  %16 = getelementptr inbounds i8, ptr %3, i64 40
  store double 0.000000e+00, ptr %16, align 8, !tbaa !17
  %17 = tail call noalias ptr @malloc(i64 noundef %6) #3
  %18 = getelementptr inbounds i8, ptr %3, i64 48
  store ptr %17, ptr %18, align 8, !tbaa !18
  %19 = icmp sgt i32 %0, 0
  br i1 %19, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %2
  %20 = zext nneg i32 %0 to i64
  %21 = shl nuw nsw i64 %20, 3
  tail call void @llvm.memset.p0.i64(ptr align 8 %17, i8 0, i64 %21, i1 false), !tbaa !19
  br label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph.preheader, %2
  %22 = getelementptr inbounds i8, ptr %3, i64 56
  store <2 x double> <double 1.000000e+07, double 1.000000e-05>, ptr %22, align 8, !tbaa !19
  %23 = shl nsw i32 %1, 1
  %24 = add i32 %23, 5
  %25 = mul i32 %24, %0
  %26 = mul i32 %1, 11
  %reass.add = add i32 %26, 8
  %reass.mul = mul i32 %reass.add, %1
  %27 = add i32 %reass.mul, %25
  %28 = sext i32 %27 to i64
  %29 = shl nsw i64 %28, 3
  %30 = tail call noalias ptr @malloc(i64 noundef %29) #3
  %31 = getelementptr inbounds i8, ptr %3, i64 72
  store ptr %30, ptr %31, align 8, !tbaa !20
  %32 = mul nsw i32 %0, 3
  %33 = sext i32 %32 to i64
  %34 = shl nsw i64 %33, 2
  %35 = tail call noalias ptr @malloc(i64 noundef %34) #3
  %36 = getelementptr inbounds i8, ptr %3, i64 80
  store ptr %35, ptr %36, align 8, !tbaa !21
  %37 = getelementptr inbounds i8, ptr %3, i64 148
  store i8 0, ptr %37, align 4, !tbaa !22
  %38 = getelementptr inbounds i8, ptr %3, i64 152
  store i32 -1, ptr %38, align 8, !tbaa !23
  ret ptr %3
}

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #1

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

attributes #0 = { mustprogress nofree nounwind willreturn memory(write, argmem: none, inaccessiblemem: 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 allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" "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 nounwind willreturn memory(argmem: write) }
attributes #3 = { nounwind allocsize(0) }

!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 0}
!6 = !{!"lbfgsb", !7, i64 0, !7, i64 4, !10, i64 8, !10, i64 16, !10, i64 24, !10, i64 32, !11, i64 40, !10, i64 48, !11, i64 56, !11, i64 64, !10, i64 72, !10, i64 80, !8, i64 88, !7, i64 152, !8, i64 156, !8, i64 216, !8, i64 232, !8, i64 408}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!"double", !8, i64 0}
!12 = !{!6, !7, i64 4}
!13 = !{!6, !10, i64 8}
!14 = !{!6, !10, i64 16}
!15 = !{!6, !10, i64 24}
!16 = !{!6, !10, i64 32}
!17 = !{!6, !11, i64 40}
!18 = !{!6, !10, i64 48}
!19 = !{!11, !11, i64 0}
!20 = !{!6, !10, i64 72}
!21 = !{!6, !10, i64 80}
!22 = !{!8, !8, i64 0}
!23 = !{!6, !7, i64 152}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LoopIdiomRecognizePass,LoopRotatePass,LoopSimplifyPass,PostOrderFunctionAttrsPass,ReassociatePass,SLPVectorizerPass,SROAPass,SimplifyCFGPass,TailCallElimPass