; LLVM IR from jingweizhanghuai/Morn :: src/deep_learning (morn_learning_net)

; 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.MObject = type { i32, %union.anon }
%union.anon = type { ptr }

@morn_network_time = external dso_local global i32, align 4
@morn_network_time_max = external dso_local global i32, align 4
@morn_network_error_thresh = external dso_local global float, align 4
@morn_network_flag = external dso_local global i32, align 4
@morn_log_levelset = external global i32, align 4
@morn_log_level = external thread_local global i32, align 4
@.str.25 = external hidden unnamed_addr constant [18 x i8], align 1
@morn_network_error = external dso_local global float, align 4

; 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 ptr @mNetworkGenerate(ptr noundef) #1

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

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

; Function Attrs: nounwind uwtable
define dso_local void @mDeeplearningTrain(ptr noundef %0) #1 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  store i32 1, ptr @morn_network_flag, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #4
  %5 = call ptr @SheetCreate(i32 noundef -1, ptr noundef null, ptr noundef null, ptr noundef null)
  store ptr %5, ptr %3, align 8, !tbaa !5
  %6 = load ptr, ptr %3, align 8, !tbaa !5
  %7 = load ptr, ptr %2, align 8, !tbaa !5
  %8 = getelementptr inbounds %struct.MObject, ptr %7, i32 0, i32 1
  %9 = load ptr, ptr %8, align 8, !tbaa !11
  call void (ptr, ptr, ...) @mINILoad(ptr noundef %6, ptr noundef %9)
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #4
  %10 = load ptr, ptr %3, align 8, !tbaa !5
  %11 = call ptr @mNetworkGenerate(ptr noundef %10)
  store ptr %11, ptr %4, align 8, !tbaa !5
  store i32 0, ptr @morn_network_time, align 4, !tbaa !9
  br label %12

12:                                               ; preds = %36, %1
  %13 = load i32, ptr @morn_network_time, align 4, !tbaa !9
  %14 = load i32, ptr @morn_network_time_max, align 4, !tbaa !9
  %15 = icmp sle i32 %13, %14
  br i1 %15, label %16, label %39

16:                                               ; preds = %12
  %17 = load ptr, ptr %3, align 8, !tbaa !5
  call void @mTrainData(ptr noundef %17)
  %18 = load ptr, ptr %4, align 8, !tbaa !5
  call void @mNetworkForward(ptr noundef %18)
  %19 = load ptr, ptr %4, align 8, !tbaa !5
  call void @mNetworkBackward(ptr noundef %19)
  br label %20

20:                                               ; preds = %16
  %21 = load i32, ptr @morn_log_levelset, align 4, !tbaa !9
  %22 = icmp sge i32 32, %21
  br i1 %22, label %23, label %28

23:                                               ; preds = %20
  %24 = call align 4 ptr @llvm.threadlocal.address.p0(ptr align 4 @morn_log_level)
  store i32 32, ptr %24, align 4, !tbaa !9
  %25 = load i32, ptr @morn_network_time, align 4, !tbaa !9
  %26 = load float, ptr @morn_network_error, align 4, !tbaa !12
  %27 = fpext float %26 to double
  call void (i32, ptr, ...) @m_Log(i32 noundef 32, ptr noundef @.str.25, i32 noundef %25, double noundef %27)
  br label %28

28:                                               ; preds = %23, %20
  br label %29

29:                                               ; preds = %28
  br label %30

30:                                               ; preds = %29
  %31 = load float, ptr @morn_network_error, align 4, !tbaa !12
  %32 = load float, ptr @morn_network_error_thresh, align 4, !tbaa !12
  %33 = fcmp ole float %31, %32
  br i1 %33, label %34, label %35

34:                                               ; preds = %30
  br label %39

35:                                               ; preds = %30
  br label %36

36:                                               ; preds = %35
  %37 = load i32, ptr @morn_network_time, align 4, !tbaa !9
  %38 = add nsw i32 %37, 1
  store i32 %38, ptr @morn_network_time, align 4, !tbaa !9
  br label %12, !llvm.loop !14

39:                                               ; preds = %34, %12
  %40 = load ptr, ptr %3, align 8, !tbaa !5
  call void @mSheetRelease(ptr noundef %40)
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #4
  ret void
}

declare ptr @SheetCreate(i32 noundef, ptr noundef, ptr noundef, ptr noundef) #2

declare void @mINILoad(ptr noundef, ptr noundef, ...) #2

declare void @mTrainData(ptr noundef) #2

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare nonnull ptr @llvm.threadlocal.address.p0(ptr nonnull) #3

declare void @m_Log(i32 noundef, ptr noundef, ...) #2

declare void @mSheetRelease(ptr noundef) #2

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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"float", !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}


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

@morn_network_time = external dso_local local_unnamed_addr global i32, align 4
@morn_network_time_max = external dso_local local_unnamed_addr global i32, align 4
@morn_network_error_thresh = external dso_local local_unnamed_addr global float, align 4
@morn_network_flag = external dso_local local_unnamed_addr global i32, align 4
@morn_log_levelset = external local_unnamed_addr global i32, align 4
@morn_log_level = external thread_local local_unnamed_addr global i32, align 4
@.str.25 = external hidden unnamed_addr constant [18 x i8], align 1
@morn_network_error = external dso_local local_unnamed_addr global float, align 4

; Function Attrs: nounwind uwtable
declare dso_local ptr @mNetworkGenerate(ptr noundef) local_unnamed_addr #0

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

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

; Function Attrs: nounwind uwtable
define dso_local void @mDeeplearningTrain(ptr nocapture noundef readonly %0) local_unnamed_addr #0 {
  store i32 1, ptr @morn_network_flag, align 4, !tbaa !5
  %2 = tail call ptr @SheetCreate(i32 noundef -1, ptr noundef null, ptr noundef null, ptr noundef null) #3
  %3 = getelementptr inbounds i8, ptr %0, i64 8
  %4 = load ptr, ptr %3, align 8, !tbaa !9
  tail call void (ptr, ptr, ...) @mINILoad(ptr noundef %2, ptr noundef %4) #3
  %5 = tail call ptr @mNetworkGenerate(ptr noundef %2)
  store i32 0, ptr @morn_network_time, align 4, !tbaa !5
  %6 = load i32, ptr @morn_network_time_max, align 4, !tbaa !5
  %.not7 = icmp slt i32 %6, 0
  br i1 %.not7, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %1
  %7 = tail call align 4 ptr @llvm.threadlocal.address.p0(ptr align 4 @morn_log_level)
  br label %8

8:                                                ; preds = %.lr.ph, %19
  tail call void @mTrainData(ptr noundef %2) #3
  tail call void @mNetworkForward(ptr noundef %5)
  tail call void @mNetworkBackward(ptr noundef %5)
  %9 = load i32, ptr @morn_log_levelset, align 4, !tbaa !5
  %10 = icmp slt i32 %9, 33
  br i1 %10, label %11, label %15

11:                                               ; preds = %8
  store i32 32, ptr %7, align 4, !tbaa !5
  %12 = load i32, ptr @morn_network_time, align 4, !tbaa !5
  %13 = load float, ptr @morn_network_error, align 4, !tbaa !10
  %14 = fpext float %13 to double
  tail call void (i32, ptr, ...) @m_Log(i32 noundef 32, ptr noundef nonnull @.str.25, i32 noundef %12, double noundef %14) #3
  br label %15

15:                                               ; preds = %11, %8
  %16 = load float, ptr @morn_network_error, align 4, !tbaa !10
  %17 = load float, ptr @morn_network_error_thresh, align 4, !tbaa !10
  %18 = fcmp ugt float %16, %17
  br i1 %18, label %19, label %._crit_edge

19:                                               ; preds = %15
  %20 = load i32, ptr @morn_network_time, align 4, !tbaa !5
  %21 = add nsw i32 %20, 1
  store i32 %21, ptr @morn_network_time, align 4, !tbaa !5
  %22 = load i32, ptr @morn_network_time_max, align 4, !tbaa !5
  %.not.not = icmp slt i32 %20, %22
  br i1 %.not.not, label %8, label %._crit_edge, !llvm.loop !12

._crit_edge:                                      ; preds = %19, %15, %1
  tail call void @mSheetRelease(ptr noundef %2) #3
  ret void
}

declare ptr @SheetCreate(i32 noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

declare void @mINILoad(ptr noundef, ptr noundef, ...) local_unnamed_addr #1

declare void @mTrainData(ptr noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare nonnull ptr @llvm.threadlocal.address.p0(ptr nonnull) #2

declare void @m_Log(i32 noundef, ptr noundef, ...) local_unnamed_addr #1

declare void @mSheetRelease(ptr noundef) local_unnamed_addr #1

attributes #0 = { 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 #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 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!7, !7, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"float", !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}


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