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

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

; 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_SRAM_Read_16b(ptr noundef %0, ptr noundef %1, ptr noundef %2, i32 noundef %3) #1 {
  %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 ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca i8, align 1
  %14 = alloca i32, align 4
  %15 = 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) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #2
  %16 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %16, ptr %11, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #2
  %17 = load ptr, ptr %8, align 8, !tbaa !5
  store ptr %17, ptr %12, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 1, ptr %13) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #2
  %18 = load ptr, ptr %6, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.SRAM_HandleTypeDef, ptr %18, i32 0, i32 4
  %20 = load volatile i32, ptr %19, align 8, !tbaa !11
  store i32 %20, ptr %14, align 4, !tbaa !9
  %21 = load i32, ptr %14, align 4, !tbaa !9
  %22 = icmp eq i32 %21, 1
  br i1 %22, label %26, label %23

23:                                               ; preds = %4
  %24 = load i32, ptr %14, align 4, !tbaa !9
  %25 = icmp eq i32 %24, 4
  br i1 %25, label %26, label %93

26:                                               ; preds = %23, %4
  br label %27

27:                                               ; preds = %26
  %28 = load ptr, ptr %6, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.SRAM_HandleTypeDef, ptr %28, i32 0, i32 3
  %30 = load i32, ptr %29, align 4, !tbaa !14
  %31 = icmp eq i32 %30, 1
  br i1 %31, label %32, label %33

32:                                               ; preds = %27
  store i32 2, ptr %5, align 4
  store i32 1, ptr %15, align 4
  br label %95

33:                                               ; preds = %27
  %34 = load ptr, ptr %6, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.SRAM_HandleTypeDef, ptr %34, i32 0, i32 3
  store i32 1, ptr %35, align 4, !tbaa !14
  br label %36

36:                                               ; preds = %33
  br label %37

37:                                               ; preds = %36
  br label %38

38:                                               ; preds = %37
  %39 = load ptr, ptr %6, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.SRAM_HandleTypeDef, ptr %39, i32 0, i32 4
  store volatile i32 2, ptr %40, align 8, !tbaa !11
  %41 = load i32, ptr %9, align 4, !tbaa !9
  %42 = urem i32 %41, 2
  %43 = icmp ne i32 %42, 0
  %44 = zext i1 %43 to i64
  %45 = select i1 %43, i32 1, i32 0
  %46 = trunc i32 %45 to i8
  store i8 %46, ptr %13, align 1, !tbaa !15
  %47 = load i32, ptr %9, align 4, !tbaa !9
  store i32 %47, ptr %10, align 4, !tbaa !9
  br label %48

48:                                               ; preds = %71, %38
  %49 = load i32, ptr %10, align 4, !tbaa !9
  %50 = load i8, ptr %13, align 1, !tbaa !15
  %51 = zext i8 %50 to i32
  %52 = icmp ne i32 %49, %51
  br i1 %52, label %53, label %74

53:                                               ; preds = %48
  %54 = load ptr, ptr %11, align 8, !tbaa !5
  %55 = load volatile i32, ptr %54, align 4, !tbaa !9
  %56 = and i32 %55, 65535
  %57 = trunc i32 %56 to i16
  %58 = load ptr, ptr %12, align 8, !tbaa !5
  store i16 %57, ptr %58, align 2, !tbaa !16
  %59 = load ptr, ptr %12, align 8, !tbaa !5
  %60 = getelementptr inbounds i16, ptr %59, i32 1
  store ptr %60, ptr %12, align 8, !tbaa !5
  %61 = load ptr, ptr %11, align 8, !tbaa !5
  %62 = load volatile i32, ptr %61, align 4, !tbaa !9
  %63 = and i32 %62, -65536
  %64 = lshr i32 %63, 16
  %65 = trunc i32 %64 to i16
  %66 = load ptr, ptr %12, align 8, !tbaa !5
  store i16 %65, ptr %66, align 2, !tbaa !16
  %67 = load ptr, ptr %12, align 8, !tbaa !5
  %68 = getelementptr inbounds i16, ptr %67, i32 1
  store ptr %68, ptr %12, align 8, !tbaa !5
  %69 = load ptr, ptr %11, align 8, !tbaa !5
  %70 = getelementptr inbounds i32, ptr %69, i32 1
  store ptr %70, ptr %11, align 8, !tbaa !5
  br label %71

71:                                               ; preds = %53
  %72 = load i32, ptr %10, align 4, !tbaa !9
  %73 = sub i32 %72, 2
  store i32 %73, ptr %10, align 4, !tbaa !9
  br label %48, !llvm.loop !18

74:                                               ; preds = %48
  %75 = load i8, ptr %13, align 1, !tbaa !15
  %76 = zext i8 %75 to i32
  %77 = icmp ne i32 %76, 0
  br i1 %77, label %78, label %84

78:                                               ; preds = %74
  %79 = load ptr, ptr %11, align 8, !tbaa !5
  %80 = load volatile i32, ptr %79, align 4, !tbaa !9
  %81 = and i32 %80, 65535
  %82 = trunc i32 %81 to i16
  %83 = load ptr, ptr %12, align 8, !tbaa !5
  store i16 %82, ptr %83, align 2, !tbaa !16
  br label %84

84:                                               ; preds = %78, %74
  %85 = load i32, ptr %14, align 4, !tbaa !9
  %86 = load ptr, ptr %6, align 8, !tbaa !5
  %87 = getelementptr inbounds %struct.SRAM_HandleTypeDef, ptr %86, i32 0, i32 4
  store volatile i32 %85, ptr %87, align 8, !tbaa !11
  br label %88

88:                                               ; preds = %84
  %89 = load ptr, ptr %6, align 8, !tbaa !5
  %90 = getelementptr inbounds %struct.SRAM_HandleTypeDef, ptr %89, i32 0, i32 3
  store i32 0, ptr %90, align 4, !tbaa !14
  br label %91

91:                                               ; preds = %88
  br label %92

92:                                               ; preds = %91
  br label %94

93:                                               ; preds = %23
  store i32 1, ptr %5, align 4
  store i32 1, ptr %15, align 4
  br label %95

94:                                               ; preds = %92
  store i32 0, ptr %5, align 4
  store i32 1, ptr %15, align 4
  br label %95

95:                                               ; preds = %94, %93, %32
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #2
  call void @llvm.lifetime.end.p0(i64 1, ptr %13) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #2
  %96 = load i32, ptr %5, align 4
  ret i32 %96
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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, !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 80}
!12 = !{!"", !6, i64 0, !6, i64 8, !13, i64 16, !10, i64 76, !10, i64 80, !6, i64 88}
!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 76}
!15 = !{!7, !7, i64 0}
!16 = !{!17, !17, i64 0}
!17 = !{!"short", !7, i64 0}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}


; 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"

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

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

11:                                               ; preds = %7
  store i32 1, ptr %8, align 4, !tbaa !12
  store volatile i32 2, ptr %5, align 8, !tbaa !5
  %12 = and i32 %3, 1
  %.not32 = icmp ult i32 %3, 2
  br i1 %.not32, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %11, %.lr.ph
  %.02735 = phi i32 [ %21, %.lr.ph ], [ %3, %11 ]
  %.02834 = phi ptr [ %19, %.lr.ph ], [ %2, %11 ]
  %.02933 = phi ptr [ %20, %.lr.ph ], [ %1, %11 ]
  %13 = load volatile i32, ptr %.02933, align 4, !tbaa !13
  %14 = trunc i32 %13 to i16
  store i16 %14, ptr %.02834, align 2, !tbaa !14
  %15 = getelementptr inbounds i8, ptr %.02834, i64 2
  %16 = load volatile i32, ptr %.02933, align 4, !tbaa !13
  %17 = lshr i32 %16, 16
  %18 = trunc nuw i32 %17 to i16
  store i16 %18, ptr %15, align 2, !tbaa !14
  %19 = getelementptr inbounds i8, ptr %.02834, i64 4
  %20 = getelementptr inbounds i8, ptr %.02933, i64 4
  %21 = add i32 %.02735, -2
  %.not = icmp eq i32 %21, %12
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !16

._crit_edge:                                      ; preds = %.lr.ph, %11
  %.029.lcssa = phi ptr [ %1, %11 ], [ %20, %.lr.ph ]
  %.028.lcssa = phi ptr [ %2, %11 ], [ %19, %.lr.ph ]
  %.not31 = icmp eq i32 %12, 0
  br i1 %.not31, label %25, label %22

22:                                               ; preds = %._crit_edge
  %23 = load volatile i32, ptr %.029.lcssa, align 4, !tbaa !13
  %24 = trunc i32 %23 to i16
  store i16 %24, ptr %.028.lcssa, align 2, !tbaa !14
  br label %25

25:                                               ; preds = %22, %._crit_edge
  store volatile i32 %6, ptr %5, align 8, !tbaa !5
  store i32 0, ptr %8, align 4, !tbaa !12
  br label %26

26:                                               ; preds = %4, %7, %25
  %.0 = phi i32 [ 0, %25 ], [ 2, %7 ], [ 1, %4 ]
  ret i32 %.0
}

attributes #0 = { nofree norecurse 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, i64 88}
!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 = !{!11, !11, i64 0}
!14 = !{!15, !15, i64 0}
!15 = !{!"short", !8, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}


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