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

; 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.TensorRegister = type { [32 x i8], ptr, ptr, ptr }
%struct.TensorReshapePara = type { ptr, i32, i32, i32, i32 }
%struct.MLayer = type { [32 x i8], i32, ptr, ptr, ptr, i32 }

@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [95 x i8], align 1
@__FUNCTION__.mTensorReshapePara = external hidden unnamed_addr constant [19 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [13 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [6 x i8], align 1
@morn_tensor_register = external global [256 x %struct.TensorRegister], align 16
@.str.4 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [8 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local ptr @mTensorReshapePara(ptr noundef %0, ptr noundef %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #5
  %8 = call ptr @m_Malloc(i32 noundef 24)
  store ptr %8, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #5
  %9 = load ptr, ptr %3, align 8, !tbaa !5
  %10 = load ptr, ptr %4, align 8, !tbaa !5
  %11 = ptrtoint ptr %10 to i64
  %12 = call ptr (ptr, i64, i64, ptr, ...) @m_INIRead(ptr noundef %9, i64 noundef %11, i64 noundef ptrtoint (ptr @.str to i64), ptr noundef inttoptr (i64 -1 to ptr), i32 noundef -1)
  store ptr %12, ptr %6, align 8, !tbaa !5
  %13 = load ptr, ptr %3, align 8, !tbaa !5
  %14 = load ptr, ptr %6, align 8, !tbaa !5
  %15 = call ptr @mNetworkLayer(ptr noundef %13, ptr noundef %14)
  %16 = load ptr, ptr %5, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.TensorReshapePara, ptr %16, i32 0, i32 0
  store ptr %15, ptr %17, align 8, !tbaa !9
  br label %18

18:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #5
  %19 = load ptr, ptr %5, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.TensorReshapePara, ptr %19, i32 0, i32 0
  %21 = load ptr, ptr %20, align 8, !tbaa !9
  %22 = icmp eq ptr %21, null
  %23 = zext i1 %22 to i32
  store i32 %23, ptr %7, align 4, !tbaa !12
  %24 = load i32, ptr %7, align 4, !tbaa !12
  %25 = icmp ne i32 %24, 0
  br i1 %25, label %26, label %28

26:                                               ; preds = %18
  %27 = load i32, ptr %7, align 4, !tbaa !12
  call void (i32, i32, ptr, i32, ptr, ptr, ...) @m_Exception(i32 noundef %27, i32 noundef -1, ptr noundef @.str.1, i32 noundef 26, ptr noundef @__FUNCTION__.mTensorReshapePara, ptr noundef @.str.2)
  br label %28

28:                                               ; preds = %26, %18
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #5
  br label %29

29:                                               ; preds = %28
  br label %30

30:                                               ; preds = %29
  %31 = load ptr, ptr %5, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.TensorReshapePara, ptr %31, i32 0, i32 0
  %33 = load ptr, ptr %32, align 8, !tbaa !9
  %34 = getelementptr inbounds %struct.MLayer, ptr %33, i32 0, i32 1
  %35 = load i32, ptr %34, align 8, !tbaa !13
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds [256 x %struct.TensorRegister], ptr @morn_tensor_register, i64 0, i64 %36
  %38 = getelementptr inbounds %struct.TensorRegister, ptr %37, i32 0, i32 0
  %39 = getelementptr inbounds [32 x i8], ptr %38, i64 0, i64 0
  %40 = call i32 @strcmp(ptr noundef @.str.3, ptr noundef %39) #6
  %41 = icmp ne i32 %40, 0
  %42 = zext i1 %41 to i32
  %43 = load ptr, ptr %5, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.TensorReshapePara, ptr %43, i32 0, i32 4
  store i32 %42, ptr %44, align 4, !tbaa !15
  %45 = load ptr, ptr %3, align 8, !tbaa !5
  %46 = load ptr, ptr %4, align 8, !tbaa !5
  %47 = ptrtoint ptr %46 to i64
  %48 = call ptr (ptr, i64, i64, ptr, ...) @m_INIRead(ptr noundef %45, i64 noundef %47, i64 noundef ptrtoint (ptr @.str.4 to i64), ptr noundef inttoptr (i64 -1 to ptr), i32 noundef -1)
  store ptr %48, ptr %6, align 8, !tbaa !5
  %49 = load ptr, ptr %6, align 8, !tbaa !5
  %50 = icmp ne ptr %49, null
  br i1 %50, label %51, label %56

51:                                               ; preds = %30
  %52 = load ptr, ptr %6, align 8, !tbaa !5
  %53 = call i32 @atoi(ptr noundef %52) #6
  %54 = load ptr, ptr %5, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.TensorReshapePara, ptr %54, i32 0, i32 2
  store i32 %53, ptr %55, align 4, !tbaa !16
  br label %59

56:                                               ; preds = %30
  %57 = load ptr, ptr %5, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.TensorReshapePara, ptr %57, i32 0, i32 2
  store i32 -1, ptr %58, align 4, !tbaa !16
  br label %59

59:                                               ; preds = %56, %51
  %60 = load ptr, ptr %3, align 8, !tbaa !5
  %61 = load ptr, ptr %4, align 8, !tbaa !5
  %62 = ptrtoint ptr %61 to i64
  %63 = call ptr (ptr, i64, i64, ptr, ...) @m_INIRead(ptr noundef %60, i64 noundef %62, i64 noundef ptrtoint (ptr @.str.5 to i64), ptr noundef inttoptr (i64 -1 to ptr), i32 noundef -1)
  store ptr %63, ptr %6, align 8, !tbaa !5
  %64 = load ptr, ptr %6, align 8, !tbaa !5
  %65 = icmp ne ptr %64, null
  br i1 %65, label %66, label %71

66:                                               ; preds = %59
  %67 = load ptr, ptr %6, align 8, !tbaa !5
  %68 = call i32 @atoi(ptr noundef %67) #6
  %69 = load ptr, ptr %5, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct.TensorReshapePara, ptr %69, i32 0, i32 3
  store i32 %68, ptr %70, align 8, !tbaa !17
  br label %74

71:                                               ; preds = %59
  %72 = load ptr, ptr %5, align 8, !tbaa !5
  %73 = getelementptr inbounds %struct.TensorReshapePara, ptr %72, i32 0, i32 3
  store i32 -1, ptr %73, align 8, !tbaa !17
  br label %74

74:                                               ; preds = %71, %66
  %75 = load ptr, ptr %3, align 8, !tbaa !5
  %76 = load ptr, ptr %4, align 8, !tbaa !5
  %77 = ptrtoint ptr %76 to i64
  %78 = call ptr (ptr, i64, i64, ptr, ...) @m_INIRead(ptr noundef %75, i64 noundef %77, i64 noundef ptrtoint (ptr @.str.6 to i64), ptr noundef inttoptr (i64 -1 to ptr), i32 noundef -1)
  store ptr %78, ptr %6, align 8, !tbaa !5
  %79 = load ptr, ptr %6, align 8, !tbaa !5
  %80 = icmp ne ptr %79, null
  br i1 %80, label %81, label %86

81:                                               ; preds = %74
  %82 = load ptr, ptr %6, align 8, !tbaa !5
  %83 = call i32 @atoi(ptr noundef %82) #6
  %84 = load ptr, ptr %5, align 8, !tbaa !5
  %85 = getelementptr inbounds %struct.TensorReshapePara, ptr %84, i32 0, i32 1
  store i32 %83, ptr %85, align 8, !tbaa !18
  br label %89

86:                                               ; preds = %74
  %87 = load ptr, ptr %5, align 8, !tbaa !5
  %88 = getelementptr inbounds %struct.TensorReshapePara, ptr %87, i32 0, i32 1
  store i32 -1, ptr %88, align 8, !tbaa !18
  br label %89

89:                                               ; preds = %86, %81
  %90 = load ptr, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #5
  ret ptr %90
}

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

declare ptr @m_Malloc(i32 noundef) #2

declare ptr @m_INIRead(ptr noundef, i64 noundef, i64 noundef, ptr noundef, ...) #2

declare ptr @mNetworkLayer(ptr noundef, ptr noundef) #2

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

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

; Function Attrs: nounwind willreturn memory(read)
declare i32 @strcmp(ptr noundef, ptr noundef) #3

; Function Attrs: inlinehint nounwind willreturn memory(read) uwtable
declare i32 @atoi(ptr noundef nonnull) #4

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 willreturn memory(read) "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 = { inlinehint nounwind willreturn memory(read) 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 #5 = { nounwind }
attributes #6 = { nounwind willreturn memory(read) }

!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, !6, i64 0}
!10 = !{!"TensorReshapePara", !6, i64 0, !11, i64 8, !11, i64 12, !11, i64 16, !11, i64 20}
!11 = !{!"int", !7, i64 0}
!12 = !{!11, !11, i64 0}
!13 = !{!14, !11, i64 32}
!14 = !{!"MLayer", !7, i64 0, !11, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !11, i64 64}
!15 = !{!10, !11, i64 20}
!16 = !{!10, !11, i64 12}
!17 = !{!10, !11, i64 16}
!18 = !{!10, !11, i64 8}


; 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.TensorRegister = type { [32 x i8], ptr, ptr, ptr }

@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [95 x i8], align 1
@__FUNCTION__.mTensorReshapePara = external hidden unnamed_addr constant [19 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [13 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [6 x i8], align 1
@morn_tensor_register = external global [256 x %struct.TensorRegister], align 16
@.str.4 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [8 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local ptr @mTensorReshapePara(ptr noundef %0, ptr noundef %1) local_unnamed_addr #0 {
  %3 = tail call ptr @m_Malloc(i32 noundef 24) #4
  %4 = ptrtoint ptr %1 to i64
  %5 = tail call ptr (ptr, i64, i64, ptr, ...) @m_INIRead(ptr noundef %0, i64 noundef %4, i64 noundef ptrtoint (ptr @.str to i64), ptr noundef nonnull inttoptr (i64 -1 to ptr), i32 noundef -1) #4
  %6 = tail call ptr @mNetworkLayer(ptr noundef %0, ptr noundef %5) #4
  store ptr %6, ptr %3, align 8, !tbaa !5
  %7 = icmp eq ptr %6, null
  br i1 %7, label %8, label %9

8:                                                ; preds = %2
  tail call void (i32, i32, ptr, i32, ptr, ptr, ...) @m_Exception(i32 noundef 1, i32 noundef -1, ptr noundef nonnull @.str.1, i32 noundef 26, ptr noundef nonnull @__FUNCTION__.mTensorReshapePara, ptr noundef nonnull @.str.2) #4
  %.pre = load ptr, ptr %3, align 8, !tbaa !5
  br label %9

9:                                                ; preds = %8, %2
  %10 = phi ptr [ %.pre, %8 ], [ %6, %2 ]
  %11 = getelementptr inbounds i8, ptr %10, i64 32
  %12 = load i32, ptr %11, align 8, !tbaa !11
  %13 = sext i32 %12 to i64
  %14 = getelementptr inbounds [256 x %struct.TensorRegister], ptr @morn_tensor_register, i64 0, i64 %13
  %15 = tail call i32 @strcmp(ptr noundef nonnull dereferenceable(1) @.str.3, ptr noundef nonnull dereferenceable(1) %14) #5
  %16 = icmp ne i32 %15, 0
  %17 = zext i1 %16 to i32
  %18 = getelementptr inbounds i8, ptr %3, i64 20
  store i32 %17, ptr %18, align 4, !tbaa !13
  %19 = tail call ptr (ptr, i64, i64, ptr, ...) @m_INIRead(ptr noundef %0, i64 noundef %4, i64 noundef ptrtoint (ptr @.str.4 to i64), ptr noundef nonnull inttoptr (i64 -1 to ptr), i32 noundef -1) #4
  %.not = icmp eq ptr %19, null
  br i1 %.not, label %22, label %20

20:                                               ; preds = %9
  %21 = tail call i32 @atoi(ptr nocapture noundef %19) #5
  br label %22

22:                                               ; preds = %9, %20
  %.sink = phi i32 [ %21, %20 ], [ -1, %9 ]
  %23 = getelementptr inbounds i8, ptr %3, i64 12
  store i32 %.sink, ptr %23, align 4
  %24 = tail call ptr (ptr, i64, i64, ptr, ...) @m_INIRead(ptr noundef %0, i64 noundef %4, i64 noundef ptrtoint (ptr @.str.5 to i64), ptr noundef nonnull inttoptr (i64 -1 to ptr), i32 noundef -1) #4
  %.not30 = icmp eq ptr %24, null
  br i1 %.not30, label %27, label %25

25:                                               ; preds = %22
  %26 = tail call i32 @atoi(ptr nocapture noundef %24) #5
  br label %27

27:                                               ; preds = %22, %25
  %.sink32 = phi i32 [ %26, %25 ], [ -1, %22 ]
  %28 = getelementptr inbounds i8, ptr %3, i64 16
  store i32 %.sink32, ptr %28, align 8
  %29 = tail call ptr (ptr, i64, i64, ptr, ...) @m_INIRead(ptr noundef %0, i64 noundef %4, i64 noundef ptrtoint (ptr @.str.6 to i64), ptr noundef nonnull inttoptr (i64 -1 to ptr), i32 noundef -1) #4
  %.not31 = icmp eq ptr %29, null
  br i1 %.not31, label %32, label %30

30:                                               ; preds = %27
  %31 = tail call i32 @atoi(ptr nocapture noundef %29) #5
  br label %32

32:                                               ; preds = %27, %30
  %.sink33 = phi i32 [ %31, %30 ], [ -1, %27 ]
  %33 = getelementptr inbounds i8, ptr %3, i64 8
  store i32 %.sink33, ptr %33, align 8
  ret ptr %3
}

declare ptr @m_Malloc(i32 noundef) local_unnamed_addr #1

declare ptr @m_INIRead(ptr noundef, i64 noundef, i64 noundef, ptr noundef, ...) local_unnamed_addr #1

declare ptr @mNetworkLayer(ptr noundef, ptr noundef) local_unnamed_addr #1

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

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare i32 @strcmp(ptr nocapture noundef, ptr nocapture noundef) local_unnamed_addr #2

; Function Attrs: inlinehint mustprogress nofree nounwind willreturn memory(read) uwtable
declare i32 @atoi(ptr nocapture noundef nonnull) local_unnamed_addr #3

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 nofree nounwind willreturn memory(argmem: read) "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 = { inlinehint mustprogress nofree nounwind willreturn memory(read) 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 #4 = { nounwind }
attributes #5 = { nounwind willreturn memory(read) }

!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 = !{!"TensorReshapePara", !7, i64 0, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!12, !10, i64 32}
!12 = !{!"MLayer", !8, i64 0, !10, i64 32, !7, i64 40, !7, i64 48, !7, i64 56, !10, i64 64}
!13 = !{!6, !10, i64 20}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,MergedLoadStoreMotionPass,SROAPass,SimplifyCFGPass,TailCallElimPass