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

; 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.DCMI_HandleTypeDef = type { ptr, %struct.DCMI_InitTypeDef, i32, i32, i32, i32, i32, i32, ptr, i32 }
%struct.DCMI_InitTypeDef = type { i32, i32, i32, i32, i32, i32, %struct.DCMI_CodesInitTypeDef, i32, i32, i32, i32, i32 }
%struct.DCMI_CodesInitTypeDef = type { i8, i8, i8, i8 }
%struct.DCMI_TypeDef = type { i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32 }

@SystemCoreClock = external 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: 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_DCMI_Suspend(ptr noundef %0) #1 {
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #2
  %7 = load i32, ptr @SystemCoreClock, align 4, !tbaa !9
  %8 = udiv i32 %7, 8
  %9 = udiv i32 %8, 1000
  %10 = mul i32 1000, %9
  store i32 %10, ptr %4, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #2
  store i32 0, ptr %5, align 4, !tbaa !9
  br label %11

11:                                               ; preds = %1
  %12 = load ptr, ptr %3, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.DCMI_HandleTypeDef, ptr %12, i32 0, i32 2
  %14 = load i32, ptr %13, align 8, !tbaa !11
  %15 = icmp eq i32 %14, 1
  br i1 %15, label %16, label %17

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

17:                                               ; preds = %11
  %18 = load ptr, ptr %3, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.DCMI_HandleTypeDef, ptr %18, i32 0, i32 2
  store i32 1, ptr %19, align 8, !tbaa !11
  br label %20

20:                                               ; preds = %17
  br label %21

21:                                               ; preds = %20
  br label %22

22:                                               ; preds = %21
  %23 = load ptr, ptr %3, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.DCMI_HandleTypeDef, ptr %23, i32 0, i32 3
  %25 = load volatile i32, ptr %24, align 4, !tbaa !15
  %26 = icmp eq i32 %25, 2
  br i1 %26, label %27, label %61

27:                                               ; preds = %22
  %28 = load ptr, ptr %3, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.DCMI_HandleTypeDef, ptr %28, i32 0, i32 3
  store volatile i32 5, ptr %29, align 4, !tbaa !15
  %30 = load ptr, ptr %3, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.DCMI_HandleTypeDef, ptr %30, i32 0, i32 0
  %32 = load ptr, ptr %31, align 8, !tbaa !16
  %33 = getelementptr inbounds %struct.DCMI_TypeDef, ptr %32, i32 0, i32 0
  %34 = load volatile i32, ptr %33, align 4, !tbaa !17
  %35 = zext i32 %34 to i64
  %36 = and i64 %35, -2
  %37 = trunc i64 %36 to i32
  store volatile i32 %37, ptr %33, align 4, !tbaa !17
  br label %38

38:                                               ; preds = %51, %27
  %39 = load i32, ptr %4, align 4, !tbaa !9
  %40 = add i32 %39, -1
  store i32 %40, ptr %4, align 4, !tbaa !9
  %41 = load i32, ptr %4, align 4, !tbaa !9
  %42 = icmp eq i32 %41, 0
  br i1 %42, label %43, label %50

43:                                               ; preds = %38
  %44 = load ptr, ptr %3, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.DCMI_HandleTypeDef, ptr %44, i32 0, i32 9
  %46 = load volatile i32, ptr %45, align 8, !tbaa !19
  %47 = or i32 %46, 32
  store volatile i32 %47, ptr %45, align 8, !tbaa !19
  %48 = load ptr, ptr %3, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.DCMI_HandleTypeDef, ptr %48, i32 0, i32 3
  store volatile i32 1, ptr %49, align 4, !tbaa !15
  store i32 3, ptr %5, align 4, !tbaa !9
  br label %60

50:                                               ; preds = %38
  br label %51

51:                                               ; preds = %50
  %52 = load ptr, ptr %3, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.DCMI_HandleTypeDef, ptr %52, i32 0, i32 0
  %54 = load ptr, ptr %53, align 8, !tbaa !16
  %55 = getelementptr inbounds %struct.DCMI_TypeDef, ptr %54, i32 0, i32 0
  %56 = load volatile i32, ptr %55, align 4, !tbaa !17
  %57 = zext i32 %56 to i64
  %58 = and i64 %57, 1
  %59 = icmp ne i64 %58, 0
  br i1 %59, label %38, label %60, !llvm.loop !20

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

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

62:                                               ; preds = %61
  %63 = load ptr, ptr %3, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.DCMI_HandleTypeDef, ptr %63, i32 0, i32 2
  store i32 0, ptr %64, align 8, !tbaa !11
  br label %65

65:                                               ; preds = %62
  br label %66

66:                                               ; preds = %65
  %67 = load i32, ptr %5, align 4, !tbaa !9
  store i32 %67, ptr %2, align 4
  store i32 1, ptr %6, align 4
  br label %68

68:                                               ; preds = %66, %16
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #2
  %69 = load i32, ptr %2, align 4
  ret i32 %69
}

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 56}
!12 = !{!"", !6, i64 0, !13, i64 8, !10, i64 56, !10, i64 60, !10, i64 64, !10, i64 68, !10, i64 72, !10, i64 76, !6, i64 80, !10, i64 88}
!13 = !{!"", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20, !14, i64 24, !10, i64 28, !10, i64 32, !10, i64 36, !10, i64 40, !10, i64 44}
!14 = !{!"", !7, i64 0, !7, i64 1, !7, i64 2, !7, i64 3}
!15 = !{!12, !10, i64 60}
!16 = !{!12, !6, i64 0}
!17 = !{!18, !10, i64 0}
!18 = !{!"", !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}
!19 = !{!12, !10, i64 88}
!20 = distinct !{!20, !21}
!21 = !{!"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"

@SystemCoreClock = external local_unnamed_addr global i32, align 4

; Function Attrs: nofree norecurse nounwind uwtable
define dso_local range(i32 0, 4) i32 @HAL_DCMI_Suspend(ptr noundef %0) local_unnamed_addr #0 {
  %2 = load i32, ptr @SystemCoreClock, align 4, !tbaa !5
  %3 = udiv i32 %2, 8000
  %4 = mul nuw nsw i32 %3, 1000
  %5 = getelementptr inbounds i8, ptr %0, i64 56
  %6 = load i32, ptr %5, align 8, !tbaa !9
  %7 = icmp eq i32 %6, 1
  br i1 %7, label %26, label %8

8:                                                ; preds = %1
  %9 = getelementptr inbounds i8, ptr %0, i64 60
  %10 = load volatile i32, ptr %9, align 4, !tbaa !14
  %11 = icmp eq i32 %10, 2
  br i1 %11, label %12, label %.loopexit

12:                                               ; preds = %8
  store volatile i32 5, ptr %9, align 4, !tbaa !14
  %13 = load ptr, ptr %0, align 8, !tbaa !15
  %14 = load volatile i32, ptr %13, align 4, !tbaa !16
  %15 = and i32 %14, -2
  store volatile i32 %15, ptr %13, align 4, !tbaa !16
  br label %16

16:                                               ; preds = %23, %12
  %.012 = phi i32 [ %4, %12 ], [ %17, %23 ]
  %17 = add i32 %.012, -1
  %18 = icmp eq i32 %17, 0
  br i1 %18, label %19, label %23

19:                                               ; preds = %16
  %20 = getelementptr inbounds i8, ptr %0, i64 88
  %21 = load volatile i32, ptr %20, align 8, !tbaa !18
  %22 = or i32 %21, 32
  store volatile i32 %22, ptr %20, align 8, !tbaa !18
  store volatile i32 1, ptr %9, align 4, !tbaa !14
  br label %.loopexit

23:                                               ; preds = %16
  %24 = load volatile i32, ptr %13, align 4, !tbaa !16
  %25 = and i32 %24, 1
  %.not = icmp eq i32 %25, 0
  br i1 %.not, label %.loopexit, label %16, !llvm.loop !19

.loopexit:                                        ; preds = %23, %8, %19
  %.0 = phi i32 [ 3, %19 ], [ 0, %8 ], [ 0, %23 ]
  store i32 0, ptr %5, align 8, !tbaa !9
  br label %26

26:                                               ; preds = %1, %.loopexit
  %.013 = phi i32 [ %.0, %.loopexit ], [ 2, %1 ]
  ret i32 %.013
}

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, !6, i64 0}
!6 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !6, i64 56}
!10 = !{!"", !11, i64 0, !12, i64 8, !6, i64 56, !6, i64 60, !6, i64 64, !6, i64 68, !6, i64 72, !6, i64 76, !11, i64 80, !6, i64 88}
!11 = !{!"any pointer", !7, i64 0}
!12 = !{!"", !6, i64 0, !6, i64 4, !6, i64 8, !6, i64 12, !6, i64 16, !6, i64 20, !13, i64 24, !6, i64 28, !6, i64 32, !6, i64 36, !6, i64 40, !6, i64 44}
!13 = !{!"", !7, i64 0, !7, i64 1, !7, i64 2, !7, i64 3}
!14 = !{!10, !6, i64 60}
!15 = !{!10, !11, i64 0}
!16 = !{!17, !6, i64 0}
!17 = !{!"", !6, i64 0, !6, i64 4, !6, i64 8, !6, i64 12, !6, i64 16, !6, i64 20, !6, i64 24, !6, i64 28, !6, i64 32, !6, i64 36, !6, i64 40}
!18 = !{!10, !6, i64 88}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: DSEPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass