; 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_RegularCmdTypeDef = type { i32, i32, i32, i32, i32, 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
declare hidden i32 @OSPI_ConfigCmd(ptr noundef, ptr noundef) #2

; Function Attrs: nounwind uwtable
define dso_local i32 @HAL_OSPI_Command_IT(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 1
  %10 = getelementptr inbounds %struct.OSPI_InitTypeDef, ptr %9, i32 0, i32 1
  %11 = load i32, ptr %10, align 4, !tbaa !11
  %12 = icmp eq i32 %11, 0
  br i1 %12, label %13, label %14

13:                                               ; preds = %2
  br label %14

14:                                               ; preds = %13, %2
  %15 = load ptr, ptr %4, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.OSPI_RegularCmdTypeDef, ptr %15, i32 0, i32 3
  %17 = load i32, ptr %16, align 4, !tbaa !14
  %18 = icmp ne i32 %17, 0
  br i1 %18, label %19, label %20

19:                                               ; preds = %14
  br label %20

20:                                               ; preds = %19, %14
  %21 = load ptr, ptr %4, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.OSPI_RegularCmdTypeDef, ptr %21, i32 0, i32 7
  %23 = load i32, ptr %22, align 4, !tbaa !16
  %24 = icmp ne i32 %23, 0
  br i1 %24, label %25, label %26

25:                                               ; preds = %20
  br label %26

26:                                               ; preds = %25, %20
  %27 = load ptr, ptr %4, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.OSPI_RegularCmdTypeDef, ptr %27, i32 0, i32 11
  %29 = load i32, ptr %28, align 4, !tbaa !17
  %30 = icmp ne i32 %29, 0
  br i1 %30, label %31, label %32

31:                                               ; preds = %26
  br label %32

32:                                               ; preds = %31, %26
  %33 = load ptr, ptr %4, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.OSPI_RegularCmdTypeDef, ptr %33, i32 0, i32 14
  %35 = load i32, ptr %34, align 4, !tbaa !18
  %36 = icmp ne i32 %35, 0
  br i1 %36, label %37, label %38

37:                                               ; preds = %32
  br label %38

38:                                               ; preds = %37, %32
  %39 = load ptr, ptr %3, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.OSPI_HandleTypeDef, ptr %39, i32 0, i32 6
  %41 = load volatile i32, ptr %40, align 8, !tbaa !19
  %42 = icmp eq i32 %41, 2
  br i1 %42, label %43, label %93

43:                                               ; preds = %38
  %44 = load ptr, ptr %4, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.OSPI_RegularCmdTypeDef, ptr %44, i32 0, i32 0
  %46 = load i32, ptr %45, align 4, !tbaa !20
  %47 = icmp eq i32 %46, 0
  br i1 %47, label %48, label %93

48:                                               ; preds = %43
  %49 = load ptr, ptr %4, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.OSPI_RegularCmdTypeDef, ptr %49, i32 0, i32 14
  %51 = load i32, ptr %50, align 4, !tbaa !18
  %52 = icmp eq i32 %51, 0
  br i1 %52, label %53, label %93

53:                                               ; preds = %48
  %54 = load ptr, ptr %3, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.OSPI_HandleTypeDef, ptr %54, i32 0, i32 1
  %56 = getelementptr inbounds %struct.OSPI_InitTypeDef, ptr %55, i32 0, i32 2
  %57 = load i32, ptr %56, align 8, !tbaa !21
  %58 = icmp ne i32 %57, 67108864
  br i1 %58, label %59, label %93

59:                                               ; preds = %53
  %60 = load ptr, ptr %3, align 8, !tbaa !5
  %61 = load i32, ptr %6, align 4, !tbaa !9
  %62 = load ptr, ptr %3, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.OSPI_HandleTypeDef, ptr %62, i32 0, i32 8
  %64 = load i32, ptr %63, align 8, !tbaa !22
  %65 = call i32 @OSPI_WaitFlagStateUntilTimeout(ptr noundef %60, i32 noundef 32, i32 noundef 0, i32 noundef %61, i32 noundef %64)
  store i32 %65, ptr %5, align 4, !tbaa !9
  %66 = load i32, ptr %5, align 4, !tbaa !9
  %67 = icmp eq i32 %66, 0
  br i1 %67, label %68, label %92

68:                                               ; preds = %59
  %69 = load ptr, ptr %3, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct.OSPI_HandleTypeDef, ptr %69, i32 0, i32 7
  store volatile i32 0, ptr %70, align 4, !tbaa !23
  %71 = load ptr, ptr %3, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct.OSPI_HandleTypeDef, ptr %71, i32 0, i32 0
  %73 = load ptr, ptr %72, align 8, !tbaa !24
  %74 = getelementptr inbounds %struct.OCTOSPI_TypeDef, ptr %73, i32 0, i32 8
  store volatile i32 3, ptr %74, align 4, !tbaa !25
  %75 = load ptr, ptr %3, align 8, !tbaa !5
  %76 = load ptr, ptr %4, align 8, !tbaa !5
  %77 = call i32 @OSPI_ConfigCmd(ptr noundef %75, ptr noundef %76)
  store i32 %77, ptr %5, align 4, !tbaa !9
  %78 = load i32, ptr %5, align 4, !tbaa !9
  %79 = icmp eq i32 %78, 0
  br i1 %79, label %80, label %91

80:                                               ; preds = %68
  %81 = load ptr, ptr %3, align 8, !tbaa !5
  %82 = getelementptr inbounds %struct.OSPI_HandleTypeDef, ptr %81, i32 0, i32 6
  store volatile i32 8, ptr %82, align 8, !tbaa !19
  %83 = load ptr, ptr %3, align 8, !tbaa !5
  %84 = getelementptr inbounds %struct.OSPI_HandleTypeDef, ptr %83, i32 0, i32 0
  %85 = load ptr, ptr %84, align 8, !tbaa !24
  %86 = getelementptr inbounds %struct.OCTOSPI_TypeDef, ptr %85, i32 0, i32 0
  %87 = load volatile i32, ptr %86, align 4, !tbaa !27
  %88 = zext i32 %87 to i64
  %89 = or i64 %88, 196608
  %90 = trunc i64 %89 to i32
  store volatile i32 %90, ptr %86, align 4, !tbaa !27
  br label %91

91:                                               ; preds = %80, %68
  br label %92

92:                                               ; preds = %91, %59
  br label %96

93:                                               ; preds = %53, %48, %43, %38
  store i32 1, ptr %5, align 4, !tbaa !9
  %94 = load ptr, ptr %3, align 8, !tbaa !5
  %95 = getelementptr inbounds %struct.OSPI_HandleTypeDef, ptr %94, i32 0, i32 7
  store volatile i32 16, ptr %95, align 4, !tbaa !23
  br label %96

96:                                               ; preds = %93, %92
  %97 = 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 %97
}

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 12}
!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 = !{!15, !10, i64 12}
!15 = !{!"", !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, !10, i64 72, !10, i64 76}
!16 = !{!15, !10, i64 28}
!17 = !{!15, !10, i64 44}
!18 = !{!15, !10, i64 56}
!19 = !{!12, !10, i64 96}
!20 = !{!15, !10, i64 0}
!21 = !{!12, !10, i64 16}
!22 = !{!12, !10, i64 104}
!23 = !{!12, !10, i64 100}
!24 = !{!12, !6, i64 0}
!25 = !{!26, !10, i64 36}
!26 = !{!"", !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}
!27 = !{!26, !10, i64 0}


; 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
declare hidden i32 @OSPI_ConfigCmd(ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local i32 @HAL_OSPI_Command_IT(ptr noundef %0, ptr noundef %1) local_unnamed_addr #1 {
  %3 = tail call i32 @HAL_GetTick() #2
  %4 = getelementptr inbounds i8, ptr %1, i64 56
  %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 %32

8:                                                ; preds = %2
  %9 = load i32, ptr %1, align 4, !tbaa !12
  %10 = icmp eq i32 %9, 0
  br i1 %10, label %11, label %32

11:                                               ; preds = %8
  %12 = load i32, ptr %4, align 4, !tbaa !14
  %13 = icmp eq i32 %12, 0
  br i1 %13, label %14, label %32

14:                                               ; preds = %11
  %15 = getelementptr inbounds i8, ptr %0, i64 16
  %16 = load i32, ptr %15, align 8, !tbaa !15
  %.not = icmp eq i32 %16, 67108864
  br i1 %.not, label %32, label %17

17:                                               ; preds = %14
  %18 = getelementptr inbounds i8, ptr %0, i64 104
  %19 = load i32, ptr %18, align 8, !tbaa !16
  %20 = tail call i32 @OSPI_WaitFlagStateUntilTimeout(ptr noundef nonnull %0, i32 noundef 32, i32 noundef 0, i32 noundef %3, i32 noundef %19)
  %21 = icmp eq i32 %20, 0
  br i1 %21, label %22, label %34

22:                                               ; preds = %17
  %23 = getelementptr inbounds i8, ptr %0, i64 100
  store volatile i32 0, ptr %23, align 4, !tbaa !17
  %24 = load ptr, ptr %0, align 8, !tbaa !18
  %25 = getelementptr inbounds i8, ptr %24, i64 36
  store volatile i32 3, ptr %25, align 4, !tbaa !19
  %26 = tail call i32 @OSPI_ConfigCmd(ptr noundef nonnull %0, ptr noundef nonnull %1)
  %27 = icmp eq i32 %26, 0
  br i1 %27, label %28, label %34

28:                                               ; preds = %22
  store volatile i32 8, ptr %5, align 8, !tbaa !5
  %29 = load ptr, ptr %0, align 8, !tbaa !18
  %30 = load volatile i32, ptr %29, align 4, !tbaa !21
  %31 = or i32 %30, 196608
  store volatile i32 %31, ptr %29, align 4, !tbaa !21
  br label %34

32:                                               ; preds = %14, %11, %8, %2
  %33 = getelementptr inbounds i8, ptr %0, i64 100
  store volatile i32 16, ptr %33, align 4, !tbaa !17
  br label %34

34:                                               ; preds = %17, %28, %22, %32
  %.0 = phi i32 [ 0, %28 ], [ %26, %22 ], [ %20, %17 ], [ 1, %32 ]
  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 = !{!13, !11, i64 0}
!13 = !{!"", !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, i64 60, !11, i64 64, !11, i64 68, !11, i64 72, !11, i64 76}
!14 = !{!13, !11, i64 56}
!15 = !{!6, !11, i64 16}
!16 = !{!6, !11, i64 104}
!17 = !{!6, !11, i64 100}
!18 = !{!6, !7, i64 0}
!19 = !{!20, !11, i64 36}
!20 = !{!"", !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}
!21 = !{!20, !11, i64 0}


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