; 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.__SMARTCARD_HandleTypeDef = type { ptr, %struct.SMARTCARD_InitTypeDef, %struct.SMARTCARD_AdvFeatureInitTypeDef, ptr, i16, i16, ptr, i16, i16, i16, i16, i32, ptr, ptr, ptr, ptr, i32, i32, i32, i32 }
%struct.SMARTCARD_InitTypeDef = type { i32, i32, i32, i16, i16, i16, i16, i16, i16, i8, i8, i16, i32, i32, i8, i8, i32 }
%struct.SMARTCARD_AdvFeatureInitTypeDef = type { i32, i32, i32, i32, i32, i32, i32, i32, i16 }
%struct.USART_TypeDef = type { i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32 }

; Function Attrs: nounwind uwtable
define dso_local i32 @HAL_SMARTCARD_Init(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 %88

7:                                                ; preds = %1
  %8 = load ptr, ptr %3, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct.__SMARTCARD_HandleTypeDef, ptr %8, i32 0, i32 17
  %10 = load volatile i32, ptr %9, align 4, !tbaa !9
  %11 = icmp eq i32 %10, 0
  br i1 %11, label %12, label %16

12:                                               ; preds = %7
  %13 = load ptr, ptr %3, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.__SMARTCARD_HandleTypeDef, ptr %13, i32 0, i32 16
  store i32 0, ptr %14, align 8, !tbaa !15
  %15 = load ptr, ptr %3, align 8, !tbaa !5
  call void @HAL_SMARTCARD_MspInit(ptr noundef %15)
  br label %16

16:                                               ; preds = %12, %7
  %17 = load ptr, ptr %3, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.__SMARTCARD_HandleTypeDef, ptr %17, i32 0, i32 17
  store volatile i32 36, ptr %18, align 4, !tbaa !9
  %19 = load ptr, ptr %3, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.__SMARTCARD_HandleTypeDef, ptr %19, i32 0, i32 0
  %21 = load ptr, ptr %20, align 8, !tbaa !16
  %22 = getelementptr inbounds %struct.USART_TypeDef, ptr %21, i32 0, i32 0
  %23 = load volatile i32, ptr %22, align 4, !tbaa !17
  %24 = zext i32 %23 to i64
  %25 = and i64 %24, -2
  %26 = trunc i64 %25 to i32
  store volatile i32 %26, ptr %22, align 4, !tbaa !17
  %27 = load ptr, ptr %3, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.__SMARTCARD_HandleTypeDef, ptr %27, i32 0, i32 0
  %29 = load ptr, ptr %28, align 8, !tbaa !16
  %30 = getelementptr inbounds %struct.USART_TypeDef, ptr %29, i32 0, i32 1
  %31 = load volatile i32, ptr %30, align 4, !tbaa !19
  %32 = zext i32 %31 to i64
  %33 = and i64 %32, -16385
  %34 = trunc i64 %33 to i32
  store volatile i32 %34, ptr %30, align 4, !tbaa !19
  %35 = load ptr, ptr %3, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.__SMARTCARD_HandleTypeDef, ptr %35, i32 0, i32 0
  %37 = load ptr, ptr %36, align 8, !tbaa !16
  %38 = getelementptr inbounds %struct.USART_TypeDef, ptr %37, i32 0, i32 2
  %39 = load volatile i32, ptr %38, align 4, !tbaa !20
  %40 = zext i32 %39 to i64
  %41 = and i64 %40, -11
  %42 = trunc i64 %41 to i32
  store volatile i32 %42, ptr %38, align 4, !tbaa !20
  %43 = load ptr, ptr %3, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.__SMARTCARD_HandleTypeDef, ptr %43, i32 0, i32 0
  %45 = load ptr, ptr %44, align 8, !tbaa !16
  %46 = getelementptr inbounds %struct.USART_TypeDef, ptr %45, i32 0, i32 2
  %47 = load volatile i32, ptr %46, align 4, !tbaa !20
  %48 = zext i32 %47 to i64
  %49 = or i64 %48, 32
  %50 = trunc i64 %49 to i32
  store volatile i32 %50, ptr %46, align 4, !tbaa !20
  %51 = load ptr, ptr %3, align 8, !tbaa !5
  %52 = call i32 @SMARTCARD_SetConfig(ptr noundef %51)
  %53 = icmp eq i32 %52, 1
  br i1 %53, label %54, label %55

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

55:                                               ; preds = %16
  br label %56

56:                                               ; preds = %55
  %57 = load ptr, ptr %3, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.__SMARTCARD_HandleTypeDef, ptr %57, i32 0, i32 2
  %59 = getelementptr inbounds %struct.SMARTCARD_AdvFeatureInitTypeDef, ptr %58, i32 0, i32 0
  %60 = load i32, ptr %59, align 4, !tbaa !21
  %61 = and i32 %60, 256
  %62 = icmp eq i32 %61, 0
  br i1 %62, label %63, label %67

63:                                               ; preds = %56
  %64 = load ptr, ptr %3, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.__SMARTCARD_HandleTypeDef, ptr %64, i32 0, i32 2
  %66 = getelementptr inbounds %struct.SMARTCARD_AdvFeatureInitTypeDef, ptr %65, i32 0, i32 8
  store i16 1574, ptr %66, align 4, !tbaa !22
  br label %68

67:                                               ; preds = %56
  br label %68

68:                                               ; preds = %67, %63
  br label %69

69:                                               ; preds = %68
  %70 = load ptr, ptr %3, align 8, !tbaa !5
  %71 = getelementptr inbounds %struct.__SMARTCARD_HandleTypeDef, ptr %70, i32 0, i32 2
  %72 = getelementptr inbounds %struct.SMARTCARD_AdvFeatureInitTypeDef, ptr %71, i32 0, i32 0
  %73 = load i32, ptr %72, align 4, !tbaa !21
  %74 = icmp ne i32 %73, 0
  br i1 %74, label %75, label %77

75:                                               ; preds = %69
  %76 = load ptr, ptr %3, align 8, !tbaa !5
  call void @SMARTCARD_AdvFeatureConfig(ptr noundef %76)
  br label %77

77:                                               ; preds = %75, %69
  %78 = load ptr, ptr %3, align 8, !tbaa !5
  %79 = getelementptr inbounds %struct.__SMARTCARD_HandleTypeDef, ptr %78, i32 0, i32 0
  %80 = load ptr, ptr %79, align 8, !tbaa !16
  %81 = getelementptr inbounds %struct.USART_TypeDef, ptr %80, i32 0, i32 0
  %82 = load volatile i32, ptr %81, align 4, !tbaa !17
  %83 = zext i32 %82 to i64
  %84 = or i64 %83, 1
  %85 = trunc i64 %84 to i32
  store volatile i32 %85, ptr %81, align 4, !tbaa !17
  %86 = load ptr, ptr %3, align 8, !tbaa !5
  %87 = call i32 @SMARTCARD_CheckIdleState(ptr noundef %86)
  store i32 %87, ptr %2, align 4
  br label %88

88:                                               ; preds = %77, %54, %6
  %89 = load i32, ptr %2, align 4
  ret i32 %89
}

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

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

; Function Attrs: nounwind uwtable
declare hidden void @SMARTCARD_AdvFeatureConfig(ptr noundef) #0

; Function Attrs: nounwind uwtable
declare hidden i32 @SMARTCARD_CheckIdleState(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, !12, i64 164}
!10 = !{!"__SMARTCARD_HandleTypeDef", !6, i64 0, !11, i64 8, !14, i64 52, !6, i64 88, !13, i64 96, !13, i64 98, !6, i64 104, !13, i64 112, !13, i64 114, !13, i64 116, !13, i64 118, !12, i64 120, !6, i64 128, !6, i64 136, !6, i64 144, !6, i64 152, !12, i64 160, !12, i64 164, !12, i64 168, !12, i64 172}
!11 = !{!"", !12, i64 0, !12, i64 4, !12, i64 8, !13, i64 12, !13, i64 14, !13, i64 16, !13, i64 18, !13, i64 20, !13, i64 22, !7, i64 24, !7, i64 25, !13, i64 26, !12, i64 28, !12, i64 32, !7, i64 36, !7, i64 37, !12, i64 40}
!12 = !{!"int", !7, i64 0}
!13 = !{!"short", !7, i64 0}
!14 = !{!"", !12, i64 0, !12, i64 4, !12, i64 8, !12, i64 12, !12, i64 16, !12, i64 20, !12, i64 24, !12, i64 28, !13, i64 32}
!15 = !{!10, !12, i64 160}
!16 = !{!10, !6, i64 0}
!17 = !{!18, !12, i64 0}
!18 = !{!"", !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, i64 40, !12, i64 44}
!19 = !{!18, !12, i64 4}
!20 = !{!18, !12, i64 8}
!21 = !{!10, !12, i64 52}
!22 = !{!10, !13, i64 84}


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

3:                                                ; preds = %1
  %4 = getelementptr inbounds i8, ptr %0, i64 164
  %5 = load volatile i32, ptr %4, align 4, !tbaa !5
  %6 = icmp eq i32 %5, 0
  br i1 %6, label %7, label %9

7:                                                ; preds = %3
  %8 = getelementptr inbounds i8, ptr %0, i64 160
  store i32 0, ptr %8, align 8, !tbaa !14
  tail call void @HAL_SMARTCARD_MspInit(ptr noundef nonnull %0)
  br label %9

9:                                                ; preds = %7, %3
  store volatile i32 36, ptr %4, align 4, !tbaa !5
  %10 = load ptr, ptr %0, align 8, !tbaa !15
  %11 = load volatile i32, ptr %10, align 4, !tbaa !16
  %12 = and i32 %11, -2
  store volatile i32 %12, ptr %10, align 4, !tbaa !16
  %13 = getelementptr inbounds i8, ptr %10, i64 4
  %14 = load volatile i32, ptr %13, align 4, !tbaa !18
  %15 = and i32 %14, -16385
  store volatile i32 %15, ptr %13, align 4, !tbaa !18
  %16 = getelementptr inbounds i8, ptr %10, i64 8
  %17 = load volatile i32, ptr %16, align 4, !tbaa !19
  %18 = and i32 %17, -11
  store volatile i32 %18, ptr %16, align 4, !tbaa !19
  %19 = load volatile i32, ptr %16, align 4, !tbaa !19
  %20 = or i32 %19, 32
  store volatile i32 %20, ptr %16, align 4, !tbaa !19
  %21 = tail call i32 @SMARTCARD_SetConfig(ptr noundef nonnull %0)
  %22 = icmp eq i32 %21, 1
  br i1 %22, label %35, label %23

23:                                               ; preds = %9
  %24 = getelementptr inbounds i8, ptr %0, i64 52
  %25 = load i32, ptr %24, align 4, !tbaa !20
  %26 = and i32 %25, 256
  %27 = icmp eq i32 %26, 0
  br i1 %27, label %28, label %.thread

28:                                               ; preds = %23
  %29 = getelementptr inbounds i8, ptr %0, i64 84
  store i16 1574, ptr %29, align 4, !tbaa !21
  %.not = icmp eq i32 %25, 0
  br i1 %.not, label %30, label %.thread

.thread:                                          ; preds = %23, %28
  tail call void @SMARTCARD_AdvFeatureConfig(ptr noundef nonnull %0)
  br label %30

30:                                               ; preds = %.thread, %28
  %31 = load ptr, ptr %0, align 8, !tbaa !15
  %32 = load volatile i32, ptr %31, align 4, !tbaa !16
  %33 = or i32 %32, 1
  store volatile i32 %33, ptr %31, align 4, !tbaa !16
  %34 = tail call i32 @SMARTCARD_CheckIdleState(ptr noundef nonnull %0)
  br label %35

35:                                               ; preds = %9, %1, %30
  %.0 = phi i32 [ %34, %30 ], [ 1, %1 ], [ 1, %9 ]
  ret i32 %.0
}

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

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

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

; Function Attrs: nounwind uwtable
declare hidden i32 @SMARTCARD_CheckIdleState(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, !11, i64 164}
!6 = !{!"__SMARTCARD_HandleTypeDef", !7, i64 0, !10, i64 8, !13, i64 52, !7, i64 88, !12, i64 96, !12, i64 98, !7, i64 104, !12, i64 112, !12, i64 114, !12, i64 116, !12, i64 118, !11, i64 120, !7, i64 128, !7, i64 136, !7, i64 144, !7, i64 152, !11, i64 160, !11, i64 164, !11, i64 168, !11, i64 172}
!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, !12, i64 12, !12, i64 14, !12, i64 16, !12, i64 18, !12, i64 20, !12, i64 22, !8, i64 24, !8, i64 25, !12, i64 26, !11, i64 28, !11, i64 32, !8, i64 36, !8, i64 37, !11, i64 40}
!11 = !{!"int", !8, i64 0}
!12 = !{!"short", !8, i64 0}
!13 = !{!"", !11, i64 0, !11, i64 4, !11, i64 8, !11, i64 12, !11, i64 16, !11, i64 20, !11, i64 24, !11, i64 28, !12, i64 32}
!14 = !{!6, !11, i64 160}
!15 = !{!6, !7, i64 0}
!16 = !{!17, !11, i64 0}
!17 = !{!"", !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, i64 40, !11, i64 44}
!18 = !{!17, !11, i64 4}
!19 = !{!17, !11, i64 8}
!20 = !{!6, !11, i64 52}
!21 = !{!6, !12, i64 84}


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