; LLVM IR from Sentdex/NNfSiX :: C (p006-Softmax-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 [27 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
declare dso_local void @activation_softmax(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 %struct.layer_dense_t, align 8
  %8 = 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 @llvm.lifetime.start.p0(i64 40, ptr %7) #4
  call void @spiral_data(i32 noundef 100, i32 noundef 3, ptr noundef %4)
  %9 = getelementptr inbounds %struct.spiral_data_t, ptr %4, i32 0, i32 0
  %10 = load ptr, ptr %9, align 8, !tbaa !9
  %11 = icmp eq ptr %10, null
  br i1 %11, label %12, label %14

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

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

18:                                               ; preds = %49, %14
  %19 = load i32, ptr %2, align 4, !tbaa !5
  %20 = icmp slt i32 %19, 300
  br i1 %20, label %21, label %52

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

31:                                               ; preds = %44, %21
  %32 = load i32, ptr %3, align 4, !tbaa !5
  %33 = getelementptr inbounds %struct.layer_dense_t, ptr %7, i32 0, i32 4
  %34 = load i32, ptr %33, align 4, !tbaa !15
  %35 = icmp slt i32 %32, %34
  br i1 %35, label %36, label %47

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

44:                                               ; preds = %36
  %45 = load i32, ptr %3, align 4, !tbaa !5
  %46 = add nsw i32 %45, 1
  store i32 %46, ptr %3, align 4, !tbaa !5
  br label %31, !llvm.loop !18

47:                                               ; preds = %31
  %48 = call i32 (ptr, ...) @printf(ptr noundef @.str.8)
  br label %49

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

52:                                               ; preds = %18
  call void @deloc_layer(ptr noundef %6)
  call void @deloc_layer(ptr noundef %7)
  call void @deloc_spiral(ptr noundef %4)
  store i32 0, ptr %1, align 4
  store i32 1, ptr %8, align 4
  br label %53

53:                                               ; preds = %52, %12
  call void @llvm.lifetime.end.p0(i64 40, ptr %7) #4
  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
  %54 = load i32, ptr %1, align 4
  ret i32 %54
}

; 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 [27 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
declare dso_local void @activation_softmax(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
  %4 = 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 @llvm.lifetime.start.p0(i64 40, ptr nonnull %4) #4
  call void @spiral_data(i32 noundef 100, i32 noundef 3, ptr noundef nonnull %1)
  %5 = load ptr, ptr %1, align 8, !tbaa !5
  %6 = icmp eq ptr %5, null
  br i1 %6, label %7, label %9

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

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

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

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

._crit_edge:                                      ; preds = %.lr.ph, %16
  %30 = 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 %31, label %16, !llvm.loop !19

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

32:                                               ; preds = %31, %7
  call void @llvm.lifetime.end.p0(i64 40, ptr nonnull %4) #4
  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