; 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_Transmit(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
  %9 = alloca ptr, align 8
  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
  %10 = call i32 @HAL_GetTick()
  store i32 %10, ptr %8, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  %11 = load ptr, ptr %4, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.OSPI_HandleTypeDef, ptr %11, i32 0, i32 0
  %13 = load ptr, ptr %12, align 8, !tbaa !11
  %14 = getelementptr inbounds %struct.OCTOSPI_TypeDef, ptr %13, i32 0, i32 14
  store ptr %14, ptr %9, align 8, !tbaa !5
  %15 = load ptr, ptr %5, align 8, !tbaa !5
  %16 = icmp eq ptr %15, null
  br i1 %16, label %17, label %20

17:                                               ; preds = %3
  store i32 1, ptr %7, align 4, !tbaa !9
  %18 = load ptr, ptr %4, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.OSPI_HandleTypeDef, ptr %18, i32 0, i32 7
  store volatile i32 8, ptr %19, align 4, !tbaa !14
  br label %105

20:                                               ; preds = %3
  %21 = load ptr, ptr %4, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.OSPI_HandleTypeDef, ptr %21, i32 0, i32 6
  %23 = load volatile i32, ptr %22, align 8, !tbaa !15
  %24 = icmp eq i32 %23, 4
  br i1 %24, label %25, label %101

25:                                               ; preds = %20
  %26 = load ptr, ptr %4, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.OSPI_HandleTypeDef, ptr %26, i32 0, i32 0
  %28 = load ptr, ptr %27, align 8, !tbaa !11
  %29 = getelementptr inbounds %struct.OCTOSPI_TypeDef, ptr %28, i32 0, i32 10
  %30 = load volatile i32, ptr %29, align 4, !tbaa !16
  %31 = add i32 %30, 1
  %32 = load ptr, ptr %4, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.OSPI_HandleTypeDef, ptr %32, i32 0, i32 4
  store volatile i32 %31, ptr %33, align 4, !tbaa !18
  %34 = load ptr, ptr %4, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.OSPI_HandleTypeDef, ptr %34, i32 0, i32 4
  %36 = load volatile i32, ptr %35, align 4, !tbaa !18
  %37 = load ptr, ptr %4, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.OSPI_HandleTypeDef, ptr %37, i32 0, i32 3
  store volatile i32 %36, ptr %38, align 8, !tbaa !19
  %39 = load ptr, ptr %5, align 8, !tbaa !5
  %40 = load ptr, ptr %4, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.OSPI_HandleTypeDef, ptr %40, i32 0, i32 2
  store ptr %39, ptr %41, align 8, !tbaa !20
  %42 = load ptr, ptr %4, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.OSPI_HandleTypeDef, ptr %42, i32 0, i32 0
  %44 = load ptr, ptr %43, align 8, !tbaa !11
  %45 = getelementptr inbounds %struct.OCTOSPI_TypeDef, ptr %44, i32 0, i32 0
  %46 = load volatile i32, ptr %45, align 4, !tbaa !21
  %47 = zext i32 %46 to i64
  %48 = and i64 %47, -805306369
  %49 = or i64 %48, 0
  %50 = trunc i64 %49 to i32
  %51 = load ptr, ptr %4, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.OSPI_HandleTypeDef, ptr %51, i32 0, i32 0
  %53 = load ptr, ptr %52, align 8, !tbaa !11
  %54 = getelementptr inbounds %struct.OCTOSPI_TypeDef, ptr %53, i32 0, i32 0
  store volatile i32 %50, ptr %54, align 4, !tbaa !21
  br label %55

55:                                               ; preds = %77, %25
  %56 = load ptr, ptr %4, align 8, !tbaa !5
  %57 = load i32, ptr %8, align 4, !tbaa !9
  %58 = load i32, ptr %6, align 4, !tbaa !9
  %59 = call i32 @OSPI_WaitFlagStateUntilTimeout(ptr noundef %56, i32 noundef 4, i32 noundef 1, i32 noundef %57, i32 noundef %58)
  store i32 %59, ptr %7, align 4, !tbaa !9
  %60 = load i32, ptr %7, align 4, !tbaa !9
  %61 = icmp ne i32 %60, 0
  br i1 %61, label %62, label %63

62:                                               ; preds = %55
  br label %82

63:                                               ; preds = %55
  %64 = load ptr, ptr %4, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.OSPI_HandleTypeDef, ptr %64, i32 0, i32 2
  %66 = load ptr, ptr %65, align 8, !tbaa !20
  %67 = load i8, ptr %66, align 1, !tbaa !22
  %68 = load ptr, ptr %9, align 8, !tbaa !5
  store volatile i8 %67, ptr %68, align 1, !tbaa !22
  %69 = load ptr, ptr %4, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct.OSPI_HandleTypeDef, ptr %69, i32 0, i32 2
  %71 = load ptr, ptr %70, align 8, !tbaa !20
  %72 = getelementptr inbounds i8, ptr %71, i32 1
  store ptr %72, ptr %70, align 8, !tbaa !20
  %73 = load ptr, ptr %4, align 8, !tbaa !5
  %74 = getelementptr inbounds %struct.OSPI_HandleTypeDef, ptr %73, i32 0, i32 4
  %75 = load volatile i32, ptr %74, align 4, !tbaa !18
  %76 = add i32 %75, -1
  store volatile i32 %76, ptr %74, align 4, !tbaa !18
  br label %77

77:                                               ; preds = %63
  %78 = load ptr, ptr %4, align 8, !tbaa !5
  %79 = getelementptr inbounds %struct.OSPI_HandleTypeDef, ptr %78, i32 0, i32 4
  %80 = load volatile i32, ptr %79, align 4, !tbaa !18
  %81 = icmp ugt i32 %80, 0
  br i1 %81, label %55, label %82, !llvm.loop !23

82:                                               ; preds = %77, %62
  %83 = load i32, ptr %7, align 4, !tbaa !9
  %84 = icmp eq i32 %83, 0
  br i1 %84, label %85, label %100

85:                                               ; preds = %82
  %86 = load ptr, ptr %4, align 8, !tbaa !5
  %87 = load i32, ptr %8, align 4, !tbaa !9
  %88 = load i32, ptr %6, align 4, !tbaa !9
  %89 = call i32 @OSPI_WaitFlagStateUntilTimeout(ptr noundef %86, i32 noundef 2, i32 noundef 1, i32 noundef %87, i32 noundef %88)
  store i32 %89, ptr %7, align 4, !tbaa !9
  %90 = load i32, ptr %7, align 4, !tbaa !9
  %91 = icmp eq i32 %90, 0
  br i1 %91, label %92, label %99

92:                                               ; preds = %85
  %93 = load ptr, ptr %4, align 8, !tbaa !5
  %94 = getelementptr inbounds %struct.OSPI_HandleTypeDef, ptr %93, i32 0, i32 0
  %95 = load ptr, ptr %94, align 8, !tbaa !11
  %96 = getelementptr inbounds %struct.OCTOSPI_TypeDef, ptr %95, i32 0, i32 8
  store volatile i32 2, ptr %96, align 4, !tbaa !25
  %97 = load ptr, ptr %4, align 8, !tbaa !5
  %98 = getelementptr inbounds %struct.OSPI_HandleTypeDef, ptr %97, i32 0, i32 6
  store volatile i32 2, ptr %98, align 8, !tbaa !15
  br label %99

99:                                               ; preds = %92, %85
  br label %100

100:                                              ; preds = %99, %82
  br label %104

101:                                              ; preds = %20
  store i32 1, ptr %7, align 4, !tbaa !9
  %102 = load ptr, ptr %4, align 8, !tbaa !5
  %103 = getelementptr inbounds %struct.OSPI_HandleTypeDef, ptr %102, i32 0, i32 7
  store volatile i32 16, ptr %103, align 4, !tbaa !14
  br label %104

104:                                              ; preds = %101, %100
  br label %105

105:                                              ; preds = %104, %17
  %106 = load i32, ptr %7, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  ret i32 %106
}

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, !6, i64 0}
!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 100}
!15 = !{!12, !10, i64 96}
!16 = !{!17, !10, i64 64}
!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 = !{!12, !10, i64 84}
!19 = !{!12, !10, i64 80}
!20 = !{!12, !6, i64 72}
!21 = !{!17, !10, i64 0}
!22 = !{!7, !7, i64 0}
!23 = distinct !{!23, !24}
!24 = !{!"llvm.loop.mustprogress"}
!25 = !{!17, !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_Transmit(ptr noundef %0, ptr noundef %1, i32 noundef %2) local_unnamed_addr #1 {
  %4 = tail call i32 @HAL_GetTick() #2
  %5 = load ptr, ptr %0, align 8, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %5, i64 80
  %7 = icmp eq ptr %1, null
  br i1 %7, label %8, label %10

8:                                                ; preds = %3
  %9 = getelementptr inbounds i8, ptr %0, i64 100
  store volatile i32 8, ptr %9, align 4, !tbaa !12
  br label %.loopexit

10:                                               ; preds = %3
  %11 = getelementptr inbounds i8, ptr %0, i64 96
  %12 = load volatile i32, ptr %11, align 8, !tbaa !13
  %13 = icmp eq i32 %12, 4
  br i1 %13, label %14, label %40

14:                                               ; preds = %10
  %15 = getelementptr inbounds i8, ptr %5, i64 64
  %16 = load volatile i32, ptr %15, align 4, !tbaa !14
  %17 = add i32 %16, 1
  %18 = getelementptr inbounds i8, ptr %0, i64 84
  store volatile i32 %17, ptr %18, align 4, !tbaa !16
  %19 = load volatile i32, ptr %18, align 4, !tbaa !16
  %20 = getelementptr inbounds i8, ptr %0, i64 80
  store volatile i32 %19, ptr %20, align 8, !tbaa !17
  %21 = getelementptr inbounds i8, ptr %0, i64 72
  store ptr %1, ptr %21, align 8, !tbaa !18
  %22 = load volatile i32, ptr %5, align 4, !tbaa !19
  %23 = and i32 %22, -805306369
  store volatile i32 %23, ptr %5, align 4, !tbaa !19
  br label %24

24:                                               ; preds = %26, %14
  %25 = tail call i32 @OSPI_WaitFlagStateUntilTimeout(ptr noundef nonnull %0, i32 noundef 4, i32 noundef 1, i32 noundef %4, i32 noundef %2)
  %cond = icmp eq i32 %25, 0
  br i1 %cond, label %26, label %.loopexit

26:                                               ; preds = %24
  %27 = load ptr, ptr %21, align 8, !tbaa !18
  %28 = load i8, ptr %27, align 1, !tbaa !20
  store volatile i8 %28, ptr %6, align 1, !tbaa !20
  %29 = load ptr, ptr %21, align 8, !tbaa !18
  %30 = getelementptr inbounds i8, ptr %29, i64 1
  store ptr %30, ptr %21, align 8, !tbaa !18
  %31 = load volatile i32, ptr %18, align 4, !tbaa !16
  %32 = add i32 %31, -1
  store volatile i32 %32, ptr %18, align 4, !tbaa !16
  %33 = load volatile i32, ptr %18, align 4, !tbaa !16
  %.not32 = icmp eq i32 %33, 0
  br i1 %.not32, label %34, label %24, !llvm.loop !21

34:                                               ; preds = %26
  %35 = tail call i32 @OSPI_WaitFlagStateUntilTimeout(ptr noundef nonnull %0, i32 noundef 2, i32 noundef 1, i32 noundef %4, i32 noundef %2)
  %36 = icmp eq i32 %35, 0
  br i1 %36, label %37, label %.loopexit

37:                                               ; preds = %34
  %38 = load ptr, ptr %0, align 8, !tbaa !5
  %39 = getelementptr inbounds i8, ptr %38, i64 36
  store volatile i32 2, ptr %39, align 4, !tbaa !23
  store volatile i32 2, ptr %11, align 8, !tbaa !13
  br label %.loopexit

40:                                               ; preds = %10
  %41 = getelementptr inbounds i8, ptr %0, i64 100
  store volatile i32 16, ptr %41, align 4, !tbaa !12
  br label %.loopexit

.loopexit:                                        ; preds = %24, %40, %34, %37, %8
  %.0 = phi i32 [ 1, %8 ], [ 0, %37 ], [ %35, %34 ], [ 1, %40 ], [ %25, %24 ]
  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, !7, i64 0}
!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 100}
!13 = !{!6, !11, i64 96}
!14 = !{!15, !11, i64 64}
!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 = !{!6, !11, i64 84}
!17 = !{!6, !11, i64 80}
!18 = !{!6, !7, i64 72}
!19 = !{!15, !11, i64 0}
!20 = !{!8, !8, i64 0}
!21 = distinct !{!21, !22}
!22 = !{!"llvm.loop.mustprogress"}
!23 = !{!15, !11, i64 36}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass