; LLVM IR from reazon-research/OpenArm :: control/canfd_control/Drivers/STM32H7xx_HAL_Driver/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, [3 x 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: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nounwind uwtable
define dso_local void @HAL_FLASH_IRQHandler() #1 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  %4 = load volatile i32, ptr getelementptr inbounds (%struct.FLASH_TypeDef, ptr inttoptr (i64 1375739904 to ptr), i32 0, i32 4), align 4, !tbaa !5
  %5 = zext i32 %4 to i64
  %6 = and i64 %5, 65536
  %7 = icmp eq i64 %6, 65536
  %8 = zext i1 %7 to i32
  %9 = icmp ne i32 %8, 0
  br i1 %9, label %10, label %55

10:                                               ; preds = %0
  %11 = load volatile i32, ptr @pFlash, align 4, !tbaa !10
  %12 = icmp eq i32 %11, 1
  br i1 %12, label %13, label %28

13:                                               ; preds = %10
  %14 = load volatile i32, ptr getelementptr inbounds (%struct.FLASH_ProcessTypeDef, ptr @pFlash, i32 0, i32 1), align 4, !tbaa !12
  %15 = add i32 %14, -1
  store volatile i32 %15, ptr getelementptr inbounds (%struct.FLASH_ProcessTypeDef, ptr @pFlash, i32 0, i32 1), align 4, !tbaa !12
  %16 = load volatile i32, ptr getelementptr inbounds (%struct.FLASH_ProcessTypeDef, ptr @pFlash, i32 0, i32 1), align 4, !tbaa !12
  %17 = icmp ne i32 %16, 0
  br i1 %17, label %18, label %25

18:                                               ; preds = %13
  %19 = load volatile i32, ptr getelementptr inbounds (%struct.FLASH_ProcessTypeDef, ptr @pFlash, i32 0, i32 3), align 4, !tbaa !13
  call void @HAL_FLASH_EndOfOperationCallback(i32 noundef %19)
  store volatile i32 65536, ptr getelementptr inbounds (%struct.FLASH_TypeDef, ptr inttoptr (i64 1375739904 to ptr), i32 0, i32 5), align 4, !tbaa !14
  %20 = load volatile i32, ptr getelementptr inbounds (%struct.FLASH_ProcessTypeDef, ptr @pFlash, i32 0, i32 3), align 4, !tbaa !13
  %21 = add i32 %20, 1
  store volatile i32 %21, ptr getelementptr inbounds (%struct.FLASH_ProcessTypeDef, ptr @pFlash, i32 0, i32 3), align 4, !tbaa !13
  %22 = load volatile i32, ptr getelementptr inbounds (%struct.FLASH_ProcessTypeDef, ptr @pFlash, i32 0, i32 3), align 4, !tbaa !13
  store i32 %22, ptr %1, align 4, !tbaa !15
  %23 = load i32, ptr %1, align 4, !tbaa !15
  %24 = load volatile i32, ptr getelementptr inbounds (%struct.FLASH_ProcessTypeDef, ptr @pFlash, i32 0, i32 2), align 4, !tbaa !16
  call void @FLASH_Erase_Sector(i32 noundef %23, i32 noundef 1, i32 noundef %24)
  br label %27

25:                                               ; preds = %13
  store volatile i32 -1, ptr getelementptr inbounds (%struct.FLASH_ProcessTypeDef, ptr @pFlash, i32 0, i32 3), align 4, !tbaa !13
  store volatile i32 0, ptr @pFlash, align 4, !tbaa !10
  %26 = load volatile i32, ptr getelementptr inbounds (%struct.FLASH_ProcessTypeDef, ptr @pFlash, i32 0, i32 3), align 4, !tbaa !13
  call void @HAL_FLASH_EndOfOperationCallback(i32 noundef %26)
  store volatile i32 65536, ptr getelementptr inbounds (%struct.FLASH_TypeDef, ptr inttoptr (i64 1375739904 to ptr), i32 0, i32 5), align 4, !tbaa !14
  br label %27

27:                                               ; preds = %25, %18
  br label %54

28:                                               ; preds = %10
  %29 = load volatile i32, ptr @pFlash, align 4, !tbaa !10
  store i32 %29, ptr %3, align 4, !tbaa !15
  %30 = load i32, ptr %3, align 4, !tbaa !15
  %31 = icmp eq i32 %30, 2
  br i1 %31, label %35, label %32

32:                                               ; preds = %28
  %33 = load i32, ptr %3, align 4, !tbaa !15
  %34 = icmp eq i32 %33, 7
  br i1 %34, label %35, label %36

35:                                               ; preds = %32, %28
  call void @HAL_FLASH_EndOfOperationCallback(i32 noundef 1)
  br label %43

36:                                               ; preds = %32
  %37 = load i32, ptr %3, align 4, !tbaa !15
  %38 = icmp eq i32 %37, 3
  br i1 %38, label %39, label %41

39:                                               ; preds = %36
  %40 = load volatile i32, ptr getelementptr inbounds (%struct.FLASH_ProcessTypeDef, ptr @pFlash, i32 0, i32 4), align 4, !tbaa !17
  call void @HAL_FLASH_EndOfOperationCallback(i32 noundef %40)
  br label %42

41:                                               ; preds = %36
  br label %42

42:                                               ; preds = %41, %39
  br label %43

43:                                               ; preds = %42, %35
  %44 = load i32, ptr %3, align 4, !tbaa !15
  %45 = icmp ne i32 %44, 4
  br i1 %45, label %46, label %53

46:                                               ; preds = %43
  %47 = load i32, ptr %3, align 4, !tbaa !15
  %48 = icmp ne i32 %47, 5
  br i1 %48, label %49, label %53

49:                                               ; preds = %46
  %50 = load i32, ptr %3, align 4, !tbaa !15
  %51 = icmp ne i32 %50, 6
  br i1 %51, label %52, label %53

52:                                               ; preds = %49
  store volatile i32 0, ptr @pFlash, align 4, !tbaa !10
  store volatile i32 65536, ptr getelementptr inbounds (%struct.FLASH_TypeDef, ptr inttoptr (i64 1375739904 to ptr), i32 0, i32 5), align 4, !tbaa !14
  br label %53

53:                                               ; preds = %52, %49, %46, %43
  br label %54

54:                                               ; preds = %53, %27
  br label %55

55:                                               ; preds = %54, %0
  %56 = load volatile i32, ptr getelementptr inbounds (%struct.FLASH_TypeDef, ptr inttoptr (i64 1375739904 to ptr), i32 0, i32 4), align 4, !tbaa !5
  %57 = zext i32 %56 to i64
  %58 = and i64 %57, 7208960
  %59 = trunc i64 %58 to i32
  store i32 %59, ptr %2, align 4, !tbaa !15
  %60 = load i32, ptr %2, align 4, !tbaa !15
  %61 = icmp ne i32 %60, 0
  br i1 %61, label %62, label %84

62:                                               ; preds = %55
  %63 = load i32, ptr %2, align 4, !tbaa !15
  %64 = load volatile i32, ptr getelementptr inbounds (%struct.FLASH_ProcessTypeDef, ptr @pFlash, i32 0, i32 6), align 4, !tbaa !18
  %65 = or i32 %64, %63
  store volatile i32 %65, ptr getelementptr inbounds (%struct.FLASH_ProcessTypeDef, ptr @pFlash, i32 0, i32 6), align 4, !tbaa !18
  %66 = load i32, ptr %2, align 4, !tbaa !15
  store volatile i32 %66, ptr getelementptr inbounds (%struct.FLASH_TypeDef, ptr inttoptr (i64 1375739904 to ptr), i32 0, i32 5), align 4, !tbaa !14
  %67 = load volatile i32, ptr @pFlash, align 4, !tbaa !10
  store i32 %67, ptr %3, align 4, !tbaa !15
  %68 = load i32, ptr %3, align 4, !tbaa !15
  %69 = icmp eq i32 %68, 1
  br i1 %69, label %70, label %72

70:                                               ; preds = %62
  %71 = load volatile i32, ptr getelementptr inbounds (%struct.FLASH_ProcessTypeDef, ptr @pFlash, i32 0, i32 3), align 4, !tbaa !13
  store i32 %71, ptr %1, align 4, !tbaa !15
  store volatile i32 -1, ptr getelementptr inbounds (%struct.FLASH_ProcessTypeDef, ptr @pFlash, i32 0, i32 3), align 4, !tbaa !13
  br label %82

72:                                               ; preds = %62
  %73 = load i32, ptr %3, align 4, !tbaa !15
  %74 = icmp eq i32 %73, 2
  br i1 %74, label %78, label %75

75:                                               ; preds = %72
  %76 = load i32, ptr %3, align 4, !tbaa !15
  %77 = icmp eq i32 %76, 7
  br i1 %77, label %78, label %79

78:                                               ; preds = %75, %72
  store i32 1, ptr %1, align 4, !tbaa !15
  br label %81

79:                                               ; preds = %75
  %80 = load volatile i32, ptr getelementptr inbounds (%struct.FLASH_ProcessTypeDef, ptr @pFlash, i32 0, i32 4), align 4, !tbaa !17
  store i32 %80, ptr %1, align 4, !tbaa !15
  br label %81

81:                                               ; preds = %79, %78
  br label %82

82:                                               ; preds = %81, %70
  store volatile i32 0, ptr @pFlash, align 4, !tbaa !10
  %83 = load i32, ptr %1, align 4, !tbaa !15
  call void @HAL_FLASH_OperationErrorCallback(i32 noundef %83)
  br label %84

84:                                               ; preds = %82, %55
  %85 = load volatile i32, ptr @pFlash, align 4, !tbaa !10
  %86 = icmp eq i32 %85, 0
  br i1 %86, label %87, label %93

87:                                               ; preds = %84
  %88 = load volatile i32, ptr getelementptr inbounds (%struct.FLASH_TypeDef, ptr inttoptr (i64 1375739904 to ptr), i32 0, i32 3), align 4, !tbaa !19
  %89 = and i32 %88, -7274497
  store volatile i32 %89, ptr getelementptr inbounds (%struct.FLASH_TypeDef, ptr inttoptr (i64 1375739904 to ptr), i32 0, i32 3), align 4, !tbaa !19
  br label %90

90:                                               ; preds = %87
  store i32 0, ptr getelementptr inbounds (%struct.FLASH_ProcessTypeDef, ptr @pFlash, i32 0, i32 5), align 4, !tbaa !20
  br label %91

91:                                               ; preds = %90
  br label %92

92:                                               ; preds = %91
  br label %93

93:                                               ; preds = %92, %84
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #3
  ret void
}

; Function Attrs: nounwind uwtable
declare dso_local void @HAL_FLASH_EndOfOperationCallback(i32 noundef) #1

declare void @FLASH_Erase_Sector(i32 noundef, i32 noundef, i32 noundef) #2

; Function Attrs: nounwind uwtable
declare dso_local void @HAL_FLASH_OperationErrorCallback(i32 noundef) #1

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, !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 112, !7, i64 116}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!11, !7, i64 0}
!11 = !{!"", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12, !7, i64 16, !7, i64 20, !7, i64 24}
!12 = !{!11, !7, i64 4}
!13 = !{!11, !7, i64 12}
!14 = !{!6, !7, i64 20}
!15 = !{!7, !7, i64 0}
!16 = !{!11, !7, i64 8}
!17 = !{!11, !7, i64 16}
!18 = !{!11, !7, i64 24}
!19 = !{!6, !7, i64 12}
!20 = !{!11, !7, i64 20}


; 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 void @HAL_FLASH_IRQHandler() local_unnamed_addr #0 {
  %1 = load volatile i32, ptr inttoptr (i64 1375739920 to ptr), align 16, !tbaa !5
  %2 = and i32 %1, 65536
  %.not = icmp eq i32 %2, 0
  br i1 %.not, label %25, label %3

3:                                                ; preds = %0
  %4 = load volatile i32, ptr @pFlash, align 4, !tbaa !10
  %5 = icmp eq i32 %4, 1
  br i1 %5, label %6, label %18

6:                                                ; preds = %3
  %7 = load volatile i32, ptr getelementptr inbounds (i8, ptr @pFlash, i64 4), align 4, !tbaa !12
  %8 = add i32 %7, -1
  store volatile i32 %8, ptr getelementptr inbounds (i8, ptr @pFlash, i64 4), align 4, !tbaa !12
  %9 = load volatile i32, ptr getelementptr inbounds (i8, ptr @pFlash, i64 4), align 4, !tbaa !12
  %.not24 = icmp eq i32 %9, 0
  br i1 %.not24, label %16, label %10

10:                                               ; preds = %6
  %11 = load volatile i32, ptr getelementptr inbounds (i8, ptr @pFlash, i64 12), align 4, !tbaa !13
  tail call void @HAL_FLASH_EndOfOperationCallback(i32 noundef %11)
  store volatile i32 65536, ptr inttoptr (i64 1375739924 to ptr), align 4, !tbaa !14
  %12 = load volatile i32, ptr getelementptr inbounds (i8, ptr @pFlash, i64 12), align 4, !tbaa !13
  %13 = add i32 %12, 1
  store volatile i32 %13, ptr getelementptr inbounds (i8, ptr @pFlash, i64 12), align 4, !tbaa !13
  %14 = load volatile i32, ptr getelementptr inbounds (i8, ptr @pFlash, i64 12), align 4, !tbaa !13
  %15 = load volatile i32, ptr getelementptr inbounds (i8, ptr @pFlash, i64 8), align 4, !tbaa !15
  tail call void @FLASH_Erase_Sector(i32 noundef %14, i32 noundef 1, i32 noundef %15) #2
  br label %25

16:                                               ; preds = %6
  store volatile i32 -1, ptr getelementptr inbounds (i8, ptr @pFlash, i64 12), align 4, !tbaa !13
  store volatile i32 0, ptr @pFlash, align 4, !tbaa !10
  %17 = load volatile i32, ptr getelementptr inbounds (i8, ptr @pFlash, i64 12), align 4, !tbaa !13
  tail call void @HAL_FLASH_EndOfOperationCallback(i32 noundef %17)
  store volatile i32 65536, ptr inttoptr (i64 1375739924 to ptr), align 4, !tbaa !14
  br label %25

18:                                               ; preds = %3
  %19 = load volatile i32, ptr @pFlash, align 4, !tbaa !10
  switch i32 %19, label %22 [
    i32 7, label %20
    i32 2, label %20
    i32 3, label %.thread
  ]

20:                                               ; preds = %18, %18
  tail call void @HAL_FLASH_EndOfOperationCallback(i32 noundef 1)
  br label %22

.thread:                                          ; preds = %18
  %21 = load volatile i32, ptr getelementptr inbounds (i8, ptr @pFlash, i64 16), align 4, !tbaa !16
  tail call void @HAL_FLASH_EndOfOperationCallback(i32 noundef %21)
  br label %24

22:                                               ; preds = %18, %20
  %23 = add i32 %19, -7
  %or.cond5 = icmp ult i32 %23, -3
  br i1 %or.cond5, label %24, label %25

24:                                               ; preds = %.thread, %22
  store volatile i32 0, ptr @pFlash, align 4, !tbaa !10
  store volatile i32 65536, ptr inttoptr (i64 1375739924 to ptr), align 4, !tbaa !14
  br label %25

25:                                               ; preds = %16, %10, %24, %22, %0
  %26 = load volatile i32, ptr inttoptr (i64 1375739920 to ptr), align 16, !tbaa !5
  %27 = and i32 %26, 7208960
  %.not25 = icmp eq i32 %27, 0
  br i1 %.not25, label %37, label %28

28:                                               ; preds = %25
  %29 = load volatile i32, ptr getelementptr inbounds (i8, ptr @pFlash, i64 24), align 4, !tbaa !17
  %30 = or i32 %29, %27
  store volatile i32 %30, ptr getelementptr inbounds (i8, ptr @pFlash, i64 24), align 4, !tbaa !17
  store volatile i32 %27, ptr inttoptr (i64 1375739924 to ptr), align 4, !tbaa !14
  %31 = load volatile i32, ptr @pFlash, align 4, !tbaa !10
  switch i32 %31, label %34 [
    i32 1, label %32
    i32 7, label %36
    i32 2, label %36
  ]

32:                                               ; preds = %28
  %33 = load volatile i32, ptr getelementptr inbounds (i8, ptr @pFlash, i64 12), align 4, !tbaa !13
  store volatile i32 -1, ptr getelementptr inbounds (i8, ptr @pFlash, i64 12), align 4, !tbaa !13
  br label %36

34:                                               ; preds = %28
  %35 = load volatile i32, ptr getelementptr inbounds (i8, ptr @pFlash, i64 16), align 4, !tbaa !16
  br label %36

36:                                               ; preds = %28, %28, %34, %32
  %.0 = phi i32 [ %33, %32 ], [ %35, %34 ], [ 1, %28 ], [ 1, %28 ]
  store volatile i32 0, ptr @pFlash, align 4, !tbaa !10
  tail call void @HAL_FLASH_OperationErrorCallback(i32 noundef %.0)
  br label %37

37:                                               ; preds = %36, %25
  %38 = load volatile i32, ptr @pFlash, align 4, !tbaa !10
  %39 = icmp eq i32 %38, 0
  br i1 %39, label %40, label %43

40:                                               ; preds = %37
  %41 = load volatile i32, ptr inttoptr (i64 1375739916 to ptr), align 4, !tbaa !18
  %42 = and i32 %41, -7274497
  store volatile i32 %42, ptr inttoptr (i64 1375739916 to ptr), align 4, !tbaa !18
  store i32 0, ptr getelementptr inbounds (i8, ptr @pFlash, i64 20), align 4, !tbaa !19
  br label %43

43:                                               ; preds = %40, %37
  ret void
}

; Function Attrs: nounwind uwtable
declare dso_local void @HAL_FLASH_EndOfOperationCallback(i32 noundef) local_unnamed_addr #0

declare void @FLASH_Erase_Sector(i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local void @HAL_FLASH_OperationErrorCallback(i32 noundef) local_unnamed_addr #0

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 112, !7, i64 116}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!11, !7, i64 0}
!11 = !{!"", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12, !7, i64 16, !7, i64 20, !7, i64 24}
!12 = !{!11, !7, i64 4}
!13 = !{!11, !7, i64 12}
!14 = !{!6, !7, i64 20}
!15 = !{!11, !7, i64 8}
!16 = !{!11, !7, i64 16}
!17 = !{!11, !7, i64 24}
!18 = !{!6, !7, i64 12}
!19 = !{!11, !7, i64 20}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,SROAPass,SimplifyCFGPass,TailCallElimPass