; LLVM IR from Ali-Mirghasemi/Signal :: Src (Signal)

; 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._Signal = type { ptr, ptr, %union.Signal_Callbacks, i8 }
%union.Signal_Callbacks = type { [4 x ptr] }

@lastSignal = external hidden global ptr, align 8

; 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 zeroext i8 @Signal_remove(ptr noundef %0) #1 {
  %2 = alloca i8, align 1
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #2
  %6 = load ptr, ptr @lastSignal, align 8, !tbaa !5
  store ptr %6, ptr %4, align 8, !tbaa !5
  %7 = load ptr, ptr %3, align 8, !tbaa !5
  %8 = load ptr, ptr %4, align 8, !tbaa !5
  %9 = icmp eq ptr %7, %8
  br i1 %9, label %10, label %28

10:                                               ; preds = %1
  %11 = load ptr, ptr %3, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct._Signal, ptr %11, i32 0, i32 0
  %13 = load ptr, ptr %12, align 8, !tbaa !9
  %14 = load ptr, ptr %4, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct._Signal, ptr %14, i32 0, i32 0
  store ptr %13, ptr %15, align 8, !tbaa !9
  %16 = load ptr, ptr %3, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct._Signal, ptr %16, i32 0, i32 0
  store ptr null, ptr %17, align 8, !tbaa !9
  %18 = load ptr, ptr %3, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct._Signal, ptr %18, i32 0, i32 3
  %20 = load i8, ptr %19, align 8
  %21 = and i8 %20, -9
  %22 = or i8 %21, 0
  store i8 %22, ptr %19, align 8
  %23 = load ptr, ptr %3, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct._Signal, ptr %23, i32 0, i32 3
  %25 = load i8, ptr %24, align 8
  %26 = and i8 %25, -17
  %27 = or i8 %26, 0
  store i8 %27, ptr %24, align 8
  store i8 1, ptr %2, align 1
  store i32 1, ptr %5, align 4
  br label %61

28:                                               ; preds = %1
  br label %29

29:                                               ; preds = %56, %28
  %30 = load ptr, ptr %4, align 8, !tbaa !5
  %31 = icmp ne ptr null, %30
  br i1 %31, label %32, label %60

32:                                               ; preds = %29
  %33 = load ptr, ptr %3, align 8, !tbaa !5
  %34 = load ptr, ptr %4, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct._Signal, ptr %34, i32 0, i32 0
  %36 = load ptr, ptr %35, align 8, !tbaa !9
  %37 = icmp eq ptr %33, %36
  br i1 %37, label %38, label %56

38:                                               ; preds = %32
  %39 = load ptr, ptr %3, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct._Signal, ptr %39, i32 0, i32 0
  %41 = load ptr, ptr %40, align 8, !tbaa !9
  %42 = load ptr, ptr %4, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct._Signal, ptr %42, i32 0, i32 0
  store ptr %41, ptr %43, align 8, !tbaa !9
  %44 = load ptr, ptr %3, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct._Signal, ptr %44, i32 0, i32 0
  store ptr null, ptr %45, align 8, !tbaa !9
  %46 = load ptr, ptr %3, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct._Signal, ptr %46, i32 0, i32 3
  %48 = load i8, ptr %47, align 8
  %49 = and i8 %48, -9
  %50 = or i8 %49, 0
  store i8 %50, ptr %47, align 8
  %51 = load ptr, ptr %3, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct._Signal, ptr %51, i32 0, i32 3
  %53 = load i8, ptr %52, align 8
  %54 = and i8 %53, -17
  %55 = or i8 %54, 0
  store i8 %55, ptr %52, align 8
  store i8 1, ptr %2, align 1
  store i32 1, ptr %5, align 4
  br label %61

56:                                               ; preds = %32
  %57 = load ptr, ptr %4, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct._Signal, ptr %57, i32 0, i32 0
  %59 = load ptr, ptr %58, align 8, !tbaa !9
  store ptr %59, ptr %4, align 8, !tbaa !5
  br label %29, !llvm.loop !11

60:                                               ; preds = %29
  store i8 0, ptr %2, align 1
  store i32 1, ptr %5, align 4
  br label %61

61:                                               ; preds = %60, %38, %10
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #2
  %62 = load i8, ptr %2, align 1
  ret i8 %62
}

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, !6, i64 0}
!10 = !{!"_Signal", !6, i64 0, !6, i64 8, !7, i64 16, !7, i64 48, !7, i64 48, !7, i64 48, !7, i64 48, !7, i64 48}
!11 = distinct !{!11, !12}
!12 = !{!"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"

@lastSignal = external hidden local_unnamed_addr global ptr, align 8

; Function Attrs: nofree norecurse nosync nounwind memory(readwrite, inaccessiblemem: none) uwtable
define dso_local zeroext range(i8 0, 2) i8 @Signal_remove(ptr noundef %0) local_unnamed_addr #0 {
  %2 = load ptr, ptr @lastSignal, align 8, !tbaa !5
  %3 = icmp eq ptr %2, %0
  br i1 %3, label %.loopexit.sink.split, label %.preheader

.preheader:                                       ; preds = %1, %4
  %.0 = phi ptr [ %5, %4 ], [ %2, %1 ]
  %.not = icmp eq ptr %.0, null
  br i1 %.not, label %.loopexit, label %4

4:                                                ; preds = %.preheader
  %5 = load ptr, ptr %.0, align 8, !tbaa !9
  %6 = icmp eq ptr %5, %0
  br i1 %6, label %.loopexit.sink.split, label %.preheader, !llvm.loop !11

.loopexit.sink.split:                             ; preds = %4, %1
  %.0.lcssa23.sink = phi ptr [ %2, %1 ], [ %.0, %4 ]
  %7 = load ptr, ptr %0, align 8, !tbaa !9
  store ptr %7, ptr %.0.lcssa23.sink, align 8, !tbaa !9
  store ptr null, ptr %0, align 8, !tbaa !9
  %8 = getelementptr inbounds i8, ptr %0, i64 48
  %9 = load i8, ptr %8, align 8
  %10 = and i8 %9, -25
  store i8 %10, ptr %8, align 8
  br label %.loopexit

.loopexit:                                        ; preds = %.preheader, %.loopexit.sink.split
  %.016 = phi i8 [ 1, %.loopexit.sink.split ], [ 0, %.preheader ]
  ret i8 %.016
}

attributes #0 = { nofree norecurse nosync nounwind memory(readwrite, inaccessiblemem: none) 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, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !6, i64 0}
!10 = !{!"_Signal", !6, i64 0, !6, i64 8, !7, i64 16, !7, i64 48, !7, i64 48, !7, i64 48, !7, i64 48, !7, i64 48}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


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