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

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

16:                                               ; preds = %3
  br label %17

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

22:                                               ; preds = %17
  br label %23

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

28:                                               ; preds = %23
  br label %29

29:                                               ; preds = %28, %23
  br label %30

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

35:                                               ; preds = %30
  store i32 2, ptr %4, align 4
  store i32 1, ptr %10, align 4
  br label %113

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

39:                                               ; preds = %36
  br label %40

40:                                               ; preds = %39
  br label %41

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

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

59:                                               ; preds = %46
  %60 = load ptr, ptr %5, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.QSPI_HandleTypeDef, ptr %60, i32 0, i32 0
  %62 = load ptr, ptr %61, align 8, !tbaa !21
  %63 = getelementptr inbounds %struct.QUADSPI_TypeDef, ptr %62, i32 0, i32 0
  %64 = load volatile i32, ptr %63, align 4, !tbaa !22
  %65 = zext i32 %64 to i64
  %66 = and i64 %65, -9
  %67 = load ptr, ptr %7, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct.QSPI_MemoryMappedTypeDef, ptr %67, i32 0, i32 1
  %69 = load i32, ptr %68, align 4, !tbaa !24
  %70 = zext i32 %69 to i64
  %71 = or i64 %66, %70
  %72 = trunc i64 %71 to i32
  %73 = load ptr, ptr %5, align 8, !tbaa !5
  %74 = getelementptr inbounds %struct.QSPI_HandleTypeDef, ptr %73, i32 0, i32 0
  %75 = load ptr, ptr %74, align 8, !tbaa !21
  %76 = getelementptr inbounds %struct.QUADSPI_TypeDef, ptr %75, i32 0, i32 0
  store volatile i32 %72, ptr %76, align 4, !tbaa !22
  %77 = load ptr, ptr %7, align 8, !tbaa !5
  %78 = getelementptr inbounds %struct.QSPI_MemoryMappedTypeDef, ptr %77, i32 0, i32 1
  %79 = load i32, ptr %78, align 4, !tbaa !24
  %80 = icmp eq i32 %79, 8
  br i1 %80, label %81, label %101

81:                                               ; preds = %59
  %82 = load ptr, ptr %7, align 8, !tbaa !5
  %83 = getelementptr inbounds %struct.QSPI_MemoryMappedTypeDef, ptr %82, i32 0, i32 0
  %84 = load i32, ptr %83, align 4, !tbaa !26
  %85 = load ptr, ptr %5, align 8, !tbaa !5
  %86 = getelementptr inbounds %struct.QSPI_HandleTypeDef, ptr %85, i32 0, i32 0
  %87 = load ptr, ptr %86, align 8, !tbaa !21
  %88 = getelementptr inbounds %struct.QUADSPI_TypeDef, ptr %87, i32 0, i32 12
  store volatile i32 %84, ptr %88, align 4, !tbaa !27
  %89 = load ptr, ptr %5, align 8, !tbaa !5
  %90 = getelementptr inbounds %struct.QSPI_HandleTypeDef, ptr %89, i32 0, i32 0
  %91 = load ptr, ptr %90, align 8, !tbaa !21
  %92 = getelementptr inbounds %struct.QUADSPI_TypeDef, ptr %91, i32 0, i32 3
  store volatile i32 16, ptr %92, align 4, !tbaa !28
  %93 = load ptr, ptr %5, align 8, !tbaa !5
  %94 = getelementptr inbounds %struct.QSPI_HandleTypeDef, ptr %93, i32 0, i32 0
  %95 = load ptr, ptr %94, align 8, !tbaa !21
  %96 = getelementptr inbounds %struct.QUADSPI_TypeDef, ptr %95, i32 0, i32 0
  %97 = load volatile i32, ptr %96, align 4, !tbaa !22
  %98 = zext i32 %97 to i64
  %99 = or i64 %98, 1048576
  %100 = trunc i64 %99 to i32
  store volatile i32 %100, ptr %96, align 4, !tbaa !22
  br label %101

101:                                              ; preds = %81, %59
  %102 = load ptr, ptr %5, align 8, !tbaa !5
  %103 = load ptr, ptr %6, align 8, !tbaa !5
  call void @QSPI_Config(ptr noundef %102, ptr noundef %103, i32 noundef 201326592)
  br label %104

104:                                              ; preds = %101, %46
  br label %106

105:                                              ; preds = %41
  store i32 2, ptr %8, align 4, !tbaa !9
  br label %106

106:                                              ; preds = %105, %104
  br label %107

107:                                              ; preds = %106
  %108 = load ptr, ptr %5, align 8, !tbaa !5
  %109 = getelementptr inbounds %struct.QSPI_HandleTypeDef, ptr %108, i32 0, i32 9
  store volatile i32 0, ptr %109, align 8, !tbaa !15
  br label %110

110:                                              ; preds = %107
  br label %111

111:                                              ; preds = %110
  %112 = load i32, ptr %8, align 4, !tbaa !9
  store i32 %112, ptr %4, align 4
  store i32 1, ptr %10, align 4
  br label %113

113:                                              ; preds = %111, %35
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  %114 = load i32, ptr %4, align 4
  ret i32 %114
}

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 = !{!16, !10, i64 92}
!21 = !{!16, !6, i64 0}
!22 = !{!23, !10, i64 0}
!23 = !{!"", !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}
!24 = !{!25, !10, i64 4}
!25 = !{!"", !10, i64 0, !10, i64 4}
!26 = !{!25, !10, i64 0}
!27 = !{!23, !10, i64 48}
!28 = !{!23, !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_MemoryMapped(ptr noundef %0, ptr noundef %1, ptr nocapture noundef readonly %2) local_unnamed_addr #1 {
  %4 = tail call i32 @HAL_GetTick() #2
  %5 = getelementptr inbounds i8, ptr %0, i64 80
  %6 = load volatile i32, ptr %5, align 8, !tbaa !5
  %7 = icmp eq i32 %6, 1
  br i1 %7, label %34, label %8

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

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

18:                                               ; preds = %12
  %19 = load ptr, ptr %0, align 8, !tbaa !15
  %20 = load volatile i32, ptr %19, align 4, !tbaa !16
  %21 = and i32 %20, -9
  %22 = getelementptr inbounds i8, ptr %2, i64 4
  %23 = load i32, ptr %22, align 4, !tbaa !18
  %24 = or i32 %21, %23
  store volatile i32 %24, ptr %19, align 4, !tbaa !16
  %25 = icmp eq i32 %23, 8
  br i1 %25, label %26, label %32

26:                                               ; preds = %18
  %27 = load i32, ptr %2, align 4, !tbaa !20
  %28 = getelementptr inbounds i8, ptr %19, i64 48
  store volatile i32 %27, ptr %28, align 4, !tbaa !21
  %29 = getelementptr inbounds i8, ptr %19, i64 12
  store volatile i32 16, ptr %29, align 4, !tbaa !22
  %30 = load volatile i32, ptr %19, align 4, !tbaa !16
  %31 = or i32 %30, 1048576
  store volatile i32 %31, ptr %19, align 4, !tbaa !16
  br label %32

32:                                               ; preds = %26, %18
  tail call void @QSPI_Config(ptr noundef nonnull %0, ptr noundef %1, i32 noundef 201326592)
  br label %33

33:                                               ; preds = %8, %32, %12
  %.024 = phi i32 [ 0, %32 ], [ %16, %12 ], [ 2, %8 ]
  store volatile i32 0, ptr %5, align 8, !tbaa !5
  br label %34

34:                                               ; preds = %3, %33
  %.0 = phi i32 [ %.024, %33 ], [ 2, %3 ]
  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 = !{!6, !11, i64 92}
!15 = !{!6, !7, i64 0}
!16 = !{!17, !11, i64 0}
!17 = !{!"", !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}
!18 = !{!19, !11, i64 4}
!19 = !{!"", !11, i64 0, !11, i64 4}
!20 = !{!19, !11, i64 0}
!21 = !{!17, !11, i64 48}
!22 = !{!17, !11, i64 12}


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