; 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_wait(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3, ptr noundef %4) #3 {
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  %14 = alloca ptr, align 8
  store ptr %0, ptr %7, align 8, !tbaa !5
  store ptr %1, ptr %8, align 8, !tbaa !5
  store ptr %2, ptr %9, align 8, !tbaa !5
  store ptr %3, ptr %10, align 8, !tbaa !5
  store ptr %4, ptr %11, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #4
  %15 = load ptr, ptr %7, align 8, !tbaa !5
  %16 = load ptr, ptr %8, align 8, !tbaa !5
  %17 = load ptr, ptr %9, align 8, !tbaa !5
  %18 = load ptr, ptr %10, align 8, !tbaa !5
  %19 = call i32 @rl_poll(ptr noundef %15, ptr noundef %16, ptr noundef %17, ptr noundef %18)
  store i32 %19, ptr %12, align 4, !tbaa !9
  %20 = load i32, ptr %12, align 4, !tbaa !9
  %21 = icmp eq i32 %20, 3
  br i1 %21, label %22, label %56

22:                                               ; preds = %5
  %23 = load ptr, ptr %7, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.rlite, ptr %23, i32 0, i32 19
  %25 = load ptr, ptr %24, align 8, !tbaa !11
  %26 = icmp eq ptr %25, null
  br i1 %26, label %27, label %35

27:                                               ; preds = %22
  %28 = load ptr, ptr %7, align 8, !tbaa !5
  call void @generate_subscriber_id(ptr noundef %28)
  %29 = load ptr, ptr %7, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.rlite, ptr %29, i32 0, i32 19
  %31 = load ptr, ptr %30, align 8, !tbaa !11
  %32 = icmp eq ptr %31, null
  br i1 %32, label %33, label %34

33:                                               ; preds = %27
  store i32 6, ptr %6, align 4
  store i32 1, ptr %13, align 4
  br label %58

34:                                               ; preds = %27
  br label %35

35:                                               ; preds = %34, %22
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #4
  %36 = load ptr, ptr %7, align 8, !tbaa !5
  %37 = load ptr, ptr %7, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.rlite, ptr %37, i32 0, i32 19
  %39 = load ptr, ptr %38, align 8, !tbaa !11
  %40 = call ptr @get_signal_filename(ptr noundef %36, ptr noundef %39)
  store ptr %40, ptr %14, align 8, !tbaa !5
  %41 = load ptr, ptr %7, align 8, !tbaa !5
  %42 = call i32 @rl_discard(ptr noundef %41)
  %43 = load ptr, ptr %14, align 8, !tbaa !5
  %44 = call i32 @rl_create_signal(ptr noundef %43)
  %45 = load ptr, ptr %14, align 8, !tbaa !5
  %46 = load ptr, ptr %11, align 8, !tbaa !5
  %47 = call i32 @rl_read_signal(ptr noundef %45, ptr noundef %46, ptr noundef null, ptr noundef null)
  %48 = load ptr, ptr %14, align 8, !tbaa !5
  call void @free(ptr noundef %48) #4
  %49 = load ptr, ptr %7, align 8, !tbaa !5
  %50 = call i32 @rl_refresh(ptr noundef %49)
  %51 = load ptr, ptr %7, align 8, !tbaa !5
  %52 = load ptr, ptr %8, align 8, !tbaa !5
  %53 = load ptr, ptr %9, align 8, !tbaa !5
  %54 = load ptr, ptr %10, align 8, !tbaa !5
  %55 = call i32 @rl_poll(ptr noundef %51, ptr noundef %52, ptr noundef %53, ptr noundef %54)
  store i32 %55, ptr %12, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #4
  br label %56

56:                                               ; preds = %35, %5
  %57 = load i32, ptr %12, align 4, !tbaa !9
  store i32 %57, ptr %6, align 4
  store i32 1, ptr %13, align 4
  br label %58

58:                                               ; preds = %56, %33
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #4
  %59 = load i32, ptr %6, align 4
  ret i32 %59
}

; Function Attrs: nounwind uwtable
declare dso_local i32 @rl_poll(ptr noundef, ptr noundef, ptr noundef, ptr noundef) #3

; Function Attrs: nounwind uwtable
declare hidden void @generate_subscriber_id(ptr noundef) #3

; Function Attrs: nounwind uwtable
declare hidden ptr @get_signal_filename(ptr noundef, ptr noundef) #3

declare i32 @rl_discard(ptr noundef) #0

declare i32 @rl_create_signal(ptr noundef) #0

declare i32 @rl_read_signal(ptr noundef, ptr noundef, ptr noundef, 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 }

!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, !6, i64 136}
!12 = !{!"rlite", !13, i64 0, !13, i64 8, !10, i64 16, !6, i64 24, !13, i64 32, !13, i64 40, !13, i64 48, !6, i64 56, !10, i64 64, !10, i64 68, !10, i64 72, !10, i64 76, !6, i64 80, !13, i64 88, !13, i64 96, !6, i64 104, !13, i64 112, !13, i64 120, !6, i64 128, !6, i64 136, !6, i64 144, !6, i64 152}
!13 = !{!"long", !7, 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_refresh(ptr noundef) local_unnamed_addr #0

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

; Function Attrs: nounwind uwtable
define dso_local i32 @rl_poll_wait(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3, ptr noundef %4) local_unnamed_addr #2 {
  %6 = tail call i32 @rl_poll(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3)
  %7 = icmp eq i32 %6, 3
  br i1 %7, label %8, label %23

8:                                                ; preds = %5
  %9 = getelementptr inbounds i8, ptr %0, i64 136
  %10 = load ptr, ptr %9, align 8, !tbaa !5
  %11 = icmp eq ptr %10, null
  br i1 %11, label %12, label %15

12:                                               ; preds = %8
  tail call void @generate_subscriber_id(ptr noundef nonnull %0)
  %13 = load ptr, ptr %9, align 8, !tbaa !5
  %14 = icmp eq ptr %13, null
  br i1 %14, label %23, label %15

15:                                               ; preds = %12, %8
  %16 = phi ptr [ %13, %12 ], [ %10, %8 ]
  %17 = tail call ptr @get_signal_filename(ptr noundef nonnull %0, ptr noundef nonnull %16)
  %18 = tail call i32 @rl_discard(ptr noundef nonnull %0) #3
  %19 = tail call i32 @rl_create_signal(ptr noundef %17) #3
  %20 = tail call i32 @rl_read_signal(ptr noundef %17, ptr noundef %4, ptr noundef null, ptr noundef null) #3
  tail call void @free(ptr noundef %17) #3
  %21 = tail call i32 @rl_refresh(ptr noundef nonnull %0) #3
  %22 = tail call i32 @rl_poll(ptr noundef nonnull %0, ptr noundef %1, ptr noundef %2, ptr noundef %3)
  br label %23

23:                                               ; preds = %5, %15, %12
  %.0 = phi i32 [ 6, %12 ], [ %22, %15 ], [ %6, %5 ]
  ret i32 %.0
}

; Function Attrs: nounwind uwtable
declare dso_local i32 @rl_poll(ptr noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
declare hidden void @generate_subscriber_id(ptr noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
declare hidden ptr @get_signal_filename(ptr noundef, ptr noundef) local_unnamed_addr #2

declare i32 @rl_discard(ptr noundef) local_unnamed_addr #0

declare i32 @rl_create_signal(ptr noundef) local_unnamed_addr #0

declare i32 @rl_read_signal(ptr noundef, ptr noundef, ptr noundef, 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 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 #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, !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}


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