; LLVM IR from jingweizhanghuai/Morn :: src/util (morn_sheet)

; 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.HandleSheetInfoRead = type { i32 }
%struct.MSheet = type { i32, ptr, ptr, ptr }

@.str = external hidden unnamed_addr constant [77 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [14 x i8], align 1
@__FUNCTION__.mSheetInfoRead = external hidden unnamed_addr constant [15 x i8], align 1

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

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

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

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

; 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) #2

; Function Attrs: nounwind
declare ptr @strcpy(ptr noundef, ptr noundef) #3

; Function Attrs: nounwind uwtable
declare dso_local void @endSheetInfoRead(ptr noundef) #4

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

14:                                               ; preds = %4
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #5
  %15 = load ptr, ptr %6, align 8, !tbaa !5
  %16 = icmp eq ptr %15, null
  br i1 %16, label %21, label %17

17:                                               ; preds = %14
  %18 = load ptr, ptr %6, align 8, !tbaa !5
  %19 = ptrtoint ptr %18 to i64
  %20 = icmp eq i64 %19, -1
  br label %21

21:                                               ; preds = %17, %14
  %22 = phi i1 [ true, %14 ], [ %20, %17 ]
  %23 = zext i1 %22 to i32
  store i32 %23, ptr %10, align 4, !tbaa !9
  %24 = load i32, ptr %10, align 4, !tbaa !9
  %25 = icmp ne i32 %24, 0
  br i1 %25, label %26, label %28

26:                                               ; preds = %21
  %27 = load i32, ptr %10, align 4, !tbaa !9
  call void (i32, i32, ptr, i32, ptr, ptr, ...) @m_Exception(i32 noundef %27, i32 noundef -1, ptr noundef @.str, i32 noundef 414, ptr noundef @__FUNCTION__.mSheetInfoRead, ptr noundef @.str.2)
  br label %28

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

29:                                               ; preds = %28
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #5
  %30 = load ptr, ptr %6, align 8, !tbaa !5
  %31 = call ptr @GetHandle(ptr noundef %30, i32 noundef 4, i32 noundef 2088482906, ptr noundef @endSheetInfoRead)
  store ptr %31, ptr %11, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #5
  %32 = load ptr, ptr %11, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.MHandle, ptr %32, i32 0, i32 3
  %34 = load ptr, ptr %33, align 8, !tbaa !11
  store ptr %34, ptr %12, align 8, !tbaa !5
  %35 = load i32, ptr %7, align 4, !tbaa !9
  %36 = icmp slt i32 %35, 0
  br i1 %36, label %37, label %41

37:                                               ; preds = %29
  %38 = load ptr, ptr %12, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.HandleSheetInfoRead, ptr %38, i32 0, i32 0
  %40 = load i32, ptr %39, align 4, !tbaa !13
  store i32 %40, ptr %7, align 4, !tbaa !9
  br label %41

41:                                               ; preds = %37, %29
  %42 = load i32, ptr %7, align 4, !tbaa !9
  %43 = load ptr, ptr %6, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.MSheet, ptr %43, i32 0, i32 0
  %45 = load i32, ptr %44, align 8, !tbaa !15
  %46 = icmp sge i32 %42, %45
  br i1 %46, label %47, label %48

47:                                               ; preds = %41
  store ptr null, ptr %5, align 8
  store i32 1, ptr %13, align 4
  br label %84

48:                                               ; preds = %41
  %49 = load ptr, ptr %8, align 8, !tbaa !5
  %50 = icmp ne ptr %49, null
  br i1 %50, label %51, label %76

51:                                               ; preds = %48
  %52 = load i32, ptr %9, align 4, !tbaa !9
  %53 = icmp sgt i32 %52, 0
  br i1 %53, label %54, label %65

54:                                               ; preds = %51
  %55 = load ptr, ptr %8, align 8, !tbaa !5
  %56 = load ptr, ptr %6, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.MSheet, ptr %56, i32 0, i32 1
  %58 = load ptr, ptr %57, align 8, !tbaa !17
  %59 = load i32, ptr %7, align 4, !tbaa !9
  %60 = sext i32 %59 to i64
  %61 = getelementptr inbounds ptr, ptr %58, i64 %60
  %62 = load ptr, ptr %61, align 8, !tbaa !5
  %63 = load i32, ptr %9, align 4, !tbaa !9
  %64 = sext i32 %63 to i64
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %55, ptr align 1 %62, i64 %64, i1 false)
  br label %75

65:                                               ; preds = %51
  %66 = load ptr, ptr %8, align 8, !tbaa !5
  %67 = load ptr, ptr %6, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct.MSheet, ptr %67, i32 0, i32 1
  %69 = load ptr, ptr %68, align 8, !tbaa !17
  %70 = load i32, ptr %7, align 4, !tbaa !9
  %71 = sext i32 %70 to i64
  %72 = getelementptr inbounds ptr, ptr %69, i64 %71
  %73 = load ptr, ptr %72, align 8, !tbaa !5
  %74 = call ptr @strcpy(ptr noundef %66, ptr noundef %73) #5
  br label %75

75:                                               ; preds = %65, %54
  br label %76

76:                                               ; preds = %75, %48
  %77 = load ptr, ptr %6, align 8, !tbaa !5
  %78 = getelementptr inbounds %struct.MSheet, ptr %77, i32 0, i32 1
  %79 = load ptr, ptr %78, align 8, !tbaa !17
  %80 = load i32, ptr %7, align 4, !tbaa !9
  %81 = sext i32 %80 to i64
  %82 = getelementptr inbounds ptr, ptr %79, i64 %81
  %83 = load ptr, ptr %82, align 8, !tbaa !5
  store ptr %83, ptr %5, align 8
  store i32 1, ptr %13, align 4
  br label %84

84:                                               ; preds = %76, %47
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #5
  %85 = load ptr, ptr %5, align 8
  ret ptr %85
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { nocallback nofree 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 = { 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 #5 = { 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 = !{!14, !10, i64 0}
!14 = !{!"HandleSheetInfoRead", !10, i64 0}
!15 = !{!16, !10, i64 0}
!16 = !{!"MSheet", !10, i64 0, !6, i64 8, !6, i64 16, !6, i64 24}
!17 = !{!16, !6, 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"

@.str = external hidden unnamed_addr constant [77 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [14 x i8], align 1
@__FUNCTION__.mSheetInfoRead = external hidden unnamed_addr constant [15 x i8], align 1

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

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

; Function Attrs: mustprogress 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) #1

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: readwrite)
declare ptr @strcpy(ptr noalias noundef returned writeonly, ptr noalias nocapture noundef readonly) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
declare dso_local void @endSheetInfoRead(ptr noundef) #3

; Function Attrs: nounwind uwtable
define dso_local ptr @mSheetInfoRead(ptr noundef %0, i32 noundef %1, ptr noundef %2, i32 noundef %3) local_unnamed_addr #3 {
  %magicptr = ptrtoint ptr %0 to i64
  switch i64 %magicptr, label %10 [
    i64 -1, label %5
    i64 0, label %5
  ]

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

10:                                               ; preds = %4, %5
  %11 = tail call ptr @GetHandle(ptr noundef %0, i32 noundef 4, i32 noundef 2088482906, ptr noundef nonnull @endSheetInfoRead) #4
  %12 = icmp slt i32 %1, 0
  br i1 %12, label %13, label %17

13:                                               ; preds = %10
  %14 = getelementptr inbounds i8, ptr %11, i64 16
  %15 = load ptr, ptr %14, align 8, !tbaa !5
  %16 = load i32, ptr %15, align 4, !tbaa !11
  br label %17

17:                                               ; preds = %13, %10
  %.021 = phi i32 [ %16, %13 ], [ %1, %10 ]
  %18 = load i32, ptr %0, align 8, !tbaa !13
  %.not = icmp slt i32 %.021, %18
  br i1 %.not, label %19, label %36

19:                                               ; preds = %17
  %.not25 = icmp eq ptr %2, null
  br i1 %.not25, label %._crit_edge, label %20

._crit_edge:                                      ; preds = %19
  %.pre = sext i32 %.021 to i64
  br label %31

20:                                               ; preds = %19
  %21 = icmp sgt i32 %3, 0
  %22 = getelementptr inbounds i8, ptr %0, i64 8
  %23 = load ptr, ptr %22, align 8, !tbaa !15
  %24 = sext i32 %.021 to i64
  %25 = getelementptr inbounds ptr, ptr %23, i64 %24
  %26 = load ptr, ptr %25, align 8, !tbaa !16
  br i1 %21, label %27, label %29

27:                                               ; preds = %20
  %28 = zext nneg i32 %3 to i64
  tail call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 1 %2, ptr align 1 %26, i64 %28, i1 false)
  br label %31

29:                                               ; preds = %20
  %30 = tail call ptr @strcpy(ptr noundef nonnull dereferenceable(1) %2, ptr noundef nonnull dereferenceable(1) %26) #4
  br label %31

31:                                               ; preds = %._crit_edge, %27, %29
  %.pre-phi = phi i64 [ %.pre, %._crit_edge ], [ %24, %27 ], [ %24, %29 ]
  %32 = getelementptr inbounds i8, ptr %0, i64 8
  %33 = load ptr, ptr %32, align 8, !tbaa !15
  %34 = getelementptr inbounds ptr, ptr %33, i64 %.pre-phi
  %35 = load ptr, ptr %34, align 8, !tbaa !16
  br label %36

36:                                               ; preds = %17, %31
  %.0 = phi ptr [ %35, %31 ], [ null, %17 ]
  ret ptr %.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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { mustprogress nofree nounwind willreturn memory(argmem: readwrite) "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 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 }

!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 = !{!12, !7, i64 0}
!12 = !{!"HandleSheetInfoRead", !7, i64 0}
!13 = !{!14, !7, i64 0}
!14 = !{!"MSheet", !7, i64 0, !10, i64 8, !10, i64 16, !10, i64 24}
!15 = !{!14, !10, i64 8}
!16 = !{!10, !10, i64 0}


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