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

; 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.TIM_HandleTypeDef = type { ptr, %struct.TIM_Base_InitTypeDef, i32, [7 x ptr], i32, i32 }
%struct.TIM_Base_InitTypeDef = type { i32, i32, i32, i32, i32, i32 }
%struct.TIM_TypeDef = type { i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32 }

; Function Attrs: nounwind uwtable
define dso_local i32 @HAL_TIMEx_ConfigCommutEvent(ptr noundef %0, i32 noundef %1, i32 noundef %2) #0 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !9
  store i32 %2, ptr %7, align 4, !tbaa !9
  br label %8

8:                                                ; preds = %3
  %9 = load ptr, ptr %5, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct.TIM_HandleTypeDef, ptr %9, i32 0, i32 4
  %11 = load i32, ptr %10, align 8, !tbaa !11
  %12 = icmp eq i32 %11, 1
  br i1 %12, label %13, label %14

13:                                               ; preds = %8
  store i32 2, ptr %4, align 4
  br label %93

14:                                               ; preds = %8
  %15 = load ptr, ptr %5, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.TIM_HandleTypeDef, ptr %15, i32 0, i32 4
  store i32 1, ptr %16, align 8, !tbaa !11
  br label %17

17:                                               ; preds = %14
  br label %18

18:                                               ; preds = %17
  %19 = load i32, ptr %6, align 4, !tbaa !9
  %20 = icmp eq i32 %19, 0
  br i1 %20, label %33, label %21

21:                                               ; preds = %18
  %22 = load i32, ptr %6, align 4, !tbaa !9
  %23 = zext i32 %22 to i64
  %24 = icmp eq i64 %23, 16
  br i1 %24, label %33, label %25

25:                                               ; preds = %21
  %26 = load i32, ptr %6, align 4, !tbaa !9
  %27 = zext i32 %26 to i64
  %28 = icmp eq i64 %27, 32
  br i1 %28, label %33, label %29

29:                                               ; preds = %25
  %30 = load i32, ptr %6, align 4, !tbaa !9
  %31 = zext i32 %30 to i64
  %32 = icmp eq i64 %31, 48
  br i1 %32, label %33, label %49

33:                                               ; preds = %29, %25, %21, %18
  %34 = load ptr, ptr %5, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.TIM_HandleTypeDef, ptr %34, i32 0, i32 0
  %36 = load ptr, ptr %35, align 8, !tbaa !14
  %37 = getelementptr inbounds %struct.TIM_TypeDef, ptr %36, i32 0, i32 2
  %38 = load volatile i32, ptr %37, align 4, !tbaa !15
  %39 = zext i32 %38 to i64
  %40 = and i64 %39, -3145841
  %41 = trunc i64 %40 to i32
  store volatile i32 %41, ptr %37, align 4, !tbaa !15
  %42 = load i32, ptr %6, align 4, !tbaa !9
  %43 = load ptr, ptr %5, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.TIM_HandleTypeDef, ptr %43, i32 0, i32 0
  %45 = load ptr, ptr %44, align 8, !tbaa !14
  %46 = getelementptr inbounds %struct.TIM_TypeDef, ptr %45, i32 0, i32 2
  %47 = load volatile i32, ptr %46, align 4, !tbaa !15
  %48 = or i32 %47, %42
  store volatile i32 %48, ptr %46, align 4, !tbaa !15
  br label %49

49:                                               ; preds = %33, %29
  %50 = load ptr, ptr %5, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.TIM_HandleTypeDef, ptr %50, i32 0, i32 0
  %52 = load ptr, ptr %51, align 8, !tbaa !14
  %53 = getelementptr inbounds %struct.TIM_TypeDef, ptr %52, i32 0, i32 1
  %54 = load volatile i32, ptr %53, align 4, !tbaa !17
  %55 = zext i32 %54 to i64
  %56 = or i64 %55, 1
  %57 = trunc i64 %56 to i32
  store volatile i32 %57, ptr %53, align 4, !tbaa !17
  %58 = load ptr, ptr %5, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.TIM_HandleTypeDef, ptr %58, i32 0, i32 0
  %60 = load ptr, ptr %59, align 8, !tbaa !14
  %61 = getelementptr inbounds %struct.TIM_TypeDef, ptr %60, i32 0, i32 1
  %62 = load volatile i32, ptr %61, align 4, !tbaa !17
  %63 = zext i32 %62 to i64
  %64 = and i64 %63, -5
  %65 = trunc i64 %64 to i32
  store volatile i32 %65, ptr %61, align 4, !tbaa !17
  %66 = load i32, ptr %7, align 4, !tbaa !9
  %67 = load ptr, ptr %5, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct.TIM_HandleTypeDef, ptr %67, i32 0, i32 0
  %69 = load ptr, ptr %68, align 8, !tbaa !14
  %70 = getelementptr inbounds %struct.TIM_TypeDef, ptr %69, i32 0, i32 1
  %71 = load volatile i32, ptr %70, align 4, !tbaa !17
  %72 = or i32 %71, %66
  store volatile i32 %72, ptr %70, align 4, !tbaa !17
  %73 = load ptr, ptr %5, align 8, !tbaa !5
  %74 = getelementptr inbounds %struct.TIM_HandleTypeDef, ptr %73, i32 0, i32 0
  %75 = load ptr, ptr %74, align 8, !tbaa !14
  %76 = getelementptr inbounds %struct.TIM_TypeDef, ptr %75, i32 0, i32 3
  %77 = load volatile i32, ptr %76, align 4, !tbaa !18
  %78 = zext i32 %77 to i64
  %79 = and i64 %78, -33
  %80 = trunc i64 %79 to i32
  store volatile i32 %80, ptr %76, align 4, !tbaa !18
  %81 = load ptr, ptr %5, align 8, !tbaa !5
  %82 = getelementptr inbounds %struct.TIM_HandleTypeDef, ptr %81, i32 0, i32 0
  %83 = load ptr, ptr %82, align 8, !tbaa !14
  %84 = getelementptr inbounds %struct.TIM_TypeDef, ptr %83, i32 0, i32 3
  %85 = load volatile i32, ptr %84, align 4, !tbaa !18
  %86 = zext i32 %85 to i64
  %87 = and i64 %86, -8193
  %88 = trunc i64 %87 to i32
  store volatile i32 %88, ptr %84, align 4, !tbaa !18
  br label %89

89:                                               ; preds = %49
  %90 = load ptr, ptr %5, align 8, !tbaa !5
  %91 = getelementptr inbounds %struct.TIM_HandleTypeDef, ptr %90, i32 0, i32 4
  store i32 0, ptr %91, align 8, !tbaa !11
  br label %92

92:                                               ; preds = %89
  store i32 0, ptr %4, align 4
  br label %93

93:                                               ; preds = %92, %13
  %94 = load i32, ptr %4, align 4
  ret i32 %94
}

attributes #0 = { 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, !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 96}
!12 = !{!"", !6, i64 0, !13, i64 8, !10, i64 32, !7, i64 40, !10, i64 96, !10, i64 100}
!13 = !{!"", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20}
!14 = !{!12, !6, i64 0}
!15 = !{!16, !10, i64 8}
!16 = !{!"", !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, !10, i64 60, !10, i64 64, !10, i64 68, !10, i64 72, !10, i64 76, !10, i64 80, !10, i64 84, !10, i64 88, !10, i64 92, !10, i64 96, !10, i64 100, !10, i64 104}
!17 = !{!16, !10, i64 4}
!18 = !{!16, !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"

; Function Attrs: nofree norecurse nounwind uwtable
define dso_local range(i32 0, 3) i32 @HAL_TIMEx_ConfigCommutEvent(ptr nocapture noundef %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = getelementptr inbounds i8, ptr %0, i64 96
  %5 = load i32, ptr %4, align 8, !tbaa !5
  %6 = icmp eq i32 %5, 1
  br i1 %6, label %28, label %7

7:                                                ; preds = %3
  %8 = tail call i32 @llvm.fshl.i32(i32 %1, i32 %1, i32 28)
  %switch = icmp ult i32 %8, 4
  %.pre = load ptr, ptr %0, align 8, !tbaa !12
  br i1 %switch, label %9, label %15

9:                                                ; preds = %7
  %10 = getelementptr inbounds i8, ptr %.pre, i64 8
  %11 = load volatile i32, ptr %10, align 4, !tbaa !13
  %12 = and i32 %11, -3145841
  store volatile i32 %12, ptr %10, align 4, !tbaa !13
  %13 = load volatile i32, ptr %10, align 4, !tbaa !13
  %14 = or i32 %13, %1
  store volatile i32 %14, ptr %10, align 4, !tbaa !13
  br label %15

15:                                               ; preds = %7, %9
  %16 = getelementptr inbounds i8, ptr %.pre, i64 4
  %17 = load volatile i32, ptr %16, align 4, !tbaa !15
  %18 = or i32 %17, 1
  store volatile i32 %18, ptr %16, align 4, !tbaa !15
  %19 = load volatile i32, ptr %16, align 4, !tbaa !15
  %20 = and i32 %19, -5
  store volatile i32 %20, ptr %16, align 4, !tbaa !15
  %21 = load volatile i32, ptr %16, align 4, !tbaa !15
  %22 = or i32 %21, %2
  store volatile i32 %22, ptr %16, align 4, !tbaa !15
  %23 = getelementptr inbounds i8, ptr %.pre, i64 12
  %24 = load volatile i32, ptr %23, align 4, !tbaa !16
  %25 = and i32 %24, -33
  store volatile i32 %25, ptr %23, align 4, !tbaa !16
  %26 = load volatile i32, ptr %23, align 4, !tbaa !16
  %27 = and i32 %26, -8193
  store volatile i32 %27, ptr %23, align 4, !tbaa !16
  store i32 0, ptr %4, align 8, !tbaa !5
  br label %28

28:                                               ; preds = %3, %15
  %.0 = phi i32 [ 0, %15 ], [ 2, %3 ]
  ret i32 %.0
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.fshl.i32(i32, i32, 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, !11, i64 96}
!6 = !{!"", !7, i64 0, !10, i64 8, !11, i64 32, !8, i64 40, !11, i64 96, !11, i64 100}
!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 = !{!"int", !8, i64 0}
!12 = !{!6, !7, i64 0}
!13 = !{!14, !11, i64 8}
!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, !11, i64 32, !11, i64 36, !11, i64 40, !11, i64 44, !11, i64 48, !11, i64 52, !11, i64 56, !11, i64 60, !11, i64 64, !11, i64 68, !11, i64 72, !11, i64 76, !11, i64 80, !11, i64 84, !11, i64 88, !11, i64 92, !11, i64 96, !11, i64 100, !11, i64 104}
!15 = !{!14, !11, i64 4}
!16 = !{!14, !11, i64 12}


; Effective O3 passes: DSEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass