; LLVM IR from seppo0010/rlite :: src (pubsub)

; 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.rlite = type { i64, i64, i32, ptr, i64, i64, i64, ptr, i32, i32, i32, i32, ptr, i64, i64, ptr, i64, i64, ptr, 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

declare i32 @rl_select_internal(ptr noundef, i32 noundef) #1

declare i32 @rl_scard(ptr noundef, ptr noundef, i64 noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local i32 @rl_pubsub_count_subscriptions(ptr noundef %0, ptr noundef %1) #2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  %8 = load ptr, ptr %3, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct.rlite, ptr %8, i32 0, i32 19
  %10 = load ptr, ptr %9, align 8, !tbaa !9
  %11 = icmp ne ptr %10, null
  br i1 %11, label %14, label %12

12:                                               ; preds = %2
  %13 = load ptr, ptr %4, align 8, !tbaa !5
  store i64 0, ptr %13, align 8, !tbaa !13
  store i32 0, ptr %5, align 4, !tbaa !14
  br label %55

14:                                               ; preds = %2
  store i64 0, ptr %6, align 8, !tbaa !13
  store i64 0, ptr %7, align 8, !tbaa !13
  %15 = load ptr, ptr %3, align 8, !tbaa !5
  %16 = call i32 @rl_select_internal(ptr noundef %15, i32 noundef 2)
  store i32 %16, ptr %5, align 4, !tbaa !14
  %17 = load i32, ptr %5, align 4, !tbaa !14
  %18 = icmp ne i32 0, %17
  br i1 %18, label %19, label %20

19:                                               ; preds = %14
  br label %55

20:                                               ; preds = %14
  %21 = load ptr, ptr %3, align 8, !tbaa !5
  %22 = load ptr, ptr %3, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.rlite, ptr %22, i32 0, i32 19
  %24 = load ptr, ptr %23, align 8, !tbaa !9
  %25 = call i32 @rl_scard(ptr noundef %21, ptr noundef %24, i64 noundef 40, ptr noundef %6)
  store i32 %25, ptr %5, align 4, !tbaa !14
  %26 = load i32, ptr %5, align 4, !tbaa !14
  %27 = icmp ne i32 0, %26
  br i1 %27, label %28, label %32

28:                                               ; preds = %20
  %29 = load i32, ptr %5, align 4, !tbaa !14
  %30 = icmp ne i32 3, %29
  br i1 %30, label %31, label %32

31:                                               ; preds = %28
  br label %55

32:                                               ; preds = %28, %20
  %33 = load ptr, ptr %3, align 8, !tbaa !5
  %34 = call i32 @rl_select_internal(ptr noundef %33, i32 noundef 4)
  store i32 %34, ptr %5, align 4, !tbaa !14
  %35 = load i32, ptr %5, align 4, !tbaa !14
  %36 = icmp ne i32 0, %35
  br i1 %36, label %37, label %38

37:                                               ; preds = %32
  br label %55

38:                                               ; preds = %32
  %39 = load ptr, ptr %3, align 8, !tbaa !5
  %40 = load ptr, ptr %3, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.rlite, ptr %40, i32 0, i32 19
  %42 = load ptr, ptr %41, align 8, !tbaa !9
  %43 = call i32 @rl_scard(ptr noundef %39, ptr noundef %42, i64 noundef 40, ptr noundef %7)
  store i32 %43, ptr %5, align 4, !tbaa !14
  %44 = load i32, ptr %5, align 4, !tbaa !14
  %45 = icmp ne i32 0, %44
  br i1 %45, label %46, label %50

46:                                               ; preds = %38
  %47 = load i32, ptr %5, align 4, !tbaa !14
  %48 = icmp ne i32 3, %47
  br i1 %48, label %49, label %50

49:                                               ; preds = %46
  br label %55

50:                                               ; preds = %46, %38
  %51 = load i64, ptr %6, align 8, !tbaa !13
  %52 = load i64, ptr %7, align 8, !tbaa !13
  %53 = add nsw i64 %51, %52
  %54 = load ptr, ptr %4, align 8, !tbaa !5
  store i64 %53, ptr %54, align 8, !tbaa !13
  store i32 0, ptr %5, align 4, !tbaa !14
  br label %55

55:                                               ; preds = %50, %49, %37, %31, %19, %12
  %56 = load ptr, ptr %3, align 8, !tbaa !5
  %57 = call i32 @rl_select_internal(ptr noundef %56, i32 noundef 0)
  %58 = load i32, ptr %5, align 4, !tbaa !14
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  ret i32 %58
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 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 = { 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 136}
!10 = !{!"rlite", !11, i64 0, !11, i64 8, !12, i64 16, !6, i64 24, !11, i64 32, !11, i64 40, !11, i64 48, !6, i64 56, !12, i64 64, !12, i64 68, !12, i64 72, !12, i64 76, !6, i64 80, !11, i64 88, !11, i64 96, !6, i64 104, !11, i64 112, !11, i64 120, !6, i64 128, !6, i64 136, !6, i64 144, !6, i64 152}
!11 = !{!"long", !7, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!11, !11, i64 0}
!14 = !{!12, !12, 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"

declare i32 @rl_select_internal(ptr noundef, i32 noundef) local_unnamed_addr #0

declare i32 @rl_scard(ptr noundef, ptr noundef, i64 noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local i32 @rl_pubsub_count_subscriptions(ptr noundef %0, ptr nocapture noundef writeonly %1) local_unnamed_addr #1 {
  %3 = alloca i64, align 8
  %4 = alloca i64, align 8
  %5 = getelementptr inbounds i8, ptr %0, i64 136
  %6 = load ptr, ptr %5, align 8, !tbaa !5
  %.not = icmp eq ptr %6, null
  br i1 %.not, label %.sink.split, label %7

7:                                                ; preds = %2
  store i64 0, ptr %3, align 8, !tbaa !12
  store i64 0, ptr %4, align 8, !tbaa !12
  %8 = tail call i32 @rl_select_internal(ptr noundef nonnull %0, i32 noundef 2) #2
  %.not23 = icmp eq i32 %8, 0
  br i1 %.not23, label %9, label %21

9:                                                ; preds = %7
  %10 = load ptr, ptr %5, align 8, !tbaa !5
  %11 = call i32 @rl_scard(ptr noundef nonnull %0, ptr noundef %10, i64 noundef 40, ptr noundef nonnull %3) #2
  switch i32 %11, label %21 [
    i32 3, label %12
    i32 0, label %12
  ]

12:                                               ; preds = %9, %9
  %13 = call i32 @rl_select_internal(ptr noundef nonnull %0, i32 noundef 4) #2
  %.not24 = icmp eq i32 %13, 0
  br i1 %.not24, label %14, label %21

14:                                               ; preds = %12
  %15 = load ptr, ptr %5, align 8, !tbaa !5
  %16 = call i32 @rl_scard(ptr noundef nonnull %0, ptr noundef %15, i64 noundef 40, ptr noundef nonnull %4) #2
  switch i32 %16, label %21 [
    i32 3, label %17
    i32 0, label %17
  ]

17:                                               ; preds = %14, %14
  %18 = load i64, ptr %3, align 8, !tbaa !12
  %19 = load i64, ptr %4, align 8, !tbaa !12
  %20 = add nsw i64 %19, %18
  br label %.sink.split

.sink.split:                                      ; preds = %2, %17
  %.sink = phi i64 [ %20, %17 ], [ 0, %2 ]
  store i64 %.sink, ptr %1, align 8, !tbaa !12
  br label %21

21:                                               ; preds = %.sink.split, %14, %9, %12, %7
  %.0 = phi i32 [ %8, %7 ], [ %11, %9 ], [ %13, %12 ], [ %16, %14 ], [ 0, %.sink.split ]
  %22 = call i32 @rl_select_internal(ptr noundef nonnull %0, i32 noundef 0) #2
  ret i32 %.0
}

attributes #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 = { 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, !11, i64 136}
!6 = !{!"rlite", !7, i64 0, !7, i64 8, !10, i64 16, !11, i64 24, !7, i64 32, !7, i64 40, !7, i64 48, !11, i64 56, !10, i64 64, !10, i64 68, !10, i64 72, !10, i64 76, !11, i64 80, !7, i64 88, !7, i64 96, !11, i64 104, !7, i64 112, !7, i64 120, !11, i64 128, !11, i64 136, !11, i64 144, !11, i64 152}
!7 = !{!"long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"any pointer", !8, i64 0}
!12 = !{!7, !7, i64 0}


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