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

; 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 uwtable
declare dso_local void @_ZN3qOS5input13analogChannel17lowThresholdStateERS1_(ptr noundef nonnull align 8 dereferenceable(152)) #2 align 2

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

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN3qOS5input13analogChannel14setInitalStateEv(ptr noundef nonnull align 8 dereferenceable(152) %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::analogChannel", ptr %4, i32 0, i32 3
  %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::analogChannel", ptr %4, i32 0, i32 3
  %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 !16
  %13 = invoke noundef i32 %10(i8 noundef zeroext %12)
          to label %14 unwind label %42

14:                                               ; preds = %8
  br label %16

15:                                               ; preds = %1
  br label %16

16:                                               ; preds = %15, %14
  %17 = phi i32 [ %13, %14 ], [ 0, %15 ]
  store i32 %17, ptr %3, align 4, !tbaa !17
  %18 = load i32, ptr %3, align 4, !tbaa !17
  %19 = getelementptr inbounds %"class.qOS::input::analogChannel", ptr %4, i32 0, i32 5
  %20 = load i32, ptr %19, align 8, !tbaa !18
  %21 = icmp ugt i32 %18, %20
  br i1 %21, label %22, label %24

22:                                               ; preds = %16
  %23 = getelementptr inbounds %"class.qOS::input::analogChannel", ptr %4, i32 0, i32 4
  store ptr @_ZN3qOS5input13analogChannel18highThresholdStateERS1_, ptr %23, align 8, !tbaa !19
  br label %34

24:                                               ; preds = %16
  %25 = load i32, ptr %3, align 4, !tbaa !17
  %26 = getelementptr inbounds %"class.qOS::input::analogChannel", ptr %4, i32 0, i32 6
  %27 = load i32, ptr %26, align 4, !tbaa !20
  %28 = icmp ult i32 %25, %27
  br i1 %28, label %29, label %31

29:                                               ; preds = %24
  %30 = getelementptr inbounds %"class.qOS::input::analogChannel", ptr %4, i32 0, i32 4
  store ptr @_ZN3qOS5input13analogChannel17lowThresholdStateERS1_, ptr %30, align 8, !tbaa !19
  br label %33

31:                                               ; preds = %24
  %32 = getelementptr inbounds %"class.qOS::input::analogChannel", ptr %4, i32 0, i32 4
  store ptr @_ZN3qOS5input13analogChannel11inBandStateERS1_, ptr %32, align 8, !tbaa !19
  br label %33

33:                                               ; preds = %31, %29
  br label %34

34:                                               ; preds = %33, %22
  %35 = load i32, ptr %3, align 4, !tbaa !17
  %36 = getelementptr inbounds %"class.qOS::input::analogChannel", ptr %4, i32 0, i32 10
  %37 = load i32, ptr %36, align 4, !tbaa !21
  %38 = udiv i32 %35, %37
  %39 = getelementptr inbounds %"class.qOS::input::analogChannel", ptr %4, i32 0, i32 7
  store i32 %38, ptr %39, align 8, !tbaa !22
  %40 = load i32, ptr %3, align 4, !tbaa !17
  %41 = getelementptr inbounds %"class.qOS::input::analogChannel", ptr %4, i32 0, i32 8
  store i32 %40, ptr %41, align 4, !tbaa !23
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #4
  ret void

42:                                               ; preds = %8
  %43 = landingpad { ptr, i32 }
          catch ptr null
  %44 = extractvalue { ptr, i32 } %43, 0
  call void @__clang_call_terminate(ptr %44) #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 = !{!"_ZTSN3qOS5input13analogChannelE", !11, i64 0, !15, i64 80, !6, i64 88, !6, i64 96, !6, i64 104, !15, i64 112, !15, i64 116, !15, i64 120, !15, i64 124, !15, i64 128, !15, i64 132, !15, i64 136, !14, i64 144}
!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 = !{!11, !7, i64 36}
!17 = !{!15, !15, i64 0}
!18 = !{!10, !15, i64 112}
!19 = !{!10, !6, i64 104}
!20 = !{!10, !15, i64 116}
!21 = !{!10, !15, i64 132}
!22 = !{!10, !15, i64 120}
!23 = !{!10, !15, i64 124}


; 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 @_ZN3qOS5input13analogChannel17lowThresholdStateERS1_(ptr noundef nonnull align 8 dereferenceable(152)) #1 align 2

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

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN3qOS5input13analogChannel14setInitalStateEv(ptr nocapture noundef nonnull align 8 dereferenceable(152) %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 %.thread, label %4

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

8:                                                ; preds = %4
  %9 = getelementptr inbounds i8, ptr %0, i64 112
  %10 = load i32, ptr %9, align 8, !tbaa !16
  %11 = icmp ugt i32 %7, %10
  br i1 %11, label %12, label %.thread

12:                                               ; preds = %8
  %13 = getelementptr inbounds i8, ptr %0, i64 104
  store ptr @_ZN3qOS5input13analogChannel18highThresholdStateERS1_, ptr %13, align 8, !tbaa !17
  br label %21

.thread:                                          ; preds = %1, %8
  %14 = phi i32 [ %7, %8 ], [ 0, %1 ]
  %15 = getelementptr inbounds i8, ptr %0, i64 116
  %16 = load i32, ptr %15, align 4, !tbaa !18
  %17 = icmp ult i32 %14, %16
  %18 = getelementptr inbounds i8, ptr %0, i64 104
  br i1 %17, label %19, label %20

19:                                               ; preds = %.thread
  store ptr @_ZN3qOS5input13analogChannel17lowThresholdStateERS1_, ptr %18, align 8, !tbaa !17
  br label %21

20:                                               ; preds = %.thread
  store ptr @_ZN3qOS5input13analogChannel11inBandStateERS1_, ptr %18, align 8, !tbaa !17
  br label %21

21:                                               ; preds = %19, %20, %12
  %22 = phi i32 [ %14, %19 ], [ %14, %20 ], [ %7, %12 ]
  %23 = getelementptr inbounds i8, ptr %0, i64 132
  %24 = load i32, ptr %23, align 4, !tbaa !19
  %25 = udiv i32 %22, %24
  %26 = getelementptr inbounds i8, ptr %0, i64 120
  store i32 %25, ptr %26, align 8, !tbaa !20
  %27 = getelementptr inbounds i8, ptr %0, i64 124
  store i32 %22, ptr %27, align 4, !tbaa !21
  ret void

28:                                               ; preds = %4
  %29 = landingpad { ptr, i32 }
          catch ptr null
  %30 = extractvalue { ptr, i32 } %29, 0
  tail call void @__clang_call_terminate(ptr %30) #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 = !{!"_ZTSN3qOS5input13analogChannelE", !7, i64 0, !14, i64 80, !9, i64 88, !9, i64 96, !9, i64 104, !14, i64 112, !14, i64 116, !14, i64 120, !14, i64 124, !14, i64 128, !14, i64 132, !14, i64 136, !13, i64 144}
!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 = !{!7, !10, i64 36}
!16 = !{!6, !14, i64 112}
!17 = !{!6, !9, i64 104}
!18 = !{!6, !14, i64 116}
!19 = !{!6, !14, i64 132}
!20 = !{!6, !14, i64 120}
!21 = !{!6, !14, i64 124}


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