; 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.SDRAM_HandleTypeDef = type { ptr, %struct.FMC_SDRAM_InitTypeDef, i32, i32, ptr }
%struct.FMC_SDRAM_InitTypeDef = type { i32, i32, i32, i32, i32, i32, i32, i32, i32, i32 }

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

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

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

14:                                               ; preds = %9
  %15 = load ptr, ptr %4, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.SDRAM_HandleTypeDef, ptr %15, i32 0, i32 3
  store i32 0, ptr %16, align 4, !tbaa !13
  %17 = load ptr, ptr %4, align 8, !tbaa !5
  call void @HAL_SDRAM_MspInit(ptr noundef %17)
  br label %18

18:                                               ; preds = %14, %9
  %19 = load ptr, ptr %4, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.SDRAM_HandleTypeDef, ptr %19, i32 0, i32 2
  store volatile i32 2, ptr %20, align 8, !tbaa !9
  %21 = load ptr, ptr %4, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.SDRAM_HandleTypeDef, ptr %21, i32 0, i32 0
  %23 = load ptr, ptr %22, align 8, !tbaa !14
  %24 = load ptr, ptr %4, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.SDRAM_HandleTypeDef, ptr %24, i32 0, i32 1
  %26 = call i32 @FMC_SDRAM_Init(ptr noundef %23, ptr noundef %25)
  %27 = load ptr, ptr %4, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.SDRAM_HandleTypeDef, ptr %27, i32 0, i32 0
  %29 = load ptr, ptr %28, align 8, !tbaa !14
  %30 = load ptr, ptr %5, align 8, !tbaa !5
  %31 = load ptr, ptr %4, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.SDRAM_HandleTypeDef, ptr %31, i32 0, i32 1
  %33 = getelementptr inbounds %struct.FMC_SDRAM_InitTypeDef, ptr %32, i32 0, i32 0
  %34 = load i32, ptr %33, align 8, !tbaa !15
  %35 = call i32 @FMC_SDRAM_Timing_Init(ptr noundef %29, ptr noundef %30, i32 noundef %34)
  %36 = load volatile i32, ptr inttoptr (i64 1375748096 to ptr), align 4, !tbaa !16
  %37 = zext i32 %36 to i64
  %38 = or i64 %37, 2147483648
  %39 = trunc i64 %38 to i32
  store volatile i32 %39, ptr inttoptr (i64 1375748096 to ptr), align 4, !tbaa !16
  %40 = load ptr, ptr %4, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.SDRAM_HandleTypeDef, ptr %40, i32 0, i32 2
  store volatile i32 1, ptr %41, align 8, !tbaa !9
  store i32 0, ptr %3, align 4
  br label %42

42:                                               ; preds = %18, %8
  %43 = load i32, ptr %3, align 4
  ret i32 %43
}

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

declare i32 @FMC_SDRAM_Init(ptr noundef, ptr noundef) #1

declare i32 @FMC_SDRAM_Timing_Init(ptr noundef, ptr noundef, i32 noundef) #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" }

!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, !12, i64 48}
!10 = !{!"", !6, i64 0, !11, i64 8, !12, i64 48, !12, i64 52, !6, i64 56}
!11 = !{!"", !12, i64 0, !12, i64 4, !12, i64 8, !12, i64 12, !12, i64 16, !12, i64 20, !12, i64 24, !12, i64 28, !12, i64 32, !12, i64 36}
!12 = !{!"int", !7, i64 0}
!13 = !{!10, !12, i64 52}
!14 = !{!10, !6, i64 0}
!15 = !{!10, !12, i64 8}
!16 = !{!12, !12, i64 0}


; 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, 2) i32 @HAL_SDRAM_Init(ptr noundef %0, ptr noundef %1) local_unnamed_addr #0 {
  %3 = icmp eq ptr %0, null
  br i1 %3, label %19, label %4

4:                                                ; preds = %2
  %5 = getelementptr inbounds i8, ptr %0, i64 48
  %6 = load volatile i32, ptr %5, align 8, !tbaa !5
  %7 = icmp eq i32 %6, 0
  br i1 %7, label %8, label %10

8:                                                ; preds = %4
  %9 = getelementptr inbounds i8, ptr %0, i64 52
  store i32 0, ptr %9, align 4, !tbaa !12
  tail call void @HAL_SDRAM_MspInit(ptr noundef nonnull %0)
  br label %10

10:                                               ; preds = %8, %4
  store volatile i32 2, ptr %5, align 8, !tbaa !5
  %11 = load ptr, ptr %0, align 8, !tbaa !13
  %12 = getelementptr inbounds i8, ptr %0, i64 8
  %13 = tail call i32 @FMC_SDRAM_Init(ptr noundef %11, ptr noundef nonnull %12) #2
  %14 = load ptr, ptr %0, align 8, !tbaa !13
  %15 = load i32, ptr %12, align 8, !tbaa !14
  %16 = tail call i32 @FMC_SDRAM_Timing_Init(ptr noundef %14, ptr noundef %1, i32 noundef %15) #2
  %17 = load volatile i32, ptr inttoptr (i64 1375748096 to ptr), align 16384, !tbaa !15
  %18 = or i32 %17, -2147483648
  store volatile i32 %18, ptr inttoptr (i64 1375748096 to ptr), align 16384, !tbaa !15
  store volatile i32 1, ptr %5, align 8, !tbaa !5
  br label %19

19:                                               ; preds = %2, %10
  %.0 = phi i32 [ 0, %10 ], [ 1, %2 ]
  ret i32 %.0
}

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

declare i32 @FMC_SDRAM_Init(ptr noundef, ptr noundef) local_unnamed_addr #1

declare i32 @FMC_SDRAM_Timing_Init(ptr noundef, ptr noundef, i32 noundef) 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 48}
!6 = !{!"", !7, i64 0, !10, i64 8, !11, i64 48, !11, i64 52, !7, 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 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 = !{!"int", !8, i64 0}
!12 = !{!6, !11, i64 52}
!13 = !{!6, !7, i64 0}
!14 = !{!6, !11, i64 8}
!15 = !{!11, !11, i64 0}


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