; LLVM IR from ctlst-tech/catpilot :: bsp/mcu/core/stm32/h753/hal/src (stm32h7xx_hal_flash)

; 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
  store i32 4, ptr %6, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  store i32 0, ptr %7, align 4, !tbaa !5
  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, 2
  br i1 %12, label %13, label %14

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

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

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

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

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

38:                                               ; preds = %29, %22
  %39 = phi i32 [ %28, %22 ], [ %37, %29 ]
  %40 = icmp ne i32 %39, 0
  br i1 %40, label %41, label %56

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

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

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

53:                                               ; preds = %50, %44
  store i32 3, ptr %3, align 4
  store i32 1, ptr %9, align 4
  br label %109

54:                                               ; preds = %50
  br label %55

55:                                               ; preds = %54, %41
  br label %15, !llvm.loop !12

56:                                               ; preds = %38
  %57 = load i32, ptr %5, align 4, !tbaa !5
  %58 = icmp eq i32 %57, 1
  br i1 %58, label %59, label %64

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

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

70:                                               ; preds = %64, %59
  %71 = load i32, ptr %7, align 4, !tbaa !5
  %72 = and i32 %71, 2147483647
  %73 = icmp ne i32 %72, 0
  br i1 %73, label %74, label %91

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

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

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

89:                                               ; preds = %86, %84
  %90 = phi i32 [ %85, %84 ], [ %88, %86 ]
  store i32 1, ptr %3, align 4
  store i32 1, ptr %9, align 4
  br label %109

91:                                               ; preds = %70
  %92 = load i32, ptr %5, align 4, !tbaa !5
  %93 = icmp eq i32 %92, 1
  br i1 %93, label %94, label %101

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

99:                                               ; preds = %94
  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 %100

100:                                              ; preds = %99, %94
  br label %108

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

106:                                              ; preds = %101
  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 %107

107:                                              ; preds = %106, %101
  br label %108

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

109:                                              ; preds = %108, %89, %53
  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
  %110 = load i32, ptr %3, align 4
  ret i32 %110
}

; 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
  %.not = icmp eq i32 %1, 2
  %.not29 = icmp eq i32 %0, -1
  %4 = icmp eq i32 %0, 0
  br i1 %.not, label %.split.us, label %.split

.split.us:                                        ; preds = %2
  %5 = load volatile i32, ptr inttoptr (i64 1375740176 to ptr), align 16, !tbaa !5
  %6 = and i32 %5, 4
  %.not2530.us35 = icmp eq i32 %6, 0
  br i1 %.not2530.us35, label %.thread, label %.lr.ph36

.lr.ph36:                                         ; preds = %.split.us
  br i1 %.not29, label %.thread.us.us, label %.lr.ph36.split

.thread.us.us:                                    ; preds = %.lr.ph36, %.thread.us.us
  %7 = load volatile i32, ptr inttoptr (i64 1375740176 to ptr), align 16, !tbaa !5
  %8 = and i32 %7, 4
  %.not2530.us.us = icmp eq i32 %8, 0
  br i1 %.not2530.us.us, label %.thread, label %.thread.us.us, !llvm.loop !10

.lr.ph36.split:                                   ; preds = %.lr.ph36
  br i1 %4, label %.lr.ph36.split.split.us, label %.lr.ph36.split.split

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

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

.thread.us:                                       ; preds = %.lr.ph36.split.split
  %13 = load volatile i32, ptr inttoptr (i64 1375740176 to ptr), align 16, !tbaa !5
  %14 = and i32 %13, 4
  %.not2530.us = icmp eq i32 %14, 0
  br i1 %.not2530.us, label %.thread, label %.lr.ph36.split.split, !llvm.loop !10

.split:                                           ; preds = %2
  %15 = load volatile i32, ptr inttoptr (i64 1375739920 to ptr), align 16, !tbaa !12
  %16 = and i32 %15, 4
  %.not2533 = icmp eq i32 %16, 0
  br i1 %.not2533, label %._crit_edge, label %.lr.ph

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

.lr.ph.split.us:                                  ; preds = %.lr.ph, %.lr.ph.split.us
  %17 = load volatile i32, ptr inttoptr (i64 1375739920 to ptr), align 16, !tbaa !12
  %18 = and i32 %17, 4
  %.not25.us = icmp eq i32 %18, 0
  br i1 %.not25.us, label %._crit_edge, label %.lr.ph.split.us, !llvm.loop !10

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

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

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

23:                                               ; preds = %.lr.ph.split.split
  %24 = load volatile i32, ptr inttoptr (i64 1375739920 to ptr), align 16, !tbaa !12
  %25 = and i32 %24, 4
  %.not25 = icmp eq i32 %25, 0
  br i1 %.not25, label %._crit_edge, label %.lr.ph.split.split, !llvm.loop !10

._crit_edge:                                      ; preds = %23, %.lr.ph.split.us, %.split
  %26 = icmp eq i32 %1, 1
  br i1 %26, label %27, label %.thread

27:                                               ; preds = %._crit_edge
  %28 = load volatile i32, ptr inttoptr (i64 1375739920 to ptr), align 16, !tbaa !12
  %29 = and i32 %28, 401473536
  %.not26 = icmp eq i32 %29, 0
  br i1 %.not26, label %41, label %33

.thread:                                          ; preds = %.thread.us, %.thread.us.us, %._crit_edge, %.split.us
  %30 = load volatile i32, ptr inttoptr (i64 1375740176 to ptr), align 16, !tbaa !5
  %31 = and i32 %30, 401473536
  %32 = or disjoint i32 %31, -2147483648
  %.not2641 = icmp eq i32 %31, 0
  br i1 %.not2641, label %45, label %33

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

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

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

41:                                               ; preds = %27
  %42 = load volatile i32, ptr inttoptr (i64 1375739920 to ptr), align 16, !tbaa !12
  %43 = and i32 %42, 65536
  %.not28 = icmp eq i32 %43, 0
  br i1 %.not28, label %.loopexit, label %44

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

45:                                               ; preds = %.thread
  %46 = load volatile i32, ptr inttoptr (i64 1375740176 to ptr), align 16, !tbaa !5
  %47 = and i32 %46, 65536
  %.not27 = icmp eq i32 %47, 0
  br i1 %.not27, label %.loopexit, label %48

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

.loopexit:                                        ; preds = %.lr.ph.split.split, %.lr.ph36.split.split, %.lr.ph36.split.split.us, %.lr.ph.split.split.us, %44, %41, %48, %45, %39, %40
  %.0 = phi i32 [ 1, %40 ], [ 1, %39 ], [ 0, %45 ], [ 0, %48 ], [ 0, %41 ], [ 0, %44 ], [ 3, %.lr.ph.split.split.us ], [ 3, %.lr.ph36.split.split.us ], [ 3, %.lr.ph36.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 272}
!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 16}
!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