; LLVM IR from lichen-community-systems/signaletic :: hosts/daisy/vendor/libDaisy/Drivers/STM32H7xx_HAL_Driver/Src (ConfigSupply)

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

%struct.PWR_TypeDef = type { i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32 }

; Function Attrs: nounwind uwtable
define dso_local i32 @HAL_PWREx_ConfigSupply(i32 noundef %0) #0 {
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  store i32 %0, ptr %3, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  br i1 false, label %6, label %11

6:                                                ; preds = %1
  %7 = load volatile i32, ptr getelementptr inbounds (%struct.PWR_TypeDef, ptr inttoptr (i64 1476544512 to ptr), i32 0, i32 1), align 4, !tbaa !9
  %8 = zext i32 %7 to i64
  %9 = and i64 %8, 16
  %10 = icmp eq i64 %9, 16
  br i1 %10, label %73, label %64

11:                                               ; preds = %1
  br i1 false, label %12, label %17

12:                                               ; preds = %11
  %13 = load volatile i32, ptr getelementptr inbounds (%struct.PWR_TypeDef, ptr inttoptr (i64 1476544512 to ptr), i32 0, i32 1), align 4, !tbaa !9
  %14 = zext i32 %13 to i64
  %15 = and i64 %14, 65536
  %16 = icmp eq i64 %15, 65536
  br i1 %16, label %73, label %64

17:                                               ; preds = %11
  br i1 false, label %18, label %23

18:                                               ; preds = %17
  %19 = load volatile i32, ptr getelementptr inbounds (%struct.PWR_TypeDef, ptr inttoptr (i64 1476544512 to ptr), i32 0, i32 1), align 4, !tbaa !9
  %20 = zext i32 %19 to i64
  %21 = and i64 %20, 8192
  %22 = icmp eq i64 %21, 8192
  br i1 %22, label %73, label %64

23:                                               ; preds = %17
  br i1 false, label %24, label %29

24:                                               ; preds = %23
  %25 = load volatile i32, ptr getelementptr inbounds (%struct.PWR_TypeDef, ptr inttoptr (i64 1476544512 to ptr), i32 0, i32 6), align 4, !tbaa !11
  %26 = zext i32 %25 to i64
  %27 = and i64 %26, 8192
  %28 = icmp eq i64 %27, 8192
  br i1 %28, label %73, label %64

29:                                               ; preds = %23
  br i1 true, label %30, label %35

30:                                               ; preds = %29
  %31 = load volatile i32, ptr getelementptr inbounds (%struct.PWR_TypeDef, ptr inttoptr (i64 1476544512 to ptr), i32 0, i32 3), align 4, !tbaa !12
  %32 = zext i32 %31 to i64
  %33 = and i64 %32, 4
  %34 = icmp eq i64 %33, 4
  br i1 %34, label %73, label %64

35:                                               ; preds = %29
  br i1 false, label %36, label %41

36:                                               ; preds = %35
  %37 = load volatile i32, ptr getelementptr inbounds (%struct.PWR_TypeDef, ptr inttoptr (i64 1476544512 to ptr), i32 0, i32 2), align 4, !tbaa !13
  %38 = zext i32 %37 to i64
  %39 = and i64 %38, 65536
  %40 = icmp eq i64 %39, 65536
  br i1 %40, label %73, label %64

41:                                               ; preds = %35
  br i1 false, label %42, label %47

42:                                               ; preds = %41
  %43 = load volatile i32, ptr getelementptr inbounds (%struct.PWR_TypeDef, ptr inttoptr (i64 1476544512 to ptr), i32 0, i32 4), align 4, !tbaa !14
  %44 = zext i32 %43 to i64
  %45 = and i64 %44, 64
  %46 = icmp eq i64 %45, 64
  br i1 %46, label %73, label %64

47:                                               ; preds = %41
  br i1 false, label %48, label %53

48:                                               ; preds = %47
  %49 = load volatile i32, ptr getelementptr inbounds (%struct.PWR_TypeDef, ptr inttoptr (i64 1476544512 to ptr), i32 0, i32 4), align 4, !tbaa !14
  %50 = zext i32 %49 to i64
  %51 = and i64 %50, 32
  %52 = icmp eq i64 %51, 32
  br i1 %52, label %73, label %64

53:                                               ; preds = %47
  br i1 false, label %54, label %59

54:                                               ; preds = %53
  %55 = load volatile i32, ptr getelementptr inbounds (%struct.PWR_TypeDef, ptr inttoptr (i64 1476544512 to ptr), i32 0, i32 4), align 4, !tbaa !14
  %56 = zext i32 %55 to i64
  %57 = and i64 %56, 128
  %58 = icmp eq i64 %57, 128
  br i1 %58, label %73, label %64

59:                                               ; preds = %53
  %60 = load volatile i32, ptr getelementptr inbounds (%struct.PWR_TypeDef, ptr inttoptr (i64 1476544512 to ptr), i32 0, i32 4), align 4, !tbaa !14
  %61 = zext i32 %60 to i64
  %62 = and i64 %61, 256
  %63 = icmp eq i64 %62, 256
  br i1 %63, label %73, label %64

64:                                               ; preds = %59, %54, %48, %42, %36, %30, %24, %18, %12, %6
  %65 = load volatile i32, ptr getelementptr inbounds (%struct.PWR_TypeDef, ptr inttoptr (i64 1476544512 to ptr), i32 0, i32 3), align 4, !tbaa !12
  %66 = zext i32 %65 to i64
  %67 = and i64 %66, 7
  %68 = load i32, ptr %3, align 4, !tbaa !5
  %69 = zext i32 %68 to i64
  %70 = icmp ne i64 %67, %69
  br i1 %70, label %71, label %72

71:                                               ; preds = %64
  store i32 1, ptr %2, align 4
  store i32 1, ptr %5, align 4
  br label %96

72:                                               ; preds = %64
  br label %73

73:                                               ; preds = %72, %59, %54, %48, %42, %36, %30, %24, %18, %12, %6
  %74 = load volatile i32, ptr getelementptr inbounds (%struct.PWR_TypeDef, ptr inttoptr (i64 1476544512 to ptr), i32 0, i32 3), align 4, !tbaa !12
  %75 = zext i32 %74 to i64
  %76 = and i64 %75, -8
  %77 = load i32, ptr %3, align 4, !tbaa !5
  %78 = zext i32 %77 to i64
  %79 = or i64 %76, %78
  %80 = trunc i64 %79 to i32
  store volatile i32 %80, ptr getelementptr inbounds (%struct.PWR_TypeDef, ptr inttoptr (i64 1476544512 to ptr), i32 0, i32 3), align 4, !tbaa !12
  %81 = call i32 @HAL_GetTick()
  store i32 %81, ptr %4, align 4, !tbaa !5
  br label %82

82:                                               ; preds = %94, %73
  %83 = load volatile i32, ptr getelementptr inbounds (%struct.PWR_TypeDef, ptr inttoptr (i64 1476544512 to ptr), i32 0, i32 1), align 4, !tbaa !9
  %84 = zext i32 %83 to i64
  %85 = and i64 %84, 8192
  %86 = icmp eq i64 %85, 8192
  %87 = xor i1 %86, true
  br i1 %87, label %88, label %95

88:                                               ; preds = %82
  %89 = call i32 @HAL_GetTick()
  %90 = load i32, ptr %4, align 4, !tbaa !5
  %91 = sub i32 %89, %90
  %92 = icmp ugt i32 %91, 1000
  br i1 %92, label %93, label %94

93:                                               ; preds = %88
  store i32 3, ptr %2, align 4
  store i32 1, ptr %5, align 4
  br label %96

94:                                               ; preds = %88
  br label %82, !llvm.loop !15

95:                                               ; preds = %82
  store i32 0, ptr %2, align 4
  store i32 1, ptr %5, align 4
  br label %96

96:                                               ; preds = %95, %93, %71
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  %97 = load i32, ptr %2, align 4
  ret i32 %97
}

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

declare i32 @HAL_GetTick() #2

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

attributes #0 = { 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 = { "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 }

!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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !6, i64 4}
!10 = !{!"", !6, i64 0, !6, i64 4, !6, i64 8, !6, i64 12, !6, i64 16, !6, i64 20, !6, i64 24, !6, i64 28, !6, i64 32, !6, i64 36, !6, i64 40}
!11 = !{!10, !6, i64 24}
!12 = !{!10, !6, i64 12}
!13 = !{!10, !6, i64 8}
!14 = !{!10, !6, i64 16}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}


; 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: nounwind uwtable
define dso_local range(i32 0, 4) i32 @HAL_PWREx_ConfigSupply(i32 noundef %0) local_unnamed_addr #0 {
  %2 = load volatile i32, ptr inttoptr (i64 1476544524 to ptr), align 4, !tbaa !5
  %3 = and i32 %2, 4
  %.not = icmp eq i32 %3, 0
  br i1 %.not, label %4, label %7

4:                                                ; preds = %1
  %5 = load volatile i32, ptr inttoptr (i64 1476544524 to ptr), align 4, !tbaa !5
  %6 = and i32 %5, 7
  %.not4 = icmp eq i32 %6, %0
  br i1 %.not4, label %7, label %.loopexit

7:                                                ; preds = %4, %1
  %8 = load volatile i32, ptr inttoptr (i64 1476544524 to ptr), align 4, !tbaa !5
  %9 = and i32 %8, -8
  %10 = or i32 %9, %0
  store volatile i32 %10, ptr inttoptr (i64 1476544524 to ptr), align 4, !tbaa !5
  %11 = tail call i32 @HAL_GetTick() #2
  br label %12

12:                                               ; preds = %15, %7
  %13 = load volatile i32, ptr inttoptr (i64 1476544516 to ptr), align 4, !tbaa !10
  %14 = and i32 %13, 8192
  %.not5 = icmp eq i32 %14, 0
  br i1 %.not5, label %15, label %.loopexit

15:                                               ; preds = %12
  %16 = tail call i32 @HAL_GetTick() #2
  %17 = sub i32 %16, %11
  %18 = icmp ugt i32 %17, 1000
  br i1 %18, label %.loopexit, label %12, !llvm.loop !11

.loopexit:                                        ; preds = %12, %15, %4
  %.0 = phi i32 [ 1, %4 ], [ 0, %12 ], [ 3, %15 ]
  ret i32 %.0
}

declare i32 @HAL_GetTick() local_unnamed_addr #1

attributes #0 = { 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 = { "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 = { 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, !7, i64 12}
!6 = !{!"", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12, !7, i64 16, !7, i64 20, !7, i64 24, !7, i64 28, !7, i64 32, !7, i64 36, !7, i64 40}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!6, !7, i64 4}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass