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

; 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.DFSDM_Channel_HandleTypeDef = type { ptr, %struct.DFSDM_Channel_InitTypeDef, i32 }
%struct.DFSDM_Channel_InitTypeDef = type { %struct.DFSDM_Channel_OutputClockTypeDef, %struct.DFSDM_Channel_InputTypeDef, %struct.DFSDM_Channel_SerialInterfaceTypeDef, %struct.DFSDM_Channel_AwdTypeDef, i32, i32 }
%struct.DFSDM_Channel_OutputClockTypeDef = type { i32, i32, i32 }
%struct.DFSDM_Channel_InputTypeDef = type { i32, i32, i32 }
%struct.DFSDM_Channel_SerialInterfaceTypeDef = type { i32, i32 }
%struct.DFSDM_Channel_AwdTypeDef = type { i32, i32 }
%struct.DFSDM_Channel_TypeDef = type { i32, i32, i32, i32, i32 }

@a_dfsdm1ChannelHandle = external hidden global [8 x ptr], align 16
@v_dfsdm1ChannelCounter = external hidden global i32, align 4

; Function Attrs: nounwind uwtable
declare hidden i32 @DFSDM_GetChannelFromInstance(ptr noundef) #0

; Function Attrs: nounwind uwtable
define dso_local i32 @HAL_DFSDM_ChannelDeInit(ptr noundef %0) #0 {
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  %4 = load ptr, ptr %3, align 8, !tbaa !5
  %5 = icmp eq ptr %4, null
  br i1 %5, label %6, label %7

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

7:                                                ; preds = %1
  %8 = load ptr, ptr %3, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct.DFSDM_Channel_HandleTypeDef, ptr %8, i32 0, i32 0
  %10 = load ptr, ptr %9, align 8, !tbaa !9
  %11 = call i32 @DFSDM_GetChannelFromInstance(ptr noundef %10)
  %12 = zext i32 %11 to i64
  %13 = getelementptr inbounds [8 x ptr], ptr @a_dfsdm1ChannelHandle, i64 0, i64 %12
  %14 = load ptr, ptr %13, align 8, !tbaa !5
  %15 = icmp eq ptr %14, null
  br i1 %15, label %16, label %17

16:                                               ; preds = %7
  store i32 1, ptr %2, align 4
  br label %45

17:                                               ; preds = %7
  %18 = load ptr, ptr %3, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.DFSDM_Channel_HandleTypeDef, ptr %18, i32 0, i32 0
  %20 = load ptr, ptr %19, align 8, !tbaa !9
  %21 = getelementptr inbounds %struct.DFSDM_Channel_TypeDef, ptr %20, i32 0, i32 0
  %22 = load volatile i32, ptr %21, align 4, !tbaa !15
  %23 = zext i32 %22 to i64
  %24 = and i64 %23, -129
  %25 = trunc i64 %24 to i32
  store volatile i32 %25, ptr %21, align 4, !tbaa !15
  %26 = load volatile i32, ptr @v_dfsdm1ChannelCounter, align 4, !tbaa !17
  %27 = add i32 %26, -1
  store volatile i32 %27, ptr @v_dfsdm1ChannelCounter, align 4, !tbaa !17
  %28 = load volatile i32, ptr @v_dfsdm1ChannelCounter, align 4, !tbaa !17
  %29 = icmp eq i32 %28, 0
  br i1 %29, label %30, label %35

30:                                               ; preds = %17
  %31 = load volatile i32, ptr inttoptr (i64 1073836032 to ptr), align 4, !tbaa !15
  %32 = zext i32 %31 to i64
  %33 = and i64 %32, -2147483649
  %34 = trunc i64 %33 to i32
  store volatile i32 %34, ptr inttoptr (i64 1073836032 to ptr), align 4, !tbaa !15
  br label %35

35:                                               ; preds = %30, %17
  %36 = load ptr, ptr %3, align 8, !tbaa !5
  call void @HAL_DFSDM_ChannelMspDeInit(ptr noundef %36)
  %37 = load ptr, ptr %3, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.DFSDM_Channel_HandleTypeDef, ptr %37, i32 0, i32 2
  store i32 0, ptr %38, align 8, !tbaa !18
  %39 = load ptr, ptr %3, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.DFSDM_Channel_HandleTypeDef, ptr %39, i32 0, i32 0
  %41 = load ptr, ptr %40, align 8, !tbaa !9
  %42 = call i32 @DFSDM_GetChannelFromInstance(ptr noundef %41)
  %43 = zext i32 %42 to i64
  %44 = getelementptr inbounds [8 x ptr], ptr @a_dfsdm1ChannelHandle, i64 0, i64 %43
  store ptr null, ptr %44, align 8, !tbaa !5
  store i32 0, ptr %2, align 4
  br label %45

45:                                               ; preds = %35, %16, %6
  %46 = load i32, ptr %2, align 4
  ret i32 %46
}

; Function Attrs: nounwind uwtable
declare dso_local void @HAL_DFSDM_ChannelMspDeInit(ptr noundef) #0

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, !6, i64 0}
!10 = !{!"", !6, i64 0, !11, i64 8, !13, i64 56}
!11 = !{!"", !12, i64 0, !12, i64 12, !14, i64 24, !14, i64 32, !13, i64 40, !13, i64 44}
!12 = !{!"", !13, i64 0, !13, i64 4, !13, i64 8}
!13 = !{!"int", !7, i64 0}
!14 = !{!"", !13, i64 0, !13, i64 4}
!15 = !{!16, !13, i64 0}
!16 = !{!"", !13, i64 0, !13, i64 4, !13, i64 8, !13, i64 12, !13, i64 16}
!17 = !{!13, !13, i64 0}
!18 = !{!10, !13, i64 56}


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

@a_dfsdm1ChannelHandle = external hidden local_unnamed_addr global [8 x ptr], align 16
@v_dfsdm1ChannelCounter = external hidden global i32, align 4

; Function Attrs: nounwind uwtable
declare hidden i32 @DFSDM_GetChannelFromInstance(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 2) i32 @HAL_DFSDM_ChannelDeInit(ptr noundef %0) local_unnamed_addr #0 {
  %2 = icmp eq ptr %0, null
  br i1 %2, label %27, label %3

3:                                                ; preds = %1
  %4 = load ptr, ptr %0, align 8, !tbaa !5
  %5 = tail call i32 @DFSDM_GetChannelFromInstance(ptr noundef %4)
  %6 = zext i32 %5 to i64
  %7 = getelementptr inbounds [8 x ptr], ptr @a_dfsdm1ChannelHandle, i64 0, i64 %6
  %8 = load ptr, ptr %7, align 8, !tbaa !14
  %9 = icmp eq ptr %8, null
  br i1 %9, label %27, label %10

10:                                               ; preds = %3
  %11 = load ptr, ptr %0, align 8, !tbaa !5
  %12 = load volatile i32, ptr %11, align 4, !tbaa !15
  %13 = and i32 %12, -129
  store volatile i32 %13, ptr %11, align 4, !tbaa !15
  %14 = load volatile i32, ptr @v_dfsdm1ChannelCounter, align 4, !tbaa !17
  %15 = add i32 %14, -1
  store volatile i32 %15, ptr @v_dfsdm1ChannelCounter, align 4, !tbaa !17
  %16 = load volatile i32, ptr @v_dfsdm1ChannelCounter, align 4, !tbaa !17
  %17 = icmp eq i32 %16, 0
  br i1 %17, label %18, label %21

18:                                               ; preds = %10
  %19 = load volatile i32, ptr inttoptr (i64 1073836032 to ptr), align 4096, !tbaa !15
  %20 = and i32 %19, 2147483647
  store volatile i32 %20, ptr inttoptr (i64 1073836032 to ptr), align 4096, !tbaa !15
  br label %21

21:                                               ; preds = %18, %10
  tail call void @HAL_DFSDM_ChannelMspDeInit(ptr noundef nonnull %0)
  %22 = getelementptr inbounds i8, ptr %0, i64 56
  store i32 0, ptr %22, align 8, !tbaa !18
  %23 = load ptr, ptr %0, align 8, !tbaa !5
  %24 = tail call i32 @DFSDM_GetChannelFromInstance(ptr noundef %23)
  %25 = zext i32 %24 to i64
  %26 = getelementptr inbounds [8 x ptr], ptr @a_dfsdm1ChannelHandle, i64 0, i64 %25
  store ptr null, ptr %26, align 8, !tbaa !14
  br label %27

27:                                               ; preds = %3, %1, %21
  %.0 = phi i32 [ 0, %21 ], [ 1, %1 ], [ 1, %3 ]
  ret i32 %.0
}

; Function Attrs: nounwind uwtable
declare dso_local void @HAL_DFSDM_ChannelMspDeInit(ptr noundef) local_unnamed_addr #0

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, !7, i64 0}
!6 = !{!"", !7, i64 0, !10, i64 8, !12, i64 56}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"", !11, i64 0, !11, i64 12, !13, i64 24, !13, i64 32, !12, i64 40, !12, i64 44}
!11 = !{!"", !12, i64 0, !12, i64 4, !12, i64 8}
!12 = !{!"int", !8, i64 0}
!13 = !{!"", !12, i64 0, !12, i64 4}
!14 = !{!7, !7, i64 0}
!15 = !{!16, !12, i64 0}
!16 = !{!"", !12, i64 0, !12, i64 4, !12, i64 8, !12, i64 12, !12, i64 16}
!17 = !{!12, !12, i64 0}
!18 = !{!6, !12, i64 56}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferAlignmentPass,InstCombinePass,SROAPass,SimplifyCFGPass,TailCallElimPass