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

; 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.OSPI_HandleTypeDef = type { ptr, %struct.OSPI_InitTypeDef, ptr, i32, i32, ptr, i32, i32, i32 }
%struct.OSPI_InitTypeDef = type { i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32 }
%struct.OCTOSPI_TypeDef = type { i32, i32, i32, i32, i32, i32, [2 x i32], i32, i32, [6 x i32], i32, i32, i32, i32, i32, [11 x i32], i32, i32, i32, i32, i32, [27 x i32], i32, i32, i32, i32, i32, [3 x i32], i32, [3 x i32], i32, [3 x i32], i32, i32, i32, i32, i32, [3 x i32], i32, [7 x i32], i32, i32, i32, i32, i32, [3 x i32], i32, [23 x i32], i32, [122 x i32], i32, i32, i32, i32 }

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

declare i32 @HAL_GetTick() #1

; Function Attrs: nounwind uwtable
declare hidden i32 @OSPI_WaitFlagStateUntilTimeout(ptr noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef) #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_OSPI_Abort(ptr noundef %0) #2 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  store i32 0, ptr %3, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  %6 = call i32 @HAL_GetTick()
  store i32 %6, ptr %5, align 4, !tbaa !9
  %7 = load ptr, ptr %2, align 8, !tbaa !5
  %8 = getelementptr inbounds %struct.OSPI_HandleTypeDef, ptr %7, i32 0, i32 6
  %9 = load volatile i32, ptr %8, align 8, !tbaa !11
  store i32 %9, ptr %4, align 4, !tbaa !9
  %10 = load i32, ptr %4, align 4, !tbaa !9
  %11 = and i32 %10, 8
  %12 = icmp ne i32 %11, 0
  br i1 %12, label %17, label %13

13:                                               ; preds = %1
  %14 = load i32, ptr %4, align 4, !tbaa !9
  %15 = and i32 %14, 4
  %16 = icmp ne i32 %15, 0
  br i1 %16, label %17, label %96

17:                                               ; preds = %13, %1
  %18 = load ptr, ptr %2, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.OSPI_HandleTypeDef, ptr %18, i32 0, i32 0
  %20 = load ptr, ptr %19, align 8, !tbaa !14
  %21 = getelementptr inbounds %struct.OCTOSPI_TypeDef, ptr %20, i32 0, i32 0
  %22 = load volatile i32, ptr %21, align 4, !tbaa !15
  %23 = zext i32 %22 to i64
  %24 = and i64 %23, 4
  %25 = icmp ne i64 %24, 0
  br i1 %25, label %26, label %45

26:                                               ; preds = %17
  %27 = load ptr, ptr %2, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.OSPI_HandleTypeDef, ptr %27, i32 0, i32 0
  %29 = load ptr, ptr %28, align 8, !tbaa !14
  %30 = getelementptr inbounds %struct.OCTOSPI_TypeDef, ptr %29, i32 0, i32 0
  %31 = load volatile i32, ptr %30, align 4, !tbaa !15
  %32 = zext i32 %31 to i64
  %33 = and i64 %32, -5
  %34 = trunc i64 %33 to i32
  store volatile i32 %34, ptr %30, align 4, !tbaa !15
  %35 = load ptr, ptr %2, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.OSPI_HandleTypeDef, ptr %35, i32 0, i32 5
  %37 = load ptr, ptr %36, align 8, !tbaa !17
  %38 = call i32 @HAL_MDMA_Abort(ptr noundef %37)
  store i32 %38, ptr %3, align 4, !tbaa !9
  %39 = load i32, ptr %3, align 4, !tbaa !9
  %40 = icmp ne i32 %39, 0
  br i1 %40, label %41, label %44

41:                                               ; preds = %26
  %42 = load ptr, ptr %2, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.OSPI_HandleTypeDef, ptr %42, i32 0, i32 7
  store volatile i32 4, ptr %43, align 4, !tbaa !18
  br label %44

44:                                               ; preds = %41, %26
  br label %45

45:                                               ; preds = %44, %17
  %46 = load ptr, ptr %2, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.OSPI_HandleTypeDef, ptr %46, i32 0, i32 0
  %48 = load ptr, ptr %47, align 8, !tbaa !14
  %49 = getelementptr inbounds %struct.OCTOSPI_TypeDef, ptr %48, i32 0, i32 7
  %50 = load volatile i32, ptr %49, align 4, !tbaa !19
  %51 = zext i32 %50 to i64
  %52 = and i64 %51, 32
  %53 = icmp ne i64 %52, 0
  %54 = zext i1 %53 to i64
  %55 = select i1 %53, i32 1, i32 0
  %56 = icmp ne i32 %55, 0
  br i1 %56, label %57, label %92

57:                                               ; preds = %45
  %58 = load ptr, ptr %2, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.OSPI_HandleTypeDef, ptr %58, i32 0, i32 0
  %60 = load ptr, ptr %59, align 8, !tbaa !14
  %61 = getelementptr inbounds %struct.OCTOSPI_TypeDef, ptr %60, i32 0, i32 0
  %62 = load volatile i32, ptr %61, align 4, !tbaa !15
  %63 = zext i32 %62 to i64
  %64 = or i64 %63, 2
  %65 = trunc i64 %64 to i32
  store volatile i32 %65, ptr %61, align 4, !tbaa !15
  %66 = load ptr, ptr %2, align 8, !tbaa !5
  %67 = load i32, ptr %5, align 4, !tbaa !9
  %68 = load ptr, ptr %2, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.OSPI_HandleTypeDef, ptr %68, i32 0, i32 8
  %70 = load i32, ptr %69, align 8, !tbaa !20
  %71 = call i32 @OSPI_WaitFlagStateUntilTimeout(ptr noundef %66, i32 noundef 2, i32 noundef 1, i32 noundef %67, i32 noundef %70)
  store i32 %71, ptr %3, align 4, !tbaa !9
  %72 = load i32, ptr %3, align 4, !tbaa !9
  %73 = icmp eq i32 %72, 0
  br i1 %73, label %74, label %91

74:                                               ; preds = %57
  %75 = load ptr, ptr %2, align 8, !tbaa !5
  %76 = getelementptr inbounds %struct.OSPI_HandleTypeDef, ptr %75, i32 0, i32 0
  %77 = load ptr, ptr %76, align 8, !tbaa !14
  %78 = getelementptr inbounds %struct.OCTOSPI_TypeDef, ptr %77, i32 0, i32 8
  store volatile i32 2, ptr %78, align 4, !tbaa !21
  %79 = load ptr, ptr %2, align 8, !tbaa !5
  %80 = load i32, ptr %5, align 4, !tbaa !9
  %81 = load ptr, ptr %2, align 8, !tbaa !5
  %82 = getelementptr inbounds %struct.OSPI_HandleTypeDef, ptr %81, i32 0, i32 8
  %83 = load i32, ptr %82, align 8, !tbaa !20
  %84 = call i32 @OSPI_WaitFlagStateUntilTimeout(ptr noundef %79, i32 noundef 32, i32 noundef 0, i32 noundef %80, i32 noundef %83)
  store i32 %84, ptr %3, align 4, !tbaa !9
  %85 = load i32, ptr %3, align 4, !tbaa !9
  %86 = icmp eq i32 %85, 0
  br i1 %86, label %87, label %90

87:                                               ; preds = %74
  %88 = load ptr, ptr %2, align 8, !tbaa !5
  %89 = getelementptr inbounds %struct.OSPI_HandleTypeDef, ptr %88, i32 0, i32 6
  store volatile i32 2, ptr %89, align 8, !tbaa !11
  br label %90

90:                                               ; preds = %87, %74
  br label %91

91:                                               ; preds = %90, %57
  br label %95

92:                                               ; preds = %45
  %93 = load ptr, ptr %2, align 8, !tbaa !5
  %94 = getelementptr inbounds %struct.OSPI_HandleTypeDef, ptr %93, i32 0, i32 6
  store volatile i32 2, ptr %94, align 8, !tbaa !11
  br label %95

95:                                               ; preds = %92, %91
  br label %99

96:                                               ; preds = %13
  store i32 1, ptr %3, align 4, !tbaa !9
  %97 = load ptr, ptr %2, align 8, !tbaa !5
  %98 = getelementptr inbounds %struct.OSPI_HandleTypeDef, ptr %97, i32 0, i32 7
  store volatile i32 16, ptr %98, align 4, !tbaa !18
  br label %99

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

declare i32 @HAL_MDMA_Abort(ptr noundef) #1

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 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 = !{!"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 96}
!12 = !{!"", !6, i64 0, !13, i64 8, !6, i64 72, !10, i64 80, !10, i64 84, !6, i64 88, !10, i64 96, !10, i64 100, !10, i64 104}
!13 = !{!"", !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}
!14 = !{!12, !6, i64 0}
!15 = !{!16, !10, i64 0}
!16 = !{!"", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20, !7, i64 24, !10, i64 32, !10, i64 36, !7, i64 40, !10, i64 64, !10, i64 68, !10, i64 72, !10, i64 76, !10, i64 80, !7, i64 84, !10, i64 128, !10, i64 132, !10, i64 136, !10, i64 140, !10, i64 144, !7, i64 148, !10, i64 256, !10, i64 260, !10, i64 264, !10, i64 268, !10, i64 272, !7, i64 276, !10, i64 288, !7, i64 292, !10, i64 304, !7, i64 308, !10, i64 320, !10, i64 324, !10, i64 328, !10, i64 332, !10, i64 336, !7, i64 340, !10, i64 352, !7, i64 356, !10, i64 384, !10, i64 388, !10, i64 392, !10, i64 396, !10, i64 400, !7, i64 404, !10, i64 416, !7, i64 420, !10, i64 512, !7, i64 516, !10, i64 1004, !10, i64 1008, !10, i64 1012, !10, i64 1016}
!17 = !{!12, !6, i64 88}
!18 = !{!12, !10, i64 100}
!19 = !{!16, !10, i64 32}
!20 = !{!12, !10, i64 104}
!21 = !{!16, !10, i64 36}


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

declare i32 @HAL_GetTick() local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare hidden i32 @OSPI_WaitFlagStateUntilTimeout(ptr noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local i32 @HAL_OSPI_Abort(ptr noundef %0) local_unnamed_addr #1 {
  %2 = tail call i32 @HAL_GetTick() #2
  %3 = getelementptr inbounds i8, ptr %0, i64 96
  %4 = load volatile i32, ptr %3, align 8, !tbaa !5
  %5 = and i32 %4, 12
  %or.cond = icmp eq i32 %5, 0
  br i1 %or.cond, label %38, label %6

6:                                                ; preds = %1
  %7 = load ptr, ptr %0, align 8, !tbaa !12
  %8 = load volatile i32, ptr %7, align 4, !tbaa !13
  %9 = and i32 %8, 4
  %.not28 = icmp eq i32 %9, 0
  br i1 %.not28, label %18, label %10

10:                                               ; preds = %6
  %11 = load volatile i32, ptr %7, align 4, !tbaa !13
  %12 = and i32 %11, -5
  store volatile i32 %12, ptr %7, align 4, !tbaa !13
  %13 = getelementptr inbounds i8, ptr %0, i64 88
  %14 = load ptr, ptr %13, align 8, !tbaa !15
  %15 = tail call i32 @HAL_MDMA_Abort(ptr noundef %14) #2
  %.not29 = icmp eq i32 %15, 0
  br i1 %.not29, label %18, label %16

16:                                               ; preds = %10
  %17 = getelementptr inbounds i8, ptr %0, i64 100
  store volatile i32 4, ptr %17, align 4, !tbaa !16
  br label %18

18:                                               ; preds = %10, %16, %6
  %.0 = phi i32 [ %15, %16 ], [ 0, %10 ], [ 0, %6 ]
  %19 = load ptr, ptr %0, align 8, !tbaa !12
  %20 = getelementptr inbounds i8, ptr %19, i64 32
  %21 = load volatile i32, ptr %20, align 4, !tbaa !17
  %22 = and i32 %21, 32
  %.not30 = icmp eq i32 %22, 0
  br i1 %.not30, label %37, label %23

23:                                               ; preds = %18
  %24 = load volatile i32, ptr %19, align 4, !tbaa !13
  %25 = or i32 %24, 2
  store volatile i32 %25, ptr %19, align 4, !tbaa !13
  %26 = getelementptr inbounds i8, ptr %0, i64 104
  %27 = load i32, ptr %26, align 8, !tbaa !18
  %28 = tail call i32 @OSPI_WaitFlagStateUntilTimeout(ptr noundef nonnull %0, i32 noundef 2, i32 noundef 1, i32 noundef %2, i32 noundef %27)
  %29 = icmp eq i32 %28, 0
  br i1 %29, label %30, label %40

30:                                               ; preds = %23
  %31 = load ptr, ptr %0, align 8, !tbaa !12
  %32 = getelementptr inbounds i8, ptr %31, i64 36
  store volatile i32 2, ptr %32, align 4, !tbaa !19
  %33 = load i32, ptr %26, align 8, !tbaa !18
  %34 = tail call i32 @OSPI_WaitFlagStateUntilTimeout(ptr noundef nonnull %0, i32 noundef 32, i32 noundef 0, i32 noundef %2, i32 noundef %33)
  %35 = icmp eq i32 %34, 0
  br i1 %35, label %36, label %40

36:                                               ; preds = %30
  store volatile i32 2, ptr %3, align 8, !tbaa !5
  br label %40

37:                                               ; preds = %18
  store volatile i32 2, ptr %3, align 8, !tbaa !5
  br label %40

38:                                               ; preds = %1
  %39 = getelementptr inbounds i8, ptr %0, i64 100
  store volatile i32 16, ptr %39, align 4, !tbaa !16
  br label %40

40:                                               ; preds = %37, %30, %36, %23, %38
  %.1 = phi i32 [ 0, %36 ], [ %34, %30 ], [ %28, %23 ], [ %.0, %37 ], [ 1, %38 ]
  ret i32 %.1
}

declare i32 @HAL_MDMA_Abort(ptr noundef) local_unnamed_addr #0

attributes #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 = { 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 = { 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, !11, i64 96}
!6 = !{!"", !7, i64 0, !10, i64 8, !7, i64 72, !11, i64 80, !11, i64 84, !7, i64 88, !11, i64 96, !11, i64 100, !11, i64 104}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"", !11, i64 0, !11, i64 4, !11, i64 8, !11, i64 12, !11, i64 16, !11, i64 20, !11, i64 24, !11, i64 28, !11, i64 32, !11, i64 36, !11, i64 40, !11, i64 44, !11, i64 48, !11, i64 52, !11, i64 56}
!11 = !{!"int", !8, i64 0}
!12 = !{!6, !7, i64 0}
!13 = !{!14, !11, i64 0}
!14 = !{!"", !11, i64 0, !11, i64 4, !11, i64 8, !11, i64 12, !11, i64 16, !11, i64 20, !8, i64 24, !11, i64 32, !11, i64 36, !8, i64 40, !11, i64 64, !11, i64 68, !11, i64 72, !11, i64 76, !11, i64 80, !8, i64 84, !11, i64 128, !11, i64 132, !11, i64 136, !11, i64 140, !11, i64 144, !8, i64 148, !11, i64 256, !11, i64 260, !11, i64 264, !11, i64 268, !11, i64 272, !8, i64 276, !11, i64 288, !8, i64 292, !11, i64 304, !8, i64 308, !11, i64 320, !11, i64 324, !11, i64 328, !11, i64 332, !11, i64 336, !8, i64 340, !11, i64 352, !8, i64 356, !11, i64 384, !11, i64 388, !11, i64 392, !11, i64 396, !11, i64 400, !8, i64 404, !11, i64 416, !8, i64 420, !11, i64 512, !8, i64 516, !11, i64 1004, !11, i64 1008, !11, i64 1012, !11, i64 1016}
!15 = !{!6, !7, i64 88}
!16 = !{!6, !11, i64 100}
!17 = !{!14, !11, i64 32}
!18 = !{!6, !11, i64 104}
!19 = !{!14, !11, i64 36}


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