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

; 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

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

; Function Attrs: nounwind uwtable
define dso_local ptr @m_ObjectCreate(ptr noundef %0, i32 noundef %1) #2 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  %8 = call ptr @ObjectAlloc(i32 noundef 16)
  store ptr %8, ptr %5, align 8, !tbaa !5
  %9 = load ptr, ptr %5, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct.HandleList, ptr %9, i64 -1
  %11 = getelementptr inbounds %struct.HandleList, ptr %10, i32 0, i32 4
  store i32 -1122137992, ptr %11, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  %12 = load ptr, ptr %5, align 8, !tbaa !5
  %13 = call ptr @GetHandle(ptr noundef %12, i32 noundef 112, i32 noundef -1122137992, ptr noundef @endObjectCreate)
  store ptr %13, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  %14 = load ptr, ptr %6, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.MHandle, ptr %14, i32 0, i32 3
  %16 = load ptr, ptr %15, align 8, !tbaa !14
  store ptr %16, ptr %7, align 8, !tbaa !5
  %17 = load ptr, ptr %5, align 8, !tbaa !5
  %18 = load ptr, ptr %7, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.HandleObjectCreate, ptr %18, i32 0, i32 0
  store ptr %17, ptr %19, align 8, !tbaa !16
  %20 = load i32, ptr %4, align 4, !tbaa !9
  %21 = load ptr, ptr %5, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.MObject, ptr %21, i32 0, i32 0
  store i32 %20, ptr %22, align 8, !tbaa !19
  %23 = load ptr, ptr %3, align 8, !tbaa !5
  %24 = load ptr, ptr %5, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.MObject, ptr %24, i32 0, i32 1
  store ptr %23, ptr %25, align 8, !tbaa !21
  %26 = load ptr, ptr %3, align 8, !tbaa !5
  %27 = icmp eq ptr %26, null
  br i1 %27, label %28, label %53

28:                                               ; preds = %2
  %29 = load i32, ptr %4, align 4, !tbaa !9
  %30 = icmp sgt i32 %29, 0
  br i1 %30, label %31, label %53

31:                                               ; preds = %28
  %32 = load i32, ptr %4, align 4, !tbaa !9
  %33 = sext i32 %32 to i64
  %34 = icmp ule i64 %33, 8
  br i1 %34, label %35, label %38

35:                                               ; preds = %31
  %36 = load ptr, ptr %7, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.HandleObjectCreate, ptr %36, i32 0, i32 4
  store ptr %37, ptr %3, align 8, !tbaa !5
  br label %49

38:                                               ; preds = %31
  %39 = load i32, ptr %4, align 4, !tbaa !9
  %40 = call ptr @m_Malloc(i32 noundef %39)
  %41 = load ptr, ptr %7, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.HandleObjectCreate, ptr %41, i32 0, i32 5
  store ptr %40, ptr %42, align 8, !tbaa !22
  %43 = load ptr, ptr %7, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.HandleObjectCreate, ptr %43, i32 0, i32 5
  %45 = load ptr, ptr %44, align 8, !tbaa !22
  store ptr %45, ptr %3, align 8, !tbaa !5
  %46 = load i32, ptr %4, align 4, !tbaa !9
  %47 = load ptr, ptr %7, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.HandleObjectCreate, ptr %47, i32 0, i32 6
  store i32 %46, ptr %48, align 8, !tbaa !23
  br label %49

49:                                               ; preds = %38, %35
  %50 = load ptr, ptr %3, align 8, !tbaa !5
  %51 = load ptr, ptr %5, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.MObject, ptr %51, i32 0, i32 1
  store ptr %50, ptr %52, align 8, !tbaa !21
  br label %67

53:                                               ; preds = %28, %2
  %54 = load ptr, ptr %3, align 8, !tbaa !5
  %55 = icmp ne ptr %54, null
  br i1 %55, label %56, label %66

56:                                               ; preds = %53
  %57 = load i32, ptr %4, align 4, !tbaa !9
  %58 = icmp sle i32 %57, 0
  br i1 %58, label %59, label %66

59:                                               ; preds = %56
  %60 = load ptr, ptr %3, align 8, !tbaa !5
  %61 = call i64 @strlen(ptr noundef %60) #5
  %62 = trunc i64 %61 to i32
  store i32 %62, ptr %4, align 4, !tbaa !9
  %63 = load i32, ptr %4, align 4, !tbaa !9
  %64 = load ptr, ptr %5, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.MObject, ptr %64, i32 0, i32 0
  store i32 %63, ptr %65, align 8, !tbaa !19
  br label %66

66:                                               ; preds = %59, %56, %53
  br label %67

67:                                               ; preds = %66, %49
  %68 = load ptr, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  ret ptr %68
}

; Function Attrs: nounwind uwtable
declare dso_local ptr @ObjectAlloc(i32 noundef) #2

; Function Attrs: nounwind uwtable
declare dso_local ptr @GetHandle(ptr noundef, i32 noundef, i32 noundef, ptr noundef) #2

declare ptr @m_Malloc(i32 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 = { 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 = { "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, !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 28}
!12 = !{!"HandleList", !13, i64 0, !10, i64 16, !10, i64 20, !10, i64 24, !10, i64 28}
!13 = !{!"MList", !10, i64 0, !6, i64 8}
!14 = !{!15, !6, i64 16}
!15 = !{!"MHandle", !10, i64 0, !10, i64 4, !6, i64 8, !6, i64 16}
!16 = !{!17, !6, i64 0}
!17 = !{!"HandleObjectCreate", !6, i64 0, !6, i64 8, !7, i64 16, !10, i64 80, !18, i64 88, !6, i64 96, !10, i64 104}
!18 = !{!"long", !7, i64 0}
!19 = !{!20, !10, i64 0}
!20 = !{!"MObject", !10, i64 0, !7, i64 8}
!21 = !{!7, !7, i64 0}
!22 = !{!17, !6, i64 96}
!23 = !{!17, !10, i64 104}


; 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

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

; Function Attrs: nounwind uwtable
define dso_local noundef ptr @m_ObjectCreate(ptr noundef %0, i32 noundef %1) local_unnamed_addr #1 {
  %3 = tail call ptr @ObjectAlloc(i32 noundef 16)
  %4 = getelementptr inbounds i8, ptr %3, i64 -4
  store i32 -1122137992, ptr %4, align 4, !tbaa !5
  %5 = tail call ptr @GetHandle(ptr noundef %3, i32 noundef 112, i32 noundef -1122137992, ptr noundef nonnull @endObjectCreate)
  %6 = getelementptr inbounds i8, ptr %5, i64 16
  %7 = load ptr, ptr %6, align 8, !tbaa !12
  store ptr %3, ptr %7, align 8, !tbaa !14
  store i32 %1, ptr %3, align 8, !tbaa !17
  %8 = getelementptr inbounds i8, ptr %3, i64 8
  store ptr %0, ptr %8, align 8, !tbaa !19
  %9 = icmp eq ptr %0, null
  %10 = icmp sgt i32 %1, 0
  %or.cond = and i1 %9, %10
  br i1 %or.cond, label %11, label %20

11:                                               ; preds = %2
  %12 = icmp ult i32 %1, 9
  br i1 %12, label %13, label %15

13:                                               ; preds = %11
  %14 = getelementptr inbounds i8, ptr %7, i64 88
  br label %19

15:                                               ; preds = %11
  %16 = tail call ptr @m_Malloc(i32 noundef %1) #3
  %17 = getelementptr inbounds i8, ptr %7, i64 96
  store ptr %16, ptr %17, align 8, !tbaa !20
  %18 = getelementptr inbounds i8, ptr %7, i64 104
  store i32 %1, ptr %18, align 8, !tbaa !21
  br label %19

19:                                               ; preds = %15, %13
  %.0 = phi ptr [ %14, %13 ], [ %16, %15 ]
  store ptr %.0, ptr %8, align 8, !tbaa !19
  br label %26

20:                                               ; preds = %2
  %21 = icmp ne ptr %0, null
  %22 = icmp slt i32 %1, 1
  %or.cond3 = and i1 %21, %22
  br i1 %or.cond3, label %23, label %26

23:                                               ; preds = %20
  %24 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %0) #4
  %25 = trunc i64 %24 to i32
  store i32 %25, ptr %3, align 8, !tbaa !17
  br label %26

26:                                               ; preds = %20, %23, %19
  ret ptr %3
}

; Function Attrs: nounwind uwtable
declare dso_local ptr @ObjectAlloc(i32 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local ptr @GetHandle(ptr noundef, i32 noundef, i32 noundef, ptr noundef) local_unnamed_addr #1

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


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