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

; 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.IWDG_HandleTypeDef = type { ptr, %struct.IWDG_InitTypeDef }
%struct.IWDG_InitTypeDef = type { i32, i32, i32 }
%struct.IWDG_TypeDef = type { i32, i32, i32, i32, i32 }

; Function Attrs: nounwind uwtable
define dso_local i32 @HAL_IWDG_Init(ptr noundef %0) #0 {
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  %6 = load ptr, ptr %3, align 8, !tbaa !5
  %7 = icmp eq ptr %6, null
  br i1 %7, label %8, label %9

8:                                                ; preds = %1
  store i32 1, ptr %2, align 4
  store i32 1, ptr %5, align 4
  br label %75

9:                                                ; preds = %1
  %10 = load ptr, ptr %3, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.IWDG_HandleTypeDef, ptr %10, i32 0, i32 0
  %12 = load ptr, ptr %11, align 8, !tbaa !9
  %13 = getelementptr inbounds %struct.IWDG_TypeDef, ptr %12, i32 0, i32 0
  store volatile i32 52428, ptr %13, align 4, !tbaa !13
  %14 = load ptr, ptr %3, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.IWDG_HandleTypeDef, ptr %14, i32 0, i32 0
  %16 = load ptr, ptr %15, align 8, !tbaa !9
  %17 = getelementptr inbounds %struct.IWDG_TypeDef, ptr %16, i32 0, i32 0
  store volatile i32 21845, ptr %17, align 4, !tbaa !13
  %18 = load ptr, ptr %3, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.IWDG_HandleTypeDef, ptr %18, i32 0, i32 1
  %20 = getelementptr inbounds %struct.IWDG_InitTypeDef, ptr %19, i32 0, i32 0
  %21 = load i32, ptr %20, align 8, !tbaa !15
  %22 = load ptr, ptr %3, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.IWDG_HandleTypeDef, ptr %22, i32 0, i32 0
  %24 = load ptr, ptr %23, align 8, !tbaa !9
  %25 = getelementptr inbounds %struct.IWDG_TypeDef, ptr %24, i32 0, i32 1
  store volatile i32 %21, ptr %25, align 4, !tbaa !16
  %26 = load ptr, ptr %3, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.IWDG_HandleTypeDef, ptr %26, i32 0, i32 1
  %28 = getelementptr inbounds %struct.IWDG_InitTypeDef, ptr %27, i32 0, i32 1
  %29 = load i32, ptr %28, align 4, !tbaa !17
  %30 = load ptr, ptr %3, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.IWDG_HandleTypeDef, ptr %30, i32 0, i32 0
  %32 = load ptr, ptr %31, align 8, !tbaa !9
  %33 = getelementptr inbounds %struct.IWDG_TypeDef, ptr %32, i32 0, i32 2
  store volatile i32 %29, ptr %33, align 4, !tbaa !18
  %34 = call i32 @HAL_GetTick()
  store i32 %34, ptr %4, align 4, !tbaa !19
  br label %35

35:                                               ; preds = %48, %9
  %36 = load ptr, ptr %3, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.IWDG_HandleTypeDef, ptr %36, i32 0, i32 0
  %38 = load ptr, ptr %37, align 8, !tbaa !9
  %39 = getelementptr inbounds %struct.IWDG_TypeDef, ptr %38, i32 0, i32 3
  %40 = load volatile i32, ptr %39, align 4, !tbaa !20
  %41 = icmp ne i32 %40, 0
  br i1 %41, label %42, label %49

42:                                               ; preds = %35
  %43 = call i32 @HAL_GetTick()
  %44 = load i32, ptr %4, align 4, !tbaa !19
  %45 = sub i32 %43, %44
  %46 = icmp ugt i32 %45, 48
  br i1 %46, label %47, label %48

47:                                               ; preds = %42
  store i32 3, ptr %2, align 4
  store i32 1, ptr %5, align 4
  br label %75

48:                                               ; preds = %42
  br label %35, !llvm.loop !21

49:                                               ; preds = %35
  %50 = load ptr, ptr %3, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.IWDG_HandleTypeDef, ptr %50, i32 0, i32 0
  %52 = load ptr, ptr %51, align 8, !tbaa !9
  %53 = getelementptr inbounds %struct.IWDG_TypeDef, ptr %52, i32 0, i32 4
  %54 = load volatile i32, ptr %53, align 4, !tbaa !23
  %55 = load ptr, ptr %3, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.IWDG_HandleTypeDef, ptr %55, i32 0, i32 1
  %57 = getelementptr inbounds %struct.IWDG_InitTypeDef, ptr %56, i32 0, i32 2
  %58 = load i32, ptr %57, align 8, !tbaa !24
  %59 = icmp ne i32 %54, %58
  br i1 %59, label %60, label %69

60:                                               ; preds = %49
  %61 = load ptr, ptr %3, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.IWDG_HandleTypeDef, ptr %61, i32 0, i32 1
  %63 = getelementptr inbounds %struct.IWDG_InitTypeDef, ptr %62, i32 0, i32 2
  %64 = load i32, ptr %63, align 8, !tbaa !24
  %65 = load ptr, ptr %3, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.IWDG_HandleTypeDef, ptr %65, i32 0, i32 0
  %67 = load ptr, ptr %66, align 8, !tbaa !9
  %68 = getelementptr inbounds %struct.IWDG_TypeDef, ptr %67, i32 0, i32 4
  store volatile i32 %64, ptr %68, align 4, !tbaa !23
  br label %74

69:                                               ; preds = %49
  %70 = load ptr, ptr %3, align 8, !tbaa !5
  %71 = getelementptr inbounds %struct.IWDG_HandleTypeDef, ptr %70, i32 0, i32 0
  %72 = load ptr, ptr %71, align 8, !tbaa !9
  %73 = getelementptr inbounds %struct.IWDG_TypeDef, ptr %72, i32 0, i32 0
  store volatile i32 43690, ptr %73, align 4, !tbaa !13
  br label %74

74:                                               ; preds = %69, %60
  store i32 0, ptr %2, align 4
  store i32 1, ptr %5, align 4
  br label %75

75:                                               ; preds = %74, %47, %8
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  %76 = load i32, ptr %2, align 4
  ret i32 %76
}

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

declare i32 @HAL_GetTick() #2

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

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" }
attributes #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { "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 #3 = { 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}
!11 = !{!"", !12, i64 0, !12, i64 4, !12, i64 8}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !12, i64 0}
!14 = !{!"", !12, i64 0, !12, i64 4, !12, i64 8, !12, i64 12, !12, i64 16}
!15 = !{!10, !12, i64 8}
!16 = !{!14, !12, i64 4}
!17 = !{!10, !12, i64 12}
!18 = !{!14, !12, i64 8}
!19 = !{!12, !12, i64 0}
!20 = !{!14, !12, i64 12}
!21 = distinct !{!21, !22}
!22 = !{!"llvm.loop.mustprogress"}
!23 = !{!14, !12, i64 16}
!24 = !{!10, !12, i64 16}


; 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: nounwind uwtable
define dso_local range(i32 0, 4) i32 @HAL_IWDG_Init(ptr noundef readonly %0) local_unnamed_addr #0 {
  %2 = icmp eq ptr %0, null
  br i1 %2, label %.loopexit, label %3

3:                                                ; preds = %1
  %4 = load ptr, ptr %0, align 8, !tbaa !5
  store volatile i32 52428, ptr %4, align 4, !tbaa !12
  store volatile i32 21845, ptr %4, align 4, !tbaa !12
  %5 = getelementptr inbounds i8, ptr %0, i64 8
  %6 = load i32, ptr %5, align 8, !tbaa !14
  %7 = getelementptr inbounds i8, ptr %4, i64 4
  store volatile i32 %6, ptr %7, align 4, !tbaa !15
  %8 = getelementptr inbounds i8, ptr %0, i64 12
  %9 = load i32, ptr %8, align 4, !tbaa !16
  %10 = getelementptr inbounds i8, ptr %4, i64 8
  store volatile i32 %9, ptr %10, align 4, !tbaa !17
  %11 = tail call i32 @HAL_GetTick() #2
  br label %12

12:                                               ; preds = %16, %3
  %13 = load ptr, ptr %0, align 8, !tbaa !5
  %14 = getelementptr inbounds i8, ptr %13, i64 12
  %15 = load volatile i32, ptr %14, align 4, !tbaa !18
  %.not = icmp eq i32 %15, 0
  br i1 %.not, label %20, label %16

16:                                               ; preds = %12
  %17 = tail call i32 @HAL_GetTick() #2
  %18 = sub i32 %17, %11
  %19 = icmp ugt i32 %18, 48
  br i1 %19, label %.loopexit, label %12, !llvm.loop !19

20:                                               ; preds = %12
  %21 = getelementptr inbounds i8, ptr %13, i64 16
  %22 = load volatile i32, ptr %21, align 4, !tbaa !21
  %23 = getelementptr inbounds i8, ptr %0, i64 16
  %24 = load i32, ptr %23, align 8, !tbaa !22
  %.not16 = icmp eq i32 %22, %24
  br i1 %.not16, label %26, label %25

25:                                               ; preds = %20
  store volatile i32 %24, ptr %21, align 4, !tbaa !21
  br label %.loopexit

26:                                               ; preds = %20
  store volatile i32 43690, ptr %13, align 4, !tbaa !12
  br label %.loopexit

.loopexit:                                        ; preds = %16, %25, %26, %1
  %.0 = phi i32 [ 1, %1 ], [ 0, %26 ], [ 0, %25 ], [ 3, %16 ]
  ret i32 %.0
}

declare i32 @HAL_GetTick() local_unnamed_addr #1

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" }
attributes #1 = { "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, !7, i64 0}
!6 = !{!"", !7, i64 0, !10, i64 8}
!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 = !{!"int", !8, i64 0}
!12 = !{!13, !11, i64 0}
!13 = !{!"", !11, i64 0, !11, i64 4, !11, i64 8, !11, i64 12, !11, i64 16}
!14 = !{!6, !11, i64 8}
!15 = !{!13, !11, i64 4}
!16 = !{!6, !11, i64 12}
!17 = !{!13, !11, i64 8}
!18 = !{!13, !11, i64 12}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}
!21 = !{!13, !11, i64 16}
!22 = !{!6, !11, i64 16}


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