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

; 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.FLASH_ProcessTypeDef = type { i32, i32, i32, i32, i32, i32, i32 }
%struct.FLASH_TypeDef = type { i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, [2 x i32], i32, i32, i32, i32, i32, [40 x i32], i32, i32, i32, i32, i32, [4 x i32], i32, i32, i32, i32, i32, i32, [4 x i32], i32, i32, i32, i32, i32 }

@pFlash = external dso_local global %struct.FLASH_ProcessTypeDef, align 4

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

; Function Attrs: nounwind uwtable
define dso_local i32 @FLASH_WaitForLastOperation(i32 noundef %0, i32 noundef %1) #1 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %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 i32 %0, ptr %4, align 4, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  %10 = call i32 @HAL_GetTick()
  store i32 %10, ptr %8, align 4, !tbaa !5
  %11 = load i32, ptr %5, align 4, !tbaa !5
  %12 = icmp eq i32 %11, 1
  br i1 %12, label %13, label %14

13:                                               ; preds = %2
  store i32 4, ptr %6, align 4, !tbaa !5
  br label %15

14:                                               ; preds = %2
  store i32 -2147483644, ptr %6, align 4, !tbaa !5
  br label %15

15:                                               ; preds = %14, %13
  br label %16

16:                                               ; preds = %56, %15
  %17 = load i32, ptr %6, align 4, !tbaa !5
  %18 = zext i32 %17 to i64
  %19 = and i64 %18, 535756815
  %20 = load i32, ptr %6, align 4, !tbaa !5
  %21 = zext i32 %20 to i64
  %22 = icmp eq i64 %19, %21
  br i1 %22, label %23, label %30

23:                                               ; preds = %16
  %24 = load volatile i32, ptr getelementptr inbounds (%struct.FLASH_TypeDef, ptr inttoptr (i64 1375739904 to ptr), i32 0, i32 4), align 4, !tbaa !9
  %25 = load i32, ptr %6, align 4, !tbaa !5
  %26 = and i32 %24, %25
  %27 = load i32, ptr %6, align 4, !tbaa !5
  %28 = icmp eq i32 %26, %27
  %29 = zext i1 %28 to i32
  br label %39

30:                                               ; preds = %16
  %31 = load volatile i32, ptr getelementptr inbounds (%struct.FLASH_TypeDef, ptr inttoptr (i64 1375739904 to ptr), i32 0, i32 28), align 4, !tbaa !11
  %32 = load i32, ptr %6, align 4, !tbaa !5
  %33 = and i32 %32, 2147483647
  %34 = and i32 %31, %33
  %35 = load i32, ptr %6, align 4, !tbaa !5
  %36 = and i32 %35, 2147483647
  %37 = icmp eq i32 %34, %36
  %38 = zext i1 %37 to i32
  br label %39

39:                                               ; preds = %30, %23
  %40 = phi i32 [ %29, %23 ], [ %38, %30 ]
  %41 = icmp ne i32 %40, 0
  br i1 %41, label %42, label %57

42:                                               ; preds = %39
  %43 = load i32, ptr %4, align 4, !tbaa !5
  %44 = icmp ne i32 %43, -1
  br i1 %44, label %45, label %56

45:                                               ; preds = %42
  %46 = call i32 @HAL_GetTick()
  %47 = load i32, ptr %8, align 4, !tbaa !5
  %48 = sub i32 %46, %47
  %49 = load i32, ptr %4, align 4, !tbaa !5
  %50 = icmp ugt i32 %48, %49
  br i1 %50, label %54, label %51

51:                                               ; preds = %45
  %52 = load i32, ptr %4, align 4, !tbaa !5
  %53 = icmp eq i32 %52, 0
  br i1 %53, label %54, label %55

54:                                               ; preds = %51, %45
  store i32 3, ptr %3, align 4
  store i32 1, ptr %9, align 4
  br label %110

55:                                               ; preds = %51
  br label %56

56:                                               ; preds = %55, %42
  br label %16, !llvm.loop !12

57:                                               ; preds = %39
  %58 = load i32, ptr %5, align 4, !tbaa !5
  %59 = icmp eq i32 %58, 1
  br i1 %59, label %60, label %65

60:                                               ; preds = %57
  %61 = load volatile i32, ptr getelementptr inbounds (%struct.FLASH_TypeDef, ptr inttoptr (i64 1375739904 to ptr), i32 0, i32 4), align 4, !tbaa !9
  %62 = zext i32 %61 to i64
  %63 = and i64 %62, 401473536
  %64 = trunc i64 %63 to i32
  store i32 %64, ptr %7, align 4, !tbaa !5
  br label %71

65:                                               ; preds = %57
  %66 = load volatile i32, ptr getelementptr inbounds (%struct.FLASH_TypeDef, ptr inttoptr (i64 1375739904 to ptr), i32 0, i32 28), align 4, !tbaa !11
  %67 = zext i32 %66 to i64
  %68 = and i64 %67, 2548957184
  %69 = or i64 %68, 2147483648
  %70 = trunc i64 %69 to i32
  store i32 %70, ptr %7, align 4, !tbaa !5
  br label %71

71:                                               ; preds = %65, %60
  %72 = load i32, ptr %7, align 4, !tbaa !5
  %73 = and i32 %72, 2147483647
  %74 = icmp ne i32 %73, 0
  br i1 %74, label %75, label %92

75:                                               ; preds = %71
  %76 = load i32, ptr %7, align 4, !tbaa !5
  %77 = load volatile i32, ptr getelementptr inbounds (%struct.FLASH_ProcessTypeDef, ptr @pFlash, i32 0, i32 6), align 4, !tbaa !14
  %78 = or i32 %77, %76
  store volatile i32 %78, ptr getelementptr inbounds (%struct.FLASH_ProcessTypeDef, ptr @pFlash, i32 0, i32 6), align 4, !tbaa !14
  %79 = load i32, ptr %7, align 4, !tbaa !5
  %80 = zext i32 %79 to i64
  %81 = and i64 %80, 535756815
  %82 = load i32, ptr %7, align 4, !tbaa !5
  %83 = zext i32 %82 to i64
  %84 = icmp eq i64 %81, %83
  br i1 %84, label %85, label %87

85:                                               ; preds = %75
  %86 = load i32, ptr %7, align 4, !tbaa !5
  store volatile i32 %86, ptr getelementptr inbounds (%struct.FLASH_TypeDef, ptr inttoptr (i64 1375739904 to ptr), i32 0, i32 5), align 4, !tbaa !16
  br label %90

87:                                               ; preds = %75
  %88 = load i32, ptr %7, align 4, !tbaa !5
  %89 = and i32 %88, 2147483647
  store volatile i32 %89, ptr getelementptr inbounds (%struct.FLASH_TypeDef, ptr inttoptr (i64 1375739904 to ptr), i32 0, i32 29), align 4, !tbaa !17
  br label %90

90:                                               ; preds = %87, %85
  %91 = phi i32 [ %86, %85 ], [ %89, %87 ]
  store i32 1, ptr %3, align 4
  store i32 1, ptr %9, align 4
  br label %110

92:                                               ; preds = %71
  %93 = load i32, ptr %5, align 4, !tbaa !5
  %94 = icmp eq i32 %93, 1
  br i1 %94, label %95, label %102

95:                                               ; preds = %92
  %96 = load volatile i32, ptr getelementptr inbounds (%struct.FLASH_TypeDef, ptr inttoptr (i64 1375739904 to ptr), i32 0, i32 4), align 4, !tbaa !9
  %97 = zext i32 %96 to i64
  %98 = and i64 %97, 65536
  %99 = icmp eq i64 %98, 65536
  br i1 %99, label %100, label %101

100:                                              ; preds = %95
  store volatile i32 65536, ptr getelementptr inbounds (%struct.FLASH_TypeDef, ptr inttoptr (i64 1375739904 to ptr), i32 0, i32 5), align 4, !tbaa !16
  br label %101

101:                                              ; preds = %100, %95
  br label %109

102:                                              ; preds = %92
  %103 = load volatile i32, ptr getelementptr inbounds (%struct.FLASH_TypeDef, ptr inttoptr (i64 1375739904 to ptr), i32 0, i32 28), align 4, !tbaa !11
  %104 = zext i32 %103 to i64
  %105 = and i64 %104, 65536
  %106 = icmp eq i64 %105, 65536
  br i1 %106, label %107, label %108

107:                                              ; preds = %102
  store volatile i32 65536, ptr getelementptr inbounds (%struct.FLASH_TypeDef, ptr inttoptr (i64 1375739904 to ptr), i32 0, i32 29), align 4, !tbaa !17
  br label %108

108:                                              ; preds = %107, %102
  br label %109

109:                                              ; preds = %108, %101
  store i32 0, ptr %3, align 4
  store i32 1, ptr %9, align 4
  br label %110

110:                                              ; preds = %109, %90, %54
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  %111 = load i32, ptr %3, align 4
  ret i32 %111
}

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

declare i32 @HAL_GetTick() #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 = { "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 16}
!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, !6, i64 44, !6, i64 48, !6, i64 52, !6, i64 56, !6, i64 60, !6, i64 64, !6, i64 68, !7, i64 72, !6, i64 80, !6, i64 84, !6, i64 88, !6, i64 92, !6, i64 96, !7, i64 100, !6, i64 260, !6, i64 264, !6, i64 268, !6, i64 272, !6, i64 276, !7, i64 280, !6, i64 296, !6, i64 300, !6, i64 304, !6, i64 308, !6, i64 312, !6, i64 316, !7, i64 320, !6, i64 336, !6, i64 340, !6, i64 344, !6, i64 348, !6, i64 352}
!11 = !{!10, !6, i64 272}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = !{!15, !6, i64 24}
!15 = !{!"", !6, i64 0, !6, i64 4, !6, i64 8, !6, i64 12, !6, i64 16, !6, i64 20, !6, i64 24}
!16 = !{!10, !6, i64 20}
!17 = !{!10, !6, i64 276}


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

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

@pFlash = external dso_local global %struct.FLASH_ProcessTypeDef, align 4

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 4) i32 @FLASH_WaitForLastOperation(i32 noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = tail call i32 @HAL_GetTick() #2
  %4 = icmp eq i32 %1, 1
  %.not28 = icmp eq i32 %0, -1
  %5 = icmp eq i32 %0, 0
  br i1 %4, label %.split.us, label %.split

.split.us:                                        ; preds = %2
  %6 = load volatile i32, ptr inttoptr (i64 1375739920 to ptr), align 16, !tbaa !5
  %7 = and i32 %6, 4
  %.not.us40 = icmp eq i32 %7, 0
  br i1 %.not.us40, label %.split37.us, label %.lr.ph41

.lr.ph41:                                         ; preds = %.split.us
  br i1 %.not28, label %.lr.ph41.split.us, label %.lr.ph41.split

.lr.ph41.split.us:                                ; preds = %.lr.ph41, %.lr.ph41.split.us
  %8 = load volatile i32, ptr inttoptr (i64 1375739920 to ptr), align 16, !tbaa !5
  %9 = and i32 %8, 4
  %.not.us.us = icmp eq i32 %9, 0
  br i1 %.not.us.us, label %.split37.us, label %.lr.ph41.split.us, !llvm.loop !10

.lr.ph41.split:                                   ; preds = %.lr.ph41
  br i1 %5, label %.lr.ph41.split.split.us, label %.lr.ph41.split.split

.lr.ph41.split.split.us:                          ; preds = %.lr.ph41.split
  %10 = tail call i32 @HAL_GetTick() #2
  br label %.loopexit

.lr.ph41.split.split:                             ; preds = %.lr.ph41.split, %14
  %11 = tail call i32 @HAL_GetTick() #2
  %12 = sub i32 %11, %3
  %13 = icmp ugt i32 %12, %0
  br i1 %13, label %.loopexit, label %14

14:                                               ; preds = %.lr.ph41.split.split
  %15 = load volatile i32, ptr inttoptr (i64 1375739920 to ptr), align 16, !tbaa !5
  %16 = and i32 %15, 4
  %.not.us = icmp eq i32 %16, 0
  br i1 %.not.us, label %.split37.us, label %.lr.ph41.split.split, !llvm.loop !10

.split:                                           ; preds = %2
  %17 = load volatile i32, ptr inttoptr (i64 1375740176 to ptr), align 16, !tbaa !12
  %18 = and i32 %17, 4
  %.not2938 = icmp eq i32 %18, 0
  br i1 %.not2938, label %.thread31, label %.lr.ph

.lr.ph:                                           ; preds = %.split
  br i1 %.not28, label %.thread.us, label %.lr.ph.split

.thread.us:                                       ; preds = %.lr.ph, %.thread.us
  %19 = load volatile i32, ptr inttoptr (i64 1375740176 to ptr), align 16, !tbaa !12
  %20 = and i32 %19, 4
  %.not29.us = icmp eq i32 %20, 0
  br i1 %.not29.us, label %.thread31, label %.thread.us, !llvm.loop !10

.lr.ph.split:                                     ; preds = %.lr.ph
  br i1 %5, label %.lr.ph.split.split.us, label %.lr.ph.split.split

.lr.ph.split.split.us:                            ; preds = %.lr.ph.split
  %21 = tail call i32 @HAL_GetTick() #2
  br label %.loopexit

.lr.ph.split.split:                               ; preds = %.lr.ph.split, %.thread
  %22 = tail call i32 @HAL_GetTick() #2
  %23 = sub i32 %22, %3
  %24 = icmp ugt i32 %23, %0
  br i1 %24, label %.loopexit, label %.thread

.thread:                                          ; preds = %.lr.ph.split.split
  %25 = load volatile i32, ptr inttoptr (i64 1375740176 to ptr), align 16, !tbaa !12
  %26 = and i32 %25, 4
  %.not29 = icmp eq i32 %26, 0
  br i1 %.not29, label %.thread31, label %.lr.ph.split.split, !llvm.loop !10

.split37.us:                                      ; preds = %14, %.lr.ph41.split.us, %.split.us
  %27 = load volatile i32, ptr inttoptr (i64 1375739920 to ptr), align 16, !tbaa !5
  %28 = and i32 %27, 401473536
  %.not25 = icmp eq i32 %28, 0
  br i1 %.not25, label %40, label %32

.thread31:                                        ; preds = %.thread, %.thread.us, %.split
  %29 = load volatile i32, ptr inttoptr (i64 1375740176 to ptr), align 16, !tbaa !12
  %30 = and i32 %29, 401473536
  %31 = or disjoint i32 %30, -2147483648
  %.not2533 = icmp eq i32 %30, 0
  br i1 %.not2533, label %.thread35, label %32

32:                                               ; preds = %.thread31, %.split37.us
  %33 = phi i32 [ %30, %.thread31 ], [ %28, %.split37.us ]
  %.02134 = phi i32 [ %31, %.thread31 ], [ %28, %.split37.us ]
  %34 = load volatile i32, ptr getelementptr inbounds (i8, ptr @pFlash, i64 24), align 4, !tbaa !13
  %35 = or i32 %34, %.02134
  store volatile i32 %35, ptr getelementptr inbounds (i8, ptr @pFlash, i64 24), align 4, !tbaa !13
  %36 = and i32 %.02134, -535756816
  %37 = icmp eq i32 %36, 0
  br i1 %37, label %38, label %39

38:                                               ; preds = %32
  store volatile i32 %.02134, ptr inttoptr (i64 1375739924 to ptr), align 4, !tbaa !15
  br label %.loopexit

39:                                               ; preds = %32
  store volatile i32 %33, ptr inttoptr (i64 1375740180 to ptr), align 4, !tbaa !16
  br label %.loopexit

40:                                               ; preds = %.split37.us
  %41 = load volatile i32, ptr inttoptr (i64 1375739920 to ptr), align 16, !tbaa !5
  %42 = and i32 %41, 65536
  %.not27 = icmp eq i32 %42, 0
  br i1 %.not27, label %.loopexit, label %43

43:                                               ; preds = %40
  store volatile i32 65536, ptr inttoptr (i64 1375739924 to ptr), align 4, !tbaa !15
  br label %.loopexit

.thread35:                                        ; preds = %.thread31
  %44 = load volatile i32, ptr inttoptr (i64 1375740176 to ptr), align 16, !tbaa !12
  %45 = and i32 %44, 65536
  %.not26 = icmp eq i32 %45, 0
  br i1 %.not26, label %.loopexit, label %46

46:                                               ; preds = %.thread35
  store volatile i32 65536, ptr inttoptr (i64 1375740180 to ptr), align 4, !tbaa !16
  br label %.loopexit

.loopexit:                                        ; preds = %.lr.ph.split.split, %.lr.ph41.split.split, %.lr.ph41.split.split.us, %.lr.ph.split.split.us, %43, %40, %46, %.thread35, %38, %39
  %.0 = phi i32 [ 1, %39 ], [ 1, %38 ], [ 0, %.thread35 ], [ 0, %46 ], [ 0, %40 ], [ 0, %43 ], [ 3, %.lr.ph.split.split.us ], [ 3, %.lr.ph41.split.split.us ], [ 3, %.lr.ph41.split.split ], [ 3, %.lr.ph.split.split ]
  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 16}
!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, i64 44, !7, i64 48, !7, i64 52, !7, i64 56, !7, i64 60, !7, i64 64, !7, i64 68, !8, i64 72, !7, i64 80, !7, i64 84, !7, i64 88, !7, i64 92, !7, i64 96, !8, i64 100, !7, i64 260, !7, i64 264, !7, i64 268, !7, i64 272, !7, i64 276, !8, i64 280, !7, i64 296, !7, i64 300, !7, i64 304, !7, i64 308, !7, i64 312, !7, i64 316, !8, i64 320, !7, i64 336, !7, i64 340, !7, i64 344, !7, i64 348, !7, i64 352}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}
!12 = !{!6, !7, i64 272}
!13 = !{!14, !7, i64 24}
!14 = !{!"", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12, !7, i64 16, !7, i64 20, !7, i64 24}
!15 = !{!6, !7, i64 20}
!16 = !{!6, !7, i64 276}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopInstSimplifyPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass