; LLVM IR from kmilo17pet/QuarkTS-cpp :: src/input.ll (ZN3qOS5input14digitalChannel13updateReadingEb)

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

%"class.qOS::input::digitalChannel" = type <{ %"class.qOS::input::channel", i32, [4 x i8], ptr, ptr, ptr, i8, [7 x i8], i64, i8, [7 x i8] }>
%"class.qOS::input::channel" = type { %"class.qOS::node", i32, i8, ptr, ptr, i64, i64, i64 }
%"class.qOS::node" = type { ptr, ptr, ptr, ptr }

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN3qOS5input14digitalChannel13updateReadingEb(ptr noundef nonnull align 8 dereferenceable(129) %0, i1 noundef zeroext %1) unnamed_addr #0 align 2 personality ptr @__gxx_personality_v0 {
  %3 = alloca ptr, align 8
  %4 = alloca i8, align 1
  %5 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  %6 = zext i1 %1 to i8
  store i8 %6, ptr %4, align 1, !tbaa !9
  %7 = load ptr, ptr %3, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  %8 = getelementptr inbounds %"class.qOS::input::digitalChannel", ptr %7, i32 0, i32 4
  %9 = load ptr, ptr %8, align 8, !tbaa !11
  %10 = getelementptr inbounds %"class.qOS::input::channel", ptr %7, i32 0, i32 2
  %11 = load i8, ptr %10, align 4, !tbaa !18
  %12 = invoke noundef i32 %9(i8 noundef zeroext %11)
          to label %13 unwind label %25

13:                                               ; preds = %2
  store i32 %12, ptr %5, align 4, !tbaa !19
  %14 = getelementptr inbounds %"class.qOS::input::digitalChannel", ptr %7, i32 0, i32 6
  %15 = load i8, ptr %14, align 8, !tbaa !20, !range !21, !noundef !22
  %16 = trunc i8 %15 to i1
  br i1 %16, label %17, label %22

17:                                               ; preds = %13
  %18 = load i32, ptr %5, align 4, !tbaa !19
  %19 = icmp ne i32 %18, 0
  %20 = xor i1 %19, true
  %21 = zext i1 %20 to i32
  store i32 %21, ptr %5, align 4, !tbaa !19
  br label %22

22:                                               ; preds = %17, %13
  %23 = load i32, ptr %5, align 4, !tbaa !19
  %24 = getelementptr inbounds %"class.qOS::input::digitalChannel", ptr %7, i32 0, i32 1
  store i32 %23, ptr %24, align 8, !tbaa !23
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  ret void

25:                                               ; preds = %2
  %26 = landingpad { ptr, i32 }
          catch ptr null
  %27 = extractvalue { ptr, i32 } %26, 0
  call void @__clang_call_terminate(ptr %27) #4
  unreachable
}

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

declare i32 @__gxx_personality_v0(...)

; Function Attrs: noinline noreturn nounwind uwtable
declare hidden void @__clang_call_terminate(ptr noundef) #2

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

attributes #0 = { mustprogress 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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { noinline noreturn nounwind uwtable "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 }
attributes #4 = { noreturn 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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"bool", !7, i64 0}
!11 = !{!12, !6, i64 96}
!12 = !{!"_ZTSN3qOS5input14digitalChannelE", !13, i64 0, !17, i64 80, !6, i64 88, !6, i64 96, !6, i64 104, !10, i64 112, !16, i64 120, !7, i64 128}
!13 = !{!"_ZTSN3qOS5input7channelE", !14, i64 0, !15, i64 32, !7, i64 36, !6, i64 40, !6, i64 48, !16, i64 56, !16, i64 64, !16, i64 72}
!14 = !{!"_ZTSN3qOS4nodeE", !6, i64 8, !6, i64 16, !6, i64 24}
!15 = !{!"_ZTSN3qOS5input5eventE", !7, i64 0}
!16 = !{!"long", !7, i64 0}
!17 = !{!"int", !7, i64 0}
!18 = !{!13, !7, i64 36}
!19 = !{!17, !17, i64 0}
!20 = !{!12, !10, i64 112}
!21 = !{i8 0, i8 2}
!22 = !{}
!23 = !{!12, !17, i64 80}


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

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN3qOS5input14digitalChannel13updateReadingEb(ptr nocapture noundef nonnull align 8 dereferenceable(129) %0, i1 noundef zeroext %1) unnamed_addr #0 align 2 personality ptr @__gxx_personality_v0 {
  %3 = getelementptr inbounds i8, ptr %0, i64 96
  %4 = load ptr, ptr %3, align 8, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %0, i64 36
  %6 = load i8, ptr %5, align 4, !tbaa !16
  %7 = invoke noundef i32 %4(i8 noundef zeroext %6)
          to label %8 unwind label %14

8:                                                ; preds = %2
  %9 = getelementptr inbounds i8, ptr %0, i64 112
  %10 = load i8, ptr %9, align 8, !tbaa !17, !range !18, !noundef !19
  %11 = trunc nuw i8 %10 to i1
  %.not = icmp eq i32 %7, 0
  %12 = zext i1 %.not to i32
  %.0 = select i1 %11, i32 %12, i32 %7
  %13 = getelementptr inbounds i8, ptr %0, i64 80
  store i32 %.0, ptr %13, align 8, !tbaa !20
  ret void

14:                                               ; preds = %2
  %15 = landingpad { ptr, i32 }
          catch ptr null
  %16 = extractvalue { ptr, i32 } %15, 0
  tail call void @__clang_call_terminate(ptr %16) #2
  unreachable
}

declare i32 @__gxx_personality_v0(...)

; Function Attrs: noinline noreturn nounwind uwtable
declare hidden void @__clang_call_terminate(ptr noundef) local_unnamed_addr #1

attributes #0 = { mustprogress 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 = { noinline noreturn nounwind uwtable "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 = { noreturn 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, !9, i64 96}
!6 = !{!"_ZTSN3qOS5input14digitalChannelE", !7, i64 0, !14, i64 80, !9, i64 88, !9, i64 96, !9, i64 104, !15, i64 112, !13, i64 120, !10, i64 128}
!7 = !{!"_ZTSN3qOS5input7channelE", !8, i64 0, !12, i64 32, !10, i64 36, !9, i64 40, !9, i64 48, !13, i64 56, !13, i64 64, !13, i64 72}
!8 = !{!"_ZTSN3qOS4nodeE", !9, i64 8, !9, i64 16, !9, i64 24}
!9 = !{!"any pointer", !10, i64 0}
!10 = !{!"omnipotent char", !11, i64 0}
!11 = !{!"Simple C++ TBAA"}
!12 = !{!"_ZTSN3qOS5input5eventE", !10, i64 0}
!13 = !{!"long", !10, i64 0}
!14 = !{!"int", !10, i64 0}
!15 = !{!"bool", !10, i64 0}
!16 = !{!7, !10, i64 36}
!17 = !{!6, !15, i64 112}
!18 = !{i8 0, i8 2}
!19 = !{}
!20 = !{!6, !14, i64 80}


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