; LLVM IR from reazon-research/OpenArm :: control/canfd_control/Drivers/STM32H7xx_HAL_Driver/Src (stm32h7xx_hal_flash_ex)

; 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_CRCInitTypeDef = 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 }

; 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 i32 @HAL_FLASHEx_ComputeCRC(ptr noundef %0, ptr noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  %7 = call i32 @FLASH_OB_WaitForLastOperation(i32 noundef 50000)
  store i32 %7, ptr %5, align 4, !tbaa !9
  %8 = load i32, ptr %5, align 4, !tbaa !9
  %9 = icmp eq i32 %8, 0
  br i1 %9, label %10, label %99

10:                                               ; preds = %2
  %11 = load ptr, ptr %3, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.FLASH_CRCInitTypeDef, ptr %11, i32 0, i32 2
  %13 = load i32, ptr %12, align 4, !tbaa !11
  %14 = icmp eq i32 %13, 1
  br i1 %14, label %15, label %98

15:                                               ; preds = %10
  %16 = load volatile i32, ptr getelementptr inbounds (%struct.FLASH_TypeDef, ptr inttoptr (i64 1375739904 to ptr), i32 0, i32 3), align 4, !tbaa !13
  %17 = zext i32 %16 to i64
  %18 = or i64 %17, 32768
  %19 = trunc i64 %18 to i32
  store volatile i32 %19, ptr getelementptr inbounds (%struct.FLASH_TypeDef, ptr inttoptr (i64 1375739904 to ptr), i32 0, i32 3), align 4, !tbaa !13
  %20 = load volatile i32, ptr getelementptr inbounds (%struct.FLASH_TypeDef, ptr inttoptr (i64 1375739904 to ptr), i32 0, i32 5), align 4, !tbaa !15
  %21 = zext i32 %20 to i64
  %22 = or i64 %21, 402653184
  %23 = trunc i64 %22 to i32
  store volatile i32 %23, ptr getelementptr inbounds (%struct.FLASH_TypeDef, ptr inttoptr (i64 1375739904 to ptr), i32 0, i32 5), align 4, !tbaa !15
  %24 = load ptr, ptr %3, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.FLASH_CRCInitTypeDef, ptr %24, i32 0, i32 1
  %26 = load i32, ptr %25, align 4, !tbaa !16
  %27 = zext i32 %26 to i64
  %28 = or i64 131072, %27
  %29 = load ptr, ptr %3, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.FLASH_CRCInitTypeDef, ptr %29, i32 0, i32 0
  %31 = load i32, ptr %30, align 4, !tbaa !17
  %32 = zext i32 %31 to i64
  %33 = or i64 %28, %32
  %34 = load volatile i32, ptr getelementptr inbounds (%struct.FLASH_TypeDef, ptr inttoptr (i64 1375739904 to ptr), i32 0, i32 19), align 4, !tbaa !18
  %35 = zext i32 %34 to i64
  %36 = or i64 %35, %33
  %37 = trunc i64 %36 to i32
  store volatile i32 %37, ptr getelementptr inbounds (%struct.FLASH_TypeDef, ptr inttoptr (i64 1375739904 to ptr), i32 0, i32 19), align 4, !tbaa !18
  %38 = load ptr, ptr %3, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.FLASH_CRCInitTypeDef, ptr %38, i32 0, i32 0
  %40 = load i32, ptr %39, align 4, !tbaa !17
  %41 = zext i32 %40 to i64
  %42 = icmp eq i64 %41, 256
  br i1 %42, label %43, label %67

43:                                               ; preds = %15
  %44 = load volatile i32, ptr getelementptr inbounds (%struct.FLASH_TypeDef, ptr inttoptr (i64 1375739904 to ptr), i32 0, i32 19), align 4, !tbaa !18
  %45 = zext i32 %44 to i64
  %46 = or i64 %45, 1024
  %47 = trunc i64 %46 to i32
  store volatile i32 %47, ptr getelementptr inbounds (%struct.FLASH_TypeDef, ptr inttoptr (i64 1375739904 to ptr), i32 0, i32 19), align 4, !tbaa !18
  %48 = load ptr, ptr %3, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.FLASH_CRCInitTypeDef, ptr %48, i32 0, i32 3
  %50 = load i32, ptr %49, align 4, !tbaa !19
  store i32 %50, ptr %6, align 4, !tbaa !9
  br label %51

51:                                               ; preds = %63, %43
  %52 = load i32, ptr %6, align 4, !tbaa !9
  %53 = load ptr, ptr %3, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.FLASH_CRCInitTypeDef, ptr %53, i32 0, i32 4
  %55 = load i32, ptr %54, align 4, !tbaa !20
  %56 = load ptr, ptr %3, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.FLASH_CRCInitTypeDef, ptr %56, i32 0, i32 3
  %58 = load i32, ptr %57, align 4, !tbaa !19
  %59 = add i32 %55, %58
  %60 = icmp ult i32 %52, %59
  br i1 %60, label %61, label %66

61:                                               ; preds = %51
  %62 = load i32, ptr %6, align 4, !tbaa !9
  call void @FLASH_CRC_AddSector(i32 noundef %62, i32 noundef 1)
  br label %63

63:                                               ; preds = %61
  %64 = load i32, ptr %6, align 4, !tbaa !9
  %65 = add i32 %64, 1
  store i32 %65, ptr %6, align 4, !tbaa !9
  br label %51, !llvm.loop !21

66:                                               ; preds = %51
  br label %86

67:                                               ; preds = %15
  %68 = load ptr, ptr %3, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.FLASH_CRCInitTypeDef, ptr %68, i32 0, i32 0
  %70 = load i32, ptr %69, align 4, !tbaa !17
  %71 = zext i32 %70 to i64
  %72 = icmp eq i64 %71, 4194560
  br i1 %72, label %73, label %78

73:                                               ; preds = %67
  %74 = load volatile i32, ptr getelementptr inbounds (%struct.FLASH_TypeDef, ptr inttoptr (i64 1375739904 to ptr), i32 0, i32 19), align 4, !tbaa !18
  %75 = zext i32 %74 to i64
  %76 = or i64 %75, 4194304
  %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 19), align 4, !tbaa !18
  br label %85

78:                                               ; preds = %67
  %79 = load ptr, ptr %3, align 8, !tbaa !5
  %80 = getelementptr inbounds %struct.FLASH_CRCInitTypeDef, ptr %79, i32 0, i32 5
  %81 = load i32, ptr %80, align 4, !tbaa !23
  %82 = load ptr, ptr %3, align 8, !tbaa !5
  %83 = getelementptr inbounds %struct.FLASH_CRCInitTypeDef, ptr %82, i32 0, i32 6
  %84 = load i32, ptr %83, align 4, !tbaa !24
  call void @FLASH_CRC_SelectAddress(i32 noundef %81, i32 noundef %84, i32 noundef 1)
  br label %85

85:                                               ; preds = %78, %73
  br label %86

86:                                               ; preds = %85, %66
  %87 = load volatile i32, ptr getelementptr inbounds (%struct.FLASH_TypeDef, ptr inttoptr (i64 1375739904 to ptr), i32 0, i32 19), align 4, !tbaa !18
  %88 = zext i32 %87 to i64
  %89 = or i64 %88, 65536
  %90 = trunc i64 %89 to i32
  store volatile i32 %90, ptr getelementptr inbounds (%struct.FLASH_TypeDef, ptr inttoptr (i64 1375739904 to ptr), i32 0, i32 19), align 4, !tbaa !18
  %91 = call i32 @FLASH_CRC_WaitForLastOperation(i32 noundef 50000, i32 noundef 1)
  store i32 %91, ptr %5, align 4, !tbaa !9
  %92 = load volatile i32, ptr getelementptr inbounds (%struct.FLASH_TypeDef, ptr inttoptr (i64 1375739904 to ptr), i32 0, i32 22), align 4, !tbaa !25
  %93 = load ptr, ptr %4, align 8, !tbaa !5
  store i32 %92, ptr %93, align 4, !tbaa !9
  %94 = load volatile i32, ptr getelementptr inbounds (%struct.FLASH_TypeDef, ptr inttoptr (i64 1375739904 to ptr), i32 0, i32 3), align 4, !tbaa !13
  %95 = zext i32 %94 to i64
  %96 = and i64 %95, -32769
  %97 = trunc i64 %96 to i32
  store volatile i32 %97, ptr getelementptr inbounds (%struct.FLASH_TypeDef, ptr inttoptr (i64 1375739904 to ptr), i32 0, i32 3), align 4, !tbaa !13
  store volatile i32 402653184, ptr getelementptr inbounds (%struct.FLASH_TypeDef, ptr inttoptr (i64 1375739904 to ptr), i32 0, i32 5), align 4, !tbaa !15
  br label %98

98:                                               ; preds = %86, %10
  br label %99

99:                                               ; preds = %98, %2
  %100 = load i32, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  ret i32 %100
}

declare i32 @FLASH_OB_WaitForLastOperation(i32 noundef) #2

; Function Attrs: nounwind uwtable
declare hidden void @FLASH_CRC_AddSector(i32 noundef, i32 noundef) #1

; Function Attrs: nounwind uwtable
declare hidden void @FLASH_CRC_SelectAddress(i32 noundef, i32 noundef, i32 noundef) #1

declare i32 @FLASH_CRC_WaitForLastOperation(i32 noundef, i32 noundef) #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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 8}
!12 = !{!"", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20, !10, i64 24}
!13 = !{!14, !10, i64 12}
!14 = !{!"", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20, !10, i64 24, !10, i64 28, !10, i64 32, !10, i64 36, !10, i64 40, !10, i64 44, !10, i64 48, !10, i64 52, !10, i64 56, !10, i64 60, !10, i64 64, !10, i64 68, !7, i64 72, !10, i64 80, !10, i64 84, !10, i64 88, !10, i64 92, !10, i64 96, !7, i64 100, !10, i64 112, !10, i64 116}
!15 = !{!14, !10, i64 20}
!16 = !{!12, !10, i64 4}
!17 = !{!12, !10, i64 0}
!18 = !{!14, !10, i64 80}
!19 = !{!12, !10, i64 12}
!20 = !{!12, !10, i64 16}
!21 = distinct !{!21, !22}
!22 = !{!"llvm.loop.mustprogress"}
!23 = !{!12, !10, i64 20}
!24 = !{!12, !10, i64 24}
!25 = !{!14, !10, i64 92}


; 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 i32 @HAL_FLASHEx_ComputeCRC(ptr nocapture noundef readonly %0, ptr nocapture noundef writeonly %1) local_unnamed_addr #0 {
  %3 = tail call i32 @FLASH_OB_WaitForLastOperation(i32 noundef 50000) #2
  %4 = icmp eq i32 %3, 0
  br i1 %4, label %5, label %49

5:                                                ; preds = %2
  %6 = getelementptr inbounds i8, ptr %0, i64 8
  %7 = load i32, ptr %6, align 4, !tbaa !5
  %8 = icmp eq i32 %7, 1
  br i1 %8, label %9, label %49

9:                                                ; preds = %5
  %10 = load volatile i32, ptr inttoptr (i64 1375739916 to ptr), align 4, !tbaa !10
  %11 = or i32 %10, 32768
  store volatile i32 %11, ptr inttoptr (i64 1375739916 to ptr), align 4, !tbaa !10
  %12 = load volatile i32, ptr inttoptr (i64 1375739924 to ptr), align 4, !tbaa !12
  %13 = or i32 %12, 402653184
  store volatile i32 %13, ptr inttoptr (i64 1375739924 to ptr), align 4, !tbaa !12
  %14 = getelementptr inbounds i8, ptr %0, i64 4
  %15 = load i32, ptr %14, align 4, !tbaa !13
  %16 = load i32, ptr %0, align 4, !tbaa !14
  %17 = load volatile i32, ptr inttoptr (i64 1375739984 to ptr), align 16, !tbaa !15
  %18 = or i32 %15, %17
  %19 = or i32 %18, %16
  %20 = or i32 %19, 131072
  store volatile i32 %20, ptr inttoptr (i64 1375739984 to ptr), align 16, !tbaa !15
  switch i32 %16, label %38 [
    i32 256, label %21
    i32 4194560, label %35
  ]

21:                                               ; preds = %9
  %22 = load volatile i32, ptr inttoptr (i64 1375739984 to ptr), align 16, !tbaa !15
  %23 = or i32 %22, 1024
  store volatile i32 %23, ptr inttoptr (i64 1375739984 to ptr), align 16, !tbaa !15
  %24 = getelementptr inbounds i8, ptr %0, i64 12
  %25 = load i32, ptr %24, align 4, !tbaa !16
  %26 = getelementptr inbounds i8, ptr %0, i64 16
  %27 = load i32, ptr %26, align 4, !tbaa !17
  %28 = add i32 %25, %27
  %29 = icmp ult i32 %25, %28
  br i1 %29, label %.lr.ph, label %.loopexit

.lr.ph:                                           ; preds = %21, %.lr.ph
  %.018 = phi i32 [ %30, %.lr.ph ], [ %25, %21 ]
  tail call void @FLASH_CRC_AddSector(i32 noundef %.018, i32 noundef 1)
  %30 = add nuw i32 %.018, 1
  %31 = load i32, ptr %26, align 4, !tbaa !17
  %32 = load i32, ptr %24, align 4, !tbaa !16
  %33 = add i32 %32, %31
  %34 = icmp ult i32 %30, %33
  br i1 %34, label %.lr.ph, label %.loopexit, !llvm.loop !18

35:                                               ; preds = %9
  %36 = load volatile i32, ptr inttoptr (i64 1375739984 to ptr), align 16, !tbaa !15
  %37 = or i32 %36, 4194304
  store volatile i32 %37, ptr inttoptr (i64 1375739984 to ptr), align 16, !tbaa !15
  br label %.loopexit

38:                                               ; preds = %9
  %39 = getelementptr inbounds i8, ptr %0, i64 20
  %40 = load i32, ptr %39, align 4, !tbaa !20
  %41 = getelementptr inbounds i8, ptr %0, i64 24
  %42 = load i32, ptr %41, align 4, !tbaa !21
  tail call void @FLASH_CRC_SelectAddress(i32 noundef %40, i32 noundef %42, i32 noundef 1)
  br label %.loopexit

.loopexit:                                        ; preds = %.lr.ph, %21, %35, %38
  %43 = load volatile i32, ptr inttoptr (i64 1375739984 to ptr), align 16, !tbaa !15
  %44 = or i32 %43, 65536
  store volatile i32 %44, ptr inttoptr (i64 1375739984 to ptr), align 16, !tbaa !15
  %45 = tail call i32 @FLASH_CRC_WaitForLastOperation(i32 noundef 50000, i32 noundef 1) #2
  %46 = load volatile i32, ptr inttoptr (i64 1375739996 to ptr), align 4, !tbaa !22
  store i32 %46, ptr %1, align 4, !tbaa !23
  %47 = load volatile i32, ptr inttoptr (i64 1375739916 to ptr), align 4, !tbaa !10
  %48 = and i32 %47, -32769
  store volatile i32 %48, ptr inttoptr (i64 1375739916 to ptr), align 4, !tbaa !10
  store volatile i32 402653184, ptr inttoptr (i64 1375739924 to ptr), align 4, !tbaa !12
  br label %49

49:                                               ; preds = %5, %.loopexit, %2
  %.015 = phi i32 [ %45, %.loopexit ], [ 0, %5 ], [ %3, %2 ]
  ret i32 %.015
}

declare i32 @FLASH_OB_WaitForLastOperation(i32 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare hidden void @FLASH_CRC_AddSector(i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare hidden void @FLASH_CRC_SelectAddress(i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #0

declare i32 @FLASH_CRC_WaitForLastOperation(i32 noundef, i32 noundef) 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 8}
!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 = !{!11, !7, i64 12}
!11 = !{!"", !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}
!12 = !{!11, !7, i64 20}
!13 = !{!6, !7, i64 4}
!14 = !{!6, !7, i64 0}
!15 = !{!11, !7, i64 80}
!16 = !{!6, !7, i64 12}
!17 = !{!6, !7, i64 16}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}
!20 = !{!6, !7, i64 20}
!21 = !{!6, !7, i64 24}
!22 = !{!11, !7, i64 92}
!23 = !{!7, !7, i64 0}


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