; LLVM IR from yudi-matsuzake/libgenerics :: src (map)

; 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.map_t = type { i64, i64, %struct.redblacktree_t }
%struct.redblacktree_t = type { i64, i64, ptr, ptr, i64, ptr }
%struct.redblacknode_t = type { ptr, ptr, ptr, i32, 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: 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: nounwind uwtable
define dso_local i32 @map_remove(ptr noundef %0, ptr noundef %1, ptr noundef %2) #2 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !5
  %11 = load ptr, ptr %5, align 8, !tbaa !5
  %12 = icmp ne ptr %11, null
  br i1 %12, label %14, label %13

13:                                               ; preds = %3
  store i32 1, ptr %4, align 4
  br label %48

14:                                               ; preds = %3
  %15 = load ptr, ptr %6, align 8, !tbaa !5
  %16 = icmp ne ptr %15, null
  br i1 %16, label %18, label %17

17:                                               ; preds = %14
  store i32 14, ptr %4, align 4
  br label %48

18:                                               ; preds = %14
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  %19 = load ptr, ptr %5, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.map_t, ptr %19, i32 0, i32 2
  %21 = load ptr, ptr %6, align 8, !tbaa !5
  %22 = call i32 @rbtree_find_node(ptr noundef %20, ptr noundef %21, ptr noundef %8)
  store i32 %22, ptr %9, align 4, !tbaa !9
  %23 = load i32, ptr %9, align 4, !tbaa !9
  %24 = icmp ne i32 %23, 0
  br i1 %24, label %25, label %27

25:                                               ; preds = %18
  %26 = load i32, ptr %9, align 4, !tbaa !9
  store i32 %26, ptr %4, align 4
  store i32 1, ptr %10, align 4
  br label %47

27:                                               ; preds = %18
  %28 = load ptr, ptr %7, align 8, !tbaa !5
  %29 = icmp ne ptr %28, null
  br i1 %29, label %30, label %42

30:                                               ; preds = %27
  %31 = load ptr, ptr %7, align 8, !tbaa !5
  %32 = load ptr, ptr %8, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.redblacknode_t, ptr %32, i32 0, i32 4
  %34 = load ptr, ptr %33, align 8, !tbaa !11
  %35 = load ptr, ptr %5, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.map_t, ptr %35, i32 0, i32 0
  %37 = load i64, ptr %36, align 8, !tbaa !13
  %38 = getelementptr inbounds i8, ptr %34, i64 %37
  %39 = load ptr, ptr %5, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.map_t, ptr %39, i32 0, i32 1
  %41 = load i64, ptr %40, align 8, !tbaa !17
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %31, ptr align 1 %38, i64 %41, i1 false)
  br label %42

42:                                               ; preds = %30, %27
  %43 = load ptr, ptr %5, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.map_t, ptr %43, i32 0, i32 2
  %45 = load ptr, ptr %8, align 8, !tbaa !5
  %46 = call i32 @rbtree_remove_node(ptr noundef %44, ptr noundef %45)
  store i32 %46, ptr %4, align 4
  store i32 1, ptr %10, align 4
  br label %47

47:                                               ; preds = %42, %25
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  br label %48

48:                                               ; preds = %47, %17, %13
  %49 = load i32, ptr %4, align 4
  ret i32 %49
}

declare i32 @rbtree_find_node(ptr noundef, ptr noundef, ptr noundef) #3

declare i32 @rbtree_remove_node(ptr noundef, ptr noundef) #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 }

!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 32}
!12 = !{!"redblacknode_t", !6, i64 0, !6, i64 8, !6, i64 16, !10, i64 24, !6, i64 32}
!13 = !{!14, !15, i64 0}
!14 = !{!"map_t", !15, i64 0, !15, i64 8, !16, i64 16}
!15 = !{!"long", !7, i64 0}
!16 = !{!"redblacktree_t", !15, i64 0, !15, i64 8, !6, i64 16, !6, i64 24, !15, i64 32, !6, i64 40}
!17 = !{!14, !15, 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"

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

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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: nounwind uwtable
define dso_local i32 @map_remove(ptr noundef %0, ptr noundef %1, ptr noundef writeonly %2) local_unnamed_addr #2 {
  %4 = alloca ptr, align 8
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %20, label %5

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

6:                                                ; preds = %5
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %4) #4
  %7 = getelementptr inbounds i8, ptr %0, i64 16
  %8 = call i32 @rbtree_find_node(ptr noundef nonnull %7, ptr noundef nonnull %1, ptr noundef nonnull %4) #4
  %.not16 = icmp eq i32 %8, 0
  br i1 %.not16, label %9, label %19

9:                                                ; preds = %6
  %.not17 = icmp eq ptr %2, null
  %.pre = load ptr, ptr %4, align 8, !tbaa !5
  br i1 %.not17, label %17, label %10

10:                                               ; preds = %9
  %11 = getelementptr inbounds i8, ptr %.pre, i64 32
  %12 = load ptr, ptr %11, align 8, !tbaa !9
  %13 = load i64, ptr %0, align 8, !tbaa !12
  %14 = getelementptr inbounds i8, ptr %12, i64 %13
  %15 = getelementptr inbounds i8, ptr %0, i64 8
  %16 = load i64, ptr %15, align 8, !tbaa !16
  call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 1 %2, ptr align 1 %14, i64 %16, i1 false)
  br label %17

17:                                               ; preds = %10, %9
  %18 = call i32 @rbtree_remove_node(ptr noundef nonnull %7, ptr noundef %.pre) #4
  br label %19

19:                                               ; preds = %6, %17
  %.0 = phi i32 [ %18, %17 ], [ %8, %6 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #4
  br label %20

20:                                               ; preds = %5, %3, %19
  %.1 = phi i32 [ %.0, %19 ], [ 1, %3 ], [ 14, %5 ]
  ret i32 %.1
}

declare i32 @rbtree_find_node(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #3

declare i32 @rbtree_remove_node(ptr noundef, ptr noundef) local_unnamed_addr #3

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 }

!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 32}
!10 = !{!"redblacknode_t", !6, i64 0, !6, i64 8, !6, i64 16, !11, i64 24, !6, i64 32}
!11 = !{!"int", !7, i64 0}
!12 = !{!13, !14, i64 0}
!13 = !{!"map_t", !14, i64 0, !14, i64 8, !15, i64 16}
!14 = !{!"long", !7, i64 0}
!15 = !{!"redblacktree_t", !14, i64 0, !14, i64 8, !6, i64 16, !6, i64 24, !14, i64 32, !6, i64 40}
!16 = !{!13, !14, i64 8}


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