; 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
declare dso_local i32 @FLASH_WaitForLastOperation(i32 noundef, i32 noundef) #1

; Function Attrs: alwaysinline nounwind uwtable
declare hidden void @__ISB() #2

; Function Attrs: alwaysinline nounwind uwtable
declare hidden void @__DSB() #2

; 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 i32 @HAL_FLASH_Program_IT(i32 noundef %0, i32 noundef %1, i32 noundef %2) #1 {
  %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 ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  %12 = alloca i8, align 1
  %13 = alloca i32, align 4
  store i32 %0, ptr %5, align 4, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !5
  store i32 %2, ptr %7, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  %14 = load i32, ptr %6, align 4, !tbaa !5
  %15 = zext i32 %14 to i64
  %16 = inttoptr i64 %15 to ptr
  store ptr %16, ptr %9, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  %17 = load i32, ptr %7, align 4, !tbaa !5
  %18 = zext i32 %17 to i64
  %19 = inttoptr i64 %18 to ptr
  store ptr %19, ptr %10, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  call void @llvm.lifetime.start.p0(i64 1, ptr %12) #3
  store i8 8, ptr %12, align 1, !tbaa !11
  br label %20

20:                                               ; preds = %3
  %21 = load i32, ptr getelementptr inbounds (%struct.FLASH_ProcessTypeDef, ptr @pFlash, i32 0, i32 5), align 4, !tbaa !12
  %22 = icmp eq i32 %21, 1
  br i1 %22, label %23, label %24

23:                                               ; preds = %20
  store i32 2, ptr %4, align 4
  store i32 1, ptr %13, align 4
  br label %96

24:                                               ; preds = %20
  store i32 1, ptr getelementptr inbounds (%struct.FLASH_ProcessTypeDef, ptr @pFlash, i32 0, i32 5), align 4, !tbaa !12
  br label %25

25:                                               ; preds = %24
  br label %26

26:                                               ; preds = %25
  br label %27

27:                                               ; preds = %26
  store volatile i32 0, ptr getelementptr inbounds (%struct.FLASH_ProcessTypeDef, ptr @pFlash, i32 0, i32 6), align 4, !tbaa !14
  %28 = load i32, ptr %6, align 4, !tbaa !5
  %29 = zext i32 %28 to i64
  %30 = icmp uge i64 %29, 134217728
  br i1 %30, label %31, label %36

31:                                               ; preds = %27
  %32 = load i32, ptr %6, align 4, !tbaa !5
  %33 = zext i32 %32 to i64
  %34 = icmp ult i64 %33, 135266304
  br i1 %34, label %35, label %36

35:                                               ; preds = %31
  store i32 1, ptr %11, align 4, !tbaa !5
  br label %47

36:                                               ; preds = %31, %27
  %37 = load i32, ptr %6, align 4, !tbaa !5
  %38 = zext i32 %37 to i64
  %39 = icmp uge i64 %38, 135266304
  br i1 %39, label %40, label %45

40:                                               ; preds = %36
  %41 = load i32, ptr %6, align 4, !tbaa !5
  %42 = zext i32 %41 to i64
  %43 = icmp ule i64 %42, 136314879
  br i1 %43, label %44, label %45

44:                                               ; preds = %40
  store i32 2, ptr %11, align 4, !tbaa !5
  br label %46

45:                                               ; preds = %40, %36
  store i32 1, ptr %4, align 4
  store i32 1, ptr %13, align 4
  br label %96

46:                                               ; preds = %44
  br label %47

47:                                               ; preds = %46, %35
  %48 = load i32, ptr %11, align 4, !tbaa !5
  %49 = call i32 @FLASH_WaitForLastOperation(i32 noundef 50000, i32 noundef %48)
  store i32 %49, ptr %8, align 4, !tbaa !5
  %50 = load i32, ptr %8, align 4, !tbaa !5
  %51 = icmp ne i32 %50, 0
  br i1 %51, label %52, label %56

52:                                               ; preds = %47
  br label %53

53:                                               ; preds = %52
  store i32 0, ptr getelementptr inbounds (%struct.FLASH_ProcessTypeDef, ptr @pFlash, i32 0, i32 5), align 4, !tbaa !12
  br label %54

54:                                               ; preds = %53
  br label %55

55:                                               ; preds = %54
  br label %94

56:                                               ; preds = %47
  %57 = load i32, ptr %6, align 4, !tbaa !5
  store volatile i32 %57, ptr getelementptr inbounds (%struct.FLASH_ProcessTypeDef, ptr @pFlash, i32 0, i32 4), align 4, !tbaa !15
  %58 = load i32, ptr %11, align 4, !tbaa !5
  %59 = icmp eq i32 %58, 1
  br i1 %59, label %60, label %69

60:                                               ; preds = %56
  store volatile i32 3, ptr @pFlash, align 4, !tbaa !16
  %61 = load volatile i32, ptr getelementptr inbounds (%struct.FLASH_TypeDef, ptr inttoptr (i64 1375739904 to ptr), i32 0, i32 3), align 4, !tbaa !17
  %62 = zext i32 %61 to i64
  %63 = or i64 %62, 2
  %64 = trunc i64 %63 to i32
  store volatile i32 %64, ptr getelementptr inbounds (%struct.FLASH_TypeDef, ptr inttoptr (i64 1375739904 to ptr), i32 0, i32 3), align 4, !tbaa !17
  %65 = load volatile i32, ptr getelementptr inbounds (%struct.FLASH_TypeDef, ptr inttoptr (i64 1375739904 to ptr), i32 0, i32 3), align 4, !tbaa !17
  %66 = zext i32 %65 to i64
  %67 = or i64 %66, 7274496
  %68 = trunc i64 %67 to i32
  store volatile i32 %68, ptr getelementptr inbounds (%struct.FLASH_TypeDef, ptr inttoptr (i64 1375739904 to ptr), i32 0, i32 3), align 4, !tbaa !17
  br label %78

69:                                               ; preds = %56
  store volatile i32 6, ptr @pFlash, align 4, !tbaa !16
  %70 = load volatile i32, ptr getelementptr inbounds (%struct.FLASH_TypeDef, ptr inttoptr (i64 1375739904 to ptr), i32 0, i32 27), align 4, !tbaa !19
  %71 = zext i32 %70 to i64
  %72 = or i64 %71, 2
  %73 = trunc i64 %72 to i32
  store volatile i32 %73, ptr getelementptr inbounds (%struct.FLASH_TypeDef, ptr inttoptr (i64 1375739904 to ptr), i32 0, i32 27), align 4, !tbaa !19
  %74 = load volatile i32, ptr getelementptr inbounds (%struct.FLASH_TypeDef, ptr inttoptr (i64 1375739904 to ptr), i32 0, i32 27), align 4, !tbaa !19
  %75 = zext i32 %74 to i64
  %76 = or i64 %75, 7274496
  %77 = trunc i64 %76 to i32
  store volatile i32 %77, ptr getelementptr inbounds (%struct.FLASH_TypeDef, ptr inttoptr (i64 1375739904 to ptr), i32 0, i32 27), align 4, !tbaa !19
  br label %78

78:                                               ; preds = %69, %60
  call void @__ISB()
  call void @__DSB()
  br label %79

79:                                               ; preds = %89, %78
  %80 = load ptr, ptr %10, align 8, !tbaa !9
  %81 = load volatile i32, ptr %80, align 4, !tbaa !5
  %82 = load ptr, ptr %9, align 8, !tbaa !9
  store volatile i32 %81, ptr %82, align 4, !tbaa !5
  %83 = load ptr, ptr %9, align 8, !tbaa !9
  %84 = getelementptr inbounds i32, ptr %83, i32 1
  store ptr %84, ptr %9, align 8, !tbaa !9
  %85 = load ptr, ptr %10, align 8, !tbaa !9
  %86 = getelementptr inbounds i32, ptr %85, i32 1
  store ptr %86, ptr %10, align 8, !tbaa !9
  %87 = load i8, ptr %12, align 1, !tbaa !11
  %88 = add i8 %87, -1
  store i8 %88, ptr %12, align 1, !tbaa !11
  br label %89

89:                                               ; preds = %79
  %90 = load i8, ptr %12, align 1, !tbaa !11
  %91 = zext i8 %90 to i32
  %92 = icmp ne i32 %91, 0
  br i1 %92, label %79, label %93, !llvm.loop !20

93:                                               ; preds = %89
  call void @__ISB()
  call void @__DSB()
  br label %94

94:                                               ; preds = %93, %55
  %95 = load i32, ptr %8, align 4, !tbaa !5
  store i32 %95, ptr %4, align 4
  store i32 1, ptr %13, align 4
  br label %96

96:                                               ; preds = %94, %45, %23
  call void @llvm.lifetime.end.p0(i64 1, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  %97 = load i32, ptr %4, align 4
  ret i32 %97
}

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 = { alwaysinline 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 #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, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = !{!13, !6, i64 20}
!13 = !{!"", !6, i64 0, !6, i64 4, !6, i64 8, !6, i64 12, !6, i64 16, !6, i64 20, !6, i64 24}
!14 = !{!13, !6, i64 24}
!15 = !{!13, !6, i64 16}
!16 = !{!13, !6, i64 0}
!17 = !{!18, !6, i64 12}
!18 = !{!"", !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}
!19 = !{!18, !6, i64 268}
!20 = distinct !{!20, !21}
!21 = !{!"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"

%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
declare dso_local i32 @FLASH_WaitForLastOperation(i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: alwaysinline nounwind uwtable
declare hidden void @__ISB() local_unnamed_addr #1

; Function Attrs: alwaysinline nounwind uwtable
declare hidden void @__DSB() local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local i32 @HAL_FLASH_Program_IT(i32 noundef %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = zext i32 %1 to i64
  %5 = inttoptr i64 %4 to ptr
  %6 = zext i32 %2 to i64
  %7 = inttoptr i64 %6 to ptr
  %8 = load i32, ptr getelementptr inbounds (i8, ptr @pFlash, i64 20), align 4, !tbaa !5
  %9 = icmp eq i32 %8, 1
  br i1 %9, label %44, label %10

10:                                               ; preds = %3
  store i32 1, ptr getelementptr inbounds (i8, ptr @pFlash, i64 20), align 4, !tbaa !5
  store volatile i32 0, ptr getelementptr inbounds (i8, ptr @pFlash, i64 24), align 4, !tbaa !10
  %11 = and i32 %1, -1048576
  switch i32 %11, label %44 [
    i32 134217728, label %12
    i32 135266304, label %.thread
  ]

12:                                               ; preds = %10
  %13 = tail call i32 @FLASH_WaitForLastOperation(i32 noundef 50000, i32 noundef 1)
  %.not = icmp eq i32 %13, 0
  br i1 %.not, label %17, label %15

.thread:                                          ; preds = %10
  %14 = tail call i32 @FLASH_WaitForLastOperation(i32 noundef 50000, i32 noundef 2)
  %.not28 = icmp eq i32 %14, 0
  br i1 %.not28, label %17, label %15

15:                                               ; preds = %.thread, %12
  %16 = phi i32 [ %14, %.thread ], [ %13, %12 ]
  store i32 0, ptr getelementptr inbounds (i8, ptr @pFlash, i64 20), align 4, !tbaa !5
  br label %44

17:                                               ; preds = %.thread, %12
  %.sink36 = phi i32 [ 3, %12 ], [ 6, %.thread ]
  %.sink35 = phi ptr [ inttoptr (i64 1375739916 to ptr), %12 ], [ inttoptr (i64 1375740172 to ptr), %.thread ]
  store volatile i32 %1, ptr getelementptr inbounds (i8, ptr @pFlash, i64 16), align 4, !tbaa !11
  store volatile i32 %.sink36, ptr @pFlash, align 4, !tbaa !12
  %18 = load volatile i32, ptr %.sink35, align 4, !tbaa !13
  %19 = or i32 %18, 2
  store volatile i32 %19, ptr %.sink35, align 4, !tbaa !13
  %20 = load volatile i32, ptr %.sink35, align 4, !tbaa !13
  %21 = or i32 %20, 7274496
  store volatile i32 %21, ptr %.sink35, align 4, !tbaa !13
  tail call void @__ISB()
  tail call void @__DSB()
  %22 = load volatile i32, ptr %7, align 4, !tbaa !13
  store volatile i32 %22, ptr %5, align 4, !tbaa !13
  %23 = getelementptr inbounds i8, ptr %5, i64 4
  %24 = getelementptr inbounds i8, ptr %7, i64 4
  %25 = load volatile i32, ptr %24, align 4, !tbaa !13
  store volatile i32 %25, ptr %23, align 4, !tbaa !13
  %26 = getelementptr inbounds i8, ptr %5, i64 8
  %27 = getelementptr inbounds i8, ptr %7, i64 8
  %28 = load volatile i32, ptr %27, align 4, !tbaa !13
  store volatile i32 %28, ptr %26, align 4, !tbaa !13
  %29 = getelementptr inbounds i8, ptr %5, i64 12
  %30 = getelementptr inbounds i8, ptr %7, i64 12
  %31 = load volatile i32, ptr %30, align 4, !tbaa !13
  store volatile i32 %31, ptr %29, align 4, !tbaa !13
  %32 = getelementptr inbounds i8, ptr %5, i64 16
  %33 = getelementptr inbounds i8, ptr %7, i64 16
  %34 = load volatile i32, ptr %33, align 4, !tbaa !13
  store volatile i32 %34, ptr %32, align 4, !tbaa !13
  %35 = getelementptr inbounds i8, ptr %5, i64 20
  %36 = getelementptr inbounds i8, ptr %7, i64 20
  %37 = load volatile i32, ptr %36, align 4, !tbaa !13
  store volatile i32 %37, ptr %35, align 4, !tbaa !13
  %38 = getelementptr inbounds i8, ptr %5, i64 24
  %39 = getelementptr inbounds i8, ptr %7, i64 24
  %40 = load volatile i32, ptr %39, align 4, !tbaa !13
  store volatile i32 %40, ptr %38, align 4, !tbaa !13
  %41 = getelementptr inbounds i8, ptr %5, i64 28
  %42 = getelementptr inbounds i8, ptr %7, i64 28
  %43 = load volatile i32, ptr %42, align 4, !tbaa !13
  store volatile i32 %43, ptr %41, align 4, !tbaa !13
  tail call void @__ISB()
  tail call void @__DSB()
  br label %44

44:                                               ; preds = %10, %15, %17, %3
  %.025 = phi i32 [ 2, %3 ], [ 0, %17 ], [ %16, %15 ], [ 1, %10 ]
  ret i32 %.025
}

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 = { alwaysinline 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" }

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


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,SROAPass,SimplifyCFGPass,TailCallElimPass