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

; 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.NOR_HandleTypeDef = type { ptr, ptr, %struct.FMC_NORSRAM_InitTypeDef, i32, i32 }
%struct.FMC_NORSRAM_InitTypeDef = type { i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32 }

@uwNORMemoryDataWidth = external hidden global i32, align 4

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: alwaysinline nounwind uwtable
declare hidden void @__DSB() #1

; 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_NOR_Read(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 = load ptr, ptr %5, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.NOR_HandleTypeDef, ptr %11, i32 0, i32 4
  %13 = load volatile i32, ptr %12, align 8, !tbaa !9
  store i32 %13, ptr %9, align 4, !tbaa !13
  %14 = load i32, ptr %9, align 4, !tbaa !13
  %15 = icmp eq i32 %14, 2
  br i1 %15, label %16, label %17

16:                                               ; preds = %3
  store i32 2, ptr %4, align 4
  store i32 1, ptr %10, align 4
  br label %122

17:                                               ; preds = %3
  %18 = load i32, ptr %9, align 4, !tbaa !13
  %19 = icmp eq i32 %18, 1
  br i1 %19, label %23, label %20

20:                                               ; preds = %17
  %21 = load i32, ptr %9, align 4, !tbaa !13
  %22 = icmp eq i32 %21, 4
  br i1 %22, label %23, label %119

23:                                               ; preds = %20, %17
  br label %24

24:                                               ; preds = %23
  %25 = load ptr, ptr %5, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.NOR_HandleTypeDef, ptr %25, i32 0, i32 3
  %27 = load i32, ptr %26, align 4, !tbaa !14
  %28 = icmp eq i32 %27, 1
  br i1 %28, label %29, label %30

29:                                               ; preds = %24
  store i32 2, ptr %4, align 4
  store i32 1, ptr %10, align 4
  br label %122

30:                                               ; preds = %24
  %31 = load ptr, ptr %5, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.NOR_HandleTypeDef, ptr %31, i32 0, i32 3
  store i32 1, ptr %32, align 4, !tbaa !14
  br label %33

33:                                               ; preds = %30
  br label %34

34:                                               ; preds = %33
  br label %35

35:                                               ; preds = %34
  %36 = load ptr, ptr %5, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.NOR_HandleTypeDef, ptr %36, i32 0, i32 4
  store volatile i32 2, ptr %37, align 8, !tbaa !9
  %38 = load ptr, ptr %5, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.NOR_HandleTypeDef, ptr %38, i32 0, i32 2
  %40 = getelementptr inbounds %struct.FMC_NORSRAM_InitTypeDef, ptr %39, i32 0, i32 0
  %41 = load i32, ptr %40, align 8, !tbaa !15
  %42 = icmp eq i32 %41, 0
  br i1 %42, label %43, label %44

43:                                               ; preds = %35
  store i32 1610612736, ptr %8, align 4, !tbaa !13
  br label %61

44:                                               ; preds = %35
  %45 = load ptr, ptr %5, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.NOR_HandleTypeDef, ptr %45, i32 0, i32 2
  %47 = getelementptr inbounds %struct.FMC_NORSRAM_InitTypeDef, ptr %46, i32 0, i32 0
  %48 = load i32, ptr %47, align 8, !tbaa !15
  %49 = icmp eq i32 %48, 2
  br i1 %49, label %50, label %51

50:                                               ; preds = %44
  store i32 1677721600, ptr %8, align 4, !tbaa !13
  br label %60

51:                                               ; preds = %44
  %52 = load ptr, ptr %5, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.NOR_HandleTypeDef, ptr %52, i32 0, i32 2
  %54 = getelementptr inbounds %struct.FMC_NORSRAM_InitTypeDef, ptr %53, i32 0, i32 0
  %55 = load i32, ptr %54, align 8, !tbaa !15
  %56 = icmp eq i32 %55, 4
  br i1 %56, label %57, label %58

57:                                               ; preds = %51
  store i32 1744830464, ptr %8, align 4, !tbaa !13
  br label %59

58:                                               ; preds = %51
  store i32 1811939328, ptr %8, align 4, !tbaa !13
  br label %59

59:                                               ; preds = %58, %57
  br label %60

60:                                               ; preds = %59, %50
  br label %61

61:                                               ; preds = %60, %43
  br label %62

62:                                               ; preds = %61
  %63 = load i32, ptr @uwNORMemoryDataWidth, align 4, !tbaa !13
  %64 = icmp eq i32 %63, 1
  br i1 %64, label %65, label %68

65:                                               ; preds = %62
  %66 = load i32, ptr %8, align 4, !tbaa !13
  %67 = add i32 %66, 2730
  br label %71

68:                                               ; preds = %62
  %69 = load i32, ptr %8, align 4, !tbaa !13
  %70 = add i32 %69, 1365
  br label %71

71:                                               ; preds = %68, %65
  %72 = phi i32 [ %67, %65 ], [ %70, %68 ]
  %73 = zext i32 %72 to i64
  %74 = inttoptr i64 %73 to ptr
  store volatile i16 170, ptr %74, align 2, !tbaa !16
  call void @__DSB()
  br label %75

75:                                               ; preds = %71
  br label %76

76:                                               ; preds = %75
  br label %77

77:                                               ; preds = %76
  %78 = load i32, ptr @uwNORMemoryDataWidth, align 4, !tbaa !13
  %79 = icmp eq i32 %78, 1
  br i1 %79, label %80, label %83

80:                                               ; preds = %77
  %81 = load i32, ptr %8, align 4, !tbaa !13
  %82 = add i32 %81, 1364
  br label %86

83:                                               ; preds = %77
  %84 = load i32, ptr %8, align 4, !tbaa !13
  %85 = add i32 %84, 682
  br label %86

86:                                               ; preds = %83, %80
  %87 = phi i32 [ %82, %80 ], [ %85, %83 ]
  %88 = zext i32 %87 to i64
  %89 = inttoptr i64 %88 to ptr
  store volatile i16 85, ptr %89, align 2, !tbaa !16
  call void @__DSB()
  br label %90

90:                                               ; preds = %86
  br label %91

91:                                               ; preds = %90
  br label %92

92:                                               ; preds = %91
  %93 = load i32, ptr @uwNORMemoryDataWidth, align 4, !tbaa !13
  %94 = icmp eq i32 %93, 1
  br i1 %94, label %95, label %98

95:                                               ; preds = %92
  %96 = load i32, ptr %8, align 4, !tbaa !13
  %97 = add i32 %96, 2730
  br label %101

98:                                               ; preds = %92
  %99 = load i32, ptr %8, align 4, !tbaa !13
  %100 = add i32 %99, 1365
  br label %101

101:                                              ; preds = %98, %95
  %102 = phi i32 [ %97, %95 ], [ %100, %98 ]
  %103 = zext i32 %102 to i64
  %104 = inttoptr i64 %103 to ptr
  store volatile i16 240, ptr %104, align 2, !tbaa !16
  call void @__DSB()
  br label %105

105:                                              ; preds = %101
  br label %106

106:                                              ; preds = %105
  %107 = load ptr, ptr %6, align 8, !tbaa !5
  %108 = load volatile i32, ptr %107, align 4, !tbaa !13
  %109 = trunc i32 %108 to i16
  %110 = load ptr, ptr %7, align 8, !tbaa !5
  store i16 %109, ptr %110, align 2, !tbaa !16
  %111 = load i32, ptr %9, align 4, !tbaa !13
  %112 = load ptr, ptr %5, align 8, !tbaa !5
  %113 = getelementptr inbounds %struct.NOR_HandleTypeDef, ptr %112, i32 0, i32 4
  store volatile i32 %111, ptr %113, align 8, !tbaa !9
  br label %114

114:                                              ; preds = %106
  %115 = load ptr, ptr %5, align 8, !tbaa !5
  %116 = getelementptr inbounds %struct.NOR_HandleTypeDef, ptr %115, i32 0, i32 3
  store i32 0, ptr %116, align 4, !tbaa !14
  br label %117

117:                                              ; preds = %114
  br label %118

118:                                              ; preds = %117
  br label %120

119:                                              ; preds = %20
  store i32 1, ptr %4, align 4
  store i32 1, ptr %10, align 4
  br label %122

120:                                              ; preds = %118
  br label %121

121:                                              ; preds = %120
  store i32 0, ptr %4, align 4
  store i32 1, ptr %10, align 4
  br label %122

122:                                              ; preds = %121, %119, %29, %16
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  %123 = load i32, ptr %4, align 4
  ret i32 %123
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { alwaysinline 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 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, !12, i64 80}
!10 = !{!"", !6, i64 0, !6, i64 8, !11, i64 16, !12, i64 76, !12, i64 80}
!11 = !{!"", !12, i64 0, !12, i64 4, !12, i64 8, !12, i64 12, !12, i64 16, !12, i64 20, !12, i64 24, !12, i64 28, !12, i64 32, !12, i64 36, !12, i64 40, !12, i64 44, !12, i64 48, !12, i64 52, !12, i64 56}
!12 = !{!"int", !7, i64 0}
!13 = !{!12, !12, i64 0}
!14 = !{!10, !12, i64 76}
!15 = !{!10, !12, i64 16}
!16 = !{!17, !17, i64 0}
!17 = !{!"short", !7, 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"

@uwNORMemoryDataWidth = external hidden local_unnamed_addr global i32, align 4
@switch.table.HAL_NOR_Read = private unnamed_addr constant [5 x i32] [i32 1610612736, i32 1811939328, i32 1677721600, i32 1811939328, i32 1744830464], align 4

; Function Attrs: alwaysinline nounwind uwtable
declare hidden void @__DSB() local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 3) i32 @HAL_NOR_Read(ptr noundef %0, ptr noundef %1, ptr nocapture noundef writeonly %2) local_unnamed_addr #1 {
  %4 = getelementptr inbounds i8, ptr %0, i64 80
  %5 = load volatile i32, ptr %4, align 8, !tbaa !5
  switch i32 %5, label %.fold.split [
    i32 2, label %35
    i32 4, label %6
    i32 1, label %6
  ]

6:                                                ; preds = %3, %3
  %7 = getelementptr inbounds i8, ptr %0, i64 76
  %8 = load i32, ptr %7, align 4, !tbaa !12
  %9 = icmp eq i32 %8, 1
  br i1 %9, label %35, label %10

10:                                               ; preds = %6
  store i32 1, ptr %7, align 4, !tbaa !12
  store volatile i32 2, ptr %4, align 8, !tbaa !5
  %11 = getelementptr inbounds i8, ptr %0, i64 16
  %12 = load i32, ptr %11, align 8, !tbaa !13
  %13 = icmp ult i32 %12, 5
  br i1 %13, label %switch.lookup, label %15

switch.lookup:                                    ; preds = %10
  %14 = zext nneg i32 %12 to i64
  %switch.gep = getelementptr inbounds [5 x i32], ptr @switch.table.HAL_NOR_Read, i64 0, i64 %14
  %switch.load = load i32, ptr %switch.gep, align 4
  br label %15

15:                                               ; preds = %10, %switch.lookup
  %.022 = phi i32 [ %switch.load, %switch.lookup ], [ 1811939328, %10 ]
  %16 = load i32, ptr @uwNORMemoryDataWidth, align 4, !tbaa !14
  %17 = icmp eq i32 %16, 1
  %18 = or disjoint i32 %.022, 2730
  %19 = or disjoint i32 %.022, 1365
  %20 = select i1 %17, i32 %18, i32 %19
  %21 = zext nneg i32 %20 to i64
  %22 = inttoptr i64 %21 to ptr
  store volatile i16 170, ptr %22, align 2, !tbaa !15
  tail call void @__DSB()
  %23 = load i32, ptr @uwNORMemoryDataWidth, align 4, !tbaa !14
  %24 = icmp eq i32 %23, 1
  %.v = select i1 %24, i32 1364, i32 682
  %25 = or disjoint i32 %.v, %.022
  %26 = zext nneg i32 %25 to i64
  %27 = inttoptr i64 %26 to ptr
  store volatile i16 85, ptr %27, align 2, !tbaa !15
  tail call void @__DSB()
  %28 = load i32, ptr @uwNORMemoryDataWidth, align 4, !tbaa !14
  %29 = icmp eq i32 %28, 1
  %30 = select i1 %29, i32 %18, i32 %19
  %31 = zext nneg i32 %30 to i64
  %32 = inttoptr i64 %31 to ptr
  store volatile i16 240, ptr %32, align 2, !tbaa !15
  tail call void @__DSB()
  %33 = load volatile i32, ptr %1, align 4, !tbaa !14
  %34 = trunc i32 %33 to i16
  store i16 %34, ptr %2, align 2, !tbaa !15
  store volatile i32 %5, ptr %4, align 8, !tbaa !5
  store i32 0, ptr %7, align 4, !tbaa !12
  br label %35

.fold.split:                                      ; preds = %3
  br label %35

35:                                               ; preds = %3, %.fold.split, %6, %15
  %.0 = phi i32 [ 0, %15 ], [ %5, %3 ], [ 2, %6 ], [ 1, %.fold.split ]
  ret i32 %.0
}

attributes #0 = { alwaysinline 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 #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" }

!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, !7, i64 8, !10, i64 16, !11, i64 76, !11, i64 80}
!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 76}
!13 = !{!6, !11, i64 16}
!14 = !{!11, !11, i64 0}
!15 = !{!16, !16, i64 0}
!16 = !{!"short", !8, i64 0}


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