; LLVM IR from lichen-community-systems/signaletic :: hosts/daisy/vendor/libDaisy/Drivers/STM32H7xx_HAL_Driver/Src (AutoPolling)

; 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.QSPI_CommandTypeDef = type { i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32 }
%struct.QSPI_HandleTypeDef = type { ptr, %struct.QSPI_InitTypeDef, ptr, i32, i32, ptr, i32, i32, ptr, i32, i32, i32, i32 }
%struct.QSPI_InitTypeDef = type { i32, i32, i32, i32, i32, i32, i32, i32 }
%struct.QSPI_AutoPollingTypeDef = type { i32, i32, i32, i32, i32, i32 }
%struct.QUADSPI_TypeDef = type { i32, i32, i32, i32, i32, i32, i32, i32, 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 @QSPI_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 void @QSPI_Config(ptr noundef, ptr noundef, i32 noundef) #2

; Function Attrs: nounwind uwtable
define dso_local i32 @HAL_QSPI_AutoPolling(ptr noundef %0, ptr noundef %1, ptr noundef %2, i32 noundef %3) #2 {
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store ptr %2, ptr %8, align 8, !tbaa !5
  store i32 %3, ptr %9, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  %13 = call i32 @HAL_GetTick()
  store i32 %13, ptr %11, align 4, !tbaa !9
  %14 = load ptr, ptr %7, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.QSPI_CommandTypeDef, ptr %14, i32 0, i32 6
  %16 = load i32, ptr %15, align 4, !tbaa !11
  %17 = icmp ne i32 %16, 0
  br i1 %17, label %18, label %19

18:                                               ; preds = %4
  br label %19

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

24:                                               ; preds = %19
  br label %25

25:                                               ; preds = %24, %19
  %26 = load ptr, ptr %7, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.QSPI_CommandTypeDef, ptr %26, i32 0, i32 8
  %28 = load i32, ptr %27, align 4, !tbaa !14
  %29 = icmp ne i32 %28, 0
  br i1 %29, label %30, label %31

30:                                               ; preds = %25
  br label %31

31:                                               ; preds = %30, %25
  br label %32

32:                                               ; preds = %31
  %33 = load ptr, ptr %6, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.QSPI_HandleTypeDef, ptr %33, i32 0, i32 9
  %35 = load volatile i32, ptr %34, align 8, !tbaa !15
  %36 = icmp eq i32 %35, 1
  br i1 %36, label %37, label %38

37:                                               ; preds = %32
  store i32 2, ptr %5, align 4
  store i32 1, ptr %12, align 4
  br label %129

38:                                               ; preds = %32
  %39 = load ptr, ptr %6, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.QSPI_HandleTypeDef, ptr %39, i32 0, i32 9
  store volatile i32 1, ptr %40, align 8, !tbaa !15
  br label %41

41:                                               ; preds = %38
  br label %42

42:                                               ; preds = %41
  br label %43

43:                                               ; preds = %42
  %44 = load ptr, ptr %6, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.QSPI_HandleTypeDef, ptr %44, i32 0, i32 10
  %46 = load volatile i32, ptr %45, align 4, !tbaa !18
  %47 = icmp eq i32 %46, 1
  br i1 %47, label %48, label %121

48:                                               ; preds = %43
  %49 = load ptr, ptr %6, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.QSPI_HandleTypeDef, ptr %49, i32 0, i32 11
  store volatile i32 0, ptr %50, align 8, !tbaa !19
  %51 = load ptr, ptr %6, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.QSPI_HandleTypeDef, ptr %51, i32 0, i32 10
  store volatile i32 66, ptr %52, align 4, !tbaa !18
  %53 = load ptr, ptr %6, align 8, !tbaa !5
  %54 = load i32, ptr %11, align 4, !tbaa !9
  %55 = load i32, ptr %9, align 4, !tbaa !9
  %56 = call i32 @QSPI_WaitFlagStateUntilTimeout(ptr noundef %53, i32 noundef 32, i32 noundef 0, i32 noundef %54, i32 noundef %55)
  store i32 %56, ptr %10, align 4, !tbaa !9
  %57 = load i32, ptr %10, align 4, !tbaa !9
  %58 = icmp eq i32 %57, 0
  br i1 %58, label %59, label %120

59:                                               ; preds = %48
  %60 = load ptr, ptr %8, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.QSPI_AutoPollingTypeDef, ptr %60, i32 0, i32 0
  %62 = load i32, ptr %61, align 4, !tbaa !20
  %63 = load ptr, ptr %6, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.QSPI_HandleTypeDef, ptr %63, i32 0, i32 0
  %65 = load ptr, ptr %64, align 8, !tbaa !22
  %66 = getelementptr inbounds %struct.QUADSPI_TypeDef, ptr %65, i32 0, i32 10
  store volatile i32 %62, ptr %66, align 4, !tbaa !23
  %67 = load ptr, ptr %8, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct.QSPI_AutoPollingTypeDef, ptr %67, i32 0, i32 1
  %69 = load i32, ptr %68, align 4, !tbaa !25
  %70 = load ptr, ptr %6, align 8, !tbaa !5
  %71 = getelementptr inbounds %struct.QSPI_HandleTypeDef, ptr %70, i32 0, i32 0
  %72 = load ptr, ptr %71, align 8, !tbaa !22
  %73 = getelementptr inbounds %struct.QUADSPI_TypeDef, ptr %72, i32 0, i32 9
  store volatile i32 %69, ptr %73, align 4, !tbaa !26
  %74 = load ptr, ptr %8, align 8, !tbaa !5
  %75 = getelementptr inbounds %struct.QSPI_AutoPollingTypeDef, ptr %74, i32 0, i32 2
  %76 = load i32, ptr %75, align 4, !tbaa !27
  %77 = load ptr, ptr %6, align 8, !tbaa !5
  %78 = getelementptr inbounds %struct.QSPI_HandleTypeDef, ptr %77, i32 0, i32 0
  %79 = load ptr, ptr %78, align 8, !tbaa !22
  %80 = getelementptr inbounds %struct.QUADSPI_TypeDef, ptr %79, i32 0, i32 11
  store volatile i32 %76, ptr %80, align 4, !tbaa !28
  %81 = load ptr, ptr %6, align 8, !tbaa !5
  %82 = getelementptr inbounds %struct.QSPI_HandleTypeDef, ptr %81, i32 0, i32 0
  %83 = load ptr, ptr %82, align 8, !tbaa !22
  %84 = getelementptr inbounds %struct.QUADSPI_TypeDef, ptr %83, i32 0, i32 0
  %85 = load volatile i32, ptr %84, align 4, !tbaa !29
  %86 = zext i32 %85 to i64
  %87 = and i64 %86, -12582913
  %88 = load ptr, ptr %8, align 8, !tbaa !5
  %89 = getelementptr inbounds %struct.QSPI_AutoPollingTypeDef, ptr %88, i32 0, i32 4
  %90 = load i32, ptr %89, align 4, !tbaa !30
  %91 = or i32 %90, 4194304
  %92 = zext i32 %91 to i64
  %93 = or i64 %87, %92
  %94 = trunc i64 %93 to i32
  %95 = load ptr, ptr %6, align 8, !tbaa !5
  %96 = getelementptr inbounds %struct.QSPI_HandleTypeDef, ptr %95, i32 0, i32 0
  %97 = load ptr, ptr %96, align 8, !tbaa !22
  %98 = getelementptr inbounds %struct.QUADSPI_TypeDef, ptr %97, i32 0, i32 0
  store volatile i32 %94, ptr %98, align 4, !tbaa !29
  %99 = load ptr, ptr %8, align 8, !tbaa !5
  %100 = getelementptr inbounds %struct.QSPI_AutoPollingTypeDef, ptr %99, i32 0, i32 3
  %101 = load i32, ptr %100, align 4, !tbaa !31
  %102 = load ptr, ptr %7, align 8, !tbaa !5
  %103 = getelementptr inbounds %struct.QSPI_CommandTypeDef, ptr %102, i32 0, i32 10
  store i32 %101, ptr %103, align 4, !tbaa !32
  %104 = load ptr, ptr %6, align 8, !tbaa !5
  %105 = load ptr, ptr %7, align 8, !tbaa !5
  call void @QSPI_Config(ptr noundef %104, ptr noundef %105, i32 noundef 134217728)
  %106 = load ptr, ptr %6, align 8, !tbaa !5
  %107 = load i32, ptr %11, align 4, !tbaa !9
  %108 = load i32, ptr %9, align 4, !tbaa !9
  %109 = call i32 @QSPI_WaitFlagStateUntilTimeout(ptr noundef %106, i32 noundef 8, i32 noundef 1, i32 noundef %107, i32 noundef %108)
  store i32 %109, ptr %10, align 4, !tbaa !9
  %110 = load i32, ptr %10, align 4, !tbaa !9
  %111 = icmp eq i32 %110, 0
  br i1 %111, label %112, label %119

112:                                              ; preds = %59
  %113 = load ptr, ptr %6, align 8, !tbaa !5
  %114 = getelementptr inbounds %struct.QSPI_HandleTypeDef, ptr %113, i32 0, i32 0
  %115 = load ptr, ptr %114, align 8, !tbaa !22
  %116 = getelementptr inbounds %struct.QUADSPI_TypeDef, ptr %115, i32 0, i32 3
  store volatile i32 8, ptr %116, align 4, !tbaa !33
  %117 = load ptr, ptr %6, align 8, !tbaa !5
  %118 = getelementptr inbounds %struct.QSPI_HandleTypeDef, ptr %117, i32 0, i32 10
  store volatile i32 1, ptr %118, align 4, !tbaa !18
  br label %119

119:                                              ; preds = %112, %59
  br label %120

120:                                              ; preds = %119, %48
  br label %122

121:                                              ; preds = %43
  store i32 2, ptr %10, align 4, !tbaa !9
  br label %122

122:                                              ; preds = %121, %120
  br label %123

123:                                              ; preds = %122
  %124 = load ptr, ptr %6, align 8, !tbaa !5
  %125 = getelementptr inbounds %struct.QSPI_HandleTypeDef, ptr %124, i32 0, i32 9
  store volatile i32 0, ptr %125, align 8, !tbaa !15
  br label %126

126:                                              ; preds = %123
  br label %127

127:                                              ; preds = %126
  %128 = load i32, ptr %10, align 4, !tbaa !9
  store i32 %128, ptr %5, align 4
  store i32 1, ptr %12, align 4
  br label %129

129:                                              ; preds = %127, %37
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  %130 = load i32, ptr %5, align 4
  ret i32 %130
}

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 24}
!12 = !{!"", !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}
!13 = !{!12, !10, i64 28}
!14 = !{!12, !10, i64 32}
!15 = !{!16, !10, i64 80}
!16 = !{!"", !6, i64 0, !17, i64 8, !6, i64 40, !10, i64 48, !10, i64 52, !6, i64 56, !10, i64 64, !10, i64 68, !6, i64 72, !10, i64 80, !10, i64 84, !10, i64 88, !10, i64 92}
!17 = !{!"", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20, !10, i64 24, !10, i64 28}
!18 = !{!16, !10, i64 84}
!19 = !{!16, !10, i64 88}
!20 = !{!21, !10, i64 0}
!21 = !{!"", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20}
!22 = !{!16, !6, i64 0}
!23 = !{!24, !10, i64 40}
!24 = !{!"", !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}
!25 = !{!21, !10, i64 4}
!26 = !{!24, !10, i64 36}
!27 = !{!21, !10, i64 8}
!28 = !{!24, !10, i64 44}
!29 = !{!24, !10, i64 0}
!30 = !{!21, !10, i64 16}
!31 = !{!21, !10, i64 12}
!32 = !{!12, !10, i64 40}
!33 = !{!24, !10, i64 12}


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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @HAL_QSPI_AutoPolling(ptr noundef %0, ptr noundef %1, ptr nocapture noundef readonly %2, i32 noundef %3) local_unnamed_addr #1 {
  %5 = tail call i32 @HAL_GetTick() #2
  %6 = getelementptr inbounds i8, ptr %0, i64 80
  %7 = load volatile i32, ptr %6, align 8, !tbaa !5
  %8 = icmp eq i32 %7, 1
  br i1 %8, label %42, label %9

9:                                                ; preds = %4
  store volatile i32 1, ptr %6, align 8, !tbaa !5
  %10 = getelementptr inbounds i8, ptr %0, i64 84
  %11 = load volatile i32, ptr %10, align 4, !tbaa !12
  %12 = icmp eq i32 %11, 1
  br i1 %12, label %13, label %41

13:                                               ; preds = %9
  %14 = getelementptr inbounds i8, ptr %0, i64 88
  store volatile i32 0, ptr %14, align 8, !tbaa !13
  store volatile i32 66, ptr %10, align 4, !tbaa !12
  %15 = tail call i32 @QSPI_WaitFlagStateUntilTimeout(ptr noundef nonnull %0, i32 noundef 32, i32 noundef 0, i32 noundef %5, i32 noundef %3)
  %16 = icmp eq i32 %15, 0
  br i1 %16, label %17, label %41

17:                                               ; preds = %13
  %18 = load i32, ptr %2, align 4, !tbaa !14
  %19 = load ptr, ptr %0, align 8, !tbaa !16
  %20 = getelementptr inbounds i8, ptr %19, i64 40
  store volatile i32 %18, ptr %20, align 4, !tbaa !17
  %21 = getelementptr inbounds i8, ptr %2, i64 4
  %22 = load i32, ptr %21, align 4, !tbaa !19
  %23 = getelementptr inbounds i8, ptr %19, i64 36
  store volatile i32 %22, ptr %23, align 4, !tbaa !20
  %24 = getelementptr inbounds i8, ptr %2, i64 8
  %25 = load i32, ptr %24, align 4, !tbaa !21
  %26 = getelementptr inbounds i8, ptr %19, i64 44
  store volatile i32 %25, ptr %26, align 4, !tbaa !22
  %27 = load volatile i32, ptr %19, align 4, !tbaa !23
  %28 = and i32 %27, -12582913
  %29 = getelementptr inbounds i8, ptr %2, i64 16
  %30 = load i32, ptr %29, align 4, !tbaa !24
  %31 = or i32 %30, %28
  %32 = or i32 %31, 4194304
  store volatile i32 %32, ptr %19, align 4, !tbaa !23
  %33 = getelementptr inbounds i8, ptr %2, i64 12
  %34 = load i32, ptr %33, align 4, !tbaa !25
  %35 = getelementptr inbounds i8, ptr %1, i64 40
  store i32 %34, ptr %35, align 4, !tbaa !26
  tail call void @QSPI_Config(ptr noundef nonnull %0, ptr noundef %1, i32 noundef 134217728)
  %36 = tail call i32 @QSPI_WaitFlagStateUntilTimeout(ptr noundef nonnull %0, i32 noundef 8, i32 noundef 1, i32 noundef %5, i32 noundef %3)
  %37 = icmp eq i32 %36, 0
  br i1 %37, label %38, label %41

38:                                               ; preds = %17
  %39 = load ptr, ptr %0, align 8, !tbaa !16
  %40 = getelementptr inbounds i8, ptr %39, i64 12
  store volatile i32 8, ptr %40, align 4, !tbaa !28
  store volatile i32 1, ptr %10, align 4, !tbaa !12
  br label %41

41:                                               ; preds = %9, %17, %38, %13
  %.033 = phi i32 [ 0, %38 ], [ %36, %17 ], [ %15, %13 ], [ 2, %9 ]
  store volatile i32 0, ptr %6, align 8, !tbaa !5
  br label %42

42:                                               ; preds = %4, %41
  %.0 = phi i32 [ %.033, %41 ], [ 2, %4 ]
  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 80}
!6 = !{!"", !7, i64 0, !10, i64 8, !7, i64 40, !11, i64 48, !11, i64 52, !7, i64 56, !11, i64 64, !11, i64 68, !7, i64 72, !11, i64 80, !11, i64 84, !11, i64 88, !11, i64 92}
!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 = !{!"int", !8, i64 0}
!12 = !{!6, !11, i64 84}
!13 = !{!6, !11, i64 88}
!14 = !{!15, !11, i64 0}
!15 = !{!"", !11, i64 0, !11, i64 4, !11, i64 8, !11, i64 12, !11, i64 16, !11, i64 20}
!16 = !{!6, !7, i64 0}
!17 = !{!18, !11, i64 40}
!18 = !{!"", !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}
!19 = !{!15, !11, i64 4}
!20 = !{!18, !11, i64 36}
!21 = !{!15, !11, i64 8}
!22 = !{!18, !11, i64 44}
!23 = !{!18, !11, i64 0}
!24 = !{!15, !11, i64 16}
!25 = !{!15, !11, i64 12}
!26 = !{!27, !11, i64 40}
!27 = !{!"", !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}
!28 = !{!18, !11, i64 12}


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