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

@signalDriver = external hidden global ptr, align 8
@lastSignal = external hidden global ptr, align 8

; Function Attrs: nounwind uwtable
declare dso_local void @Signal_setConfig(ptr noundef, ptr noundef) #0

; Function Attrs: nounwind uwtable
define dso_local zeroext i8 @Signal_add(ptr noundef %0, ptr noundef %1) #0 {
  %3 = alloca i8, align 1
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  %6 = load ptr, ptr %4, align 8, !tbaa !5
  %7 = icmp eq ptr null, %6
  br i1 %7, label %8, label %9

8:                                                ; preds = %2
  store i8 0, ptr %3, align 1
  br label %52

9:                                                ; preds = %2
  %10 = load ptr, ptr %4, align 8, !tbaa !5
  %11 = load ptr, ptr %5, align 8, !tbaa !5
  call void @Signal_setConfig(ptr noundef %10, ptr noundef %11)
  %12 = load ptr, ptr @signalDriver, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.Signal_Driver, ptr %12, i32 0, i32 0
  %14 = load ptr, ptr %13, align 8, !tbaa !9
  %15 = load ptr, ptr %4, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct._Signal, ptr %15, i32 0, i32 1
  %17 = load ptr, ptr %16, align 8, !tbaa !11
  %18 = call zeroext i8 %14(ptr noundef %17)
  %19 = zext i8 %18 to i32
  %20 = shl i32 %19, 1
  %21 = load ptr, ptr @signalDriver, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.Signal_Driver, ptr %21, i32 0, i32 0
  %23 = load ptr, ptr %22, align 8, !tbaa !9
  %24 = load ptr, ptr %4, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct._Signal, ptr %24, i32 0, i32 1
  %26 = load ptr, ptr %25, align 8, !tbaa !11
  %27 = call zeroext i8 %23(ptr noundef %26)
  %28 = zext i8 %27 to i32
  %29 = or i32 %20, %28
  %30 = and i32 %29, 3
  %31 = trunc i32 %30 to i8
  %32 = load ptr, ptr %4, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct._Signal, ptr %32, i32 0, i32 3
  %34 = load i8, ptr %33, align 8
  %35 = and i8 %31, 3
  %36 = and i8 %34, -4
  %37 = or i8 %36, %35
  store i8 %37, ptr %33, align 8
  %38 = load ptr, ptr @lastSignal, align 8, !tbaa !5
  %39 = load ptr, ptr %4, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct._Signal, ptr %39, i32 0, i32 0
  store ptr %38, ptr %40, align 8, !tbaa !13
  %41 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %41, ptr @lastSignal, align 8, !tbaa !5
  %42 = load ptr, ptr %4, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct._Signal, ptr %42, i32 0, i32 3
  %44 = load i8, ptr %43, align 8
  %45 = and i8 %44, -9
  %46 = or i8 %45, 8
  store i8 %46, ptr %43, align 8
  %47 = load ptr, ptr %4, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct._Signal, ptr %47, i32 0, i32 3
  %49 = load i8, ptr %48, align 8
  %50 = and i8 %49, -17
  %51 = or i8 %50, 16
  store i8 %51, ptr %48, align 8
  store i8 1, ptr %3, align 1
  br label %52

52:                                               ; preds = %9, %8
  %53 = load i8, ptr %3, align 1
  ret i8 %53
}

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

!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 = !{!"", !6, i64 0}
!11 = !{!12, !6, i64 8}
!12 = !{!"_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}
!13 = !{!12, !6, 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"

@signalDriver = external hidden local_unnamed_addr global ptr, align 8
@lastSignal = external hidden local_unnamed_addr global ptr, align 8

; Function Attrs: nounwind uwtable
declare dso_local void @Signal_setConfig(ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local zeroext range(i8 0, 2) i8 @Signal_add(ptr noundef %0, ptr noundef %1) local_unnamed_addr #0 {
  %3 = icmp eq ptr %0, null
  br i1 %3, label %23, label %4

4:                                                ; preds = %2
  tail call void @Signal_setConfig(ptr noundef nonnull %0, ptr noundef %1)
  %5 = load ptr, ptr @signalDriver, align 8, !tbaa !5
  %6 = load ptr, ptr %5, align 8, !tbaa !9
  %7 = getelementptr inbounds i8, ptr %0, i64 8
  %8 = load ptr, ptr %7, align 8, !tbaa !11
  %9 = tail call zeroext i8 %6(ptr noundef %8) #1
  %10 = shl i8 %9, 1
  %11 = load ptr, ptr @signalDriver, align 8, !tbaa !5
  %12 = load ptr, ptr %11, align 8, !tbaa !9
  %13 = load ptr, ptr %7, align 8, !tbaa !11
  %14 = tail call zeroext i8 %12(ptr noundef %13) #1
  %15 = or i8 %14, %10
  %16 = and i8 %15, 3
  %17 = getelementptr inbounds i8, ptr %0, i64 48
  %18 = load i8, ptr %17, align 8
  %19 = and i8 %18, -28
  %20 = or disjoint i8 %19, %16
  %21 = load ptr, ptr @lastSignal, align 8, !tbaa !5
  store ptr %21, ptr %0, align 8, !tbaa !13
  store ptr %0, ptr @lastSignal, align 8, !tbaa !5
  %22 = or disjoint i8 %20, 24
  store i8 %22, ptr %17, align 8
  br label %23

23:                                               ; preds = %2, %4
  %.0 = phi i8 [ 1, %4 ], [ 0, %2 ]
  ret i8 %.0
}

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 = { 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 = !{!"", !6, i64 0}
!11 = !{!12, !6, i64 8}
!12 = !{!"_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}
!13 = !{!12, !6, i64 0}


; Effective O3 passes: DSEPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,InstCombinePass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass