; 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: nounwind uwtable
define dso_local ptr @aeCreateEventLoop(i32 noundef %0) #0 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  store i32 %0, ptr %3, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  %7 = call ptr @zmalloc(i64 noundef 64)
  store ptr %7, ptr %4, align 8, !tbaa !9
  %8 = icmp eq ptr %7, null
  br i1 %8, label %9, label %10

9:                                                ; preds = %1
  br label %69

10:                                               ; preds = %1
  %11 = load i32, ptr %3, align 4, !tbaa !5
  %12 = sext i32 %11 to i64
  %13 = mul i64 32, %12
  %14 = call ptr @zmalloc(i64 noundef %13)
  %15 = load ptr, ptr %4, align 8, !tbaa !9
  %16 = getelementptr inbounds %struct.aeEventLoop, ptr %15, i32 0, i32 3
  store ptr %14, ptr %16, align 8, !tbaa !11
  %17 = load i32, ptr %3, align 4, !tbaa !5
  %18 = sext i32 %17 to i64
  %19 = mul i64 8, %18
  %20 = call ptr @zmalloc(i64 noundef %19)
  %21 = load ptr, ptr %4, align 8, !tbaa !9
  %22 = getelementptr inbounds %struct.aeEventLoop, ptr %21, i32 0, i32 4
  store ptr %20, ptr %22, align 8, !tbaa !14
  %23 = load ptr, ptr %4, align 8, !tbaa !9
  %24 = getelementptr inbounds %struct.aeEventLoop, ptr %23, i32 0, i32 3
  %25 = load ptr, ptr %24, align 8, !tbaa !11
  %26 = icmp eq ptr %25, null
  br i1 %26, label %32, label %27

27:                                               ; preds = %10
  %28 = load ptr, ptr %4, align 8, !tbaa !9
  %29 = getelementptr inbounds %struct.aeEventLoop, ptr %28, i32 0, i32 4
  %30 = load ptr, ptr %29, align 8, !tbaa !14
  %31 = icmp eq ptr %30, null
  br i1 %31, label %32, label %33

32:                                               ; preds = %27, %10
  br label %69

33:                                               ; preds = %27
  %34 = load i32, ptr %3, align 4, !tbaa !5
  %35 = load ptr, ptr %4, align 8, !tbaa !9
  %36 = getelementptr inbounds %struct.aeEventLoop, ptr %35, i32 0, i32 1
  store i32 %34, ptr %36, align 4, !tbaa !15
  %37 = load ptr, ptr %4, align 8, !tbaa !9
  %38 = getelementptr inbounds %struct.aeEventLoop, ptr %37, i32 0, i32 5
  store ptr null, ptr %38, align 8, !tbaa !16
  %39 = load ptr, ptr %4, align 8, !tbaa !9
  %40 = getelementptr inbounds %struct.aeEventLoop, ptr %39, i32 0, i32 2
  store i64 0, ptr %40, align 8, !tbaa !17
  %41 = load ptr, ptr %4, align 8, !tbaa !9
  %42 = getelementptr inbounds %struct.aeEventLoop, ptr %41, i32 0, i32 6
  store i32 0, ptr %42, align 8, !tbaa !18
  %43 = load ptr, ptr %4, align 8, !tbaa !9
  %44 = getelementptr inbounds %struct.aeEventLoop, ptr %43, i32 0, i32 0
  store i32 -1, ptr %44, align 8, !tbaa !19
  %45 = load ptr, ptr %4, align 8, !tbaa !9
  %46 = getelementptr inbounds %struct.aeEventLoop, ptr %45, i32 0, i32 8
  store ptr null, ptr %46, align 8, !tbaa !20
  %47 = load ptr, ptr %4, align 8, !tbaa !9
  %48 = call i32 @aeApiCreate(ptr noundef %47)
  %49 = icmp eq i32 %48, -1
  br i1 %49, label %50, label %51

50:                                               ; preds = %33
  br label %69

51:                                               ; preds = %33
  store i32 0, ptr %5, align 4, !tbaa !5
  br label %52

52:                                               ; preds = %64, %51
  %53 = load i32, ptr %5, align 4, !tbaa !5
  %54 = load i32, ptr %3, align 4, !tbaa !5
  %55 = icmp slt i32 %53, %54
  br i1 %55, label %56, label %67

56:                                               ; preds = %52
  %57 = load ptr, ptr %4, align 8, !tbaa !9
  %58 = getelementptr inbounds %struct.aeEventLoop, ptr %57, i32 0, i32 3
  %59 = load ptr, ptr %58, align 8, !tbaa !11
  %60 = load i32, ptr %5, align 4, !tbaa !5
  %61 = sext i32 %60 to i64
  %62 = getelementptr inbounds %struct.aeFileEvent, ptr %59, i64 %61
  %63 = getelementptr inbounds %struct.aeFileEvent, ptr %62, i32 0, i32 0
  store i32 0, ptr %63, align 8, !tbaa !21
  br label %64

64:                                               ; preds = %56
  %65 = load i32, ptr %5, align 4, !tbaa !5
  %66 = add nsw i32 %65, 1
  store i32 %66, ptr %5, align 4, !tbaa !5
  br label %52, !llvm.loop !23

67:                                               ; preds = %52
  %68 = load ptr, ptr %4, align 8, !tbaa !9
  store ptr %68, ptr %2, align 8
  store i32 1, ptr %6, align 4
  br label %81

69:                                               ; preds = %50, %32, %9
  %70 = load ptr, ptr %4, align 8, !tbaa !9
  %71 = icmp ne ptr %70, null
  br i1 %71, label %72, label %80

72:                                               ; preds = %69
  %73 = load ptr, ptr %4, align 8, !tbaa !9
  %74 = getelementptr inbounds %struct.aeEventLoop, ptr %73, i32 0, i32 3
  %75 = load ptr, ptr %74, align 8, !tbaa !11
  call void @zfree(ptr noundef %75)
  %76 = load ptr, ptr %4, align 8, !tbaa !9
  %77 = getelementptr inbounds %struct.aeEventLoop, ptr %76, i32 0, i32 4
  %78 = load ptr, ptr %77, align 8, !tbaa !14
  call void @zfree(ptr noundef %78)
  %79 = load ptr, ptr %4, align 8, !tbaa !9
  call void @zfree(ptr noundef %79)
  br label %80

80:                                               ; preds = %72, %69
  store ptr null, ptr %2, align 8
  store i32 1, ptr %6, align 4
  br label %81

81:                                               ; preds = %80, %67
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  %82 = load ptr, ptr %2, align 8
  ret ptr %82
}

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

declare ptr @zmalloc(i64 noundef) #2

; Function Attrs: nounwind uwtable
declare hidden i32 @aeApiCreate(ptr noundef) #0

declare void @zfree(ptr noundef) #2

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 willreturn memory(argmem: readwrite) }
attributes #2 = { "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, !6, i64 0}
!6 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !10, i64 16}
!12 = !{!"aeEventLoop", !6, i64 0, !6, i64 4, !13, i64 8, !10, i64 16, !10, i64 24, !10, i64 32, !6, i64 40, !10, i64 48, !10, i64 56}
!13 = !{!"long long", !7, i64 0}
!14 = !{!12, !10, i64 24}
!15 = !{!12, !6, i64 4}
!16 = !{!12, !10, i64 32}
!17 = !{!12, !13, i64 8}
!18 = !{!12, !6, i64 40}
!19 = !{!12, !6, i64 0}
!20 = !{!12, !10, i64 56}
!21 = !{!22, !6, i64 0}
!22 = !{!"aeFileEvent", !6, i64 0, !10, i64 8, !10, i64 16, !10, i64 24}
!23 = distinct !{!23, !24}
!24 = !{!"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 ptr @aeCreateEventLoop(i32 noundef %0) local_unnamed_addr #0 {
  %2 = tail call ptr @zmalloc(i64 noundef 64) #2
  %cond = icmp eq ptr %2, null
  br i1 %cond, label %.loopexit, label %3

3:                                                ; preds = %1
  %4 = sext i32 %0 to i64
  %5 = shl nsw i64 %4, 5
  %6 = tail call ptr @zmalloc(i64 noundef %5) #2
  %7 = getelementptr inbounds i8, ptr %2, i64 16
  store ptr %6, ptr %7, align 8, !tbaa !5
  %8 = shl nsw i64 %4, 3
  %9 = tail call ptr @zmalloc(i64 noundef %8) #2
  %10 = getelementptr inbounds i8, ptr %2, i64 24
  store ptr %9, ptr %10, align 8, !tbaa !12
  %11 = load ptr, ptr %7, align 8, !tbaa !5
  %12 = icmp eq ptr %11, null
  %13 = icmp eq ptr %9, null
  %or.cond = select i1 %12, i1 true, i1 %13
  br i1 %or.cond, label %30, label %14

14:                                               ; preds = %3
  %15 = getelementptr inbounds i8, ptr %2, i64 4
  store i32 %0, ptr %15, align 4, !tbaa !13
  %16 = getelementptr inbounds i8, ptr %2, i64 32
  store ptr null, ptr %16, align 8, !tbaa !14
  %17 = getelementptr inbounds i8, ptr %2, i64 8
  store i64 0, ptr %17, align 8, !tbaa !15
  %18 = getelementptr inbounds i8, ptr %2, i64 40
  store i32 0, ptr %18, align 8, !tbaa !16
  store i32 -1, ptr %2, align 8, !tbaa !17
  %19 = getelementptr inbounds i8, ptr %2, i64 56
  store ptr null, ptr %19, align 8, !tbaa !18
  %20 = tail call i32 @aeApiCreate(ptr noundef nonnull %2)
  %21 = icmp eq i32 %20, -1
  br i1 %21, label %._crit_edge, label %.preheader

._crit_edge:                                      ; preds = %14
  %.pre = load ptr, ptr %7, align 8, !tbaa !5
  br label %30

.preheader:                                       ; preds = %14
  %22 = icmp sgt i32 %0, 0
  br i1 %22, label %.lr.ph, label %.loopexit

.lr.ph:                                           ; preds = %.preheader
  %23 = load ptr, ptr %7, align 8, !tbaa !5
  %wide.trip.count = zext nneg i32 %0 to i64
  %xtraiter = and i64 %wide.trip.count, 3
  %24 = icmp ult i32 %0, 4
  br i1 %24, label %.loopexit.loopexit.unr-lcssa, label %.lr.ph.new

.lr.ph.new:                                       ; preds = %.lr.ph
  %unroll_iter = and i64 %wide.trip.count, 2147483644
  br label %25

25:                                               ; preds = %25, %.lr.ph.new
  %indvars.iv = phi i64 [ 0, %.lr.ph.new ], [ %indvars.iv.next.3, %25 ]
  %niter = phi i64 [ 0, %.lr.ph.new ], [ %niter.next.3, %25 ]
  %26 = getelementptr inbounds %struct.aeFileEvent, ptr %23, i64 %indvars.iv
  store i32 0, ptr %26, align 8, !tbaa !19
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %27 = getelementptr inbounds %struct.aeFileEvent, ptr %23, i64 %indvars.iv.next
  store i32 0, ptr %27, align 8, !tbaa !19
  %indvars.iv.next.1 = or disjoint i64 %indvars.iv, 2
  %28 = getelementptr inbounds %struct.aeFileEvent, ptr %23, i64 %indvars.iv.next.1
  store i32 0, ptr %28, align 8, !tbaa !19
  %indvars.iv.next.2 = or disjoint i64 %indvars.iv, 3
  %29 = getelementptr inbounds %struct.aeFileEvent, ptr %23, i64 %indvars.iv.next.2
  store i32 0, ptr %29, align 8, !tbaa !19
  %indvars.iv.next.3 = add nuw nsw i64 %indvars.iv, 4
  %niter.next.3 = add i64 %niter, 4
  %niter.ncmp.3 = icmp eq i64 %niter.next.3, %unroll_iter
  br i1 %niter.ncmp.3, label %.loopexit.loopexit.unr-lcssa, label %25, !llvm.loop !21

30:                                               ; preds = %._crit_edge, %3
  %31 = phi ptr [ %.pre, %._crit_edge ], [ %11, %3 ]
  tail call void @zfree(ptr noundef %31) #2
  %32 = load ptr, ptr %10, align 8, !tbaa !12
  tail call void @zfree(ptr noundef %32) #2
  tail call void @zfree(ptr noundef nonnull %2) #2
  br label %.loopexit

.loopexit.loopexit.unr-lcssa:                     ; preds = %25, %.lr.ph
  %indvars.iv.unr = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next.3, %25 ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %.loopexit, label %.epil.preheader

.epil.preheader:                                  ; preds = %.loopexit.loopexit.unr-lcssa, %.epil.preheader
  %indvars.iv.epil = phi i64 [ %indvars.iv.next.epil, %.epil.preheader ], [ %indvars.iv.unr, %.loopexit.loopexit.unr-lcssa ]
  %epil.iter = phi i64 [ %epil.iter.next, %.epil.preheader ], [ 0, %.loopexit.loopexit.unr-lcssa ]
  %33 = getelementptr inbounds %struct.aeFileEvent, ptr %23, i64 %indvars.iv.epil
  store i32 0, ptr %33, align 8, !tbaa !19
  %indvars.iv.next.epil = add nuw nsw i64 %indvars.iv.epil, 1
  %epil.iter.next = add i64 %epil.iter, 1
  %epil.iter.cmp.not = icmp eq i64 %epil.iter.next, %xtraiter
  br i1 %epil.iter.cmp.not, label %.loopexit, label %.epil.preheader, !llvm.loop !23

.loopexit:                                        ; preds = %.loopexit.loopexit.unr-lcssa, %.epil.preheader, %.preheader, %1, %30
  %.024 = phi ptr [ null, %1 ], [ null, %30 ], [ %2, %.preheader ], [ %2, %.epil.preheader ], [ %2, %.loopexit.loopexit.unr-lcssa ]
  ret ptr %.024
}

declare ptr @zmalloc(i64 noundef) local_unnamed_addr #1

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

declare void @zfree(ptr noundef) local_unnamed_addr #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 = { "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, !11, i64 16}
!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 24}
!13 = !{!6, !7, i64 4}
!14 = !{!6, !11, i64 32}
!15 = !{!6, !10, i64 8}
!16 = !{!6, !7, i64 40}
!17 = !{!6, !7, i64 0}
!18 = !{!6, !11, i64 56}
!19 = !{!20, !7, i64 0}
!20 = !{!"aeFileEvent", !7, i64 0, !11, i64 8, !11, i64 16, !11, i64 24}
!21 = distinct !{!21, !22}
!22 = !{!"llvm.loop.mustprogress"}
!23 = distinct !{!23, !24}
!24 = !{!"llvm.loop.unroll.disable"}


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