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

; 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::analogChannel" = type { %"class.qOS::input::channel", i32, ptr, ptr, ptr, i32, i32, i32, i32, i32, i32, i32, i64 }
%"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 nounwind uwtable
define dso_local void @_ZN3qOS5input13analogChannel13updateReadingEb(ptr noundef nonnull align 8 dereferenceable(152) %0, i1 noundef zeroext %1) unnamed_addr #2 align 2 personality ptr @__gxx_personality_v0 {
  %3 = alloca ptr, align 8
  %4 = alloca i8, align 1
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  %10 = zext i1 %1 to i8
  store i8 %10, ptr %4, align 1, !tbaa !9
  %11 = load ptr, ptr %3, align 8
  %12 = load ptr, ptr %11, align 8, !tbaa !11
  %13 = getelementptr inbounds ptr, ptr %12, i64 7
  %14 = load ptr, ptr %13, align 8
  %15 = call noundef zeroext i1 %14(ptr noundef nonnull align 8 dereferenceable(152) %11) #4
  br i1 %15, label %16, label %21

16:                                               ; preds = %2
  %17 = getelementptr inbounds %"class.qOS::input::analogChannel", ptr %11, i32 0, i32 2
  %18 = load ptr, ptr %17, align 8, !tbaa !13
  %19 = getelementptr inbounds i32, ptr %18, i64 0
  %20 = load i32, ptr %19, align 4, !tbaa !20
  br label %28

21:                                               ; preds = %2
  %22 = getelementptr inbounds %"class.qOS::input::analogChannel", ptr %11, i32 0, i32 3
  %23 = load ptr, ptr %22, align 8, !tbaa !21
  %24 = getelementptr inbounds %"class.qOS::input::channel", ptr %11, i32 0, i32 2
  %25 = load i8, ptr %24, align 4, !tbaa !22
  %26 = invoke noundef i32 %23(i8 noundef zeroext %25)
          to label %27 unwind label %102

27:                                               ; preds = %21
  br label %28

28:                                               ; preds = %27, %16
  %29 = phi i32 [ %20, %16 ], [ %26, %27 ]
  %30 = getelementptr inbounds %"class.qOS::input::analogChannel", ptr %11, i32 0, i32 1
  store i32 %29, ptr %30, align 8, !tbaa !23
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  %31 = getelementptr inbounds %"class.qOS::input::analogChannel", ptr %11, i32 0, i32 1
  %32 = load i32, ptr %31, align 8, !tbaa !23
  %33 = getelementptr inbounds %"class.qOS::input::analogChannel", ptr %11, i32 0, i32 10
  %34 = load i32, ptr %33, align 4, !tbaa !24
  %35 = udiv i32 %32, %34
  store i32 %35, ptr %5, align 4, !tbaa !20
  %36 = load i32, ptr %5, align 4, !tbaa !20
  %37 = getelementptr inbounds %"class.qOS::input::analogChannel", ptr %11, i32 0, i32 7
  %38 = load i32, ptr %37, align 8, !tbaa !25
  %39 = icmp ne i32 %36, %38
  br i1 %39, label %40, label %69

40:                                               ; preds = %28
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  %41 = load i32, ptr %5, align 4, !tbaa !20
  %42 = getelementptr inbounds %"class.qOS::input::analogChannel", ptr %11, i32 0, i32 7
  %43 = load i32, ptr %42, align 8, !tbaa !25
  %44 = icmp ugt i32 %41, %43
  br i1 %44, label %45, label %50

45:                                               ; preds = %40
  %46 = load i32, ptr %5, align 4, !tbaa !20
  %47 = getelementptr inbounds %"class.qOS::input::analogChannel", ptr %11, i32 0, i32 7
  %48 = load i32, ptr %47, align 8, !tbaa !25
  %49 = sub i32 %46, %48
  store i32 %49, ptr %6, align 4, !tbaa !20
  store i32 15, ptr %7, align 4, !tbaa !26
  br label %55

50:                                               ; preds = %40
  %51 = getelementptr inbounds %"class.qOS::input::analogChannel", ptr %11, i32 0, i32 7
  %52 = load i32, ptr %51, align 8, !tbaa !25
  %53 = load i32, ptr %5, align 4, !tbaa !20
  %54 = sub i32 %52, %53
  store i32 %54, ptr %6, align 4, !tbaa !20
  store i32 16, ptr %7, align 4, !tbaa !26
  br label %55

55:                                               ; preds = %50, %45
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  store i32 0, ptr %8, align 4, !tbaa !20
  br label %56

56:                                               ; preds = %63, %55
  %57 = load i32, ptr %8, align 4, !tbaa !20
  %58 = load i32, ptr %6, align 4, !tbaa !20
  %59 = icmp ult i32 %57, %58
  br i1 %59, label %61, label %60

60:                                               ; preds = %56
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  br label %66

61:                                               ; preds = %56
  %62 = load i32, ptr %7, align 4, !tbaa !26
  call void @_ZN3qOS5input7channel13dispatchEventENS0_5eventE(ptr noundef nonnull align 8 dereferenceable(80) %11, i32 noundef %62) #4
  br label %63

63:                                               ; preds = %61
  %64 = load i32, ptr %8, align 4, !tbaa !20
  %65 = add i32 %64, 1
  store i32 %65, ptr %8, align 4, !tbaa !20
  br label %56, !llvm.loop !27

66:                                               ; preds = %60
  %67 = load i32, ptr %5, align 4, !tbaa !20
  %68 = getelementptr inbounds %"class.qOS::input::analogChannel", ptr %11, i32 0, i32 7
  store i32 %67, ptr %68, align 8, !tbaa !25
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  br label %69

69:                                               ; preds = %66, %28
  %70 = load i8, ptr %4, align 1, !tbaa !9, !range !29, !noundef !30
  %71 = trunc i8 %70 to i1
  br i1 %71, label %72, label %101

72:                                               ; preds = %69
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  %73 = getelementptr inbounds %"class.qOS::input::analogChannel", ptr %11, i32 0, i32 1
  %74 = load i32, ptr %73, align 8, !tbaa !23
  %75 = getelementptr inbounds %"class.qOS::input::analogChannel", ptr %11, i32 0, i32 8
  %76 = load i32, ptr %75, align 4, !tbaa !31
  %77 = icmp ugt i32 %74, %76
  br i1 %77, label %78, label %84

78:                                               ; preds = %72
  %79 = getelementptr inbounds %"class.qOS::input::analogChannel", ptr %11, i32 0, i32 1
  %80 = load i32, ptr %79, align 8, !tbaa !23
  %81 = getelementptr inbounds %"class.qOS::input::analogChannel", ptr %11, i32 0, i32 8
  %82 = load i32, ptr %81, align 4, !tbaa !31
  %83 = sub i32 %80, %82
  br label %90

84:                                               ; preds = %72
  %85 = getelementptr inbounds %"class.qOS::input::analogChannel", ptr %11, i32 0, i32 8
  %86 = load i32, ptr %85, align 4, !tbaa !31
  %87 = getelementptr inbounds %"class.qOS::input::analogChannel", ptr %11, i32 0, i32 1
  %88 = load i32, ptr %87, align 8, !tbaa !23
  %89 = sub i32 %86, %88
  br label %90

90:                                               ; preds = %84, %78
  %91 = phi i32 [ %83, %78 ], [ %89, %84 ]
  store i32 %91, ptr %9, align 4, !tbaa !20
  %92 = load i32, ptr %9, align 4, !tbaa !20
  %93 = getelementptr inbounds %"class.qOS::input::analogChannel", ptr %11, i32 0, i32 9
  %94 = load i32, ptr %93, align 8, !tbaa !32
  %95 = icmp uge i32 %92, %94
  br i1 %95, label %96, label %97

96:                                               ; preds = %90
  call void @_ZN3qOS5input7channel13dispatchEventENS0_5eventE(ptr noundef nonnull align 8 dereferenceable(80) %11, i32 noundef 14) #4
  br label %97

97:                                               ; preds = %96, %90
  %98 = getelementptr inbounds %"class.qOS::input::analogChannel", ptr %11, i32 0, i32 1
  %99 = load i32, ptr %98, align 8, !tbaa !23
  %100 = getelementptr inbounds %"class.qOS::input::analogChannel", ptr %11, i32 0, i32 8
  store i32 %99, ptr %100, align 4, !tbaa !31
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  br label %101

101:                                              ; preds = %97, %69
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  ret void

102:                                              ; preds = %21
  %103 = landingpad { ptr, i32 }
          catch ptr null
  %104 = extractvalue { ptr, i32 } %103, 0
  call void @__clang_call_terminate(ptr %104) #5
  unreachable
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZN3qOS5input7channel13dispatchEventENS0_5eventE(ptr noundef nonnull align 8 dereferenceable(80), i32 noundef) #3 align 2

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 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 = { inlinehint 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, !10, i64 0}
!10 = !{!"bool", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"vtable pointer", !8, i64 0}
!13 = !{!14, !6, i64 88}
!14 = !{!"_ZTSN3qOS5input13analogChannelE", !15, i64 0, !19, i64 80, !6, i64 88, !6, i64 96, !6, i64 104, !19, i64 112, !19, i64 116, !19, i64 120, !19, i64 124, !19, i64 128, !19, i64 132, !19, i64 136, !18, i64 144}
!15 = !{!"_ZTSN3qOS5input7channelE", !16, i64 0, !17, i64 32, !7, i64 36, !6, i64 40, !6, i64 48, !18, i64 56, !18, i64 64, !18, i64 72}
!16 = !{!"_ZTSN3qOS4nodeE", !6, i64 8, !6, i64 16, !6, i64 24}
!17 = !{!"_ZTSN3qOS5input5eventE", !7, i64 0}
!18 = !{!"long", !7, i64 0}
!19 = !{!"int", !7, i64 0}
!20 = !{!19, !19, i64 0}
!21 = !{!14, !6, i64 96}
!22 = !{!15, !7, i64 36}
!23 = !{!14, !19, i64 80}
!24 = !{!14, !19, i64 132}
!25 = !{!14, !19, i64 120}
!26 = !{!17, !17, i64 0}
!27 = distinct !{!27, !28}
!28 = !{!"llvm.loop.mustprogress"}
!29 = !{i8 0, i8 2}
!30 = !{}
!31 = !{!14, !19, i64 124}
!32 = !{!14, !19, i64 128}


; 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 nounwind uwtable
define dso_local void @_ZN3qOS5input13analogChannel13updateReadingEb(ptr noundef nonnull align 8 dereferenceable(152) %0, i1 noundef zeroext %1) unnamed_addr #1 align 2 personality ptr @__gxx_personality_v0 {
  %3 = load ptr, ptr %0, align 8, !tbaa !5
  %4 = getelementptr inbounds i8, ptr %3, i64 56
  %5 = load ptr, ptr %4, align 8
  %6 = tail call noundef zeroext i1 %5(ptr noundef nonnull align 8 dereferenceable(152) %0) #3
  br i1 %6, label %7, label %11

7:                                                ; preds = %2
  %8 = getelementptr inbounds i8, ptr %0, i64 88
  %9 = load ptr, ptr %8, align 8, !tbaa !8
  %10 = load i32, ptr %9, align 4, !tbaa !17
  br label %17

11:                                               ; preds = %2
  %12 = getelementptr inbounds i8, ptr %0, i64 96
  %13 = load ptr, ptr %12, align 8, !tbaa !18
  %14 = getelementptr inbounds i8, ptr %0, i64 36
  %15 = load i8, ptr %14, align 4, !tbaa !19
  %16 = invoke noundef i32 %13(i8 noundef zeroext %15)
          to label %17 unwind label %45

17:                                               ; preds = %11, %7
  %18 = phi i32 [ %10, %7 ], [ %16, %11 ]
  %19 = getelementptr inbounds i8, ptr %0, i64 80
  store i32 %18, ptr %19, align 8, !tbaa !20
  %20 = getelementptr inbounds i8, ptr %0, i64 132
  %21 = load i32, ptr %20, align 4, !tbaa !21
  %22 = udiv i32 %18, %21
  %23 = getelementptr inbounds i8, ptr %0, i64 120
  %24 = load i32, ptr %23, align 8, !tbaa !22
  %.not = icmp eq i32 %22, %24
  br i1 %.not, label %30, label %25

25:                                               ; preds = %17
  %26 = icmp ugt i32 %22, %24
  %27 = sub i32 %22, %24
  %28 = sub i32 %24, %22
  %.012 = select i1 %26, i32 15, i32 16
  %.0 = select i1 %26, i32 %27, i32 %28
  %.not20 = icmp eq i32 %.0, 0
  br i1 %.not20, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %.lr.ph, %25
  store i32 %22, ptr %23, align 8, !tbaa !22
  br label %30

.lr.ph:                                           ; preds = %25, %.lr.ph
  %.01119 = phi i32 [ %29, %.lr.ph ], [ 0, %25 ]
  tail call void @_ZN3qOS5input7channel13dispatchEventENS0_5eventE(ptr noundef nonnull align 8 dereferenceable(80) %0, i32 noundef %.012) #3
  %29 = add nuw i32 %.01119, 1
  %exitcond.not = icmp eq i32 %29, %.0
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !23

30:                                               ; preds = %._crit_edge, %17
  br i1 %1, label %31, label %44

31:                                               ; preds = %30
  %32 = load i32, ptr %19, align 8, !tbaa !20
  %33 = getelementptr inbounds i8, ptr %0, i64 124
  %34 = load i32, ptr %33, align 4, !tbaa !25
  %35 = icmp ugt i32 %32, %34
  %36 = sub i32 %32, %34
  %37 = sub i32 %34, %32
  %38 = select i1 %35, i32 %36, i32 %37
  %39 = getelementptr inbounds i8, ptr %0, i64 128
  %40 = load i32, ptr %39, align 8, !tbaa !26
  %.not18 = icmp ult i32 %38, %40
  br i1 %.not18, label %42, label %41

41:                                               ; preds = %31
  tail call void @_ZN3qOS5input7channel13dispatchEventENS0_5eventE(ptr noundef nonnull align 8 dereferenceable(80) %0, i32 noundef 14) #3
  %.pre = load i32, ptr %19, align 8, !tbaa !20
  br label %42

42:                                               ; preds = %41, %31
  %43 = phi i32 [ %.pre, %41 ], [ %32, %31 ]
  store i32 %43, ptr %33, align 4, !tbaa !25
  br label %44

44:                                               ; preds = %42, %30
  ret void

45:                                               ; preds = %11
  %46 = landingpad { ptr, i32 }
          catch ptr null
  %47 = extractvalue { ptr, i32 } %46, 0
  tail call void @__clang_call_terminate(ptr %47) #4
  unreachable
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZN3qOS5input7channel13dispatchEventENS0_5eventE(ptr noundef nonnull align 8 dereferenceable(80), i32 noundef) local_unnamed_addr #2 align 2

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 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 = { inlinehint 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 = { 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 = !{!"vtable pointer", !7, i64 0}
!7 = !{!"Simple C++ TBAA"}
!8 = !{!9, !12, i64 88}
!9 = !{!"_ZTSN3qOS5input13analogChannelE", !10, i64 0, !16, i64 80, !12, i64 88, !12, i64 96, !12, i64 104, !16, i64 112, !16, i64 116, !16, i64 120, !16, i64 124, !16, i64 128, !16, i64 132, !16, i64 136, !15, i64 144}
!10 = !{!"_ZTSN3qOS5input7channelE", !11, i64 0, !14, i64 32, !13, i64 36, !12, i64 40, !12, i64 48, !15, i64 56, !15, i64 64, !15, i64 72}
!11 = !{!"_ZTSN3qOS4nodeE", !12, i64 8, !12, i64 16, !12, i64 24}
!12 = !{!"any pointer", !13, i64 0}
!13 = !{!"omnipotent char", !7, i64 0}
!14 = !{!"_ZTSN3qOS5input5eventE", !13, i64 0}
!15 = !{!"long", !13, i64 0}
!16 = !{!"int", !13, i64 0}
!17 = !{!16, !16, i64 0}
!18 = !{!9, !12, i64 96}
!19 = !{!10, !13, i64 36}
!20 = !{!9, !16, i64 80}
!21 = !{!9, !16, i64 132}
!22 = !{!9, !16, i64 120}
!23 = distinct !{!23, !24}
!24 = !{!"llvm.loop.mustprogress"}
!25 = !{!9, !16, i64 124}
!26 = !{!9, !16, i64 128}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass