; LLVM IR from KhawajaAbaid/machine-learning-in-c :: nn (initialize_mlp_normal_)

; 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.mlp = type { ptr, i64 }
%struct.layer = type { ptr, ptr, i64, i64 }

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

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

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

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

; Function Attrs: nounwind uwtable
define dso_local void @initialize_mlp_normal_(i32 noundef %0, ptr noundef %1) #3 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i64, align 8
  %9 = alloca i32, align 4
  %10 = alloca i64, align 8
  %11 = alloca i64, align 8
  store i32 %0, ptr %3, align 4, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !9
  %12 = load i32, ptr %3, align 4, !tbaa !5
  call void @srand(i32 noundef %12) #6
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #6
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #6
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #6
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #6
  store i64 0, ptr %8, align 8, !tbaa !11
  br label %13

13:                                               ; preds = %85, %2
  %14 = load i64, ptr %8, align 8, !tbaa !11
  %15 = load ptr, ptr %4, align 8, !tbaa !9
  %16 = getelementptr inbounds %struct.mlp, ptr %15, i32 0, i32 1
  %17 = load i64, ptr %16, align 8, !tbaa !13
  %18 = icmp ult i64 %14, %17
  br i1 %18, label %20, label %19

19:                                               ; preds = %13
  store i32 2, ptr %9, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #6
  br label %88

20:                                               ; preds = %13
  %21 = load ptr, ptr %4, align 8, !tbaa !9
  %22 = getelementptr inbounds %struct.mlp, ptr %21, i32 0, i32 0
  %23 = load ptr, ptr %22, align 8, !tbaa !15
  %24 = load i64, ptr %8, align 8, !tbaa !11
  %25 = getelementptr inbounds ptr, ptr %23, i64 %24
  %26 = load ptr, ptr %25, align 8, !tbaa !9
  store ptr %26, ptr %7, align 8, !tbaa !9
  %27 = load ptr, ptr %7, align 8, !tbaa !9
  %28 = getelementptr inbounds %struct.layer, ptr %27, i32 0, i32 3
  %29 = load i64, ptr %28, align 8, !tbaa !16
  %30 = mul i64 %29, 8
  %31 = call noalias ptr @malloc(i64 noundef %30) #7
  store ptr %31, ptr %5, align 8, !tbaa !9
  %32 = load ptr, ptr %7, align 8, !tbaa !9
  %33 = getelementptr inbounds %struct.layer, ptr %32, i32 0, i32 3
  %34 = load i64, ptr %33, align 8, !tbaa !16
  %35 = call noalias ptr @calloc(i64 noundef %34, i64 noundef 8) #8
  store ptr %35, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #6
  store i64 0, ptr %10, align 8, !tbaa !11
  br label %36

36:                                               ; preds = %75, %20
  %37 = load i64, ptr %10, align 8, !tbaa !11
  %38 = load ptr, ptr %7, align 8, !tbaa !9
  %39 = getelementptr inbounds %struct.layer, ptr %38, i32 0, i32 3
  %40 = load i64, ptr %39, align 8, !tbaa !16
  %41 = icmp ult i64 %37, %40
  br i1 %41, label %43, label %42

42:                                               ; preds = %36
  store i32 5, ptr %9, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #6
  br label %78

43:                                               ; preds = %36
  %44 = load ptr, ptr %7, align 8, !tbaa !9
  %45 = getelementptr inbounds %struct.layer, ptr %44, i32 0, i32 2
  %46 = load i64, ptr %45, align 8, !tbaa !18
  %47 = mul i64 %46, 8
  %48 = call noalias ptr @malloc(i64 noundef %47) #7
  %49 = load ptr, ptr %5, align 8, !tbaa !9
  %50 = load i64, ptr %10, align 8, !tbaa !11
  %51 = getelementptr inbounds ptr, ptr %49, i64 %50
  store ptr %48, ptr %51, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #6
  store i64 0, ptr %11, align 8, !tbaa !11
  br label %52

52:                                               ; preds = %67, %43
  %53 = load i64, ptr %11, align 8, !tbaa !11
  %54 = load ptr, ptr %7, align 8, !tbaa !9
  %55 = getelementptr inbounds %struct.layer, ptr %54, i32 0, i32 2
  %56 = load i64, ptr %55, align 8, !tbaa !18
  %57 = icmp ult i64 %53, %56
  br i1 %57, label %59, label %58

58:                                               ; preds = %52
  store i32 8, ptr %9, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #6
  br label %70

59:                                               ; preds = %52
  %60 = call double (...) @random_normal()
  %61 = load ptr, ptr %5, align 8, !tbaa !9
  %62 = load i64, ptr %10, align 8, !tbaa !11
  %63 = getelementptr inbounds ptr, ptr %61, i64 %62
  %64 = load ptr, ptr %63, align 8, !tbaa !9
  %65 = load i64, ptr %11, align 8, !tbaa !11
  %66 = getelementptr inbounds double, ptr %64, i64 %65
  store double %60, ptr %66, align 8, !tbaa !19
  br label %67

67:                                               ; preds = %59
  %68 = load i64, ptr %11, align 8, !tbaa !11
  %69 = add i64 %68, 1
  store i64 %69, ptr %11, align 8, !tbaa !11
  br label %52, !llvm.loop !21

70:                                               ; preds = %58
  %71 = call double (...) @random_normal()
  %72 = load ptr, ptr %6, align 8, !tbaa !9
  %73 = load i64, ptr %10, align 8, !tbaa !11
  %74 = getelementptr inbounds double, ptr %72, i64 %73
  store double %71, ptr %74, align 8, !tbaa !19
  br label %75

75:                                               ; preds = %70
  %76 = load i64, ptr %10, align 8, !tbaa !11
  %77 = add i64 %76, 1
  store i64 %77, ptr %10, align 8, !tbaa !11
  br label %36, !llvm.loop !23

78:                                               ; preds = %42
  %79 = load ptr, ptr %5, align 8, !tbaa !9
  %80 = load ptr, ptr %7, align 8, !tbaa !9
  %81 = getelementptr inbounds %struct.layer, ptr %80, i32 0, i32 0
  store ptr %79, ptr %81, align 8, !tbaa !24
  %82 = load ptr, ptr %6, align 8, !tbaa !9
  %83 = load ptr, ptr %7, align 8, !tbaa !9
  %84 = getelementptr inbounds %struct.layer, ptr %83, i32 0, i32 1
  store ptr %82, ptr %84, align 8, !tbaa !25
  br label %85

85:                                               ; preds = %78
  %86 = load i64, ptr %8, align 8, !tbaa !11
  %87 = add i64 %86, 1
  store i64 %87, ptr %8, align 8, !tbaa !11
  br label %13, !llvm.loop !26

88:                                               ; preds = %19
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #6
  ret void
}

; Function Attrs: nounwind
declare void @srand(i32 noundef) #4

declare double @random_normal(...) #5

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { nounwind allocsize(0,1) "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 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 #4 = { 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 #5 = { "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 #6 = { nounwind }
attributes #7 = { nounwind allocsize(0) }
attributes #8 = { nounwind allocsize(0,1) }

!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 = !{!"long", !7, i64 0}
!13 = !{!14, !12, i64 8}
!14 = !{!"", !10, i64 0, !12, i64 8}
!15 = !{!14, !10, i64 0}
!16 = !{!17, !12, i64 24}
!17 = !{!"", !10, i64 0, !10, i64 8, !12, i64 16, !12, i64 24}
!18 = !{!17, !12, i64 16}
!19 = !{!20, !20, i64 0}
!20 = !{!"double", !7, i64 0}
!21 = distinct !{!21, !22}
!22 = !{!"llvm.loop.mustprogress"}
!23 = distinct !{!23, !22}
!24 = !{!17, !10, i64 0}
!25 = !{!17, !10, i64 8}
!26 = distinct !{!26, !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"

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

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

; Function Attrs: nounwind uwtable
define dso_local void @initialize_mlp_normal_(i32 noundef %0, ptr nocapture noundef readonly %1) local_unnamed_addr #2 {
  tail call void @srand(i32 noundef %0) #5
  %3 = getelementptr inbounds i8, ptr %1, i64 8
  %4 = load i64, ptr %3, align 8, !tbaa !5
  %.not = icmp eq i64 %4, 0
  br i1 %.not, label %._crit_edge35, label %.lr.ph34

._crit_edge35:                                    ; preds = %._crit_edge31, %2
  ret void

.lr.ph34:                                         ; preds = %2, %._crit_edge31
  %5 = phi i64 [ %15, %._crit_edge31 ], [ %4, %2 ]
  %.02632 = phi i64 [ %17, %._crit_edge31 ], [ 0, %2 ]
  %6 = load ptr, ptr %1, align 8, !tbaa !11
  %7 = getelementptr inbounds ptr, ptr %6, i64 %.02632
  %8 = load ptr, ptr %7, align 8, !tbaa !12
  %9 = getelementptr inbounds i8, ptr %8, i64 24
  %10 = load i64, ptr %9, align 8, !tbaa !13
  %11 = shl i64 %10, 3
  %12 = tail call noalias ptr @malloc(i64 noundef %11) #6
  %13 = tail call noalias ptr @calloc(i64 noundef %10, i64 noundef 8) #7
  %.not36 = icmp eq i64 %10, 0
  br i1 %.not36, label %._crit_edge31, label %.lr.ph30

.lr.ph30:                                         ; preds = %.lr.ph34
  %14 = getelementptr inbounds i8, ptr %8, i64 16
  br label %19

._crit_edge31.loopexit:                           ; preds = %._crit_edge
  %.pre = load i64, ptr %3, align 8, !tbaa !5
  br label %._crit_edge31

._crit_edge31:                                    ; preds = %._crit_edge31.loopexit, %.lr.ph34
  %15 = phi i64 [ %.pre, %._crit_edge31.loopexit ], [ %5, %.lr.ph34 ]
  store ptr %12, ptr %8, align 8, !tbaa !15
  %16 = getelementptr inbounds i8, ptr %8, i64 8
  store ptr %13, ptr %16, align 8, !tbaa !16
  %17 = add nuw i64 %.02632, 1
  %18 = icmp ult i64 %17, %15
  br i1 %18, label %.lr.ph34, label %._crit_edge35, !llvm.loop !17

19:                                               ; preds = %.lr.ph30, %._crit_edge
  %.02528 = phi i64 [ 0, %.lr.ph30 ], [ %26, %._crit_edge ]
  %20 = load i64, ptr %14, align 8, !tbaa !19
  %21 = shl i64 %20, 3
  %22 = tail call noalias ptr @malloc(i64 noundef %21) #6
  %23 = getelementptr inbounds ptr, ptr %12, i64 %.02528
  store ptr %22, ptr %23, align 8, !tbaa !12
  %.not37 = icmp eq i64 %20, 0
  br i1 %.not37, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %.lr.ph, %19
  %24 = tail call double (...) @random_normal() #5
  %25 = getelementptr inbounds double, ptr %13, i64 %.02528
  store double %24, ptr %25, align 8, !tbaa !20
  %26 = add nuw i64 %.02528, 1
  %27 = load i64, ptr %9, align 8, !tbaa !13
  %28 = icmp ult i64 %26, %27
  br i1 %28, label %19, label %._crit_edge31.loopexit, !llvm.loop !22

.lr.ph:                                           ; preds = %19, %.lr.ph
  %.027 = phi i64 [ %32, %.lr.ph ], [ 0, %19 ]
  %29 = tail call double (...) @random_normal() #5
  %30 = load ptr, ptr %23, align 8, !tbaa !12
  %31 = getelementptr inbounds double, ptr %30, i64 %.027
  store double %29, ptr %31, align 8, !tbaa !20
  %32 = add nuw i64 %.027, 1
  %33 = load i64, ptr %14, align 8, !tbaa !19
  %34 = icmp ult i64 %32, %33
  br i1 %34, label %.lr.ph, label %._crit_edge, !llvm.loop !23
}

; Function Attrs: nounwind
declare void @srand(i32 noundef) local_unnamed_addr #3

declare double @random_normal(...) local_unnamed_addr #4

attributes #0 = { 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 #1 = { mustprogress nofree nounwind willreturn allockind("alloc,zeroed") allocsize(0,1) 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 = { 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) }
attributes #7 = { nounwind allocsize(0,1) }

!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 8}
!6 = !{!"", !7, i64 0, !10, i64 8}
!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 = !{!7, !7, i64 0}
!13 = !{!14, !10, i64 24}
!14 = !{!"", !7, i64 0, !7, i64 8, !10, i64 16, !10, i64 24}
!15 = !{!14, !7, i64 0}
!16 = !{!14, !7, i64 8}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}
!19 = !{!14, !10, i64 16}
!20 = !{!21, !21, i64 0}
!21 = !{!"double", !8, i64 0}
!22 = distinct !{!22, !18}
!23 = distinct !{!23, !18}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass