; 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 }
%struct.OSPI_HyperbusCmdTypeDef = type { 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_HyperbusCmd(ptr noundef %0, ptr noundef %1, i32 noundef %2) #2 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store i32 %2, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  %9 = call i32 @HAL_GetTick()
  store i32 %9, ptr %8, align 4, !tbaa !9
  %10 = load ptr, ptr %4, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.OSPI_HandleTypeDef, ptr %10, i32 0, i32 6
  %12 = load volatile i32, ptr %11, align 8, !tbaa !11
  %13 = icmp eq i32 %12, 2
  br i1 %13, label %14, label %112

14:                                               ; preds = %3
  %15 = load ptr, ptr %4, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.OSPI_HandleTypeDef, ptr %15, i32 0, i32 1
  %17 = getelementptr inbounds %struct.OSPI_InitTypeDef, ptr %16, i32 0, i32 2
  %18 = load i32, ptr %17, align 8, !tbaa !14
  %19 = icmp eq i32 %18, 67108864
  br i1 %19, label %20, label %112

20:                                               ; preds = %14
  %21 = load ptr, ptr %4, align 8, !tbaa !5
  %22 = load i32, ptr %8, align 4, !tbaa !9
  %23 = load i32, ptr %6, align 4, !tbaa !9
  %24 = call i32 @OSPI_WaitFlagStateUntilTimeout(ptr noundef %21, i32 noundef 32, i32 noundef 0, i32 noundef %22, i32 noundef %23)
  store i32 %24, ptr %7, align 4, !tbaa !9
  %25 = load i32, ptr %7, align 4, !tbaa !9
  %26 = icmp eq i32 %25, 0
  br i1 %26, label %27, label %111

27:                                               ; preds = %20
  %28 = load ptr, ptr %4, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.OSPI_HandleTypeDef, ptr %28, i32 0, i32 0
  %30 = load ptr, ptr %29, align 8, !tbaa !15
  %31 = getelementptr inbounds %struct.OCTOSPI_TypeDef, ptr %30, i32 0, i32 0
  %32 = load volatile i32, ptr %31, align 4, !tbaa !16
  %33 = zext i32 %32 to i64
  %34 = and i64 %33, -805306369
  %35 = or i64 %34, 0
  %36 = trunc i64 %35 to i32
  %37 = load ptr, ptr %4, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.OSPI_HandleTypeDef, ptr %37, i32 0, i32 0
  %39 = load ptr, ptr %38, align 8, !tbaa !15
  %40 = getelementptr inbounds %struct.OCTOSPI_TypeDef, ptr %39, i32 0, i32 0
  store volatile i32 %36, ptr %40, align 4, !tbaa !16
  %41 = load ptr, ptr %4, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.OSPI_HandleTypeDef, ptr %41, i32 0, i32 0
  %43 = load ptr, ptr %42, align 8, !tbaa !15
  %44 = getelementptr inbounds %struct.OCTOSPI_TypeDef, ptr %43, i32 0, i32 2
  %45 = load volatile i32, ptr %44, align 4, !tbaa !18
  %46 = zext i32 %45 to i64
  %47 = and i64 %46, -16777217
  %48 = load ptr, ptr %5, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.OSPI_HyperbusCmdTypeDef, ptr %48, i32 0, i32 0
  %50 = load i32, ptr %49, align 4, !tbaa !19
  %51 = zext i32 %50 to i64
  %52 = or i64 %47, %51
  %53 = trunc i64 %52 to i32
  %54 = load ptr, ptr %4, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.OSPI_HandleTypeDef, ptr %54, i32 0, i32 0
  %56 = load ptr, ptr %55, align 8, !tbaa !15
  %57 = getelementptr inbounds %struct.OCTOSPI_TypeDef, ptr %56, i32 0, i32 2
  store volatile i32 %53, ptr %57, align 4, !tbaa !18
  %58 = load ptr, ptr %5, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.OSPI_HyperbusCmdTypeDef, ptr %58, i32 0, i32 4
  %60 = load i32, ptr %59, align 4, !tbaa !21
  %61 = zext i32 %60 to i64
  %62 = or i64 %61, 134217728
  %63 = or i64 %62, 67108864
  %64 = load ptr, ptr %5, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.OSPI_HyperbusCmdTypeDef, ptr %64, i32 0, i32 2
  %66 = load i32, ptr %65, align 4, !tbaa !22
  %67 = zext i32 %66 to i64
  %68 = or i64 %63, %67
  %69 = or i64 %68, 2048
  %70 = or i64 %69, 1024
  %71 = trunc i64 %70 to i32
  %72 = load ptr, ptr %4, align 8, !tbaa !5
  %73 = getelementptr inbounds %struct.OSPI_HandleTypeDef, ptr %72, i32 0, i32 0
  %74 = load ptr, ptr %73, align 8, !tbaa !15
  %75 = getelementptr inbounds %struct.OCTOSPI_TypeDef, ptr %74, i32 0, i32 22
  store volatile i32 %71, ptr %75, align 4, !tbaa !23
  %76 = load ptr, ptr %5, align 8, !tbaa !5
  %77 = getelementptr inbounds %struct.OSPI_HyperbusCmdTypeDef, ptr %76, i32 0, i32 4
  %78 = load i32, ptr %77, align 4, !tbaa !21
  %79 = zext i32 %78 to i64
  %80 = or i64 %79, 134217728
  %81 = or i64 %80, 67108864
  %82 = load ptr, ptr %5, align 8, !tbaa !5
  %83 = getelementptr inbounds %struct.OSPI_HyperbusCmdTypeDef, ptr %82, i32 0, i32 2
  %84 = load i32, ptr %83, align 4, !tbaa !22
  %85 = zext i32 %84 to i64
  %86 = or i64 %81, %85
  %87 = or i64 %86, 2048
  %88 = or i64 %87, 1024
  %89 = trunc i64 %88 to i32
  %90 = load ptr, ptr %4, align 8, !tbaa !5
  %91 = getelementptr inbounds %struct.OSPI_HandleTypeDef, ptr %90, i32 0, i32 0
  %92 = load ptr, ptr %91, align 8, !tbaa !15
  %93 = getelementptr inbounds %struct.OCTOSPI_TypeDef, ptr %92, i32 0, i32 40
  store volatile i32 %89, ptr %93, align 4, !tbaa !24
  %94 = load ptr, ptr %5, align 8, !tbaa !5
  %95 = getelementptr inbounds %struct.OSPI_HyperbusCmdTypeDef, ptr %94, i32 0, i32 3
  %96 = load i32, ptr %95, align 4, !tbaa !25
  %97 = sub i32 %96, 1
  %98 = load ptr, ptr %4, align 8, !tbaa !5
  %99 = getelementptr inbounds %struct.OSPI_HandleTypeDef, ptr %98, i32 0, i32 0
  %100 = load ptr, ptr %99, align 8, !tbaa !15
  %101 = getelementptr inbounds %struct.OCTOSPI_TypeDef, ptr %100, i32 0, i32 10
  store volatile i32 %97, ptr %101, align 4, !tbaa !26
  %102 = load ptr, ptr %5, align 8, !tbaa !5
  %103 = getelementptr inbounds %struct.OSPI_HyperbusCmdTypeDef, ptr %102, i32 0, i32 1
  %104 = load i32, ptr %103, align 4, !tbaa !27
  %105 = load ptr, ptr %4, align 8, !tbaa !5
  %106 = getelementptr inbounds %struct.OSPI_HandleTypeDef, ptr %105, i32 0, i32 0
  %107 = load ptr, ptr %106, align 8, !tbaa !15
  %108 = getelementptr inbounds %struct.OCTOSPI_TypeDef, ptr %107, i32 0, i32 12
  store volatile i32 %104, ptr %108, align 4, !tbaa !28
  %109 = load ptr, ptr %4, align 8, !tbaa !5
  %110 = getelementptr inbounds %struct.OSPI_HandleTypeDef, ptr %109, i32 0, i32 6
  store volatile i32 4, ptr %110, align 8, !tbaa !11
  br label %111

111:                                              ; preds = %27, %20
  br label %115

112:                                              ; preds = %14, %3
  store i32 1, ptr %7, align 4, !tbaa !9
  %113 = load ptr, ptr %4, align 8, !tbaa !5
  %114 = getelementptr inbounds %struct.OSPI_HandleTypeDef, ptr %113, i32 0, i32 7
  store volatile i32 16, ptr %114, align 4, !tbaa !29
  br label %115

115:                                              ; preds = %112, %111
  %116 = load i32, ptr %7, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  ret i32 %116
}

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 16}
!15 = !{!12, !6, i64 0}
!16 = !{!17, !10, i64 0}
!17 = !{!"", !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}
!18 = !{!17, !10, i64 8}
!19 = !{!20, !10, i64 0}
!20 = !{!"", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !10, i64 16}
!21 = !{!20, !10, i64 16}
!22 = !{!20, !10, i64 8}
!23 = !{!17, !10, i64 256}
!24 = !{!17, !10, i64 384}
!25 = !{!20, !10, i64 12}
!26 = !{!17, !10, i64 64}
!27 = !{!20, !10, i64 4}
!28 = !{!17, !10, i64 72}
!29 = !{!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_HyperbusCmd(ptr noundef %0, ptr nocapture noundef readonly %1, i32 noundef %2) local_unnamed_addr #1 {
  %4 = tail call i32 @HAL_GetTick() #2
  %5 = getelementptr inbounds i8, ptr %0, i64 96
  %6 = load volatile i32, ptr %5, align 8, !tbaa !5
  %7 = icmp eq i32 %6, 2
  br i1 %7, label %8, label %39

8:                                                ; preds = %3
  %9 = getelementptr inbounds i8, ptr %0, i64 16
  %10 = load i32, ptr %9, align 8, !tbaa !12
  %11 = icmp eq i32 %10, 67108864
  br i1 %11, label %12, label %39

12:                                               ; preds = %8
  %13 = tail call i32 @OSPI_WaitFlagStateUntilTimeout(ptr noundef nonnull %0, i32 noundef 32, i32 noundef 0, i32 noundef %4, i32 noundef %2)
  %14 = icmp eq i32 %13, 0
  br i1 %14, label %15, label %41

15:                                               ; preds = %12
  %16 = load ptr, ptr %0, align 8, !tbaa !13
  %17 = load volatile i32, ptr %16, align 4, !tbaa !14
  %18 = and i32 %17, -805306369
  store volatile i32 %18, ptr %16, align 4, !tbaa !14
  %19 = getelementptr inbounds i8, ptr %16, i64 8
  %20 = load volatile i32, ptr %19, align 4, !tbaa !16
  %21 = and i32 %20, -16777217
  %22 = load i32, ptr %1, align 4, !tbaa !17
  %23 = or i32 %21, %22
  store volatile i32 %23, ptr %19, align 4, !tbaa !16
  %24 = getelementptr inbounds i8, ptr %1, i64 16
  %25 = load i32, ptr %24, align 4, !tbaa !19
  %26 = getelementptr inbounds i8, ptr %1, i64 8
  %27 = load i32, ptr %26, align 4, !tbaa !20
  %28 = or i32 %25, %27
  %29 = or i32 %28, 201329664
  %30 = getelementptr inbounds i8, ptr %16, i64 256
  store volatile i32 %29, ptr %30, align 4, !tbaa !21
  %31 = getelementptr inbounds i8, ptr %16, i64 384
  store volatile i32 %29, ptr %31, align 4, !tbaa !22
  %32 = getelementptr inbounds i8, ptr %1, i64 12
  %33 = load i32, ptr %32, align 4, !tbaa !23
  %34 = add i32 %33, -1
  %35 = getelementptr inbounds i8, ptr %16, i64 64
  store volatile i32 %34, ptr %35, align 4, !tbaa !24
  %36 = getelementptr inbounds i8, ptr %1, i64 4
  %37 = load i32, ptr %36, align 4, !tbaa !25
  %38 = getelementptr inbounds i8, ptr %16, i64 72
  store volatile i32 %37, ptr %38, align 4, !tbaa !26
  store volatile i32 4, ptr %5, align 8, !tbaa !5
  br label %41

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

41:                                               ; preds = %12, %15, %39
  %.0 = phi i32 [ 0, %15 ], [ %13, %12 ], [ 1, %39 ]
  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 16}
!13 = !{!6, !7, i64 0}
!14 = !{!15, !11, i64 0}
!15 = !{!"", !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}
!16 = !{!15, !11, i64 8}
!17 = !{!18, !11, i64 0}
!18 = !{!"", !11, i64 0, !11, i64 4, !11, i64 8, !11, i64 12, !11, i64 16}
!19 = !{!18, !11, i64 16}
!20 = !{!18, !11, i64 8}
!21 = !{!15, !11, i64 256}
!22 = !{!15, !11, i64 384}
!23 = !{!18, !11, i64 12}
!24 = !{!15, !11, i64 64}
!25 = !{!18, !11, i64 4}
!26 = !{!15, !11, i64 72}
!27 = !{!6, !11, i64 100}


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