; LLVM IR from YanzhenHuang/c-nn :: main (demo_nn)

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

@.str.32 = external hidden unnamed_addr constant [18 x i8], align 1
@.str.33 = external hidden unnamed_addr constant [20 x i8], align 1
@.str.34 = external hidden unnamed_addr constant [18 x i8], align 1

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

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

declare ptr @mat_create(i64 noundef, i64 noundef, ptr noundef) #0

declare void @mat_print(ptr noundef) #0

; 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
define dso_local void @demo_nn() #2 {
  %1 = alloca ptr, align 8
  %2 = alloca ptr, align 8
  %3 = alloca [2 x double], align 8
  %4 = alloca ptr, align 8
  %5 = alloca [2 x double], align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %1) #3
  %6 = call ptr @nn_buildNN(i64 noundef 2, i64 noundef 3, i64 noundef 2, i64 noundef 1, ptr noundef @ReLU, ptr noundef @nngrad_CELoss)
  store ptr %6, ptr %1, align 8, !tbaa !5
  %7 = call i32 (ptr, ...) @printf(ptr noundef @.str.32)
  %8 = load ptr, ptr %1, align 8, !tbaa !5
  call void @nn_printNN(ptr noundef %8)
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #3
  %9 = load ptr, ptr %1, align 8, !tbaa !5
  store double 1.000000e+00, ptr %3, align 8, !tbaa !9
  %10 = getelementptr inbounds double, ptr %3, i64 1
  store double 2.000000e+00, ptr %10, align 8, !tbaa !9
  %11 = getelementptr inbounds [2 x double], ptr %3, i64 0, i64 0
  %12 = call ptr @nn_forward(ptr noundef %9, ptr noundef %11, i64 noundef 2)
  store ptr %12, ptr %2, align 8, !tbaa !5
  %13 = call i32 (ptr, ...) @printf(ptr noundef @.str.33)
  %14 = load ptr, ptr %2, align 8, !tbaa !5
  call void @mat_print(ptr noundef %14)
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  store double 2.000000e+00, ptr %5, align 8, !tbaa !9
  %15 = getelementptr inbounds double, ptr %5, i64 1
  store double 1.000000e+00, ptr %15, align 8, !tbaa !9
  %16 = getelementptr inbounds [2 x double], ptr %5, i64 0, i64 0
  %17 = call ptr @mat_create(i64 noundef 2, i64 noundef 1, ptr noundef %16)
  store ptr %17, ptr %4, align 8, !tbaa !5
  %18 = load ptr, ptr %1, align 8, !tbaa !5
  %19 = load ptr, ptr %2, align 8, !tbaa !5
  %20 = load ptr, ptr %4, align 8, !tbaa !5
  %21 = call ptr @nn_backward(ptr noundef %18, ptr noundef %19, ptr noundef %20, double noundef 1.000000e-02)
  store ptr %21, ptr %1, align 8, !tbaa !5
  %22 = call i32 (ptr, ...) @printf(ptr noundef @.str.34)
  %23 = load ptr, ptr %1, align 8, !tbaa !5
  call void @nn_printNN(ptr noundef %23)
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %1) #3
  ret void
}

declare ptr @nn_buildNN(i64 noundef, i64 noundef, i64 noundef, i64 noundef, ptr noundef, ptr noundef) #0

declare ptr @ReLU(ptr noundef, i64 noundef, i64 noundef, ptr noundef) #0

declare ptr @nngrad_CELoss(ptr noundef, ptr noundef) #0

declare void @nn_printNN(ptr noundef) #0

declare ptr @nn_forward(ptr noundef, ptr noundef, i64 noundef) #0

declare ptr @nn_backward(ptr noundef, ptr noundef, ptr noundef, double noundef) #0

attributes #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 }

!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}


; 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.32 = external hidden unnamed_addr constant [18 x i8], align 1
@.str.33 = external hidden unnamed_addr constant [20 x i8], align 1
@.str.34 = external hidden unnamed_addr constant [18 x i8], align 1

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

declare ptr @mat_create(i64 noundef, i64 noundef, ptr noundef) local_unnamed_addr #1

declare void @mat_print(ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local void @demo_nn() local_unnamed_addr #2 {
  %1 = alloca [2 x double], align 16
  %2 = alloca [2 x double], align 16
  %3 = tail call ptr @nn_buildNN(i64 noundef 2, i64 noundef 3, i64 noundef 2, i64 noundef 1, ptr noundef nonnull @ReLU, ptr noundef nonnull @nngrad_CELoss) #3
  %4 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.32)
  tail call void @nn_printNN(ptr noundef %3) #3
  store <2 x double> <double 1.000000e+00, double 2.000000e+00>, ptr %1, align 16, !tbaa !5
  %5 = call ptr @nn_forward(ptr noundef %3, ptr noundef nonnull %1, i64 noundef 2) #3
  %6 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.33)
  call void @mat_print(ptr noundef %5) #3
  store <2 x double> <double 2.000000e+00, double 1.000000e+00>, ptr %2, align 16, !tbaa !5
  %7 = call ptr @mat_create(i64 noundef 2, i64 noundef 1, ptr noundef nonnull %2) #3
  %8 = call ptr @nn_backward(ptr noundef %3, ptr noundef %5, ptr noundef %7, double noundef 1.000000e-02) #3
  %9 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.34)
  call void @nn_printNN(ptr noundef %8) #3
  ret void
}

declare ptr @nn_buildNN(i64 noundef, i64 noundef, i64 noundef, i64 noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

declare ptr @ReLU(ptr noundef, i64 noundef, i64 noundef, ptr noundef) #1

declare ptr @nngrad_CELoss(ptr noundef, ptr noundef) #1

declare void @nn_printNN(ptr noundef) local_unnamed_addr #1

declare ptr @nn_forward(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #1

declare ptr @nn_backward(ptr noundef, ptr noundef, ptr noundef, double noundef) local_unnamed_addr #1

attributes #0 = { 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 #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 #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 }

!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 = !{!"double", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,SLPVectorizerPass,SROAPass,TailCallElimPass