; LLVM IR from shupx/swarm_sync_sim :: src/fw_plane_sim/src/px4_lib/hysteresis (hysteresis)

; 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.systemlib::Hysteresis" = type <{ i64, i64, i64, i8, i8, [6 x i8] }>

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN9systemlib10Hysteresis6updateERKm(ptr noundef nonnull align 8 dereferenceable(26) %0, ptr noundef nonnull align 8 dereferenceable(8) %1) #0 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i64, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  %6 = load ptr, ptr %3, align 8
  %7 = getelementptr inbounds %"class.systemlib::Hysteresis", ptr %6, i32 0, i32 4
  %8 = load i8, ptr %7, align 1, !tbaa !9, !range !13, !noundef !14
  %9 = trunc i8 %8 to i1
  %10 = zext i1 %9 to i32
  %11 = getelementptr inbounds %"class.systemlib::Hysteresis", ptr %6, i32 0, i32 3
  %12 = load i8, ptr %11, align 8, !tbaa !15, !range !13, !noundef !14
  %13 = trunc i8 %12 to i1
  %14 = zext i1 %13 to i32
  %15 = icmp ne i32 %10, %14
  br i1 %15, label %16, label %55

16:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #2
  %17 = load ptr, ptr %4, align 8, !tbaa !5
  %18 = load i64, ptr %17, align 8, !tbaa !16
  %19 = getelementptr inbounds %"class.systemlib::Hysteresis", ptr %6, i32 0, i32 0
  %20 = load i64, ptr %19, align 8, !tbaa !17
  %21 = sub i64 %18, %20
  store i64 %21, ptr %5, align 8, !tbaa !16
  %22 = getelementptr inbounds %"class.systemlib::Hysteresis", ptr %6, i32 0, i32 3
  %23 = load i8, ptr %22, align 8, !tbaa !15, !range !13, !noundef !14
  %24 = trunc i8 %23 to i1
  br i1 %24, label %25, label %37

25:                                               ; preds = %16
  %26 = getelementptr inbounds %"class.systemlib::Hysteresis", ptr %6, i32 0, i32 4
  %27 = load i8, ptr %26, align 1, !tbaa !9, !range !13, !noundef !14
  %28 = trunc i8 %27 to i1
  br i1 %28, label %37, label %29

29:                                               ; preds = %25
  %30 = load i64, ptr %5, align 8, !tbaa !16
  %31 = getelementptr inbounds %"class.systemlib::Hysteresis", ptr %6, i32 0, i32 1
  %32 = load i64, ptr %31, align 8, !tbaa !18
  %33 = icmp uge i64 %30, %32
  br i1 %33, label %34, label %36

34:                                               ; preds = %29
  %35 = getelementptr inbounds %"class.systemlib::Hysteresis", ptr %6, i32 0, i32 3
  store i8 0, ptr %35, align 8, !tbaa !15
  br label %36

36:                                               ; preds = %34, %29
  br label %54

37:                                               ; preds = %25, %16
  %38 = getelementptr inbounds %"class.systemlib::Hysteresis", ptr %6, i32 0, i32 3
  %39 = load i8, ptr %38, align 8, !tbaa !15, !range !13, !noundef !14
  %40 = trunc i8 %39 to i1
  br i1 %40, label %53, label %41

41:                                               ; preds = %37
  %42 = getelementptr inbounds %"class.systemlib::Hysteresis", ptr %6, i32 0, i32 4
  %43 = load i8, ptr %42, align 1, !tbaa !9, !range !13, !noundef !14
  %44 = trunc i8 %43 to i1
  br i1 %44, label %45, label %53

45:                                               ; preds = %41
  %46 = load i64, ptr %5, align 8, !tbaa !16
  %47 = getelementptr inbounds %"class.systemlib::Hysteresis", ptr %6, i32 0, i32 2
  %48 = load i64, ptr %47, align 8, !tbaa !19
  %49 = icmp uge i64 %46, %48
  br i1 %49, label %50, label %52

50:                                               ; preds = %45
  %51 = getelementptr inbounds %"class.systemlib::Hysteresis", ptr %6, i32 0, i32 3
  store i8 1, ptr %51, align 8, !tbaa !15
  br label %52

52:                                               ; preds = %50, %45
  br label %53

53:                                               ; preds = %52, %41, %37
  br label %54

54:                                               ; preds = %53, %36
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #2
  br label %55

55:                                               ; preds = %54, %2
  ret void
}

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

; 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 = { 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, !12, i64 25}
!10 = !{!"_ZTSN9systemlib10HysteresisE", !11, i64 0, !11, i64 8, !11, i64 16, !12, i64 24, !12, i64 25}
!11 = !{!"long", !7, i64 0}
!12 = !{!"bool", !7, i64 0}
!13 = !{i8 0, i8 2}
!14 = !{}
!15 = !{!10, !12, i64 24}
!16 = !{!11, !11, i64 0}
!17 = !{!10, !11, i64 0}
!18 = !{!10, !11, i64 8}
!19 = !{!10, !11, i64 16}


; 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 nofree norecurse nosync nounwind willreturn memory(argmem: readwrite) uwtable
define dso_local void @_ZN9systemlib10Hysteresis6updateERKm(ptr nocapture noundef nonnull align 8 dereferenceable(26) %0, ptr nocapture noundef nonnull readonly align 8 dereferenceable(8) %1) local_unnamed_addr #0 align 2 {
  %3 = getelementptr inbounds i8, ptr %0, i64 25
  %4 = load i8, ptr %3, align 1, !tbaa !5, !range !11, !noundef !12
  %5 = trunc nuw i8 %4 to i1
  %6 = getelementptr inbounds i8, ptr %0, i64 24
  %7 = load i8, ptr %6, align 8, !tbaa !13, !range !11, !noundef !12
  %.not = icmp eq i8 %4, %7
  br i1 %.not, label %20, label %8

8:                                                ; preds = %2
  %9 = trunc nuw i8 %7 to i1
  %10 = load i64, ptr %1, align 8, !tbaa !14
  %11 = load i64, ptr %0, align 8, !tbaa !15
  %12 = sub i64 %10, %11
  %.not5 = xor i1 %9, true
  %brmerge = select i1 %.not5, i1 true, i1 %5
  br i1 %brmerge, label %16, label %13

13:                                               ; preds = %8
  %14 = getelementptr inbounds i8, ptr %0, i64 8
  %15 = load i64, ptr %14, align 8, !tbaa !16
  %.not3 = icmp ult i64 %12, %15
  br i1 %.not3, label %20, label %.sink.split

16:                                               ; preds = %8
  br i1 %9, label %20, label %17

17:                                               ; preds = %16
  %18 = getelementptr inbounds i8, ptr %0, i64 16
  %19 = load i64, ptr %18, align 8
  %.not4 = icmp uge i64 %12, %19
  %or.cond.not = select i1 %5, i1 %.not4, i1 false
  br i1 %or.cond.not, label %.sink.split, label %20

.sink.split:                                      ; preds = %17, %13
  %.sink = phi i8 [ 0, %13 ], [ 1, %17 ]
  store i8 %.sink, ptr %6, align 8, !tbaa !13
  br label %20

20:                                               ; preds = %.sink.split, %13, %17, %16, %2
  ret void
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: readwrite) 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, !10, i64 25}
!6 = !{!"_ZTSN9systemlib10HysteresisE", !7, i64 0, !7, i64 8, !7, i64 16, !10, i64 24, !10, i64 25}
!7 = !{!"long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"bool", !8, i64 0}
!11 = !{i8 0, i8 2}
!12 = !{}
!13 = !{!6, !10, i64 24}
!14 = !{!7, !7, i64 0}
!15 = !{!6, !7, i64 0}
!16 = !{!6, !7, i64 8}


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