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

; 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.SPDIFRX_SetDataFormatTypeDef = type { i32, i32, i32, i32, i32, i32 }
%struct.SPDIFRX_HandleTypeDef = type { ptr, %struct.SPDIFRX_InitTypeDef, ptr, ptr, i16, i16, i16, i16, ptr, ptr, i32, i32, i32 }
%struct.SPDIFRX_InitTypeDef = type { i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32 }
%struct.SPDIFRX_TypeDef = type { 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_SPDIFRX_SetDataFormat(ptr noundef %0, ptr noundef byval(%struct.SPDIFRX_SetDataFormatTypeDef) align 8 %1) #1 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #2
  %7 = load ptr, ptr %4, align 8, !tbaa !5
  %8 = icmp eq ptr %7, null
  br i1 %8, label %9, label %10

9:                                                ; preds = %2
  store i32 1, ptr %3, align 4
  store i32 1, ptr %6, align 4
  br label %65

10:                                               ; preds = %2
  %11 = load ptr, ptr %4, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.SPDIFRX_HandleTypeDef, ptr %11, i32 0, i32 0
  %13 = load ptr, ptr %12, align 8, !tbaa !9
  %14 = getelementptr inbounds %struct.SPDIFRX_TypeDef, ptr %13, i32 0, i32 0
  %15 = load volatile i32, ptr %14, align 4, !tbaa !14
  store i32 %15, ptr %5, align 4, !tbaa !16
  %16 = load i32, ptr %5, align 4, !tbaa !16
  %17 = and i32 %16, 3
  %18 = icmp eq i32 %17, 3
  br i1 %18, label %19, label %36

19:                                               ; preds = %10
  %20 = load i32, ptr %5, align 4, !tbaa !16
  %21 = zext i32 %20 to i64
  %22 = and i64 %21, 48
  %23 = getelementptr inbounds %struct.SPDIFRX_SetDataFormatTypeDef, ptr %1, i32 0, i32 0
  %24 = load i32, ptr %23, align 8, !tbaa !17
  %25 = zext i32 %24 to i64
  %26 = icmp ne i64 %22, %25
  br i1 %26, label %35, label %27

27:                                               ; preds = %19
  %28 = load i32, ptr %5, align 4, !tbaa !16
  %29 = zext i32 %28 to i64
  %30 = and i64 %29, 8
  %31 = getelementptr inbounds %struct.SPDIFRX_SetDataFormatTypeDef, ptr %1, i32 0, i32 1
  %32 = load i32, ptr %31, align 4, !tbaa !19
  %33 = zext i32 %32 to i64
  %34 = icmp ne i64 %30, %33
  br i1 %34, label %35, label %36

35:                                               ; preds = %27, %19
  store i32 1, ptr %3, align 4
  store i32 1, ptr %6, align 4
  br label %65

36:                                               ; preds = %27, %10
  %37 = load i32, ptr %5, align 4, !tbaa !16
  %38 = zext i32 %37 to i64
  %39 = and i64 %38, -1017
  %40 = trunc i64 %39 to i32
  store i32 %40, ptr %5, align 4, !tbaa !16
  %41 = getelementptr inbounds %struct.SPDIFRX_SetDataFormatTypeDef, ptr %1, i32 0, i32 1
  %42 = load i32, ptr %41, align 4, !tbaa !19
  %43 = getelementptr inbounds %struct.SPDIFRX_SetDataFormatTypeDef, ptr %1, i32 0, i32 0
  %44 = load i32, ptr %43, align 8, !tbaa !17
  %45 = or i32 %42, %44
  %46 = getelementptr inbounds %struct.SPDIFRX_SetDataFormatTypeDef, ptr %1, i32 0, i32 2
  %47 = load i32, ptr %46, align 8, !tbaa !20
  %48 = or i32 %45, %47
  %49 = getelementptr inbounds %struct.SPDIFRX_SetDataFormatTypeDef, ptr %1, i32 0, i32 3
  %50 = load i32, ptr %49, align 4, !tbaa !21
  %51 = or i32 %48, %50
  %52 = getelementptr inbounds %struct.SPDIFRX_SetDataFormatTypeDef, ptr %1, i32 0, i32 4
  %53 = load i32, ptr %52, align 8, !tbaa !22
  %54 = or i32 %51, %53
  %55 = getelementptr inbounds %struct.SPDIFRX_SetDataFormatTypeDef, ptr %1, i32 0, i32 5
  %56 = load i32, ptr %55, align 4, !tbaa !23
  %57 = or i32 %54, %56
  %58 = load i32, ptr %5, align 4, !tbaa !16
  %59 = or i32 %58, %57
  store i32 %59, ptr %5, align 4, !tbaa !16
  %60 = load i32, ptr %5, align 4, !tbaa !16
  %61 = load ptr, ptr %4, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.SPDIFRX_HandleTypeDef, ptr %61, i32 0, i32 0
  %63 = load ptr, ptr %62, align 8, !tbaa !9
  %64 = getelementptr inbounds %struct.SPDIFRX_TypeDef, ptr %63, i32 0, i32 0
  store volatile i32 %60, ptr %64, align 4, !tbaa !14
  store i32 0, ptr %3, align 4
  store i32 1, ptr %6, align 4
  br label %65

65:                                               ; preds = %36, %35, %9
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  %66 = load i32, ptr %3, align 4
  ret i32 %66
}

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, !6, i64 0}
!10 = !{!"", !6, i64 0, !11, i64 8, !6, i64 56, !6, i64 64, !13, i64 72, !13, i64 74, !13, i64 76, !13, i64 78, !6, i64 80, !6, i64 88, !12, i64 96, !12, i64 100, !12, i64 104}
!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 = !{!"int", !7, i64 0}
!13 = !{!"short", !7, i64 0}
!14 = !{!15, !12, i64 0}
!15 = !{!"", !12, i64 0, !12, i64 4, !12, i64 8, !12, i64 12, !12, i64 16, !12, i64 20, !12, i64 24, !12, i64 28}
!16 = !{!12, !12, i64 0}
!17 = !{!18, !12, i64 0}
!18 = !{!"", !12, i64 0, !12, i64 4, !12, i64 8, !12, i64 12, !12, i64 16, !12, i64 20}
!19 = !{!18, !12, i64 4}
!20 = !{!18, !12, i64 8}
!21 = !{!18, !12, i64 12}
!22 = !{!18, !12, i64 16}
!23 = !{!18, !12, i64 20}


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

%struct.SPDIFRX_SetDataFormatTypeDef = type { i32, i32, i32, i32, i32, i32 }

; Function Attrs: nofree norecurse nounwind uwtable
define dso_local range(i32 0, 2) i32 @HAL_SPDIFRX_SetDataFormat(ptr noundef readonly %0, ptr nocapture noundef readonly byval(%struct.SPDIFRX_SetDataFormatTypeDef) align 8 %1) local_unnamed_addr #0 {
  %3 = icmp eq ptr %0, null
  br i1 %3, label %25, label %4

4:                                                ; preds = %2
  %5 = load ptr, ptr %0, align 8, !tbaa !5
  %6 = load volatile i32, ptr %5, align 4, !tbaa !13
  %7 = and i32 %6, 3
  %8 = icmp eq i32 %7, 3
  %9 = load i32, ptr %1, align 8, !tbaa !15
  br i1 %8, label %10, label %._crit_edge

._crit_edge:                                      ; preds = %4
  %.phi.trans.insert = getelementptr inbounds i8, ptr %1, i64 4
  %.pre = load i32, ptr %.phi.trans.insert, align 4, !tbaa !17
  br label %19

10:                                               ; preds = %4
  %11 = zext i32 %6 to i64
  %12 = and i64 %11, 48
  %13 = zext i32 %9 to i64
  %.not = icmp eq i64 %12, %13
  br i1 %.not, label %14, label %25

14:                                               ; preds = %10
  %15 = and i64 %11, 8
  %16 = getelementptr inbounds i8, ptr %1, i64 4
  %17 = load i32, ptr %16, align 4, !tbaa !17
  %18 = zext i32 %17 to i64
  %.not10 = icmp eq i64 %15, %18
  br i1 %.not10, label %19, label %25

19:                                               ; preds = %._crit_edge, %14
  %20 = phi i32 [ %.pre, %._crit_edge ], [ %17, %14 ]
  %21 = and i32 %6, -1017
  %22 = getelementptr inbounds i8, ptr %1, i64 8
  %23 = load <4 x i32>, ptr %22, align 8, !tbaa !18
  %24 = tail call i32 @llvm.vector.reduce.or.v4i32(<4 x i32> %23)
  %op.rdx = or i32 %24, %21
  %op.rdx12 = or i32 %20, %9
  %op.rdx13 = or i32 %op.rdx, %op.rdx12
  store volatile i32 %op.rdx13, ptr %5, align 4, !tbaa !13
  br label %25

25:                                               ; preds = %10, %14, %2, %19
  %.0 = phi i32 [ 0, %19 ], [ 1, %2 ], [ 1, %14 ], [ 1, %10 ]
  ret i32 %.0
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.vector.reduce.or.v4i32(<4 x i32>) #1

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" }
attributes #1 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }

!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, !7, i64 0}
!6 = !{!"", !7, i64 0, !10, i64 8, !7, i64 56, !7, i64 64, !12, i64 72, !12, i64 74, !12, i64 76, !12, i64 78, !7, i64 80, !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 = !{!"int", !8, i64 0}
!12 = !{!"short", !8, i64 0}
!13 = !{!14, !11, i64 0}
!14 = !{!"", !11, i64 0, !11, i64 4, !11, i64 8, !11, i64 12, !11, i64 16, !11, i64 20, !11, i64 24, !11, i64 28}
!15 = !{!16, !11, i64 0}
!16 = !{!"", !11, i64 0, !11, i64 4, !11, i64 8, !11, i64 12, !11, i64 16, !11, i64 20}
!17 = !{!16, !11, i64 4}
!18 = !{!11, !11, i64 0}


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