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

; 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.HandleINIFile = type { ptr }

@morn_INI_file = external dso_local global ptr, align 8
@.str = external hidden unnamed_addr constant [4 x i8], align 1
@morn_INI_sheet = external hidden global ptr, align 8

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

; Function Attrs: nounwind uwtable
define dso_local void @mINIFile(ptr noundef %0) #0 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  %5 = call ptr @mMornObject(ptr noundef @.str, i32 noundef -1)
  %6 = call ptr @GetHandle(ptr noundef %5, i32 noundef 8, i32 noundef -1366779511, ptr noundef @endINIFile)
  store ptr %6, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  %7 = load ptr, ptr %3, align 8, !tbaa !5
  %8 = getelementptr inbounds %struct.MHandle, ptr %7, i32 0, i32 3
  %9 = load ptr, ptr %8, align 8, !tbaa !9
  store ptr %9, ptr %4, align 8, !tbaa !5
  %10 = load ptr, ptr %3, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.MHandle, ptr %10, i32 0, i32 1
  %12 = load volatile i32, ptr %11, align 4, !tbaa !12
  %13 = icmp eq i32 %12, 0
  br i1 %13, label %14, label %26

14:                                               ; preds = %1
  %15 = load ptr, ptr %4, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.HandleINIFile, ptr %15, i32 0, i32 0
  %17 = load ptr, ptr %16, align 8, !tbaa !13
  %18 = icmp eq ptr %17, null
  br i1 %18, label %19, label %23

19:                                               ; preds = %14
  %20 = call ptr @SheetCreate(i32 noundef -1, ptr noundef null, ptr noundef null, ptr noundef null)
  %21 = load ptr, ptr %4, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.HandleINIFile, ptr %21, i32 0, i32 0
  store ptr %20, ptr %22, align 8, !tbaa !13
  br label %23

23:                                               ; preds = %19, %14
  %24 = load ptr, ptr %3, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.MHandle, ptr %24, i32 0, i32 1
  store volatile i32 1, ptr %25, align 4, !tbaa !12
  br label %26

26:                                               ; preds = %23, %1
  %27 = load ptr, ptr %2, align 8, !tbaa !5
  store ptr %27, ptr @morn_INI_file, align 8, !tbaa !5
  %28 = load ptr, ptr %4, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.HandleINIFile, ptr %28, i32 0, i32 0
  %30 = load ptr, ptr %29, align 8, !tbaa !13
  store ptr %30, ptr @morn_INI_sheet, align 8, !tbaa !5
  %31 = load ptr, ptr @morn_INI_sheet, align 8, !tbaa !5
  %32 = icmp ne ptr %31, null
  br i1 %32, label %33, label %35

33:                                               ; preds = %26
  %34 = load ptr, ptr @morn_INI_sheet, align 8, !tbaa !5
  call void @mSheetClear(ptr noundef %34)
  br label %35

35:                                               ; preds = %33, %26
  %36 = load ptr, ptr @morn_INI_sheet, align 8, !tbaa !5
  %37 = load ptr, ptr %2, align 8, !tbaa !5
  call void (ptr, ptr, ...) @mINILoad(ptr noundef %36, ptr noundef %37)
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  ret void
}

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

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

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

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

declare void @mSheetClear(ptr noundef) #2

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

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

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, !6, i64 16}
!10 = !{!"MHandle", !11, i64 0, !11, i64 4, !6, i64 8, !6, i64 16}
!11 = !{!"int", !7, i64 0}
!12 = !{!10, !11, i64 4}
!13 = !{!14, !6, i64 0}
!14 = !{!"HandleINIFile", !6, 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"

@morn_INI_file = external dso_local local_unnamed_addr global ptr, align 8
@.str = external hidden unnamed_addr constant [4 x i8], align 1
@morn_INI_sheet = external hidden local_unnamed_addr global ptr, align 8

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

; Function Attrs: nounwind uwtable
define dso_local void @mINIFile(ptr noundef %0) local_unnamed_addr #0 {
  %2 = tail call ptr @mMornObject(ptr noundef nonnull @.str, i32 noundef -1) #2
  %3 = tail call ptr @GetHandle(ptr noundef %2, i32 noundef 8, i32 noundef -1366779511, ptr noundef nonnull @endINIFile) #2
  %4 = getelementptr inbounds i8, ptr %3, i64 16
  %5 = load ptr, ptr %4, align 8, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %3, i64 4
  %7 = load volatile i32, ptr %6, align 4, !tbaa !11
  %8 = icmp eq i32 %7, 0
  br i1 %8, label %9, label %15

9:                                                ; preds = %1
  %10 = load ptr, ptr %5, align 8, !tbaa !12
  %11 = icmp eq ptr %10, null
  br i1 %11, label %12, label %14

12:                                               ; preds = %9
  %13 = tail call ptr @SheetCreate(i32 noundef -1, ptr noundef null, ptr noundef null, ptr noundef null) #2
  store ptr %13, ptr %5, align 8, !tbaa !12
  br label %14

14:                                               ; preds = %12, %9
  store volatile i32 1, ptr %6, align 4, !tbaa !11
  br label %15

15:                                               ; preds = %14, %1
  store ptr %0, ptr @morn_INI_file, align 8, !tbaa !14
  %16 = load ptr, ptr %5, align 8, !tbaa !12
  store ptr %16, ptr @morn_INI_sheet, align 8, !tbaa !14
  %.not = icmp eq ptr %16, null
  br i1 %.not, label %18, label %17

17:                                               ; preds = %15
  tail call void @mSheetClear(ptr noundef nonnull %16) #2
  %.pre = load ptr, ptr @morn_INI_sheet, align 8, !tbaa !14
  br label %18

18:                                               ; preds = %17, %15
  %19 = phi ptr [ %.pre, %17 ], [ null, %15 ]
  tail call void (ptr, ptr, ...) @mINILoad(ptr noundef %19, ptr noundef %0)
  ret void
}

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

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

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

declare void @mSheetClear(ptr noundef) local_unnamed_addr #1

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

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 = { 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 = !{!"HandleINIFile", !10, i64 0}
!14 = !{!10, !10, i64 0}


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