; LLVM IR from Water-Melon/Melon :: src (mln_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.mln_file_s = type { ptr, ptr, i32, i8, ptr, ptr, ptr, i64, i64, i64, i64, i64 }
%struct.mln_fileset_s = type { ptr, ptr, ptr, ptr, i64 }
%struct.rbtree_s = type { ptr, ptr, ptr, ptr, ptr, %struct.mln_rbtree_node_s, ptr, ptr, ptr, ptr, ptr, i64, i8 }
%struct.mln_rbtree_node_s = type { ptr, ptr, ptr, ptr, ptr, 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

declare void @mln_alloc_free(ptr noundef) #1

declare i32 @close(i32 noundef) #1

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @reg_file_chain_add(ptr noundef, ptr noundef, ptr noundef) #2

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @reg_file_chain_del(ptr noundef, ptr noundef, ptr noundef) #2

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

7:                                                ; preds = %1
  br label %76

8:                                                ; preds = %1
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #4
  %9 = load ptr, ptr %2, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct.mln_file_s, ptr %9, i32 0, i32 3
  %11 = load i8, ptr %10, align 4
  %12 = and i8 %11, 1
  %13 = zext i8 %12 to i32
  %14 = icmp ne i32 %13, 0
  br i1 %14, label %15, label %27

15:                                               ; preds = %8
  %16 = load ptr, ptr %2, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.mln_file_s, ptr %16, i32 0, i32 2
  %18 = load i32, ptr %17, align 8, !tbaa !9
  %19 = icmp sge i32 %18, 0
  br i1 %19, label %20, label %25

20:                                               ; preds = %15
  %21 = load ptr, ptr %2, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.mln_file_s, ptr %21, i32 0, i32 2
  %23 = load i32, ptr %22, align 8, !tbaa !9
  %24 = call i32 @close(i32 noundef %23)
  br label %25

25:                                               ; preds = %20, %15
  %26 = load ptr, ptr %2, align 8, !tbaa !5
  call void @mln_alloc_free(ptr noundef %26)
  store i32 1, ptr %4, align 4
  br label %74

27:                                               ; preds = %8
  %28 = load ptr, ptr %2, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.mln_file_s, ptr %28, i32 0, i32 7
  %30 = load i64, ptr %29, align 8, !tbaa !13
  %31 = add i64 %30, -1
  store i64 %31, ptr %29, align 8, !tbaa !13
  %32 = icmp ugt i64 %31, 0
  br i1 %32, label %33, label %34

33:                                               ; preds = %27
  store i32 1, ptr %4, align 4
  br label %74

34:                                               ; preds = %27
  %35 = load ptr, ptr %2, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.mln_file_s, ptr %35, i32 0, i32 5
  %37 = load ptr, ptr %36, align 8, !tbaa !14
  store ptr %37, ptr %3, align 8, !tbaa !5
  %38 = load ptr, ptr %3, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.mln_fileset_s, ptr %38, i32 0, i32 2
  %40 = load ptr, ptr %3, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.mln_fileset_s, ptr %40, i32 0, i32 3
  %42 = load ptr, ptr %2, align 8, !tbaa !5
  call void @reg_file_chain_add(ptr noundef %39, ptr noundef %41, ptr noundef %42)
  %43 = load ptr, ptr %3, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.mln_fileset_s, ptr %43, i32 0, i32 1
  %45 = load ptr, ptr %44, align 8, !tbaa !15
  %46 = getelementptr inbounds %struct.rbtree_s, ptr %45, i32 0, i32 11
  %47 = load i64, ptr %46, align 8, !tbaa !17
  %48 = load ptr, ptr %3, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.mln_fileset_s, ptr %48, i32 0, i32 4
  %50 = load i64, ptr %49, align 8, !tbaa !20
  %51 = icmp ugt i64 %47, %50
  br i1 %51, label %52, label %73

52:                                               ; preds = %34
  %53 = load ptr, ptr %3, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.mln_fileset_s, ptr %53, i32 0, i32 2
  %55 = load ptr, ptr %54, align 8, !tbaa !21
  store ptr %55, ptr %2, align 8, !tbaa !5
  %56 = load ptr, ptr %3, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.mln_fileset_s, ptr %56, i32 0, i32 2
  %58 = load ptr, ptr %3, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.mln_fileset_s, ptr %58, i32 0, i32 3
  %60 = load ptr, ptr %2, align 8, !tbaa !5
  call void @reg_file_chain_del(ptr noundef %57, ptr noundef %59, ptr noundef %60)
  %61 = load ptr, ptr %3, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.mln_fileset_s, ptr %61, i32 0, i32 1
  %63 = load ptr, ptr %62, align 8, !tbaa !15
  %64 = load ptr, ptr %2, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.mln_file_s, ptr %64, i32 0, i32 6
  %66 = load ptr, ptr %65, align 8, !tbaa !22
  call void @mln_rbtree_delete(ptr noundef %63, ptr noundef %66)
  %67 = load ptr, ptr %3, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct.mln_fileset_s, ptr %67, i32 0, i32 1
  %69 = load ptr, ptr %68, align 8, !tbaa !15
  %70 = load ptr, ptr %2, align 8, !tbaa !5
  %71 = getelementptr inbounds %struct.mln_file_s, ptr %70, i32 0, i32 6
  %72 = load ptr, ptr %71, align 8, !tbaa !22
  call void @mln_rbtree_node_free(ptr noundef %69, ptr noundef %72)
  br label %73

73:                                               ; preds = %52, %34
  store i32 0, ptr %4, align 4
  br label %74

74:                                               ; preds = %73, %33, %25
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #4
  %75 = load i32, ptr %4, align 4
  switch i32 %75, label %77 [
    i32 0, label %76
    i32 1, label %76
  ]

76:                                               ; preds = %74, %74, %7
  ret void

77:                                               ; preds = %74
  unreachable
}

declare void @mln_rbtree_delete(ptr noundef, ptr noundef) #1

declare void @mln_rbtree_node_free(ptr noundef, ptr noundef) #1

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 = { inlinehint 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 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, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !11, i64 16}
!10 = !{!"mln_file_s", !6, i64 0, !6, i64 8, !11, i64 16, !11, i64 20, !6, i64 24, !6, i64 32, !6, i64 40, !12, i64 48, !12, i64 56, !12, i64 64, !12, i64 72, !12, i64 80}
!11 = !{!"int", !7, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!10, !12, i64 48}
!14 = !{!10, !6, i64 32}
!15 = !{!16, !6, i64 8}
!16 = !{!"mln_fileset_s", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !12, i64 32}
!17 = !{!18, !12, i64 136}
!18 = !{!"rbtree_s", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !19, i64 40, !6, i64 96, !6, i64 104, !6, i64 112, !6, i64 120, !6, i64 128, !12, i64 136, !11, i64 144}
!19 = !{!"mln_rbtree_node_s", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !11, i64 48, !11, i64 48}
!20 = !{!16, !12, i64 32}
!21 = !{!16, !6, i64 16}
!22 = !{!10, !6, i64 40}


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

declare void @mln_alloc_free(ptr noundef) local_unnamed_addr #0

declare i32 @close(i32 noundef) local_unnamed_addr #0

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @reg_file_chain_add(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @reg_file_chain_del(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local void @mln_file_close(ptr noundef %0) local_unnamed_addr #2 {
  %2 = icmp eq ptr %0, null
  br i1 %2, label %37, label %3

3:                                                ; preds = %1
  %4 = getelementptr inbounds i8, ptr %0, i64 20
  %5 = load i8, ptr %4, align 4
  %6 = and i8 %5, 1
  %.not = icmp eq i8 %6, 0
  br i1 %.not, label %14, label %7

7:                                                ; preds = %3
  %8 = getelementptr inbounds i8, ptr %0, i64 16
  %9 = load i32, ptr %8, align 8, !tbaa !5
  %10 = icmp sgt i32 %9, -1
  br i1 %10, label %11, label %13

11:                                               ; preds = %7
  %12 = tail call i32 @close(i32 noundef %9) #3
  br label %13

13:                                               ; preds = %11, %7
  tail call void @mln_alloc_free(ptr noundef nonnull %0) #3
  br label %37

14:                                               ; preds = %3
  %15 = getelementptr inbounds i8, ptr %0, i64 48
  %16 = load i64, ptr %15, align 8, !tbaa !12
  %17 = add i64 %16, -1
  store i64 %17, ptr %15, align 8, !tbaa !12
  %.not21 = icmp eq i64 %17, 0
  br i1 %.not21, label %18, label %37

18:                                               ; preds = %14
  %19 = getelementptr inbounds i8, ptr %0, i64 32
  %20 = load ptr, ptr %19, align 8, !tbaa !13
  %21 = getelementptr inbounds i8, ptr %20, i64 16
  %22 = getelementptr inbounds i8, ptr %20, i64 24
  tail call void @reg_file_chain_add(ptr noundef nonnull %21, ptr noundef nonnull %22, ptr noundef nonnull %0)
  %23 = getelementptr inbounds i8, ptr %20, i64 8
  %24 = load ptr, ptr %23, align 8, !tbaa !14
  %25 = getelementptr inbounds i8, ptr %24, i64 136
  %26 = load i64, ptr %25, align 8, !tbaa !16
  %27 = getelementptr inbounds i8, ptr %20, i64 32
  %28 = load i64, ptr %27, align 8, !tbaa !19
  %29 = icmp ugt i64 %26, %28
  br i1 %29, label %30, label %37

30:                                               ; preds = %18
  %31 = load ptr, ptr %21, align 8, !tbaa !20
  tail call void @reg_file_chain_del(ptr noundef nonnull %21, ptr noundef nonnull %22, ptr noundef %31)
  %32 = load ptr, ptr %23, align 8, !tbaa !14
  %33 = getelementptr inbounds i8, ptr %31, i64 40
  %34 = load ptr, ptr %33, align 8, !tbaa !21
  tail call void @mln_rbtree_delete(ptr noundef %32, ptr noundef %34) #3
  %35 = load ptr, ptr %23, align 8, !tbaa !14
  %36 = load ptr, ptr %33, align 8, !tbaa !21
  tail call void @mln_rbtree_node_free(ptr noundef %35, ptr noundef %36) #3
  br label %37

37:                                               ; preds = %13, %14, %30, %18, %1
  ret void
}

declare void @mln_rbtree_delete(ptr noundef, ptr noundef) local_unnamed_addr #0

declare void @mln_rbtree_node_free(ptr noundef, ptr noundef) local_unnamed_addr #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 = { inlinehint 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 = { 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 }

!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 = !{!"mln_file_s", !7, i64 0, !7, i64 8, !10, i64 16, !10, i64 20, !7, i64 24, !7, i64 32, !7, i64 40, !11, i64 48, !11, i64 56, !11, i64 64, !11, i64 72, !11, i64 80}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"long", !8, i64 0}
!12 = !{!6, !11, i64 48}
!13 = !{!6, !7, i64 32}
!14 = !{!15, !7, i64 8}
!15 = !{!"mln_fileset_s", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !11, i64 32}
!16 = !{!17, !11, i64 136}
!17 = !{!"rbtree_s", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !7, i64 32, !18, i64 40, !7, i64 96, !7, i64 104, !7, i64 112, !7, i64 120, !7, i64 128, !11, i64 136, !10, i64 144}
!18 = !{!"mln_rbtree_node_s", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !7, i64 32, !7, i64 40, !10, i64 48, !10, i64 48}
!19 = !{!15, !11, i64 32}
!20 = !{!15, !7, i64 16}
!21 = !{!6, !7, i64 40}


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