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

declare i32 @rl_refresh(ptr noundef) #0

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

; Function Attrs: nounwind
declare void @free(ptr noundef) #2

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

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

19:                                               ; preds = %4
  store i32 3, ptr %9, align 4, !tbaa !13
  br label %111

20:                                               ; preds = %4
  %21 = load ptr, ptr %5, align 8, !tbaa !5
  %22 = call i32 @rl_refresh(ptr noundef %21)
  store i32 %22, ptr %9, align 4, !tbaa !13
  %23 = load i32, ptr %9, align 4, !tbaa !13
  %24 = icmp ne i32 0, %23
  br i1 %24, label %25, label %26

25:                                               ; preds = %20
  br label %111

26:                                               ; preds = %20
  %27 = load ptr, ptr %5, align 8, !tbaa !5
  %28 = call i32 @rl_select_internal(ptr noundef %27, i32 noundef 6)
  store i32 %28, ptr %9, align 4, !tbaa !13
  %29 = load i32, ptr %9, align 4, !tbaa !13
  %30 = icmp ne i32 0, %29
  br i1 %30, label %31, label %32

31:                                               ; preds = %26
  br label %111

32:                                               ; preds = %26
  %33 = load ptr, ptr %5, align 8, !tbaa !5
  %34 = load ptr, ptr %5, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.rlite, ptr %34, i32 0, i32 19
  %36 = load ptr, ptr %35, align 8, !tbaa !9
  %37 = call i32 @rl_pop(ptr noundef %33, ptr noundef %36, i64 noundef 40, ptr noundef %10, ptr noundef %12, i32 noundef 1)
  store i32 %37, ptr %9, align 4, !tbaa !13
  %38 = load i32, ptr %9, align 4, !tbaa !13
  %39 = icmp ne i32 0, %38
  br i1 %39, label %40, label %41

40:                                               ; preds = %32
  br label %111

41:                                               ; preds = %32
  %42 = load i64, ptr %12, align 8, !tbaa !14
  %43 = icmp ne i64 %42, 1
  br i1 %43, label %44, label %45

44:                                               ; preds = %41
  store i32 6, ptr %9, align 4, !tbaa !13
  br label %111

45:                                               ; preds = %41
  %46 = load ptr, ptr %10, align 8, !tbaa !5
  %47 = getelementptr inbounds i8, ptr %46, i64 0
  %48 = load i8, ptr %47, align 1, !tbaa !15
  %49 = zext i8 %48 to i32
  %50 = load ptr, ptr %6, align 8, !tbaa !5
  store i32 %49, ptr %50, align 4, !tbaa !13
  %51 = load ptr, ptr %10, align 8, !tbaa !5
  %52 = getelementptr inbounds i8, ptr %51, i64 0
  %53 = load i8, ptr %52, align 1, !tbaa !15
  %54 = zext i8 %53 to i64
  %55 = mul i64 8, %54
  %56 = call noalias ptr @malloc(i64 noundef %55) #6
  store ptr %56, ptr %13, align 8, !tbaa !5
  %57 = load ptr, ptr %13, align 8, !tbaa !5
  %58 = icmp ne ptr %57, null
  br i1 %58, label %60, label %59

59:                                               ; preds = %45
  store i32 4, ptr %9, align 4, !tbaa !13
  br label %111

60:                                               ; preds = %45
  %61 = load ptr, ptr %10, align 8, !tbaa !5
  %62 = getelementptr inbounds i8, ptr %61, i64 0
  %63 = load i8, ptr %62, align 1, !tbaa !15
  %64 = zext i8 %63 to i64
  %65 = mul i64 8, %64
  %66 = call noalias ptr @malloc(i64 noundef %65) #6
  store ptr %66, ptr %14, align 8, !tbaa !5
  %67 = load ptr, ptr %14, align 8, !tbaa !5
  %68 = icmp ne ptr %67, null
  br i1 %68, label %70, label %69

69:                                               ; preds = %60
  store i32 4, ptr %9, align 4, !tbaa !13
  br label %111

70:                                               ; preds = %60
  store i8 0, ptr %11, align 1, !tbaa !15
  br label %71

71:                                               ; preds = %97, %70
  %72 = load i8, ptr %11, align 1, !tbaa !15
  %73 = zext i8 %72 to i32
  %74 = load ptr, ptr %10, align 8, !tbaa !5
  %75 = getelementptr inbounds i8, ptr %74, i64 0
  %76 = load i8, ptr %75, align 1, !tbaa !15
  %77 = zext i8 %76 to i32
  %78 = icmp slt i32 %73, %77
  br i1 %78, label %79, label %100

79:                                               ; preds = %71
  %80 = load ptr, ptr %5, align 8, !tbaa !5
  %81 = load ptr, ptr %5, align 8, !tbaa !5
  %82 = getelementptr inbounds %struct.rlite, ptr %81, i32 0, i32 19
  %83 = load ptr, ptr %82, align 8, !tbaa !9
  %84 = load ptr, ptr %13, align 8, !tbaa !5
  %85 = load i8, ptr %11, align 1, !tbaa !15
  %86 = zext i8 %85 to i64
  %87 = getelementptr inbounds ptr, ptr %84, i64 %86
  %88 = load ptr, ptr %14, align 8, !tbaa !5
  %89 = load i8, ptr %11, align 1, !tbaa !15
  %90 = zext i8 %89 to i64
  %91 = getelementptr inbounds i64, ptr %88, i64 %90
  %92 = call i32 @rl_pop(ptr noundef %80, ptr noundef %83, i64 noundef 40, ptr noundef %87, ptr noundef %91, i32 noundef 1)
  store i32 %92, ptr %9, align 4, !tbaa !13
  %93 = load i32, ptr %9, align 4, !tbaa !13
  %94 = icmp ne i32 0, %93
  br i1 %94, label %95, label %96

95:                                               ; preds = %79
  br label %111

96:                                               ; preds = %79
  br label %97

97:                                               ; preds = %96
  %98 = load i8, ptr %11, align 1, !tbaa !15
  %99 = add i8 %98, 1
  store i8 %99, ptr %11, align 1, !tbaa !15
  br label %71, !llvm.loop !16

100:                                              ; preds = %71
  %101 = load ptr, ptr %13, align 8, !tbaa !5
  %102 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %101, ptr %102, align 8, !tbaa !5
  %103 = load ptr, ptr %14, align 8, !tbaa !5
  %104 = load ptr, ptr %8, align 8, !tbaa !5
  store ptr %103, ptr %104, align 8, !tbaa !5
  %105 = load ptr, ptr %5, align 8, !tbaa !5
  %106 = call i32 @rl_commit(ptr noundef %105)
  store i32 %106, ptr %9, align 4, !tbaa !13
  %107 = load i32, ptr %9, align 4, !tbaa !13
  %108 = icmp ne i32 0, %107
  br i1 %108, label %109, label %110

109:                                              ; preds = %100
  br label %111

110:                                              ; preds = %100
  br label %111

111:                                              ; preds = %110, %109, %95, %69, %59, %44, %40, %31, %25, %19
  %112 = load ptr, ptr %10, align 8, !tbaa !5
  call void @free(ptr noundef %112) #5
  %113 = load ptr, ptr %5, align 8, !tbaa !5
  %114 = call i32 @rl_select_internal(ptr noundef %113, i32 noundef 0)
  %115 = load i32, ptr %9, align 4, !tbaa !13
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #5
  call void @llvm.lifetime.end.p0(i64 1, ptr %11) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #5
  ret i32 %115
}

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

declare i32 @rl_pop(ptr noundef, ptr noundef, i64 noundef, ptr noundef, ptr noundef, i32 noundef) #0

; Function Attrs: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #4

declare i32 @rl_commit(ptr noundef) #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #3 = { 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 #4 = { nounwind allocsize(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 #5 = { nounwind }
attributes #6 = { nounwind allocsize(0) }

!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 = !{!12, !12, i64 0}
!14 = !{!11, !11, i64 0}
!15 = !{!7, !7, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"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"

declare i32 @rl_refresh(ptr noundef) local_unnamed_addr #0

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

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #2

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

; Function Attrs: nounwind uwtable
define dso_local i32 @rl_poll(ptr noundef %0, ptr nocapture noundef writeonly %1, ptr nocapture noundef writeonly %2, ptr nocapture noundef writeonly %3) local_unnamed_addr #3 {
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %5) #5
  store ptr null, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %6) #5
  %7 = getelementptr inbounds i8, ptr %0, i64 136
  %8 = load ptr, ptr %7, align 8, !tbaa !9
  %9 = icmp eq ptr %8, null
  br i1 %9, label %.loopexit, label %10

10:                                               ; preds = %4
  %11 = tail call i32 @rl_refresh(ptr noundef nonnull %0) #5
  %.not = icmp eq i32 %11, 0
  br i1 %.not, label %12, label %.loopexit

12:                                               ; preds = %10
  %13 = tail call i32 @rl_select_internal(ptr noundef nonnull %0, i32 noundef 6) #5
  %.not33 = icmp eq i32 %13, 0
  br i1 %.not33, label %14, label %.loopexit

14:                                               ; preds = %12
  %15 = load ptr, ptr %7, align 8, !tbaa !9
  %16 = call i32 @rl_pop(ptr noundef nonnull %0, ptr noundef %15, i64 noundef 40, ptr noundef nonnull %5, ptr noundef nonnull %6, i32 noundef 1) #5
  %.not34 = icmp eq i32 %16, 0
  br i1 %.not34, label %17, label %.loopexit

17:                                               ; preds = %14
  %18 = load i64, ptr %6, align 8, !tbaa !13
  %.not35 = icmp eq i64 %18, 1
  br i1 %.not35, label %19, label %.loopexit

19:                                               ; preds = %17
  %20 = load ptr, ptr %5, align 8, !tbaa !5
  %21 = load i8, ptr %20, align 1, !tbaa !14
  %22 = zext i8 %21 to i32
  store i32 %22, ptr %1, align 4, !tbaa !15
  %23 = load i8, ptr %20, align 1, !tbaa !14
  %24 = zext i8 %23 to i64
  %25 = shl nuw nsw i64 %24, 3
  %26 = call noalias ptr @malloc(i64 noundef %25) #6
  %.not36 = icmp eq ptr %26, null
  br i1 %.not36, label %.loopexit, label %27

27:                                               ; preds = %19
  %28 = call noalias ptr @malloc(i64 noundef %25) #6
  %.not37 = icmp eq ptr %28, null
  br i1 %.not37, label %.loopexit, label %.preheader

.preheader:                                       ; preds = %27
  %.not40 = icmp eq i8 %23, 0
  br i1 %.not40, label %._crit_edge, label %.lr.ph

29:                                               ; preds = %.lr.ph
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %30 = load ptr, ptr %5, align 8, !tbaa !5
  %31 = load i8, ptr %30, align 1, !tbaa !14
  %32 = zext i8 %31 to i64
  %33 = icmp ult i64 %indvars.iv.next, %32
  br i1 %33, label %.lr.ph, label %._crit_edge, !llvm.loop !16

.lr.ph:                                           ; preds = %.preheader, %29
  %indvars.iv = phi i64 [ %indvars.iv.next, %29 ], [ 0, %.preheader ]
  %34 = load ptr, ptr %7, align 8, !tbaa !9
  %35 = getelementptr inbounds ptr, ptr %26, i64 %indvars.iv
  %36 = getelementptr inbounds i64, ptr %28, i64 %indvars.iv
  %37 = call i32 @rl_pop(ptr noundef nonnull %0, ptr noundef %34, i64 noundef 40, ptr noundef nonnull %35, ptr noundef nonnull %36, i32 noundef 1) #5
  %.not38 = icmp eq i32 %37, 0
  br i1 %.not38, label %29, label %.loopexit

._crit_edge:                                      ; preds = %29, %.preheader
  store ptr %26, ptr %2, align 8, !tbaa !5
  store ptr %28, ptr %3, align 8, !tbaa !5
  %38 = call i32 @rl_commit(ptr noundef nonnull %0) #5
  br label %.loopexit

.loopexit:                                        ; preds = %.lr.ph, %27, %19, %17, %4, %._crit_edge, %14, %12, %10
  %.026 = phi i32 [ %11, %10 ], [ %13, %12 ], [ %16, %14 ], [ %38, %._crit_edge ], [ 3, %4 ], [ 6, %17 ], [ 4, %19 ], [ 4, %27 ], [ %37, %.lr.ph ]
  %39 = load ptr, ptr %5, align 8, !tbaa !5
  call void @free(ptr noundef %39) #5
  %40 = call i32 @rl_select_internal(ptr noundef nonnull %0, i32 noundef 0) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %6) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %5) #5
  ret i32 %.026
}

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

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

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #4

declare i32 @rl_commit(ptr noundef) local_unnamed_addr #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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite) "alloc-family"="malloc" "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 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 #4 = { mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" "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 #5 = { nounwind }
attributes #6 = { nounwind allocsize(0) }

!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 = !{!7, !7, i64 0}
!15 = !{!12, !12, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}


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