; LLVM IR from KhawajaAbaid/machine-learning-in-c :: nn (initialize_mlp_glorot_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
declare void @srand(i32 noundef) #3

; Function Attrs: nounwind uwtable
define dso_local void @initialize_mlp_glorot_normal_(i32 noundef %0, ptr noundef %1) #4 {
  %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 = %97, %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 %100

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 = %87, %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 %90

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 = %73, %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 %76

59:                                               ; preds = %52
  %60 = load ptr, ptr %7, align 8, !tbaa !9
  %61 = getelementptr inbounds %struct.layer, ptr %60, i32 0, i32 2
  %62 = load i64, ptr %61, align 8, !tbaa !18
  %63 = load ptr, ptr %7, align 8, !tbaa !9
  %64 = getelementptr inbounds %struct.layer, ptr %63, i32 0, i32 3
  %65 = load i64, ptr %64, align 8, !tbaa !16
  %66 = call double @glorot_random_normal(i64 noundef %62, i64 noundef %65)
  %67 = load ptr, ptr %5, align 8, !tbaa !9
  %68 = load i64, ptr %10, align 8, !tbaa !11
  %69 = getelementptr inbounds ptr, ptr %67, i64 %68
  %70 = load ptr, ptr %69, align 8, !tbaa !9
  %71 = load i64, ptr %11, align 8, !tbaa !11
  %72 = getelementptr inbounds double, ptr %70, i64 %71
  store double %66, ptr %72, align 8, !tbaa !19
  br label %73

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

76:                                               ; preds = %58
  %77 = load ptr, ptr %7, align 8, !tbaa !9
  %78 = getelementptr inbounds %struct.layer, ptr %77, i32 0, i32 2
  %79 = load i64, ptr %78, align 8, !tbaa !18
  %80 = load ptr, ptr %7, align 8, !tbaa !9
  %81 = getelementptr inbounds %struct.layer, ptr %80, i32 0, i32 3
  %82 = load i64, ptr %81, align 8, !tbaa !16
  %83 = call double @glorot_random_normal(i64 noundef %79, i64 noundef %82)
  %84 = load ptr, ptr %6, align 8, !tbaa !9
  %85 = load i64, ptr %10, align 8, !tbaa !11
  %86 = getelementptr inbounds double, ptr %84, i64 %85
  store double %83, ptr %86, align 8, !tbaa !19
  br label %87

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

90:                                               ; preds = %42
  %91 = load ptr, ptr %5, align 8, !tbaa !9
  %92 = load ptr, ptr %7, align 8, !tbaa !9
  %93 = getelementptr inbounds %struct.layer, ptr %92, i32 0, i32 0
  store ptr %91, ptr %93, align 8, !tbaa !24
  %94 = load ptr, ptr %6, align 8, !tbaa !9
  %95 = load ptr, ptr %7, align 8, !tbaa !9
  %96 = getelementptr inbounds %struct.layer, ptr %95, i32 0, i32 1
  store ptr %94, ptr %96, align 8, !tbaa !25
  br label %97

97:                                               ; preds = %90
  %98 = load i64, ptr %8, align 8, !tbaa !11
  %99 = add i64 %98, 1
  store i64 %99, ptr %8, align 8, !tbaa !11
  br label %13, !llvm.loop !26

100:                                              ; 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
}

declare double @glorot_random_normal(i64 noundef, i64 noundef) #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 "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 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 #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
declare void @srand(i32 noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
define dso_local void @initialize_mlp_glorot_normal_(i32 noundef %0, ptr nocapture noundef readonly %1) local_unnamed_addr #3 {
  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_edge40, label %.lr.ph39

._crit_edge40:                                    ; preds = %._crit_edge36, %2
  ret void

.lr.ph39:                                         ; preds = %2, %._crit_edge36
  %5 = phi i64 [ %15, %._crit_edge36 ], [ %4, %2 ]
  %.03037 = phi i64 [ %17, %._crit_edge36 ], [ 0, %2 ]
  %6 = load ptr, ptr %1, align 8, !tbaa !11
  %7 = getelementptr inbounds ptr, ptr %6, i64 %.03037
  %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
  %.not41 = icmp eq i64 %10, 0
  br i1 %.not41, label %._crit_edge36, label %.lr.ph35

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

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

._crit_edge36:                                    ; preds = %._crit_edge36.loopexit, %.lr.ph39
  %15 = phi i64 [ %.pre44, %._crit_edge36.loopexit ], [ %5, %.lr.ph39 ]
  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 %.03037, 1
  %18 = icmp ult i64 %17, %15
  br i1 %18, label %.lr.ph39, label %._crit_edge40, !llvm.loop !17

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

._crit_edge.loopexit:                             ; preds = %.lr.ph
  %.pre = load i64, ptr %9, align 8, !tbaa !13
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %19
  %25 = phi i64 [ %20, %19 ], [ %.pre, %._crit_edge.loopexit ]
  %.lcssa = phi i64 [ 0, %19 ], [ %37, %._crit_edge.loopexit ]
  %26 = tail call double @glorot_random_normal(i64 noundef %.lcssa, i64 noundef %25) #5
  %27 = getelementptr inbounds double, ptr %13, i64 %.02933
  store double %26, ptr %27, align 8, !tbaa !20
  %28 = add nuw i64 %.02933, 1
  %29 = load i64, ptr %9, align 8, !tbaa !13
  %30 = icmp ult i64 %28, %29
  br i1 %30, label %19, label %._crit_edge36.loopexit, !llvm.loop !22

.lr.ph:                                           ; preds = %19, %.lr.ph
  %31 = phi i64 [ %37, %.lr.ph ], [ %21, %19 ]
  %.032 = phi i64 [ %36, %.lr.ph ], [ 0, %19 ]
  %32 = load i64, ptr %9, align 8, !tbaa !13
  %33 = tail call double @glorot_random_normal(i64 noundef %31, i64 noundef %32) #5
  %34 = load ptr, ptr %24, align 8, !tbaa !12
  %35 = getelementptr inbounds double, ptr %34, i64 %.032
  store double %33, ptr %35, align 8, !tbaa !20
  %36 = add nuw i64 %.032, 1
  %37 = load i64, ptr %14, align 8, !tbaa !19
  %38 = icmp ult i64 %36, %37
  br i1 %38, label %.lr.ph, label %._crit_edge.loopexit, !llvm.loop !23
}

declare double @glorot_random_normal(i64 noundef, i64 noundef) 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 "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 = { "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,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass