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

; 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.RNG_HandleTypeDef = type { ptr, %struct.RNG_InitTypeDef, i32, i32, i32, i32 }
%struct.RNG_InitTypeDef = type { i32 }
%struct.RNG_TypeDef = type { i32, i32, i32 }

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

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

14:                                               ; preds = %9
  store i32 2, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %80

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

18:                                               ; preds = %15
  br label %19

19:                                               ; preds = %18
  br label %20

20:                                               ; preds = %19
  %21 = load ptr, ptr %4, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.RNG_HandleTypeDef, ptr %21, i32 0, i32 3
  %23 = load volatile i32, ptr %22, align 8, !tbaa !14
  %24 = icmp eq i32 %23, 1
  br i1 %24, label %25, label %72

25:                                               ; preds = %20
  %26 = load ptr, ptr %4, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.RNG_HandleTypeDef, ptr %26, i32 0, i32 3
  store volatile i32 2, ptr %27, align 8, !tbaa !14
  %28 = call i32 @HAL_GetTick()
  store i32 %28, ptr %6, align 4, !tbaa !9
  br label %29

29:                                               ; preds = %57, %25
  %30 = load ptr, ptr %4, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.RNG_HandleTypeDef, ptr %30, i32 0, i32 0
  %32 = load ptr, ptr %31, align 8, !tbaa !15
  %33 = getelementptr inbounds %struct.RNG_TypeDef, ptr %32, i32 0, i32 1
  %34 = load volatile i32, ptr %33, align 4, !tbaa !16
  %35 = zext i32 %34 to i64
  %36 = and i64 %35, 1
  %37 = icmp eq i64 %36, 1
  %38 = zext i1 %37 to i32
  %39 = icmp eq i32 %38, 0
  br i1 %39, label %40, label %58

40:                                               ; preds = %29
  %41 = call i32 @HAL_GetTick()
  %42 = load i32, ptr %6, align 4, !tbaa !9
  %43 = sub i32 %41, %42
  %44 = icmp ugt i32 %43, 2
  br i1 %44, label %45, label %57

45:                                               ; preds = %40
  %46 = load ptr, ptr %4, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.RNG_HandleTypeDef, ptr %46, i32 0, i32 3
  store volatile i32 1, ptr %47, align 8, !tbaa !14
  %48 = load ptr, ptr %4, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.RNG_HandleTypeDef, ptr %48, i32 0, i32 4
  %50 = load volatile i32, ptr %49, align 4, !tbaa !18
  %51 = or i32 %50, 2
  store volatile i32 %51, ptr %49, align 4, !tbaa !18
  br label %52

52:                                               ; preds = %45
  %53 = load ptr, ptr %4, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.RNG_HandleTypeDef, ptr %53, i32 0, i32 2
  store i32 0, ptr %54, align 4, !tbaa !11
  br label %55

55:                                               ; preds = %52
  br label %56

56:                                               ; preds = %55
  store i32 1, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %80

57:                                               ; preds = %40
  br label %29, !llvm.loop !19

58:                                               ; preds = %29
  %59 = load ptr, ptr %4, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.RNG_HandleTypeDef, ptr %59, i32 0, i32 0
  %61 = load ptr, ptr %60, align 8, !tbaa !15
  %62 = getelementptr inbounds %struct.RNG_TypeDef, ptr %61, i32 0, i32 2
  %63 = load volatile i32, ptr %62, align 4, !tbaa !21
  %64 = load ptr, ptr %4, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.RNG_HandleTypeDef, ptr %64, i32 0, i32 5
  store i32 %63, ptr %65, align 8, !tbaa !22
  %66 = load ptr, ptr %4, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.RNG_HandleTypeDef, ptr %66, i32 0, i32 5
  %68 = load i32, ptr %67, align 8, !tbaa !22
  %69 = load ptr, ptr %5, align 8, !tbaa !5
  store i32 %68, ptr %69, align 4, !tbaa !9
  %70 = load ptr, ptr %4, align 8, !tbaa !5
  %71 = getelementptr inbounds %struct.RNG_HandleTypeDef, ptr %70, i32 0, i32 3
  store volatile i32 1, ptr %71, align 8, !tbaa !14
  br label %73

72:                                               ; preds = %20
  store i32 1, ptr %7, align 4, !tbaa !9
  br label %73

73:                                               ; preds = %72, %58
  br label %74

74:                                               ; preds = %73
  %75 = load ptr, ptr %4, align 8, !tbaa !5
  %76 = getelementptr inbounds %struct.RNG_HandleTypeDef, ptr %75, i32 0, i32 2
  store i32 0, ptr %76, align 4, !tbaa !11
  br label %77

77:                                               ; preds = %74
  br label %78

78:                                               ; preds = %77
  %79 = load i32, ptr %7, align 4, !tbaa !9
  store i32 %79, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %80

80:                                               ; preds = %78, %56, %14
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  %81 = load i32, ptr %3, align 4
  ret i32 %81
}

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


; 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, 3) i32 @HAL_RNG_GenerateRandomNumber(ptr noundef %0, ptr nocapture noundef writeonly %1) local_unnamed_addr #0 {
  %3 = getelementptr inbounds i8, ptr %0, i64 12
  %4 = load i32, ptr %3, align 4, !tbaa !5
  %5 = icmp eq i32 %4, 1
  br i1 %5, label %30, label %6

6:                                                ; preds = %2
  store i32 1, ptr %3, align 4, !tbaa !5
  %7 = getelementptr inbounds i8, ptr %0, i64 16
  %8 = load volatile i32, ptr %7, align 8, !tbaa !12
  %9 = icmp eq i32 %8, 1
  br i1 %9, label %10, label %.sink.split

10:                                               ; preds = %6
  store volatile i32 2, ptr %7, align 8, !tbaa !12
  %11 = tail call i32 @HAL_GetTick() #2
  br label %12

12:                                               ; preds = %18, %10
  %13 = load ptr, ptr %0, align 8, !tbaa !13
  %14 = getelementptr inbounds i8, ptr %13, i64 4
  %15 = load volatile i32, ptr %14, align 4, !tbaa !14
  %16 = and i32 %15, 1
  %17 = icmp eq i32 %16, 0
  br i1 %17, label %18, label %26

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

22:                                               ; preds = %18
  store volatile i32 1, ptr %7, align 8, !tbaa !12
  %23 = getelementptr inbounds i8, ptr %0, i64 20
  %24 = load volatile i32, ptr %23, align 4, !tbaa !18
  %25 = or i32 %24, 2
  store volatile i32 %25, ptr %23, align 4, !tbaa !18
  br label %.sink.split

26:                                               ; preds = %12
  %27 = getelementptr inbounds i8, ptr %13, i64 8
  %28 = load volatile i32, ptr %27, align 4, !tbaa !19
  %29 = getelementptr inbounds i8, ptr %0, i64 24
  store i32 %28, ptr %29, align 8, !tbaa !20
  store i32 %28, ptr %1, align 4, !tbaa !21
  store volatile i32 1, ptr %7, align 8, !tbaa !12
  br label %.sink.split

.sink.split:                                      ; preds = %26, %6, %22
  %.016.ph = phi i32 [ 1, %22 ], [ 0, %26 ], [ 1, %6 ]
  store i32 0, ptr %3, align 4, !tbaa !5
  br label %30

30:                                               ; preds = %.sink.split, %2
  %.016 = phi i32 [ 2, %2 ], [ %.016.ph, %.sink.split ]
  ret i32 %.016
}

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, !11, i64 12}
!6 = !{!"", !7, i64 0, !10, i64 8, !11, i64 12, !11, i64 16, !11, i64 20, !11, i64 24}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"", !11, i64 0}
!11 = !{!"int", !8, i64 0}
!12 = !{!6, !11, i64 16}
!13 = !{!6, !7, i64 0}
!14 = !{!15, !11, i64 4}
!15 = !{!"", !11, i64 0, !11, i64 4, !11, i64 8}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}
!18 = !{!6, !11, i64 20}
!19 = !{!15, !11, i64 8}
!20 = !{!6, !11, i64 24}
!21 = !{!11, !11, i64 0}


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