; 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.OSPI_MemoryMappedTypeDef = type { 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_MemoryMapped(ptr noundef %0, ptr noundef %1) #2 {
  %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 @HAL_GetTick()
  store i32 %7, ptr %6, align 4, !tbaa !9
  %8 = load ptr, ptr %3, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct.OSPI_HandleTypeDef, ptr %8, i32 0, i32 6
  %10 = load volatile i32, ptr %9, align 8, !tbaa !11
  %11 = icmp eq i32 %10, 4
  br i1 %11, label %12, label %68

12:                                               ; preds = %2
  %13 = load ptr, ptr %3, align 8, !tbaa !5
  %14 = load i32, ptr %6, align 4, !tbaa !9
  %15 = load ptr, ptr %3, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.OSPI_HandleTypeDef, ptr %15, i32 0, i32 8
  %17 = load i32, ptr %16, align 8, !tbaa !14
  %18 = call i32 @OSPI_WaitFlagStateUntilTimeout(ptr noundef %13, i32 noundef 32, i32 noundef 0, i32 noundef %14, i32 noundef %17)
  store i32 %18, ptr %5, align 4, !tbaa !9
  %19 = load i32, ptr %5, align 4, !tbaa !9
  %20 = icmp eq i32 %19, 0
  br i1 %20, label %21, label %67

21:                                               ; preds = %12
  %22 = load ptr, ptr %3, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.OSPI_HandleTypeDef, ptr %22, i32 0, i32 6
  store volatile i32 136, ptr %23, align 8, !tbaa !11
  %24 = load ptr, ptr %4, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.OSPI_MemoryMappedTypeDef, ptr %24, i32 0, i32 0
  %26 = load i32, ptr %25, align 4, !tbaa !15
  %27 = icmp eq i32 %26, 8
  br i1 %27, label %28, label %48

28:                                               ; preds = %21
  %29 = load ptr, ptr %4, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.OSPI_MemoryMappedTypeDef, ptr %29, i32 0, i32 1
  %31 = load i32, ptr %30, align 4, !tbaa !17
  %32 = load ptr, ptr %3, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.OSPI_HandleTypeDef, ptr %32, i32 0, i32 0
  %34 = load ptr, ptr %33, align 8, !tbaa !18
  %35 = getelementptr inbounds %struct.OCTOSPI_TypeDef, ptr %34, i32 0, i32 30
  store volatile i32 %31, ptr %35, align 4, !tbaa !19
  %36 = load ptr, ptr %3, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.OSPI_HandleTypeDef, ptr %36, i32 0, i32 0
  %38 = load ptr, ptr %37, align 8, !tbaa !18
  %39 = getelementptr inbounds %struct.OCTOSPI_TypeDef, ptr %38, i32 0, i32 8
  store volatile i32 16, ptr %39, align 4, !tbaa !21
  %40 = load ptr, ptr %3, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.OSPI_HandleTypeDef, ptr %40, i32 0, i32 0
  %42 = load ptr, ptr %41, align 8, !tbaa !18
  %43 = getelementptr inbounds %struct.OCTOSPI_TypeDef, ptr %42, i32 0, i32 0
  %44 = load volatile i32, ptr %43, align 4, !tbaa !22
  %45 = zext i32 %44 to i64
  %46 = or i64 %45, 1048576
  %47 = trunc i64 %46 to i32
  store volatile i32 %47, ptr %43, align 4, !tbaa !22
  br label %48

48:                                               ; preds = %28, %21
  %49 = load ptr, ptr %3, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.OSPI_HandleTypeDef, ptr %49, i32 0, i32 0
  %51 = load ptr, ptr %50, align 8, !tbaa !18
  %52 = getelementptr inbounds %struct.OCTOSPI_TypeDef, ptr %51, i32 0, i32 0
  %53 = load volatile i32, ptr %52, align 4, !tbaa !22
  %54 = zext i32 %53 to i64
  %55 = and i64 %54, -805306377
  %56 = load ptr, ptr %4, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.OSPI_MemoryMappedTypeDef, ptr %56, i32 0, i32 0
  %58 = load i32, ptr %57, align 4, !tbaa !15
  %59 = or i32 %58, 805306368
  %60 = zext i32 %59 to i64
  %61 = or i64 %55, %60
  %62 = trunc i64 %61 to i32
  %63 = load ptr, ptr %3, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.OSPI_HandleTypeDef, ptr %63, i32 0, i32 0
  %65 = load ptr, ptr %64, align 8, !tbaa !18
  %66 = getelementptr inbounds %struct.OCTOSPI_TypeDef, ptr %65, i32 0, i32 0
  store volatile i32 %62, ptr %66, align 4, !tbaa !22
  br label %67

67:                                               ; preds = %48, %12
  br label %71

68:                                               ; preds = %2
  store i32 1, ptr %5, align 4, !tbaa !9
  %69 = load ptr, ptr %3, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct.OSPI_HandleTypeDef, ptr %69, i32 0, i32 7
  store volatile i32 16, ptr %70, align 4, !tbaa !23
  br label %71

71:                                               ; preds = %68, %67
  %72 = 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 %72
}

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, !10, i64 104}
!15 = !{!16, !10, i64 0}
!16 = !{!"", !10, i64 0, !10, i64 4}
!17 = !{!16, !10, i64 4}
!18 = !{!12, !6, i64 0}
!19 = !{!20, !10, i64 304}
!20 = !{!"", !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}
!21 = !{!20, !10, i64 36}
!22 = !{!20, !10, i64 0}
!23 = !{!12, !10, i64 100}


; 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_MemoryMapped(ptr noundef %0, ptr nocapture noundef readonly %1) local_unnamed_addr #1 {
  %3 = tail call i32 @HAL_GetTick() #2
  %4 = getelementptr inbounds i8, ptr %0, i64 96
  %5 = load volatile i32, ptr %4, align 8, !tbaa !5
  %6 = icmp eq i32 %5, 4
  br i1 %6, label %7, label %27

7:                                                ; preds = %2
  %8 = getelementptr inbounds i8, ptr %0, i64 104
  %9 = load i32, ptr %8, align 8, !tbaa !12
  %10 = tail call i32 @OSPI_WaitFlagStateUntilTimeout(ptr noundef nonnull %0, i32 noundef 32, i32 noundef 0, i32 noundef %3, i32 noundef %9)
  %11 = icmp eq i32 %10, 0
  br i1 %11, label %12, label %29

12:                                               ; preds = %7
  store volatile i32 136, ptr %4, align 8, !tbaa !5
  %13 = load i32, ptr %1, align 4, !tbaa !13
  %14 = icmp eq i32 %13, 8
  %.pre = load ptr, ptr %0, align 8, !tbaa !15
  br i1 %14, label %15, label %22

15:                                               ; preds = %12
  %16 = getelementptr inbounds i8, ptr %1, i64 4
  %17 = load i32, ptr %16, align 4, !tbaa !16
  %18 = getelementptr inbounds i8, ptr %.pre, i64 304
  store volatile i32 %17, ptr %18, align 4, !tbaa !17
  %19 = getelementptr inbounds i8, ptr %.pre, i64 36
  store volatile i32 16, ptr %19, align 4, !tbaa !19
  %20 = load volatile i32, ptr %.pre, align 4, !tbaa !20
  %21 = or i32 %20, 1048576
  store volatile i32 %21, ptr %.pre, align 4, !tbaa !20
  br label %22

22:                                               ; preds = %15, %12
  %23 = load volatile i32, ptr %.pre, align 4, !tbaa !20
  %24 = and i32 %23, -805306377
  %25 = or i32 %13, %24
  %26 = or i32 %25, 805306368
  store volatile i32 %26, ptr %.pre, align 4, !tbaa !20
  br label %29

27:                                               ; preds = %2
  %28 = getelementptr inbounds i8, ptr %0, i64 100
  store volatile i32 16, ptr %28, align 4, !tbaa !21
  br label %29

29:                                               ; preds = %7, %22, %27
  %.0 = phi i32 [ 0, %22 ], [ %10, %7 ], [ 1, %27 ]
  ret i32 %.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, !11, i64 104}
!13 = !{!14, !11, i64 0}
!14 = !{!"", !11, i64 0, !11, i64 4}
!15 = !{!6, !7, i64 0}
!16 = !{!14, !11, i64 4}
!17 = !{!18, !11, i64 304}
!18 = !{!"", !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}
!19 = !{!18, !11, i64 36}
!20 = !{!18, !11, i64 0}
!21 = !{!6, !11, i64 100}


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