; 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 i32 @aeCreateFileEvent(ptr noundef %0, i32 noundef %1, i32 noundef %2, ptr noundef %3, ptr noundef %4) #1 {
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca i32, align 4
  store ptr %0, ptr %7, align 8, !tbaa !5
  store i32 %1, ptr %8, align 4, !tbaa !9
  store i32 %2, ptr %9, align 4, !tbaa !9
  store ptr %3, ptr %10, align 8, !tbaa !5
  store ptr %4, ptr %11, align 8, !tbaa !5
  %14 = load i32, ptr %8, align 4, !tbaa !9
  %15 = load ptr, ptr %7, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.aeEventLoop, ptr %15, i32 0, i32 1
  %17 = load i32, ptr %16, align 4, !tbaa !11
  %18 = icmp sge i32 %14, %17
  br i1 %18, label %19, label %20

19:                                               ; preds = %5
  store i32 -1, ptr %6, align 4
  br label %69

20:                                               ; preds = %5
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #2
  %21 = load ptr, ptr %7, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.aeEventLoop, ptr %21, i32 0, i32 3
  %23 = load ptr, ptr %22, align 8, !tbaa !14
  %24 = load i32, ptr %8, align 4, !tbaa !9
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds %struct.aeFileEvent, ptr %23, i64 %25
  store ptr %26, ptr %12, align 8, !tbaa !5
  %27 = load ptr, ptr %7, align 8, !tbaa !5
  %28 = load i32, ptr %8, align 4, !tbaa !9
  %29 = load i32, ptr %9, align 4, !tbaa !9
  %30 = call i32 @aeApiAddEvent(ptr noundef %27, i32 noundef %28, i32 noundef %29)
  %31 = icmp eq i32 %30, -1
  br i1 %31, label %32, label %33

32:                                               ; preds = %20
  store i32 -1, ptr %6, align 4
  store i32 1, ptr %13, align 4
  br label %68

33:                                               ; preds = %20
  %34 = load i32, ptr %9, align 4, !tbaa !9
  %35 = load ptr, ptr %12, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.aeFileEvent, ptr %35, i32 0, i32 0
  %37 = load i32, ptr %36, align 8, !tbaa !15
  %38 = or i32 %37, %34
  store i32 %38, ptr %36, align 8, !tbaa !15
  %39 = load i32, ptr %9, align 4, !tbaa !9
  %40 = and i32 %39, 1
  %41 = icmp ne i32 %40, 0
  br i1 %41, label %42, label %46

42:                                               ; preds = %33
  %43 = load ptr, ptr %10, align 8, !tbaa !5
  %44 = load ptr, ptr %12, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.aeFileEvent, ptr %44, i32 0, i32 1
  store ptr %43, ptr %45, align 8, !tbaa !17
  br label %46

46:                                               ; preds = %42, %33
  %47 = load i32, ptr %9, align 4, !tbaa !9
  %48 = and i32 %47, 2
  %49 = icmp ne i32 %48, 0
  br i1 %49, label %50, label %54

50:                                               ; preds = %46
  %51 = load ptr, ptr %10, align 8, !tbaa !5
  %52 = load ptr, ptr %12, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.aeFileEvent, ptr %52, i32 0, i32 2
  store ptr %51, ptr %53, align 8, !tbaa !18
  br label %54

54:                                               ; preds = %50, %46
  %55 = load ptr, ptr %11, align 8, !tbaa !5
  %56 = load ptr, ptr %12, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.aeFileEvent, ptr %56, i32 0, i32 3
  store ptr %55, ptr %57, align 8, !tbaa !19
  %58 = load i32, ptr %8, align 4, !tbaa !9
  %59 = load ptr, ptr %7, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.aeEventLoop, ptr %59, i32 0, i32 0
  %61 = load i32, ptr %60, align 8, !tbaa !20
  %62 = icmp sgt i32 %58, %61
  br i1 %62, label %63, label %67

63:                                               ; preds = %54
  %64 = load i32, ptr %8, align 4, !tbaa !9
  %65 = load ptr, ptr %7, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.aeEventLoop, ptr %65, i32 0, i32 0
  store i32 %64, ptr %66, align 8, !tbaa !20
  br label %67

67:                                               ; preds = %63, %54
  store i32 0, ptr %6, align 4
  store i32 1, ptr %13, align 4
  br label %68

68:                                               ; preds = %67, %32
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #2
  br label %69

69:                                               ; preds = %68, %19
  %70 = load i32, ptr %6, align 4
  ret i32 %70
}

; Function Attrs: nounwind uwtable
declare hidden i32 @aeApiAddEvent(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 = !{!16, !6, i64 8}
!18 = !{!16, !6, i64 16}
!19 = !{!16, !6, i64 24}
!20 = !{!12, !10, 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"

%struct.aeFileEvent = type { i32, ptr, ptr, ptr }

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

8:                                                ; preds = %5
  %9 = getelementptr inbounds i8, ptr %0, i64 16
  %10 = load ptr, ptr %9, align 8, !tbaa !12
  %11 = sext i32 %1 to i64
  %12 = getelementptr inbounds %struct.aeFileEvent, ptr %10, i64 %11
  %13 = tail call i32 @aeApiAddEvent(ptr noundef nonnull %0, i32 noundef %1, i32 noundef %2)
  %14 = icmp eq i32 %13, -1
  br i1 %14, label %30, label %15

15:                                               ; preds = %8
  %16 = load i32, ptr %12, align 8, !tbaa !13
  %17 = or i32 %16, %2
  store i32 %17, ptr %12, align 8, !tbaa !13
  %18 = and i32 %2, 1
  %.not22 = icmp eq i32 %18, 0
  br i1 %.not22, label %21, label %19

19:                                               ; preds = %15
  %20 = getelementptr inbounds i8, ptr %12, i64 8
  store ptr %3, ptr %20, align 8, !tbaa !15
  br label %21

21:                                               ; preds = %19, %15
  %22 = and i32 %2, 2
  %.not23 = icmp eq i32 %22, 0
  br i1 %.not23, label %25, label %23

23:                                               ; preds = %21
  %24 = getelementptr inbounds i8, ptr %12, i64 16
  store ptr %3, ptr %24, align 8, !tbaa !16
  br label %25

25:                                               ; preds = %23, %21
  %26 = getelementptr inbounds i8, ptr %12, i64 24
  store ptr %4, ptr %26, align 8, !tbaa !17
  %27 = load i32, ptr %0, align 8, !tbaa !18
  %28 = icmp slt i32 %27, %1
  br i1 %28, label %29, label %30

29:                                               ; preds = %25
  store i32 %1, ptr %0, align 8, !tbaa !18
  br label %30

30:                                               ; preds = %8, %29, %25, %5
  %.1 = phi i32 [ -1, %5 ], [ -1, %8 ], [ 0, %29 ], [ 0, %25 ]
  ret i32 %.1
}

; Function Attrs: nounwind uwtable
declare hidden i32 @aeApiAddEvent(ptr noundef, i32 noundef, i32 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" }

!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 = !{!14, !11, i64 8}
!16 = !{!14, !11, i64 16}
!17 = !{!14, !11, i64 24}
!18 = !{!6, !7, i64 0}


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