; LLVM IR from jingweizhanghuai/Morn :: src/math (morn_MAT_file)

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

@.str = external hidden unnamed_addr constant [80 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [14 x i8], align 1
@__FUNCTION__.mMATWrite = external hidden unnamed_addr constant [10 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [17 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local void @MATSaveHeader(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 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

declare i32 @fseek(ptr noundef, i64 noundef, i32 noundef) #2

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

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

; Function Attrs: nounwind uwtable
define dso_local void @mMATWrite(ptr noundef %0, ptr noundef %1, ptr noundef %2) #0 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store ptr %2, ptr %6, align 8, !tbaa !5
  br label %12

12:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  %13 = load ptr, ptr %4, align 8, !tbaa !5
  %14 = icmp eq ptr %13, null
  br i1 %14, label %19, label %15

15:                                               ; preds = %12
  %16 = load ptr, ptr %4, align 8, !tbaa !5
  %17 = ptrtoint ptr %16 to i64
  %18 = icmp eq i64 %17, -1
  br label %19

19:                                               ; preds = %15, %12
  %20 = phi i1 [ true, %12 ], [ %18, %15 ]
  %21 = zext i1 %20 to i32
  store i32 %21, ptr %7, align 4, !tbaa !9
  %22 = load i32, ptr %7, align 4, !tbaa !9
  %23 = icmp ne i32 %22, 0
  br i1 %23, label %24, label %26

24:                                               ; preds = %19
  %25 = load i32, ptr %7, align 4, !tbaa !9
  call void (i32, i32, ptr, i32, ptr, ptr, ...) @m_Exception(i32 noundef %25, i32 noundef -1, ptr noundef @.str, i32 noundef 130, ptr noundef @__FUNCTION__.mMATWrite, ptr noundef @.str.1)
  br label %26

26:                                               ; preds = %24, %19
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  br label %27

27:                                               ; preds = %26
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  %28 = load ptr, ptr %4, align 8, !tbaa !5
  %29 = call ptr @GetHandle(ptr noundef %28, i32 noundef 8, i32 noundef -1569964467, ptr noundef @endMAT)
  store ptr %29, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  %30 = load ptr, ptr %8, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.MHandle, ptr %30, i32 0, i32 3
  %32 = load ptr, ptr %31, align 8, !tbaa !11
  store ptr %32, ptr %9, align 8, !tbaa !5
  %33 = load ptr, ptr %8, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.MHandle, ptr %33, i32 0, i32 1
  %35 = load volatile i32, ptr %34, align 4, !tbaa !13
  %36 = icmp eq i32 %35, 0
  br i1 %36, label %37, label %68

37:                                               ; preds = %27
  %38 = load ptr, ptr %9, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.HandleMAT, ptr %38, i32 0, i32 0
  %40 = load ptr, ptr %39, align 8, !tbaa !14
  %41 = icmp eq ptr %40, null
  br i1 %41, label %42, label %49

42:                                               ; preds = %37
  %43 = load ptr, ptr %4, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.MObject, ptr %43, i32 0, i32 1
  %45 = load ptr, ptr %44, align 8, !tbaa !16
  %46 = call noalias ptr @fopen(ptr noundef %45, ptr noundef @.str.3)
  %47 = load ptr, ptr %9, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.HandleMAT, ptr %47, i32 0, i32 0
  store ptr %46, ptr %48, align 8, !tbaa !14
  br label %49

49:                                               ; preds = %42, %37
  br label %50

50:                                               ; preds = %49
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  %51 = load ptr, ptr %9, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.HandleMAT, ptr %51, i32 0, i32 0
  %53 = load ptr, ptr %52, align 8, !tbaa !14
  %54 = icmp eq ptr %53, null
  %55 = zext i1 %54 to i32
  store i32 %55, ptr %10, align 4, !tbaa !9
  %56 = load i32, ptr %10, align 4, !tbaa !9
  %57 = icmp ne i32 %56, 0
  br i1 %57, label %58, label %60

58:                                               ; preds = %50
  %59 = load i32, ptr %10, align 4, !tbaa !9
  call void (i32, i32, ptr, i32, ptr, ptr, ...) @m_Exception(i32 noundef %59, i32 noundef -1, ptr noundef @.str, i32 noundef 136, ptr noundef @__FUNCTION__.mMATWrite, ptr noundef @.str.4)
  br label %60

60:                                               ; preds = %58, %50
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  br label %61

61:                                               ; preds = %60
  br label %62

62:                                               ; preds = %61
  %63 = load ptr, ptr %9, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.HandleMAT, ptr %63, i32 0, i32 0
  %65 = load ptr, ptr %64, align 8, !tbaa !14
  call void @MATSaveHeader(ptr noundef %65)
  %66 = load ptr, ptr %8, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.MHandle, ptr %66, i32 0, i32 1
  store volatile i32 1, ptr %67, align 4, !tbaa !13
  br label %68

68:                                               ; preds = %62, %27
  %69 = load ptr, ptr %9, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct.HandleMAT, ptr %69, i32 0, i32 0
  %71 = load ptr, ptr %70, align 8, !tbaa !14
  %72 = call i32 @fseek(ptr noundef %71, i64 noundef 0, i32 noundef 2)
  br label %73

73:                                               ; preds = %68
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  %74 = load ptr, ptr %6, align 8, !tbaa !5
  %75 = icmp eq ptr %74, null
  br i1 %75, label %79, label %76

76:                                               ; preds = %73
  %77 = load ptr, ptr %5, align 8, !tbaa !5
  %78 = icmp eq ptr %77, null
  br label %79

79:                                               ; preds = %76, %73
  %80 = phi i1 [ true, %73 ], [ %78, %76 ]
  %81 = zext i1 %80 to i32
  store i32 %81, ptr %11, align 4, !tbaa !9
  %82 = load i32, ptr %11, align 4, !tbaa !9
  %83 = icmp ne i32 %82, 0
  br i1 %83, label %84, label %86

84:                                               ; preds = %79
  %85 = load i32, ptr %11, align 4, !tbaa !9
  call void (i32, i32, ptr, i32, ptr, ptr, ...) @m_Exception(i32 noundef %85, i32 noundef -1, ptr noundef @.str, i32 noundef 142, ptr noundef @__FUNCTION__.mMATWrite, ptr noundef @.str.1)
  br label %86

86:                                               ; preds = %84, %79
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  br label %87

87:                                               ; preds = %86
  br label %88

88:                                               ; preds = %87
  %89 = load ptr, ptr %5, align 8, !tbaa !5
  %90 = load ptr, ptr %6, align 8, !tbaa !5
  %91 = load ptr, ptr %9, align 8, !tbaa !5
  %92 = getelementptr inbounds %struct.HandleMAT, ptr %91, i32 0, i32 0
  %93 = load ptr, ptr %92, align 8, !tbaa !14
  call void @MATSaveData(ptr noundef %89, ptr noundef %90, ptr noundef %93)
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  ret void
}

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

declare noalias ptr @fopen(ptr noundef, ptr noundef) #2

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 }

!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 = !{!12, !6, i64 16}
!12 = !{!"MHandle", !10, i64 0, !10, i64 4, !6, i64 8, !6, i64 16}
!13 = !{!12, !10, i64 4}
!14 = !{!15, !6, i64 0}
!15 = !{!"HandleMAT", !6, i64 0}
!16 = !{!7, !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 = external hidden unnamed_addr constant [80 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [14 x i8], align 1
@__FUNCTION__.mMATWrite = external hidden unnamed_addr constant [10 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [17 x i8], align 1

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

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

; Function Attrs: nofree nounwind
declare noundef i32 @fseek(ptr nocapture noundef, i64 noundef, i32 noundef) local_unnamed_addr #2

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

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

; Function Attrs: nounwind uwtable
define dso_local void @mMATWrite(ptr noundef %0, ptr noundef %1, ptr noundef %2) local_unnamed_addr #0 {
  %magicptr = ptrtoint ptr %0 to i64
  switch i64 %magicptr, label %9 [
    i64 -1, label %4
    i64 0, label %4
  ]

4:                                                ; preds = %3, %3
  %5 = icmp eq ptr %0, null
  %6 = icmp eq ptr %0, inttoptr (i64 -1 to ptr)
  %7 = or i1 %5, %6
  %8 = zext i1 %7 to i32
  tail call void (i32, i32, ptr, i32, ptr, ptr, ...) @m_Exception(i32 noundef %8, i32 noundef -1, ptr noundef nonnull @.str, i32 noundef 130, ptr noundef nonnull @__FUNCTION__.mMATWrite, ptr noundef nonnull @.str.1) #3
  br label %9

9:                                                ; preds = %3, %4
  %10 = tail call ptr @GetHandle(ptr noundef %0, i32 noundef 8, i32 noundef -1569964467, ptr noundef nonnull @endMAT) #3
  %11 = getelementptr inbounds i8, ptr %10, i64 16
  %12 = load ptr, ptr %11, align 8, !tbaa !5
  %13 = getelementptr inbounds i8, ptr %10, i64 4
  %14 = load volatile i32, ptr %13, align 4, !tbaa !11
  %15 = icmp eq i32 %14, 0
  br i1 %15, label %16, label %26

16:                                               ; preds = %9
  %17 = load ptr, ptr %12, align 8, !tbaa !12
  %18 = icmp eq ptr %17, null
  br i1 %18, label %19, label %.thread

19:                                               ; preds = %16
  %20 = getelementptr inbounds i8, ptr %0, i64 8
  %21 = load ptr, ptr %20, align 8, !tbaa !14
  %22 = tail call noalias ptr @fopen(ptr noundef %21, ptr noundef nonnull @.str.3)
  store ptr %22, ptr %12, align 8, !tbaa !12
  %23 = icmp eq ptr %22, null
  br i1 %23, label %24, label %.thread

24:                                               ; preds = %19
  tail call void (i32, i32, ptr, i32, ptr, ptr, ...) @m_Exception(i32 noundef 1, i32 noundef -1, ptr noundef nonnull @.str, i32 noundef 136, ptr noundef nonnull @__FUNCTION__.mMATWrite, ptr noundef nonnull @.str.4) #3
  %.pre = load ptr, ptr %12, align 8, !tbaa !12
  br label %.thread

.thread:                                          ; preds = %16, %24, %19
  %25 = phi ptr [ %17, %16 ], [ %.pre, %24 ], [ %22, %19 ]
  tail call void @MATSaveHeader(ptr noundef %25)
  store volatile i32 1, ptr %13, align 4, !tbaa !11
  br label %26

26:                                               ; preds = %.thread, %9
  %27 = load ptr, ptr %12, align 8, !tbaa !12
  %28 = tail call i32 @fseek(ptr noundef %27, i64 noundef 0, i32 noundef 2)
  %29 = icmp eq ptr %2, null
  %30 = icmp eq ptr %1, null
  %31 = or i1 %30, %29
  br i1 %31, label %32, label %33

32:                                               ; preds = %26
  tail call void (i32, i32, ptr, i32, ptr, ptr, ...) @m_Exception(i32 noundef 1, i32 noundef -1, ptr noundef nonnull @.str, i32 noundef 142, ptr noundef nonnull @__FUNCTION__.mMATWrite, ptr noundef nonnull @.str.1) #3
  br label %33

33:                                               ; preds = %32, %26
  %34 = load ptr, ptr %12, align 8, !tbaa !12
  tail call void @MATSaveData(ptr noundef %1, ptr noundef %2, ptr noundef %34)
  ret void
}

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

; Function Attrs: nofree nounwind
declare noalias noundef ptr @fopen(ptr nocapture noundef readonly, ptr nocapture noundef readonly) local_unnamed_addr #2

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 = { 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 }

!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, !10, i64 16}
!6 = !{!"MHandle", !7, i64 0, !7, i64 4, !10, i64 8, !10, i64 16}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!6, !7, i64 4}
!12 = !{!13, !10, i64 0}
!13 = !{!"HandleMAT", !10, i64 0}
!14 = !{!8, !8, i64 0}


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