; LLVM IR from Sentdex/NNfSiX :: C (p005-ReLU-Activation)

; 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.spiral_data_t = type { ptr, ptr }
%struct.layer_dense_t = type { ptr, ptr, ptr, i32, i32, ptr }

@.str.5 = external hidden unnamed_addr constant [11 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [26 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [2 x i8], align 1

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

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

; Function Attrs: nounwind uwtable
declare dso_local void @layer_init(ptr noundef, i32 noundef, i32 noundef) #1

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

; Function Attrs: nounwind uwtable
declare dso_local void @deloc_layer(ptr noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local void @forward(ptr noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local void @actiavtion1(ptr noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local void @spiral_data(i32 noundef, i32 noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local void @deloc_spiral(ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local i32 @main() #1 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca %struct.spiral_data_t, align 8
  %5 = alloca %struct.layer_dense_t, align 8
  %6 = alloca %struct.layer_dense_t, align 8
  %7 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  call void @srand(i32 noundef 0) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #4
  store i32 0, ptr %2, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #4
  store i32 0, ptr %3, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 16, ptr %4) #4
  call void @llvm.lifetime.start.p0(i64 40, ptr %5) #4
  call void @llvm.lifetime.start.p0(i64 40, ptr %6) #4
  call void @spiral_data(i32 noundef 100, i32 noundef 3, ptr noundef %4)
  %8 = getelementptr inbounds %struct.spiral_data_t, ptr %4, i32 0, i32 0
  %9 = load ptr, ptr %8, align 8, !tbaa !9
  %10 = icmp eq ptr %9, null
  br i1 %10, label %11, label %13

11:                                               ; preds = %0
  %12 = call i32 (ptr, ...) @printf(ptr noundef @.str.5)
  store i32 0, ptr %1, align 4
  store i32 1, ptr %7, align 4
  br label %51

13:                                               ; preds = %0
  %14 = getelementptr inbounds %struct.layer_dense_t, ptr %5, i32 0, i32 5
  store ptr null, ptr %14, align 8, !tbaa !12
  %15 = getelementptr inbounds %struct.layer_dense_t, ptr %6, i32 0, i32 5
  store ptr @actiavtion1, ptr %15, align 8, !tbaa !12
  call void @layer_init(ptr noundef %6, i32 noundef 2, i32 noundef 5)
  store i32 0, ptr %2, align 4, !tbaa !5
  br label %16

16:                                               ; preds = %47, %13
  %17 = load i32, ptr %2, align 4, !tbaa !5
  %18 = icmp slt i32 %17, 300
  br i1 %18, label %19, label %50

19:                                               ; preds = %16
  %20 = getelementptr inbounds %struct.spiral_data_t, ptr %4, i32 0, i32 0
  %21 = load ptr, ptr %20, align 8, !tbaa !9
  %22 = load i32, ptr %2, align 4, !tbaa !5
  %23 = mul nsw i32 %22, 2
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds double, ptr %21, i64 %24
  %26 = getelementptr inbounds %struct.layer_dense_t, ptr %5, i32 0, i32 2
  store ptr %25, ptr %26, align 8, !tbaa !14
  call void @forward(ptr noundef %5, ptr noundef %6)
  %27 = load i32, ptr %2, align 4, !tbaa !5
  %28 = call i32 (ptr, ...) @printf(ptr noundef @.str.6, i32 noundef %27)
  store i32 0, ptr %3, align 4, !tbaa !5
  br label %29

29:                                               ; preds = %42, %19
  %30 = load i32, ptr %3, align 4, !tbaa !5
  %31 = getelementptr inbounds %struct.layer_dense_t, ptr %6, i32 0, i32 4
  %32 = load i32, ptr %31, align 4, !tbaa !15
  %33 = icmp slt i32 %30, %32
  br i1 %33, label %34, label %45

34:                                               ; preds = %29
  %35 = getelementptr inbounds %struct.layer_dense_t, ptr %6, i32 0, i32 2
  %36 = load ptr, ptr %35, align 8, !tbaa !14
  %37 = load i32, ptr %3, align 4, !tbaa !5
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds double, ptr %36, i64 %38
  %40 = load double, ptr %39, align 8, !tbaa !16
  %41 = call i32 (ptr, ...) @printf(ptr noundef @.str.7, double noundef %40)
  br label %42

42:                                               ; preds = %34
  %43 = load i32, ptr %3, align 4, !tbaa !5
  %44 = add nsw i32 %43, 1
  store i32 %44, ptr %3, align 4, !tbaa !5
  br label %29, !llvm.loop !18

45:                                               ; preds = %29
  %46 = call i32 (ptr, ...) @printf(ptr noundef @.str.8)
  br label %47

47:                                               ; preds = %45
  %48 = load i32, ptr %2, align 4, !tbaa !5
  %49 = add nsw i32 %48, 1
  store i32 %49, ptr %2, align 4, !tbaa !5
  br label %16, !llvm.loop !20

50:                                               ; preds = %16
  call void @deloc_layer(ptr noundef %6)
  call void @deloc_spiral(ptr noundef %4)
  store i32 0, ptr %1, align 4
  store i32 1, ptr %7, align 4
  br label %51

51:                                               ; preds = %50, %11
  call void @llvm.lifetime.end.p0(i64 40, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 40, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 16, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #4
  %52 = load i32, ptr %1, align 4
  ret i32 %52
}

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

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

!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, !11, i64 0}
!10 = !{!"", !11, i64 0, !11, i64 8}
!11 = !{!"any pointer", !7, i64 0}
!12 = !{!13, !11, i64 32}
!13 = !{!"", !11, i64 0, !11, i64 8, !11, i64 16, !6, i64 24, !6, i64 28, !11, i64 32}
!14 = !{!13, !11, i64 16}
!15 = !{!13, !6, i64 28}
!16 = !{!17, !17, i64 0}
!17 = !{!"double", !7, i64 0}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}
!20 = distinct !{!20, !19}


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

%struct.spiral_data_t = type { ptr, ptr }
%struct.layer_dense_t = type { ptr, ptr, ptr, i32, i32, ptr }

@.str.5 = external hidden unnamed_addr constant [11 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [26 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [2 x i8], align 1

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

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

; Function Attrs: nounwind uwtable
declare dso_local void @layer_init(ptr noundef, i32 noundef, i32 noundef) local_unnamed_addr #1

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

; Function Attrs: nounwind uwtable
declare dso_local void @deloc_layer(ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local void @forward(ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local void @actiavtion1(ptr noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local void @spiral_data(i32 noundef, i32 noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local void @deloc_spiral(ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #1 {
  %1 = alloca %struct.spiral_data_t, align 8
  %2 = alloca %struct.layer_dense_t, align 8
  %3 = alloca %struct.layer_dense_t, align 8
  tail call void @srand(i32 noundef 0) #4
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %1) #4
  call void @llvm.lifetime.start.p0(i64 40, ptr nonnull %2) #4
  call void @llvm.lifetime.start.p0(i64 40, ptr nonnull %3) #4
  call void @spiral_data(i32 noundef 100, i32 noundef 3, ptr noundef nonnull %1)
  %4 = load ptr, ptr %1, align 8, !tbaa !5
  %5 = icmp eq ptr %4, null
  br i1 %5, label %6, label %8

6:                                                ; preds = %0
  %7 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.5)
  br label %30

8:                                                ; preds = %0
  %9 = getelementptr inbounds i8, ptr %2, i64 32
  store ptr null, ptr %9, align 8, !tbaa !10
  %10 = getelementptr inbounds i8, ptr %3, i64 32
  store ptr @actiavtion1, ptr %10, align 8, !tbaa !10
  call void @layer_init(ptr noundef nonnull %3, i32 noundef 2, i32 noundef 5)
  %11 = getelementptr inbounds i8, ptr %2, i64 16
  %12 = getelementptr inbounds i8, ptr %3, i64 28
  %13 = getelementptr inbounds i8, ptr %3, i64 16
  br label %14

14:                                               ; preds = %8, %._crit_edge
  %indvars.iv13 = phi i64 [ 0, %8 ], [ %indvars.iv.next14, %._crit_edge ]
  %15 = load ptr, ptr %1, align 8, !tbaa !5
  %.idx = shl nsw i64 %indvars.iv13, 4
  %16 = getelementptr inbounds i8, ptr %15, i64 %.idx
  store ptr %16, ptr %11, align 8, !tbaa !13
  call void @forward(ptr noundef nonnull %2, ptr noundef nonnull %3)
  %17 = trunc nuw nsw i64 %indvars.iv13 to i32
  %18 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.6, i32 noundef %17)
  %19 = load i32, ptr %12, align 4, !tbaa !14
  %20 = icmp sgt i32 %19, 0
  br i1 %20, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %14, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 0, %14 ]
  %21 = load ptr, ptr %13, align 8, !tbaa !13
  %22 = getelementptr inbounds double, ptr %21, i64 %indvars.iv
  %23 = load double, ptr %22, align 8, !tbaa !15
  %24 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.7, double noundef %23)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %25 = load i32, ptr %12, align 4, !tbaa !14
  %26 = sext i32 %25 to i64
  %27 = icmp slt i64 %indvars.iv.next, %26
  br i1 %27, label %.lr.ph, label %._crit_edge, !llvm.loop !17

._crit_edge:                                      ; preds = %.lr.ph, %14
  %28 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.8)
  %indvars.iv.next14 = add nuw nsw i64 %indvars.iv13, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next14, 300
  br i1 %exitcond.not, label %29, label %14, !llvm.loop !19

29:                                               ; preds = %._crit_edge
  call void @deloc_layer(ptr noundef nonnull %3)
  call void @deloc_spiral(ptr noundef nonnull %1)
  br label %30

30:                                               ; preds = %29, %6
  call void @llvm.lifetime.end.p0(i64 40, ptr nonnull %3) #4
  call void @llvm.lifetime.end.p0(i64 40, ptr nonnull %2) #4
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %1) #4
  ret i32 0
}

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

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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 "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 }

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


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