; LLVM IR from yinqiwen/ardb :: src/common/channel/redis (ae)

; 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.aeEventLoop = type { i32, i32, i64, ptr, ptr, ptr, i32, ptr, ptr }
%struct.aeFileEvent = type { i32, ptr, ptr, 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 uwtable
define dso_local void @aeDeleteFileEvent(ptr noundef %0, i32 noundef %1, i32 noundef %2) #1 {
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  store i32 %2, ptr %6, align 4, !tbaa !9
  %10 = load i32, ptr %5, align 4, !tbaa !9
  %11 = load ptr, ptr %4, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.aeEventLoop, ptr %11, i32 0, i32 1
  %13 = load i32, ptr %12, align 4, !tbaa !11
  %14 = icmp sge i32 %10, %13
  br i1 %14, label %15, label %16

15:                                               ; preds = %3
  br label %80

16:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #2
  %17 = load ptr, ptr %4, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.aeEventLoop, ptr %17, i32 0, i32 3
  %19 = load ptr, ptr %18, align 8, !tbaa !14
  %20 = load i32, ptr %5, align 4, !tbaa !9
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds %struct.aeFileEvent, ptr %19, i64 %21
  store ptr %22, ptr %7, align 8, !tbaa !5
  %23 = load ptr, ptr %7, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.aeFileEvent, ptr %23, i32 0, i32 0
  %25 = load i32, ptr %24, align 8, !tbaa !15
  %26 = icmp eq i32 %25, 0
  br i1 %26, label %27, label %28

27:                                               ; preds = %16
  store i32 1, ptr %8, align 4
  br label %78

28:                                               ; preds = %16
  %29 = load ptr, ptr %7, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.aeFileEvent, ptr %29, i32 0, i32 0
  %31 = load i32, ptr %30, align 8, !tbaa !15
  %32 = load i32, ptr %6, align 4, !tbaa !9
  %33 = xor i32 %32, -1
  %34 = and i32 %31, %33
  %35 = load ptr, ptr %7, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.aeFileEvent, ptr %35, i32 0, i32 0
  store i32 %34, ptr %36, align 8, !tbaa !15
  %37 = load i32, ptr %5, align 4, !tbaa !9
  %38 = load ptr, ptr %4, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.aeEventLoop, ptr %38, i32 0, i32 0
  %40 = load i32, ptr %39, align 8, !tbaa !17
  %41 = icmp eq i32 %37, %40
  br i1 %41, label %42, label %74

42:                                               ; preds = %28
  %43 = load ptr, ptr %7, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.aeFileEvent, ptr %43, i32 0, i32 0
  %45 = load i32, ptr %44, align 8, !tbaa !15
  %46 = icmp eq i32 %45, 0
  br i1 %46, label %47, label %74

47:                                               ; preds = %42
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #2
  %48 = load ptr, ptr %4, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.aeEventLoop, ptr %48, i32 0, i32 0
  %50 = load i32, ptr %49, align 8, !tbaa !17
  %51 = sub nsw i32 %50, 1
  store i32 %51, ptr %9, align 4, !tbaa !9
  br label %52

52:                                               ; preds = %67, %47
  %53 = load i32, ptr %9, align 4, !tbaa !9
  %54 = icmp sge i32 %53, 0
  br i1 %54, label %55, label %70

55:                                               ; preds = %52
  %56 = load ptr, ptr %4, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.aeEventLoop, ptr %56, i32 0, i32 3
  %58 = load ptr, ptr %57, align 8, !tbaa !14
  %59 = load i32, ptr %9, align 4, !tbaa !9
  %60 = sext i32 %59 to i64
  %61 = getelementptr inbounds %struct.aeFileEvent, ptr %58, i64 %60
  %62 = getelementptr inbounds %struct.aeFileEvent, ptr %61, i32 0, i32 0
  %63 = load i32, ptr %62, align 8, !tbaa !15
  %64 = icmp ne i32 %63, 0
  br i1 %64, label %65, label %66

65:                                               ; preds = %55
  br label %70

66:                                               ; preds = %55
  br label %67

67:                                               ; preds = %66
  %68 = load i32, ptr %9, align 4, !tbaa !9
  %69 = add nsw i32 %68, -1
  store i32 %69, ptr %9, align 4, !tbaa !9
  br label %52, !llvm.loop !18

70:                                               ; preds = %65, %52
  %71 = load i32, ptr %9, align 4, !tbaa !9
  %72 = load ptr, ptr %4, align 8, !tbaa !5
  %73 = getelementptr inbounds %struct.aeEventLoop, ptr %72, i32 0, i32 0
  store i32 %71, ptr %73, align 8, !tbaa !17
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #2
  br label %74

74:                                               ; preds = %70, %42, %28
  %75 = load ptr, ptr %4, align 8, !tbaa !5
  %76 = load i32, ptr %5, align 4, !tbaa !9
  %77 = load i32, ptr %6, align 4, !tbaa !9
  call void @aeApiDelEvent(ptr noundef %75, i32 noundef %76, i32 noundef %77)
  store i32 0, ptr %8, align 4
  br label %78

78:                                               ; preds = %74, %27
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #2
  %79 = load i32, ptr %8, align 4
  switch i32 %79, label %81 [
    i32 0, label %80
    i32 1, label %80
  ]

80:                                               ; preds = %78, %78, %15
  ret void

81:                                               ; preds = %78
  unreachable
}

; Function Attrs: nounwind uwtable
declare hidden void @aeApiDelEvent(ptr noundef, i32 noundef, i32 noundef) #1

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 4}
!12 = !{!"aeEventLoop", !10, i64 0, !10, i64 4, !13, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !10, i64 40, !6, i64 48, !6, i64 56}
!13 = !{!"long long", !7, i64 0}
!14 = !{!12, !6, i64 16}
!15 = !{!16, !10, i64 0}
!16 = !{!"aeFileEvent", !10, i64 0, !6, i64 8, !6, i64 16, !6, i64 24}
!17 = !{!12, !10, i64 0}
!18 = distinct !{!18, !19}
!19 = !{!"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.aeFileEvent = type { i32, ptr, ptr, ptr }

; Function Attrs: nounwind uwtable
define dso_local void @aeDeleteFileEvent(ptr noundef %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = getelementptr inbounds i8, ptr %0, i64 4
  %5 = load i32, ptr %4, align 4, !tbaa !5
  %.not = icmp sgt i32 %5, %1
  br i1 %.not, label %6, label %28

6:                                                ; preds = %3
  %7 = getelementptr inbounds i8, ptr %0, i64 16
  %8 = load ptr, ptr %7, align 8, !tbaa !12
  %9 = sext i32 %1 to i64
  %10 = getelementptr inbounds %struct.aeFileEvent, ptr %8, i64 %9
  %11 = load i32, ptr %10, align 8, !tbaa !13
  %12 = icmp eq i32 %11, 0
  br i1 %12, label %28, label %13

13:                                               ; preds = %6
  %14 = xor i32 %2, -1
  %15 = and i32 %11, %14
  store i32 %15, ptr %10, align 8, !tbaa !13
  %16 = load i32, ptr %0, align 8, !tbaa !15
  %17 = icmp eq i32 %16, %1
  %18 = icmp eq i32 %15, 0
  %or.cond = and i1 %18, %17
  br i1 %or.cond, label %.preheader.preheader, label %27

.preheader.preheader:                             ; preds = %13
  %19 = zext i32 %1 to i64
  %smin = tail call i32 @llvm.smin.i32(i32 %1, i32 0)
  %20 = add i32 %smin, -1
  br label %.preheader

.preheader:                                       ; preds = %.preheader.preheader, %23
  %indvars.iv = phi i64 [ %19, %.preheader.preheader ], [ %indvars.iv.next, %23 ]
  %21 = trunc nuw i64 %indvars.iv to i32
  %22 = icmp sgt i32 %21, 0
  br i1 %22, label %23, label %.split.loop.exit25

23:                                               ; preds = %.preheader
  %indvars.iv.next = add nsw i64 %indvars.iv, -1
  %24 = and i64 %indvars.iv.next, 4294967295
  %25 = getelementptr inbounds %struct.aeFileEvent, ptr %8, i64 %24
  %26 = load i32, ptr %25, align 8, !tbaa !13
  %.not23 = icmp eq i32 %26, 0
  br i1 %.not23, label %.preheader, label %.split.loop.exit, !llvm.loop !16

.split.loop.exit:                                 ; preds = %23
  %indvars.le = trunc i64 %indvars.iv.next to i32
  br label %.split.loop.exit25

.split.loop.exit25:                               ; preds = %.preheader, %.split.loop.exit
  %.0.lcssa = phi i32 [ %indvars.le, %.split.loop.exit ], [ %20, %.preheader ]
  store i32 %.0.lcssa, ptr %0, align 8, !tbaa !15
  br label %27

27:                                               ; preds = %.split.loop.exit25, %13
  tail call void @aeApiDelEvent(ptr noundef nonnull %0, i32 noundef %1, i32 noundef %2)
  br label %28

28:                                               ; preds = %27, %6, %3
  ret void
}

; Function Attrs: nounwind uwtable
declare hidden void @aeApiDelEvent(ptr noundef, i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.smin.i32(i32, i32) #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 speculatable willreturn memory(none) }

!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, !7, i64 4}
!6 = !{!"aeEventLoop", !7, i64 0, !7, i64 4, !10, i64 8, !11, i64 16, !11, i64 24, !11, i64 32, !7, i64 40, !11, i64 48, !11, i64 56}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"long long", !8, i64 0}
!11 = !{!"any pointer", !8, i64 0}
!12 = !{!6, !11, i64 16}
!13 = !{!14, !7, i64 0}
!14 = !{!"aeFileEvent", !7, i64 0, !11, i64 8, !11, i64 16, !11, i64 24}
!15 = !{!6, !7, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LICMPass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass