; LLVM IR from zchrissirhcz/pixel :: legacy/NaiveCNN/examples/nc_lenet.ll (Z14nc_train_trialv)

; 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.px_size_t = type { i32, i32 }
%struct.NcTrainConfig = type { i32, float, i32, [256 x i8] }
%struct.LenetDataConfig = type { i32, ptr, ptr, [256 x i8], [256 x i8] }
%struct.NcNet = type { i32, ptr, i32, ptr, ptr, ptr }

@_ZL11project_dir = external hidden global ptr, align 8
@.str.6 = external hidden unnamed_addr constant [26 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [23 x i8], align 1
@.str.11 = external hidden unnamed_addr constant [20 x i8], align 1

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z21nc_lenet5_train_setupP5NcNet9px_size_ti(ptr noundef, i64, i32 noundef) #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.start.p0(i64 immarg, ptr nocapture) #2

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

; Function Attrs: nounwind
declare i32 @sprintf(ptr noundef, ptr noundef, ...) #3

; Function Attrs: mustprogress uwtable
define dso_local void @_Z14nc_train_trialv() #0 {
  %1 = alloca %struct.px_size_t, align 4
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  %4 = alloca %struct.px_size_t, align 4
  %5 = alloca %struct.NcTrainConfig, align 4
  %6 = alloca %struct.LenetDataConfig, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 8, ptr %1) #6
  %9 = getelementptr inbounds %struct.px_size_t, ptr %1, i32 0, i32 1
  store i32 28, ptr %9, align 4, !tbaa !5
  %10 = getelementptr inbounds %struct.px_size_t, ptr %1, i32 0, i32 0
  store i32 28, ptr %10, align 4, !tbaa !10
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #6
  store i32 10, ptr %2, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #6
  %11 = call noalias ptr @malloc(i64 noundef 48) #7
  store ptr %11, ptr %3, align 8, !tbaa !12
  %12 = load ptr, ptr %3, align 8, !tbaa !12
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %4, ptr align 4 %1, i64 8, i1 false), !tbaa.struct !14
  %13 = load i32, ptr %2, align 4, !tbaa !11
  %14 = load i64, ptr %4, align 4
  call void @_Z21nc_lenet5_train_setupP5NcNet9px_size_ti(ptr noundef %12, i64 %14, i32 noundef %13)
  call void @llvm.lifetime.start.p0(i64 268, ptr %5) #6
  %15 = getelementptr inbounds %struct.NcTrainConfig, ptr %5, i32 0, i32 0
  store i32 1, ptr %15, align 4, !tbaa !15
  %16 = getelementptr inbounds %struct.NcTrainConfig, ptr %5, i32 0, i32 1
  store float 1.000000e+00, ptr %16, align 4, !tbaa !18
  %17 = getelementptr inbounds %struct.NcTrainConfig, ptr %5, i32 0, i32 2
  store i32 1, ptr %17, align 4, !tbaa !19
  %18 = getelementptr inbounds %struct.NcTrainConfig, ptr %5, i32 0, i32 3
  %19 = getelementptr inbounds [256 x i8], ptr %18, i64 0, i64 0
  %20 = load ptr, ptr @_ZL11project_dir, align 8, !tbaa !12
  %21 = call i32 (ptr, ptr, ...) @sprintf(ptr noundef %19, ptr noundef @.str.6, ptr noundef %20) #6
  call void @llvm.lifetime.start.p0(i64 536, ptr %6) #6
  %22 = getelementptr inbounds %struct.LenetDataConfig, ptr %6, i32 0, i32 3
  %23 = getelementptr inbounds [256 x i8], ptr %22, i64 0, i64 0
  %24 = call i32 (ptr, ptr, ...) @sprintf(ptr noundef %23, ptr noundef @.str.7, ptr noundef @.str.8) #6
  %25 = getelementptr inbounds %struct.LenetDataConfig, ptr %6, i32 0, i32 4
  %26 = getelementptr inbounds [256 x i8], ptr %25, i64 0, i64 0
  %27 = call i32 (ptr, ptr, ...) @sprintf(ptr noundef %26, ptr noundef @.str.7, ptr noundef @.str.9) #6
  call void @nc_cls_data_loader(ptr noundef %6)
  %28 = load ptr, ptr %3, align 8, !tbaa !12
  call void @nc_train_cls_net(ptr noundef %28, ptr noundef %5, ptr noundef %6)
  %29 = call i32 (ptr, ...) @printf(ptr noundef @.str.10)
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #6
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #6
  store i32 0, ptr %8, align 4, !tbaa !11
  br label %30

30:                                               ; preds = %46, %0
  %31 = load i32, ptr %8, align 4, !tbaa !11
  %32 = load ptr, ptr %3, align 8, !tbaa !12
  %33 = getelementptr inbounds %struct.NcNet, ptr %32, i32 0, i32 0
  %34 = load i32, ptr %33, align 8, !tbaa !20
  %35 = icmp slt i32 %31, %34
  br i1 %35, label %37, label %36

36:                                               ; preds = %30
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #6
  br label %49

37:                                               ; preds = %30
  %38 = load ptr, ptr %3, align 8, !tbaa !12
  %39 = getelementptr inbounds %struct.NcNet, ptr %38, i32 0, i32 1
  %40 = load ptr, ptr %39, align 8, !tbaa !22
  %41 = load i32, ptr %8, align 4, !tbaa !11
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds ptr, ptr %40, i64 %42
  %44 = load ptr, ptr %43, align 8, !tbaa !12
  store ptr %44, ptr %7, align 8, !tbaa !12
  %45 = load ptr, ptr %7, align 8, !tbaa !12
  call void @nc_destroy_layer(ptr noundef %45)
  br label %46

46:                                               ; preds = %37
  %47 = load i32, ptr %8, align 4, !tbaa !11
  %48 = add nsw i32 %47, 1
  store i32 %48, ptr %8, align 4, !tbaa !11
  br label %30, !llvm.loop !23

49:                                               ; preds = %36
  %50 = call i32 (ptr, ...) @printf(ptr noundef @.str.11)
  %51 = load ptr, ptr %3, align 8, !tbaa !12
  %52 = getelementptr inbounds %struct.NcNet, ptr %51, i32 0, i32 1
  %53 = load ptr, ptr %52, align 8, !tbaa !22
  call void @free(ptr noundef %53) #6
  %54 = load ptr, ptr %3, align 8, !tbaa !12
  %55 = getelementptr inbounds %struct.NcNet, ptr %54, i32 0, i32 4
  %56 = load ptr, ptr %55, align 8, !tbaa !25
  call void @free(ptr noundef %56) #6
  %57 = load ptr, ptr %3, align 8, !tbaa !12
  call void @free(ptr noundef %57) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #6
  call void @llvm.lifetime.end.p0(i64 536, ptr %6) #6
  call void @llvm.lifetime.end.p0(i64 268, ptr %5) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %1) #6
  ret void
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #4

; Function Attrs: mustprogress uwtable
declare dso_local void @nc_cls_data_loader(ptr noundef) #0

declare void @nc_train_cls_net(ptr noundef, ptr noundef, ptr noundef) #5

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

declare void @nc_destroy_layer(ptr noundef) #5

; Function Attrs: nounwind
declare void @free(ptr noundef) #3

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

!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 4}
!6 = !{!"_ZTS9px_size_t", !7, i64 0, !7, i64 4}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!6, !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"any pointer", !8, i64 0}
!14 = !{i64 0, i64 4, !11, i64 4, i64 4, !11}
!15 = !{!16, !7, i64 0}
!16 = !{!"_ZTS13NcTrainConfig", !7, i64 0, !17, i64 4, !7, i64 8, !8, i64 12}
!17 = !{!"float", !8, i64 0}
!18 = !{!16, !17, i64 4}
!19 = !{!16, !7, i64 8}
!20 = !{!21, !7, i64 0}
!21 = !{!"_ZTS5NcNet", !7, i64 0, !13, i64 8, !7, i64 16, !13, i64 24, !13, i64 32, !13, i64 40}
!22 = !{!21, !13, i64 8}
!23 = distinct !{!23, !24}
!24 = !{!"llvm.loop.mustprogress"}
!25 = !{!21, !13, i64 32}


; 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.NcTrainConfig = type { i32, float, i32, [256 x i8] }
%struct.LenetDataConfig = type { i32, ptr, ptr, [256 x i8], [256 x i8] }

@_ZL11project_dir = external hidden local_unnamed_addr global ptr, align 8
@.str.6 = external hidden unnamed_addr constant [26 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [23 x i8], align 1
@.str.11 = external hidden unnamed_addr constant [20 x i8], align 1

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z21nc_lenet5_train_setupP5NcNet9px_size_ti(ptr noundef, i64, i32 noundef) local_unnamed_addr #0

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

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

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

; Function Attrs: nofree nounwind
declare noundef i32 @sprintf(ptr noalias nocapture noundef writeonly, ptr nocapture noundef readonly, ...) local_unnamed_addr #3

; Function Attrs: mustprogress uwtable
define dso_local void @_Z14nc_train_trialv() local_unnamed_addr #0 {
  %1 = alloca %struct.NcTrainConfig, align 4
  %2 = alloca %struct.LenetDataConfig, align 8
  %3 = tail call noalias dereferenceable_or_null(48) ptr @malloc(i64 noundef 48) #6
  tail call void @_Z21nc_lenet5_train_setupP5NcNet9px_size_ti(ptr noundef %3, i64 120259084316, i32 noundef 10)
  call void @llvm.lifetime.start.p0(i64 268, ptr nonnull %1) #7
  store i32 1, ptr %1, align 4, !tbaa !5
  %4 = getelementptr inbounds i8, ptr %1, i64 4
  store float 1.000000e+00, ptr %4, align 4, !tbaa !11
  %5 = getelementptr inbounds i8, ptr %1, i64 8
  store i32 1, ptr %5, align 4, !tbaa !12
  %6 = getelementptr inbounds i8, ptr %1, i64 12
  %7 = load ptr, ptr @_ZL11project_dir, align 8, !tbaa !13
  %8 = call i32 (ptr, ptr, ...) @sprintf(ptr noundef nonnull dereferenceable(1) %6, ptr noundef nonnull dereferenceable(1) @.str.6, ptr noundef %7) #7
  call void @llvm.lifetime.start.p0(i64 536, ptr nonnull %2) #7
  %9 = getelementptr inbounds i8, ptr %2, i64 24
  %10 = call i32 (ptr, ptr, ...) @sprintf(ptr noundef nonnull dereferenceable(1) %9, ptr noundef nonnull dereferenceable(1) @.str.7, ptr noundef nonnull @.str.8) #7
  %11 = getelementptr inbounds i8, ptr %2, i64 280
  %12 = call i32 (ptr, ptr, ...) @sprintf(ptr noundef nonnull dereferenceable(1) %11, ptr noundef nonnull dereferenceable(1) @.str.7, ptr noundef nonnull @.str.9) #7
  call void @nc_cls_data_loader(ptr noundef nonnull %2)
  call void @nc_train_cls_net(ptr noundef %3, ptr noundef nonnull %1, ptr noundef nonnull %2)
  %13 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.10)
  %14 = load i32, ptr %3, align 8, !tbaa !15
  %15 = icmp sgt i32 %14, 0
  br i1 %15, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %0
  %16 = getelementptr inbounds i8, ptr %3, i64 8
  br label %22

._crit_edge:                                      ; preds = %22, %0
  %17 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.11)
  %18 = getelementptr inbounds i8, ptr %3, i64 8
  %19 = load ptr, ptr %18, align 8, !tbaa !17
  call void @free(ptr noundef %19) #7
  %20 = getelementptr inbounds i8, ptr %3, i64 32
  %21 = load ptr, ptr %20, align 8, !tbaa !18
  call void @free(ptr noundef %21) #7
  call void @free(ptr noundef nonnull %3) #7
  call void @llvm.lifetime.end.p0(i64 536, ptr nonnull %2) #7
  call void @llvm.lifetime.end.p0(i64 268, ptr nonnull %1) #7
  ret void

22:                                               ; preds = %.lr.ph, %22
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %22 ]
  %23 = load ptr, ptr %16, align 8, !tbaa !17
  %24 = getelementptr inbounds ptr, ptr %23, i64 %indvars.iv
  %25 = load ptr, ptr %24, align 8, !tbaa !13
  call void @nc_destroy_layer(ptr noundef %25)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %26 = load i32, ptr %3, align 8, !tbaa !15
  %27 = sext i32 %26 to i64
  %28 = icmp slt i64 %indvars.iv.next, %27
  br i1 %28, label %22, label %._crit_edge, !llvm.loop !19
}

; Function Attrs: mustprogress uwtable
declare dso_local void @nc_cls_data_loader(ptr noundef) local_unnamed_addr #0

declare void @nc_train_cls_net(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #4

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

declare void @nc_destroy_layer(ptr noundef) local_unnamed_addr #4

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #5

attributes #0 = { mustprogress 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 #1 = { 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 #2 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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 #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 = { mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, 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 #6 = { nounwind allocsize(0) }
attributes #7 = { 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 = !{!"_ZTS13NcTrainConfig", !7, i64 0, !10, i64 4, !7, i64 8, !8, i64 12}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"float", !8, i64 0}
!11 = !{!6, !10, i64 4}
!12 = !{!6, !7, i64 8}
!13 = !{!14, !14, i64 0}
!14 = !{!"any pointer", !8, i64 0}
!15 = !{!16, !7, i64 0}
!16 = !{!"_ZTS5NcNet", !7, i64 0, !14, i64 8, !7, i64 16, !14, i64 24, !14, i64 32, !14, i64 40}
!17 = !{!16, !14, i64 8}
!18 = !{!16, !14, i64 32}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}


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