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

; 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 }
%struct.HandleList = type { %struct.MList, i32, i32, i32, i32 }
%struct.MList = type { i32, ptr }
%struct.MHandle = type { i32, i32, ptr, ptr }
%struct.HandleObjectCreate = type { ptr, ptr, [8 x i64], i32, i64, ptr, i32 }

; 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 willreturn memory(read)
declare i64 @strlen(ptr noundef) #1

declare void @m_Free(ptr noundef) #2

declare ptr @m_Malloc(i32 noundef) #2

; Function Attrs: nounwind uwtable
define dso_local void @m_ObjectRedefine(ptr noundef %0, ptr noundef %1, i32 noundef %2) #3 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store i32 %2, ptr %6, align 4, !tbaa !9
  %8 = load i32, ptr %6, align 4, !tbaa !9
  %9 = icmp sle i32 %8, 0
  br i1 %9, label %10, label %22

10:                                               ; preds = %3
  %11 = load ptr, ptr %5, align 8, !tbaa !5
  %12 = icmp ne ptr %11, null
  br i1 %12, label %13, label %17

13:                                               ; preds = %10
  %14 = load ptr, ptr %5, align 8, !tbaa !5
  %15 = call i64 @strlen(ptr noundef %14) #4
  %16 = trunc i64 %15 to i32
  store i32 %16, ptr %6, align 4, !tbaa !9
  br label %21

17:                                               ; preds = %10
  %18 = load ptr, ptr %4, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.MObject, ptr %18, i32 0, i32 0
  %20 = load i32, ptr %19, align 8, !tbaa !11
  store i32 %20, ptr %6, align 4, !tbaa !9
  br label %21

21:                                               ; preds = %17, %13
  br label %22

22:                                               ; preds = %21, %3
  %23 = load ptr, ptr %5, align 8, !tbaa !5
  %24 = load ptr, ptr %4, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.MObject, ptr %24, i32 0, i32 1
  %26 = load ptr, ptr %25, align 8, !tbaa !13
  %27 = icmp eq ptr %23, %26
  br i1 %27, label %28, label %35

28:                                               ; preds = %22
  %29 = load i32, ptr %6, align 4, !tbaa !9
  %30 = load ptr, ptr %4, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.MObject, ptr %30, i32 0, i32 0
  %32 = load i32, ptr %31, align 8, !tbaa !11
  %33 = icmp eq i32 %29, %32
  br i1 %33, label %34, label %35

34:                                               ; preds = %28
  br label %87

35:                                               ; preds = %28, %22
  %36 = load ptr, ptr %5, align 8, !tbaa !5
  %37 = icmp eq ptr %36, null
  br i1 %37, label %38, label %79

38:                                               ; preds = %35
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #5
  %39 = load ptr, ptr %4, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.HandleList, ptr %39, i64 -1
  %41 = getelementptr inbounds %struct.HandleList, ptr %40, i32 0, i32 0
  %42 = getelementptr inbounds %struct.MList, ptr %41, i32 0, i32 1
  %43 = load ptr, ptr %42, align 8, !tbaa !14
  %44 = getelementptr inbounds ptr, ptr %43, i64 0
  %45 = load ptr, ptr %44, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.MHandle, ptr %45, i32 0, i32 3
  %47 = load ptr, ptr %46, align 8, !tbaa !17
  store ptr %47, ptr %7, align 8, !tbaa !5
  %48 = load ptr, ptr %7, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.HandleObjectCreate, ptr %48, i32 0, i32 6
  %50 = load i32, ptr %49, align 8, !tbaa !19
  %51 = load i32, ptr %6, align 4, !tbaa !9
  %52 = icmp slt i32 %50, %51
  br i1 %52, label %53, label %70

53:                                               ; preds = %38
  %54 = load ptr, ptr %7, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.HandleObjectCreate, ptr %54, i32 0, i32 5
  %56 = load ptr, ptr %55, align 8, !tbaa !22
  %57 = icmp ne ptr %56, null
  br i1 %57, label %58, label %62

58:                                               ; preds = %53
  %59 = load ptr, ptr %7, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.HandleObjectCreate, ptr %59, i32 0, i32 5
  %61 = load ptr, ptr %60, align 8, !tbaa !22
  call void @m_Free(ptr noundef %61)
  br label %62

62:                                               ; preds = %58, %53
  %63 = load i32, ptr %6, align 4, !tbaa !9
  %64 = call ptr @m_Malloc(i32 noundef %63)
  %65 = load ptr, ptr %7, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.HandleObjectCreate, ptr %65, i32 0, i32 5
  store ptr %64, ptr %66, align 8, !tbaa !22
  %67 = load i32, ptr %6, align 4, !tbaa !9
  %68 = load ptr, ptr %7, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.HandleObjectCreate, ptr %68, i32 0, i32 6
  store i32 %67, ptr %69, align 8, !tbaa !19
  br label %70

70:                                               ; preds = %62, %38
  %71 = load ptr, ptr %7, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct.HandleObjectCreate, ptr %71, i32 0, i32 5
  %73 = load ptr, ptr %72, align 8, !tbaa !22
  %74 = load ptr, ptr %4, align 8, !tbaa !5
  %75 = getelementptr inbounds %struct.MObject, ptr %74, i32 0, i32 1
  store ptr %73, ptr %75, align 8, !tbaa !13
  %76 = load ptr, ptr %4, align 8, !tbaa !5
  %77 = getelementptr inbounds %struct.MObject, ptr %76, i32 0, i32 1
  %78 = load ptr, ptr %77, align 8, !tbaa !13
  store ptr %78, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #5
  br label %79

79:                                               ; preds = %70, %35
  %80 = load i32, ptr %6, align 4, !tbaa !9
  %81 = load ptr, ptr %4, align 8, !tbaa !5
  %82 = getelementptr inbounds %struct.MObject, ptr %81, i32 0, i32 0
  store i32 %80, ptr %82, align 8, !tbaa !11
  %83 = load ptr, ptr %5, align 8, !tbaa !5
  %84 = load ptr, ptr %4, align 8, !tbaa !5
  %85 = getelementptr inbounds %struct.MObject, ptr %84, i32 0, i32 1
  store ptr %83, ptr %85, align 8, !tbaa !13
  %86 = load ptr, ptr %4, align 8, !tbaa !5
  call void @mHandleReset(ptr noundef %86)
  br label %87

87:                                               ; preds = %79, %34
  ret void
}

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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 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 willreturn memory(read) }
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, !10, i64 0}
!12 = !{!"MObject", !10, i64 0, !7, i64 8}
!13 = !{!7, !7, i64 0}
!14 = !{!15, !6, i64 8}
!15 = !{!"HandleList", !16, i64 0, !10, i64 16, !10, i64 20, !10, i64 24, !10, i64 28}
!16 = !{!"MList", !10, i64 0, !6, i64 8}
!17 = !{!18, !6, i64 16}
!18 = !{!"MHandle", !10, i64 0, !10, i64 4, !6, i64 8, !6, i64 16}
!19 = !{!20, !10, i64 104}
!20 = !{!"HandleObjectCreate", !6, i64 0, !6, i64 8, !7, i64 16, !10, i64 80, !21, i64 88, !6, i64 96, !10, i64 104}
!21 = !{!"long", !7, i64 0}
!22 = !{!20, !6, i64 96}


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

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare i64 @strlen(ptr nocapture noundef) local_unnamed_addr #0

declare void @m_Free(ptr noundef) local_unnamed_addr #1

declare ptr @m_Malloc(i32 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local void @m_ObjectRedefine(ptr noundef %0, ptr noundef %1, i32 noundef %2) local_unnamed_addr #2 {
  %4 = icmp slt i32 %2, 1
  br i1 %4, label %5, label %11

5:                                                ; preds = %3
  %.not = icmp eq ptr %1, null
  br i1 %.not, label %9, label %6

6:                                                ; preds = %5
  %7 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %1) #3
  %8 = trunc i64 %7 to i32
  br label %11

9:                                                ; preds = %5
  %10 = load i32, ptr %0, align 8, !tbaa !5
  br label %11

11:                                               ; preds = %6, %9, %3
  %.025 = phi i32 [ %8, %6 ], [ %10, %9 ], [ %2, %3 ]
  %12 = getelementptr inbounds i8, ptr %0, i64 8
  %13 = load ptr, ptr %12, align 8, !tbaa !10
  %14 = icmp eq ptr %13, %1
  br i1 %14, label %15, label %18

15:                                               ; preds = %11
  %16 = load i32, ptr %0, align 8, !tbaa !5
  %17 = icmp eq i32 %.025, %16
  br i1 %17, label %35, label %18

18:                                               ; preds = %15, %11
  %19 = icmp eq ptr %1, null
  br i1 %19, label %20, label %._crit_edge

20:                                               ; preds = %18
  %21 = getelementptr inbounds i8, ptr %0, i64 -24
  %22 = load ptr, ptr %21, align 8, !tbaa !11
  %23 = load ptr, ptr %22, align 8, !tbaa !15
  %24 = getelementptr inbounds i8, ptr %23, i64 16
  %25 = load ptr, ptr %24, align 8, !tbaa !16
  %26 = getelementptr inbounds i8, ptr %25, i64 104
  %27 = load i32, ptr %26, align 8, !tbaa !18
  %28 = icmp slt i32 %27, %.025
  %29 = getelementptr inbounds i8, ptr %25, i64 96
  %30 = load ptr, ptr %29, align 8, !tbaa !21
  br i1 %28, label %31, label %._crit_edge

31:                                               ; preds = %20
  %.not29 = icmp eq ptr %30, null
  br i1 %.not29, label %33, label %32

32:                                               ; preds = %31
  tail call void @m_Free(ptr noundef nonnull %30) #4
  br label %33

33:                                               ; preds = %32, %31
  %34 = tail call ptr @m_Malloc(i32 noundef %.025) #4
  store ptr %34, ptr %29, align 8, !tbaa !21
  store i32 %.025, ptr %26, align 8, !tbaa !18
  br label %._crit_edge

._crit_edge:                                      ; preds = %33, %20, %18
  %.0 = phi ptr [ %1, %18 ], [ %34, %33 ], [ %30, %20 ]
  store i32 %.025, ptr %0, align 8, !tbaa !5
  store ptr %.0, ptr %12, align 8, !tbaa !10
  tail call void @mHandleReset(ptr noundef nonnull %0)
  br label %35

35:                                               ; preds = %15, %._crit_edge
  ret void
}

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

attributes #0 = { 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 #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 = { 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 #3 = { nounwind willreturn memory(read) }
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, !7, i64 0}
!6 = !{!"MObject", !7, i64 0, !8, i64 8}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!8, !8, i64 0}
!11 = !{!12, !14, i64 8}
!12 = !{!"HandleList", !13, i64 0, !7, i64 16, !7, i64 20, !7, i64 24, !7, i64 28}
!13 = !{!"MList", !7, i64 0, !14, i64 8}
!14 = !{!"any pointer", !8, i64 0}
!15 = !{!14, !14, i64 0}
!16 = !{!17, !14, i64 16}
!17 = !{!"MHandle", !7, i64 0, !7, i64 4, !14, i64 8, !14, i64 16}
!18 = !{!19, !7, i64 104}
!19 = !{!"HandleObjectCreate", !14, i64 0, !14, i64 8, !8, i64 16, !7, i64 80, !20, i64 88, !14, i64 96, !7, i64 104}
!20 = !{!"long", !8, i64 0}
!21 = !{!19, !14, i64 96}


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