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

; 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: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

declare i32 @__gxx_personality_v0(...)

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

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN3qOS5input14digitalChannel16fallingEdgeStateERS1_(ptr noundef nonnull align 8 dereferenceable(129)) #2 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN3qOS5input14digitalChannel15risingEdgeStateERS1_(ptr noundef nonnull align 8 dereferenceable(129)) #2 align 2

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN3qOS5input14digitalChannel14setInitalStateEv(ptr noundef nonnull align 8 dereferenceable(129) %0) unnamed_addr #3 align 2 personality ptr @__gxx_personality_v0 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  %4 = load ptr, ptr %2, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #4
  %5 = getelementptr inbounds %"class.qOS::input::digitalChannel", ptr %4, i32 0, i32 4
  %6 = load ptr, ptr %5, align 8, !tbaa !9
  %7 = icmp ne ptr null, %6
  br i1 %7, label %8, label %15

8:                                                ; preds = %1
  %9 = getelementptr inbounds %"class.qOS::input::digitalChannel", ptr %4, i32 0, i32 4
  %10 = load ptr, ptr %9, align 8, !tbaa !9
  %11 = getelementptr inbounds %"class.qOS::input::channel", ptr %4, i32 0, i32 2
  %12 = load i8, ptr %11, align 4, !tbaa !17
  %13 = invoke noundef i32 %10(i8 noundef zeroext %12)
          to label %14 unwind label %32

14:                                               ; preds = %8
  br label %16

15:                                               ; preds = %1
  br label %16

16:                                               ; preds = %15, %14
  %17 = phi i32 [ %13, %14 ], [ -1, %15 ]
  store i32 %17, ptr %3, align 4, !tbaa !18
  %18 = getelementptr inbounds %"class.qOS::input::digitalChannel", ptr %4, i32 0, i32 6
  %19 = load i8, ptr %18, align 8, !tbaa !19, !range !20, !noundef !21
  %20 = trunc i8 %19 to i1
  br i1 %20, label %21, label %26

21:                                               ; preds = %16
  %22 = load i32, ptr %3, align 4, !tbaa !18
  %23 = icmp ne i32 %22, 0
  %24 = xor i1 %23, true
  %25 = zext i1 %24 to i32
  store i32 %25, ptr %3, align 4, !tbaa !18
  br label %26

26:                                               ; preds = %21, %16
  %27 = load i32, ptr %3, align 4, !tbaa !18
  %28 = icmp eq i32 0, %27
  %29 = zext i1 %28 to i64
  %30 = select i1 %28, ptr @_ZN3qOS5input14digitalChannel16fallingEdgeStateERS1_, ptr @_ZN3qOS5input14digitalChannel15risingEdgeStateERS1_
  %31 = getelementptr inbounds %"class.qOS::input::digitalChannel", ptr %4, i32 0, i32 5
  store ptr %30, ptr %31, align 8, !tbaa !22
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #4
  ret void

32:                                               ; preds = %8
  %33 = landingpad { ptr, i32 }
          catch ptr null
  %34 = extractvalue { ptr, i32 } %33, 0
  call void @__clang_call_terminate(ptr %34) #5
  unreachable
}

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


; 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 @__gxx_personality_v0(...)

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN3qOS5input14digitalChannel16fallingEdgeStateERS1_(ptr noundef nonnull align 8 dereferenceable(129)) #1 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN3qOS5input14digitalChannel15risingEdgeStateERS1_(ptr noundef nonnull align 8 dereferenceable(129)) #1 align 2

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN3qOS5input14digitalChannel14setInitalStateEv(ptr nocapture noundef nonnull align 8 dereferenceable(129) %0) unnamed_addr #2 align 2 personality ptr @__gxx_personality_v0 {
  %2 = getelementptr inbounds i8, ptr %0, i64 96
  %3 = load ptr, ptr %2, align 8, !tbaa !5
  %.not = icmp eq ptr %3, null
  br i1 %.not, label %8, label %4

4:                                                ; preds = %1
  %5 = getelementptr inbounds i8, ptr %0, i64 36
  %6 = load i8, ptr %5, align 4, !tbaa !16
  %7 = invoke noundef i32 %3(i8 noundef zeroext %6)
          to label %8 unwind label %17

8:                                                ; preds = %1, %4
  %9 = phi i32 [ %7, %4 ], [ -1, %1 ]
  %10 = getelementptr inbounds i8, ptr %0, i64 112
  %11 = load i8, ptr %10, align 8, !tbaa !17, !range !18, !noundef !19
  %12 = trunc nuw i8 %11 to i1
  %.not3 = icmp eq i32 %9, 0
  %13 = zext i1 %.not3 to i32
  %.0 = select i1 %12, i32 %13, i32 %9
  %14 = icmp eq i32 %.0, 0
  %15 = select i1 %14, ptr @_ZN3qOS5input14digitalChannel16fallingEdgeStateERS1_, ptr @_ZN3qOS5input14digitalChannel15risingEdgeStateERS1_
  %16 = getelementptr inbounds i8, ptr %0, i64 104
  store ptr %15, ptr %16, align 8, !tbaa !20
  ret void

17:                                               ; preds = %4
  %18 = landingpad { ptr, i32 }
          catch ptr null
  %19 = extractvalue { ptr, i32 } %18, 0
  tail call void @__clang_call_terminate(ptr %19) #3
  unreachable
}

attributes #0 = { 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 #1 = { mustprogress 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 = { 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 #3 = { 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, !9, i64 104}


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