; LLVM IR from Water-Melon/Melon :: src (mln_event)

; 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_event_desc_s = type { ptr, ptr, ptr, ptr, i32, i32, %union.anon }
%union.anon = type { %struct.mln_event_fd_s }
%struct.mln_event_fd_s = type { i32, i32, i32, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, i64 }
%struct.mln_event_s = type { %union.pthread_mutex_t, %union.pthread_mutex_t, %union.pthread_mutex_t, ptr, ptr, i32, i32, %struct.fd_set, %struct.fd_set, %struct.fd_set, ptr, ptr, ptr, ptr, ptr, ptr, ptr }
%union.pthread_mutex_t = type { %struct.__pthread_mutex_s }
%struct.__pthread_mutex_s = type { i32, i32, i32, i32, i32, i16, i16, %struct.__pthread_internal_list }
%struct.__pthread_internal_list = type { ptr, ptr }
%struct.fd_set = type { [16 x 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

; Function Attrs: nounwind
declare i32 @pthread_mutex_lock(ptr noundef) #1

; Function Attrs: nounwind
declare i32 @pthread_mutex_unlock(ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local void @mln_event_fd_timeout_handler_set(ptr noundef nonnull %0, i32 noundef %1, ptr noundef %2, ptr noundef %3) #2 {
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca %struct.mln_event_desc_s, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca i32, align 4
  %14 = alloca ptr, align 8
  %15 = alloca ptr, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !9
  store ptr %2, ptr %7, align 8, !tbaa !5
  store ptr %3, ptr %8, align 8, !tbaa !5
  %16 = load ptr, ptr %5, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.mln_event_s, ptr %16, i32 0, i32 0
  %18 = call i32 @pthread_mutex_lock(ptr noundef %17) #4
  call void @llvm.lifetime.start.p0(i64 136, ptr %9) #4
  call void @llvm.memset.p0.i64(ptr align 8 %9, i8 0, i64 136, i1 false)
  %19 = getelementptr inbounds %struct.mln_event_desc_s, ptr %9, i32 0, i32 4
  store i32 0, ptr %19, align 8, !tbaa !11
  %20 = load i32, ptr %6, align 4, !tbaa !9
  %21 = getelementptr inbounds %struct.mln_event_desc_s, ptr %9, i32 0, i32 6
  %22 = getelementptr inbounds %struct.mln_event_fd_s, ptr %21, i32 0, i32 0
  store i32 %20, ptr %22, align 8, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  %23 = load ptr, ptr %5, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.mln_event_s, ptr %23, i32 0, i32 10
  %25 = load ptr, ptr %24, align 8, !tbaa !14
  store ptr %25, ptr %11, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #4
  %26 = load ptr, ptr %11, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.rbtree_s, ptr %26, i32 0, i32 6
  %28 = load ptr, ptr %27, align 8, !tbaa !17
  store ptr %28, ptr %12, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #4
  br label %29

29:                                               ; preds = %53, %4
  %30 = load ptr, ptr %12, align 8, !tbaa !5
  %31 = load ptr, ptr %11, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.rbtree_s, ptr %31, i32 0, i32 5
  %33 = icmp ne ptr %30, %32
  br i1 %33, label %34, label %40

34:                                               ; preds = %29
  %35 = load ptr, ptr %12, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.mln_rbtree_node_s, ptr %35, i32 0, i32 0
  %37 = load ptr, ptr %36, align 8, !tbaa !21
  %38 = call i32 @mln_event_rbtree_fd_cmp(ptr noundef %9, ptr noundef %37)
  store i32 %38, ptr %13, align 4, !tbaa !9
  %39 = icmp ne i32 %38, 0
  br label %40

40:                                               ; preds = %34, %29
  %41 = phi i1 [ false, %29 ], [ %39, %34 ]
  br i1 %41, label %42, label %54

42:                                               ; preds = %40
  %43 = load i32, ptr %13, align 4, !tbaa !9
  %44 = icmp slt i32 %43, 0
  br i1 %44, label %45, label %49

45:                                               ; preds = %42
  %46 = load ptr, ptr %12, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.mln_rbtree_node_s, ptr %46, i32 0, i32 4
  %48 = load ptr, ptr %47, align 8, !tbaa !22
  store ptr %48, ptr %12, align 8, !tbaa !5
  br label %53

49:                                               ; preds = %42
  %50 = load ptr, ptr %12, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.mln_rbtree_node_s, ptr %50, i32 0, i32 5
  %52 = load ptr, ptr %51, align 8, !tbaa !23
  store ptr %52, ptr %12, align 8, !tbaa !5
  br label %53

53:                                               ; preds = %49, %45
  br label %29, !llvm.loop !24

54:                                               ; preds = %40
  %55 = load ptr, ptr %12, align 8, !tbaa !5
  store ptr %55, ptr %14, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  %56 = load ptr, ptr %14, align 8, !tbaa !5
  store ptr %56, ptr %10, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #4
  %57 = load ptr, ptr %10, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.mln_rbtree_node_s, ptr %57, i32 0, i32 0
  %59 = load ptr, ptr %58, align 8, !tbaa !21
  store ptr %59, ptr %15, align 8, !tbaa !5
  %60 = load ptr, ptr %7, align 8, !tbaa !5
  %61 = load ptr, ptr %15, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.mln_event_desc_s, ptr %61, i32 0, i32 6
  %63 = getelementptr inbounds %struct.mln_event_fd_s, ptr %62, i32 0, i32 9
  store ptr %60, ptr %63, align 8, !tbaa !13
  %64 = load ptr, ptr %8, align 8, !tbaa !5
  %65 = load ptr, ptr %15, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.mln_event_desc_s, ptr %65, i32 0, i32 6
  %67 = getelementptr inbounds %struct.mln_event_fd_s, ptr %66, i32 0, i32 10
  store ptr %64, ptr %67, align 8, !tbaa !13
  %68 = load ptr, ptr %5, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.mln_event_s, ptr %68, i32 0, i32 0
  %70 = call i32 @pthread_mutex_unlock(ptr noundef %69) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 136, ptr %9) #4
  ret void
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #3

; Function Attrs: nounwind uwtable
declare hidden i32 @mln_event_rbtree_fd_cmp(ptr noundef nonnull, ptr noundef nonnull) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nounwind "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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
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, !10, i64 32}
!12 = !{!"mln_event_desc_s", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !10, i64 32, !10, i64 36, !7, i64 40}
!13 = !{!7, !7, i64 0}
!14 = !{!15, !6, i64 528}
!15 = !{!"mln_event_s", !7, i64 0, !7, i64 40, !7, i64 80, !6, i64 120, !6, i64 128, !10, i64 136, !10, i64 136, !10, i64 140, !16, i64 144, !16, i64 272, !16, i64 400, !6, i64 528, !6, i64 536, !6, i64 544, !6, i64 552, !6, i64 560, !6, i64 568, !6, i64 576}
!16 = !{!"", !7, i64 0}
!17 = !{!18, !6, i64 96}
!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, !20, i64 136, !10, 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, !10, i64 48, !10, i64 48}
!20 = !{!"long", !7, i64 0}
!21 = !{!19, !6, i64 0}
!22 = !{!19, !6, i64 32}
!23 = !{!19, !6, i64 40}
!24 = distinct !{!24, !25}
!25 = !{!"llvm.loop.mustprogress"}


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

%struct.mln_event_desc_s = type { ptr, ptr, ptr, ptr, i32, i32, %union.anon }
%union.anon = type { %struct.mln_event_fd_s }
%struct.mln_event_fd_s = type { i32, i32, i32, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, i64 }

; 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: nounwind
declare i32 @pthread_mutex_lock(ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind
declare i32 @pthread_mutex_unlock(ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local void @mln_event_fd_timeout_handler_set(ptr noundef nonnull %0, i32 noundef %1, ptr noundef %2, ptr noundef %3) local_unnamed_addr #2 {
  %5 = alloca %struct.mln_event_desc_s, align 8
  %6 = tail call i32 @pthread_mutex_lock(ptr noundef nonnull %0) #4
  call void @llvm.lifetime.start.p0(i64 136, ptr nonnull %5) #4
  %7 = getelementptr inbounds i8, ptr %5, i64 40
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(136) %5, i8 0, i64 136, i1 false)
  store i32 %1, ptr %7, align 8, !tbaa !5
  %8 = getelementptr inbounds i8, ptr %0, i64 528
  %9 = load ptr, ptr %8, align 8, !tbaa !8
  %10 = getelementptr inbounds i8, ptr %9, i64 96
  %11 = getelementptr inbounds i8, ptr %9, i64 40
  %.019 = load ptr, ptr %10, align 8, !tbaa !13
  %.not20 = icmp eq ptr %.019, %11
  br i1 %.not20, label %.critedge, label %.lr.ph

.lr.ph:                                           ; preds = %4, %14
  %.021 = phi ptr [ %.0, %14 ], [ %.019, %4 ]
  %12 = load ptr, ptr %.021, align 8, !tbaa !14
  %13 = call i32 @mln_event_rbtree_fd_cmp(ptr noundef %5, ptr noundef %12)
  %.not18 = icmp eq i32 %13, 0
  br i1 %.not18, label %.critedge, label %14

14:                                               ; preds = %.lr.ph
  %15 = icmp slt i32 %13, 0
  %.1.in.v = select i1 %15, i64 32, i64 40
  %.1.in = getelementptr inbounds i8, ptr %.021, i64 %.1.in.v
  %.0 = load ptr, ptr %.1.in, align 8, !tbaa !13
  %.not = icmp eq ptr %.0, %11
  br i1 %.not, label %.critedge, label %.lr.ph, !llvm.loop !16

.critedge:                                        ; preds = %.lr.ph, %14, %4
  %.0.lcssa = phi ptr [ %.019, %4 ], [ %.0, %14 ], [ %.021, %.lr.ph ]
  %16 = load ptr, ptr %.0.lcssa, align 8, !tbaa !14
  %17 = getelementptr inbounds i8, ptr %16, i64 104
  store ptr %2, ptr %17, align 8, !tbaa !5
  %18 = getelementptr inbounds i8, ptr %16, i64 112
  store ptr %3, ptr %18, align 8, !tbaa !5
  %19 = call i32 @pthread_mutex_unlock(ptr noundef nonnull %0) #4
  call void @llvm.lifetime.end.p0(i64 136, ptr nonnull %5) #4
  ret void
}

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #3

; Function Attrs: nounwind uwtable
declare hidden i32 @mln_event_rbtree_fd_cmp(ptr noundef nonnull, ptr noundef nonnull) local_unnamed_addr #2

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nounwind "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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = !{!9, !10, i64 528}
!9 = !{!"mln_event_s", !6, i64 0, !6, i64 40, !6, i64 80, !10, i64 120, !10, i64 128, !11, i64 136, !11, i64 136, !11, i64 140, !12, i64 144, !12, i64 272, !12, i64 400, !10, i64 528, !10, i64 536, !10, i64 544, !10, i64 552, !10, i64 560, !10, i64 568, !10, i64 576}
!10 = !{!"any pointer", !6, i64 0}
!11 = !{!"int", !6, i64 0}
!12 = !{!"", !6, i64 0}
!13 = !{!10, !10, i64 0}
!14 = !{!15, !10, i64 0}
!15 = !{!"mln_rbtree_node_s", !10, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !10, i64 32, !10, i64 40, !11, i64 48, !11, i64 48}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,MemCpyOptPass,SROAPass,SimplifyCFGPass,TailCallElimPass