; LLVM IR from KhawajaAbaid/machine-learning-in-c :: logistic_regression (fit)

; 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.dataset = type { ptr, ptr, i64, i64 }
%struct.metrics = type { double, double }

@.str = external hidden unnamed_addr constant [56 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [2 x i8], align 1

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

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

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

; Function Attrs: nounwind uwtable
declare dso_local ptr @train_step(ptr noundef, ptr noundef, ptr noundef, double noundef, i64 noundef) #2

; Function Attrs: nounwind
declare void @free(ptr noundef) #3

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

22:                                               ; preds = %109, %5
  %23 = load i64, ptr %15, align 8, !tbaa !11
  %24 = load i64, ptr %10, align 8, !tbaa !11
  %25 = icmp ult i64 %23, %24
  br i1 %25, label %27, label %26

26:                                               ; preds = %22
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #5
  br label %112

27:                                               ; preds = %22
  %28 = load ptr, ptr %13, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.metrics, ptr %28, i32 0, i32 0
  store double 0.000000e+00, ptr %29, align 8, !tbaa !15
  %30 = load ptr, ptr %13, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.metrics, ptr %30, i32 0, i32 1
  store double 0.000000e+00, ptr %31, align 8, !tbaa !17
  store i64 0, ptr %14, align 8, !tbaa !11
  br label %32

32:                                               ; preds = %83, %27
  %33 = load i64, ptr %14, align 8, !tbaa !11
  %34 = load i64, ptr %11, align 8, !tbaa !11
  %35 = icmp ult i64 %33, %34
  br i1 %35, label %36, label %86

36:                                               ; preds = %32
  %37 = load ptr, ptr %6, align 8, !tbaa !5
  %38 = load ptr, ptr %7, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.dataset, ptr %38, i32 0, i32 0
  %40 = load ptr, ptr %39, align 8, !tbaa !18
  %41 = load i64, ptr %14, align 8, !tbaa !11
  %42 = load i64, ptr %9, align 8, !tbaa !11
  %43 = mul i64 %41, %42
  %44 = load ptr, ptr %7, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.dataset, ptr %44, i32 0, i32 3
  %46 = load i64, ptr %45, align 8, !tbaa !19
  %47 = mul i64 %43, %46
  %48 = getelementptr inbounds double, ptr %40, i64 %47
  %49 = load ptr, ptr %7, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.dataset, ptr %49, i32 0, i32 1
  %51 = load ptr, ptr %50, align 8, !tbaa !20
  %52 = load i64, ptr %14, align 8, !tbaa !11
  %53 = load i64, ptr %9, align 8, !tbaa !11
  %54 = mul i64 %52, %53
  %55 = getelementptr inbounds double, ptr %51, i64 %54
  %56 = load double, ptr %8, align 8, !tbaa !9
  %57 = load i64, ptr %9, align 8, !tbaa !11
  %58 = call ptr @train_step(ptr noundef %37, ptr noundef %48, ptr noundef %55, double noundef %56, i64 noundef %57)
  store ptr %58, ptr %12, align 8, !tbaa !5
  %59 = load i64, ptr %15, align 8, !tbaa !11
  %60 = load i64, ptr %14, align 8, !tbaa !11
  %61 = load ptr, ptr %12, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.metrics, ptr %61, i32 0, i32 0
  %63 = load double, ptr %62, align 8, !tbaa !15
  %64 = load ptr, ptr %12, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.metrics, ptr %64, i32 0, i32 1
  %66 = load double, ptr %65, align 8, !tbaa !17
  %67 = call i32 (ptr, ...) @printf(ptr noundef @.str, i64 noundef %59, i64 noundef %60, double noundef %63, double noundef %66)
  %68 = load ptr, ptr %12, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.metrics, ptr %68, i32 0, i32 1
  %70 = load double, ptr %69, align 8, !tbaa !17
  %71 = load ptr, ptr %13, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct.metrics, ptr %71, i32 0, i32 1
  %73 = load double, ptr %72, align 8, !tbaa !17
  %74 = fadd double %73, %70
  store double %74, ptr %72, align 8, !tbaa !17
  %75 = load ptr, ptr %12, align 8, !tbaa !5
  %76 = getelementptr inbounds %struct.metrics, ptr %75, i32 0, i32 0
  %77 = load double, ptr %76, align 8, !tbaa !15
  %78 = load ptr, ptr %13, align 8, !tbaa !5
  %79 = getelementptr inbounds %struct.metrics, ptr %78, i32 0, i32 0
  %80 = load double, ptr %79, align 8, !tbaa !15
  %81 = fadd double %80, %77
  store double %81, ptr %79, align 8, !tbaa !15
  %82 = load ptr, ptr %12, align 8, !tbaa !5
  call void @free(ptr noundef %82) #5
  br label %83

83:                                               ; preds = %36
  %84 = load i64, ptr %14, align 8, !tbaa !11
  %85 = add i64 %84, 1
  store i64 %85, ptr %14, align 8, !tbaa !11
  br label %32, !llvm.loop !21

86:                                               ; preds = %32
  %87 = load i64, ptr %11, align 8, !tbaa !11
  %88 = uitofp i64 %87 to double
  %89 = load ptr, ptr %13, align 8, !tbaa !5
  %90 = getelementptr inbounds %struct.metrics, ptr %89, i32 0, i32 1
  %91 = load double, ptr %90, align 8, !tbaa !17
  %92 = fdiv double %91, %88
  store double %92, ptr %90, align 8, !tbaa !17
  %93 = load i64, ptr %11, align 8, !tbaa !11
  %94 = uitofp i64 %93 to double
  %95 = load ptr, ptr %13, align 8, !tbaa !5
  %96 = getelementptr inbounds %struct.metrics, ptr %95, i32 0, i32 0
  %97 = load double, ptr %96, align 8, !tbaa !15
  %98 = fdiv double %97, %94
  store double %98, ptr %96, align 8, !tbaa !15
  %99 = load i64, ptr %15, align 8, !tbaa !11
  %100 = load i64, ptr %14, align 8, !tbaa !11
  %101 = load ptr, ptr %13, align 8, !tbaa !5
  %102 = getelementptr inbounds %struct.metrics, ptr %101, i32 0, i32 0
  %103 = load double, ptr %102, align 8, !tbaa !15
  %104 = load ptr, ptr %13, align 8, !tbaa !5
  %105 = getelementptr inbounds %struct.metrics, ptr %104, i32 0, i32 1
  %106 = load double, ptr %105, align 8, !tbaa !17
  %107 = call i32 (ptr, ...) @printf(ptr noundef @.str, i64 noundef %99, i64 noundef %100, double noundef %103, double noundef %106)
  %108 = call i32 (ptr, ...) @printf(ptr noundef @.str.1)
  br label %109

109:                                              ; preds = %86
  %110 = load i64, ptr %15, align 8, !tbaa !11
  %111 = add i64 %110, 1
  store i64 %111, ptr %15, align 8, !tbaa !11
  br label %22, !llvm.loop !23

112:                                              ; preds = %26
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #5
  ret void
}

declare i32 @printf(ptr noundef, ...) #4

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #3 = { 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 #4 = { "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 #5 = { nounwind }
attributes #6 = { 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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"double", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!14, !12, i64 16}
!14 = !{!"", !6, i64 0, !6, i64 8, !12, i64 16, !12, i64 24}
!15 = !{!16, !10, i64 0}
!16 = !{!"metrics", !10, i64 0, !10, i64 8}
!17 = !{!16, !10, i64 8}
!18 = !{!14, !6, i64 0}
!19 = !{!14, !12, i64 24}
!20 = !{!14, !6, i64 8}
!21 = distinct !{!21, !22}
!22 = !{!"llvm.loop.mustprogress"}
!23 = distinct !{!23, !22}


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

@.str = external hidden unnamed_addr constant [56 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [2 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local ptr @train_step(ptr noundef, ptr noundef, ptr noundef, double noundef, i64 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local void @fit(ptr noundef %0, ptr nocapture noundef readonly %1, double noundef %2, i64 noundef %3, i64 noundef %4) local_unnamed_addr #0 {
  %6 = getelementptr inbounds i8, ptr %1, i64 16
  %7 = load i64, ptr %6, align 8, !tbaa !5
  %8 = udiv i64 %7, %3
  %.not = icmp eq i64 %4, 0
  br i1 %.not, label %._crit_edge42, label %.lr.ph41

.lr.ph41:                                         ; preds = %5
  %.not47 = icmp ult i64 %7, %3
  %9 = getelementptr inbounds i8, ptr %1, i64 24
  %10 = getelementptr inbounds i8, ptr %1, i64 8
  %11 = uitofp i64 %8 to double
  br i1 %.not47, label %.lr.ph41.split, label %.lr.ph.us

.lr.ph.us:                                        ; preds = %.lr.ph41, %._crit_edge.us
  %.039.us = phi i64 [ %36, %._crit_edge.us ], [ 0, %.lr.ph41 ]
  br label %12

12:                                               ; preds = %.lr.ph.us, %12
  %.03638.us = phi i64 [ 0, %.lr.ph.us ], [ %28, %12 ]
  %13 = phi <2 x double> [ zeroinitializer, %.lr.ph.us ], [ %27, %12 ]
  %14 = load ptr, ptr %1, align 8, !tbaa !11
  %15 = mul i64 %.03638.us, %3
  %16 = load i64, ptr %9, align 8, !tbaa !12
  %17 = mul i64 %16, %15
  %18 = getelementptr inbounds double, ptr %14, i64 %17
  %19 = load ptr, ptr %10, align 8, !tbaa !13
  %20 = getelementptr inbounds double, ptr %19, i64 %15
  %21 = tail call ptr @train_step(ptr noundef %0, ptr noundef %18, ptr noundef %20, double noundef %2, i64 noundef %3)
  %22 = load double, ptr %21, align 8, !tbaa !14
  %23 = getelementptr inbounds i8, ptr %21, i64 8
  %24 = load double, ptr %23, align 8, !tbaa !17
  %25 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, i64 noundef %.039.us, i64 noundef %.03638.us, double noundef %22, double noundef %24)
  %26 = load <2 x double>, ptr %21, align 8, !tbaa !18
  %27 = fadd <2 x double> %26, %13
  tail call void @free(ptr noundef %21) #3
  %28 = add nuw i64 %.03638.us, 1
  %29 = icmp ult i64 %28, %8
  br i1 %29, label %12, label %._crit_edge.us, !llvm.loop !19

._crit_edge.us:                                   ; preds = %12
  %30 = extractelement <2 x double> %27, i64 1
  %31 = fdiv double %30, %11
  %32 = extractelement <2 x double> %27, i64 0
  %33 = fdiv double %32, %11
  %34 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, i64 noundef %.039.us, i64 noundef %28, double noundef %33, double noundef %31)
  %35 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1)
  %36 = add nuw i64 %.039.us, 1
  %exitcond.not = icmp eq i64 %36, %4
  br i1 %exitcond.not, label %._crit_edge42, label %.lr.ph.us, !llvm.loop !21

.lr.ph41.split:                                   ; preds = %.lr.ph41
  %37 = fdiv double 0.000000e+00, %11
  br label %38

._crit_edge42:                                    ; preds = %._crit_edge.us, %38, %5
  ret void

38:                                               ; preds = %.lr.ph41.split, %38
  %.039 = phi i64 [ 0, %.lr.ph41.split ], [ %41, %38 ]
  %39 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, i64 noundef %.039, i64 noundef 0, double noundef %37, double noundef %37)
  %40 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1)
  %41 = add nuw i64 %.039, 1
  %exitcond51.not = icmp eq i64 %41, %4
  br i1 %exitcond51.not, label %._crit_edge42, label %38, !llvm.loop !21
}

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #2

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 = { mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, 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 = { nofree 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 #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 16}
!6 = !{!"", !7, i64 0, !7, i64 8, !10, i64 16, !10, i64 24}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"long", !8, i64 0}
!11 = !{!6, !7, i64 0}
!12 = !{!6, !10, i64 24}
!13 = !{!6, !7, i64 8}
!14 = !{!15, !16, i64 0}
!15 = !{!"metrics", !16, i64 0, !16, i64 8}
!16 = !{!"double", !8, i64 0}
!17 = !{!15, !16, i64 8}
!18 = !{!16, !16, i64 0}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}
!21 = distinct !{!21, !20}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopInstSimplifyPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SLPVectorizerPass,SROAPass,SimplifyCFGPass,TailCallElimPass