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

; 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.IRDA_HandleTypeDef = type { ptr, %struct.IRDA_InitTypeDef, ptr, i16, i16, ptr, i16, i16, i16, ptr, ptr, i32, i32, i32, i32 }
%struct.IRDA_InitTypeDef = type { i32, i32, i32, i32, i8, i16, i32 }
%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_IRDA_Transmit(ptr noundef %0, ptr noundef %1, i16 noundef zeroext %2, i32 noundef %3) #0 {
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i16, align 2
  %9 = alloca i32, align 4
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store i16 %2, ptr %8, align 2, !tbaa !9
  store i32 %3, ptr %9, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #3
  %14 = load ptr, ptr %6, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.IRDA_HandleTypeDef, ptr %14, i32 0, i32 12
  %16 = load volatile i32, ptr %15, align 4, !tbaa !13
  %17 = icmp eq i32 %16, 32
  br i1 %17, label %18, label %129

18:                                               ; preds = %4
  %19 = load ptr, ptr %7, align 8, !tbaa !5
  %20 = icmp eq ptr %19, null
  br i1 %20, label %25, label %21

21:                                               ; preds = %18
  %22 = load i16, ptr %8, align 2, !tbaa !9
  %23 = zext i16 %22 to i32
  %24 = icmp eq i32 %23, 0
  br i1 %24, label %25, label %26

25:                                               ; preds = %21, %18
  store i32 1, ptr %5, align 4
  store i32 1, ptr %13, align 4
  br label %130

26:                                               ; preds = %21
  br label %27

27:                                               ; preds = %26
  %28 = load ptr, ptr %6, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.IRDA_HandleTypeDef, ptr %28, i32 0, i32 11
  %30 = load i32, ptr %29, align 8, !tbaa !16
  %31 = icmp eq i32 %30, 1
  br i1 %31, label %32, label %33

32:                                               ; preds = %27
  store i32 2, ptr %5, align 4
  store i32 1, ptr %13, align 4
  br label %130

33:                                               ; preds = %27
  %34 = load ptr, ptr %6, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.IRDA_HandleTypeDef, ptr %34, i32 0, i32 11
  store i32 1, ptr %35, align 8, !tbaa !16
  br label %36

36:                                               ; preds = %33
  br label %37

37:                                               ; preds = %36
  br label %38

38:                                               ; preds = %37
  %39 = load ptr, ptr %6, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.IRDA_HandleTypeDef, ptr %39, i32 0, i32 14
  store volatile i32 0, ptr %40, align 4, !tbaa !17
  %41 = load ptr, ptr %6, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.IRDA_HandleTypeDef, ptr %41, i32 0, i32 12
  store volatile i32 33, ptr %42, align 4, !tbaa !13
  %43 = call i32 @HAL_GetTick()
  store i32 %43, ptr %12, align 4, !tbaa !11
  %44 = load i16, ptr %8, align 2, !tbaa !9
  %45 = load ptr, ptr %6, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.IRDA_HandleTypeDef, ptr %45, i32 0, i32 3
  store i16 %44, ptr %46, align 8, !tbaa !18
  %47 = load i16, ptr %8, align 2, !tbaa !9
  %48 = load ptr, ptr %6, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.IRDA_HandleTypeDef, ptr %48, i32 0, i32 4
  store volatile i16 %47, ptr %49, align 2, !tbaa !19
  %50 = load ptr, ptr %6, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.IRDA_HandleTypeDef, ptr %50, i32 0, i32 1
  %52 = getelementptr inbounds %struct.IRDA_InitTypeDef, ptr %51, i32 0, i32 1
  %53 = load i32, ptr %52, align 4, !tbaa !20
  %54 = zext i32 %53 to i64
  %55 = icmp eq i64 %54, 4096
  br i1 %55, label %56, label %64

56:                                               ; preds = %38
  %57 = load ptr, ptr %6, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.IRDA_HandleTypeDef, ptr %57, i32 0, i32 1
  %59 = getelementptr inbounds %struct.IRDA_InitTypeDef, ptr %58, i32 0, i32 2
  %60 = load i32, ptr %59, align 8, !tbaa !21
  %61 = icmp eq i32 %60, 0
  br i1 %61, label %62, label %64

62:                                               ; preds = %56
  store ptr null, ptr %10, align 8, !tbaa !5
  %63 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %63, ptr %11, align 8, !tbaa !5
  br label %66

64:                                               ; preds = %56, %38
  %65 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %65, ptr %10, align 8, !tbaa !5
  store ptr null, ptr %11, align 8, !tbaa !5
  br label %66

66:                                               ; preds = %64, %62
  br label %67

67:                                               ; preds = %113, %66
  %68 = load ptr, ptr %6, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.IRDA_HandleTypeDef, ptr %68, i32 0, i32 4
  %70 = load volatile i16, ptr %69, align 2, !tbaa !19
  %71 = zext i16 %70 to i32
  %72 = icmp ugt i32 %71, 0
  br i1 %72, label %73, label %114

73:                                               ; preds = %67
  %74 = load ptr, ptr %6, align 8, !tbaa !5
  %75 = getelementptr inbounds %struct.IRDA_HandleTypeDef, ptr %74, i32 0, i32 4
  %76 = load volatile i16, ptr %75, align 2, !tbaa !19
  %77 = add i16 %76, -1
  store volatile i16 %77, ptr %75, align 2, !tbaa !19
  %78 = load ptr, ptr %6, align 8, !tbaa !5
  %79 = load i32, ptr %12, align 4, !tbaa !11
  %80 = load i32, ptr %9, align 4, !tbaa !11
  %81 = call i32 @IRDA_WaitOnFlagUntilTimeout(ptr noundef %78, i32 noundef 128, i32 noundef 0, i32 noundef %79, i32 noundef %80)
  %82 = icmp ne i32 %81, 0
  br i1 %82, label %83, label %84

83:                                               ; preds = %73
  store i32 3, ptr %5, align 4
  store i32 1, ptr %13, align 4
  br label %130

84:                                               ; preds = %73
  %85 = load ptr, ptr %10, align 8, !tbaa !5
  %86 = icmp eq ptr %85, null
  br i1 %86, label %87, label %100

87:                                               ; preds = %84
  %88 = load ptr, ptr %11, align 8, !tbaa !5
  %89 = load i16, ptr %88, align 2, !tbaa !9
  %90 = zext i16 %89 to i32
  %91 = and i32 %90, 511
  %92 = trunc i32 %91 to i16
  %93 = zext i16 %92 to i32
  %94 = load ptr, ptr %6, align 8, !tbaa !5
  %95 = getelementptr inbounds %struct.IRDA_HandleTypeDef, ptr %94, i32 0, i32 0
  %96 = load ptr, ptr %95, align 8, !tbaa !22
  %97 = getelementptr inbounds %struct.USART_TypeDef, ptr %96, i32 0, i32 10
  store volatile i32 %93, ptr %97, align 4, !tbaa !23
  %98 = load ptr, ptr %11, align 8, !tbaa !5
  %99 = getelementptr inbounds i16, ptr %98, i32 1
  store ptr %99, ptr %11, align 8, !tbaa !5
  br label %113

100:                                              ; preds = %84
  %101 = load ptr, ptr %10, align 8, !tbaa !5
  %102 = load i8, ptr %101, align 1, !tbaa !25
  %103 = zext i8 %102 to i32
  %104 = and i32 %103, 255
  %105 = trunc i32 %104 to i8
  %106 = zext i8 %105 to i32
  %107 = load ptr, ptr %6, align 8, !tbaa !5
  %108 = getelementptr inbounds %struct.IRDA_HandleTypeDef, ptr %107, i32 0, i32 0
  %109 = load ptr, ptr %108, align 8, !tbaa !22
  %110 = getelementptr inbounds %struct.USART_TypeDef, ptr %109, i32 0, i32 10
  store volatile i32 %106, ptr %110, align 4, !tbaa !23
  %111 = load ptr, ptr %10, align 8, !tbaa !5
  %112 = getelementptr inbounds i8, ptr %111, i32 1
  store ptr %112, ptr %10, align 8, !tbaa !5
  br label %113

113:                                              ; preds = %100, %87
  br label %67, !llvm.loop !26

114:                                              ; preds = %67
  %115 = load ptr, ptr %6, align 8, !tbaa !5
  %116 = load i32, ptr %12, align 4, !tbaa !11
  %117 = load i32, ptr %9, align 4, !tbaa !11
  %118 = call i32 @IRDA_WaitOnFlagUntilTimeout(ptr noundef %115, i32 noundef 64, i32 noundef 0, i32 noundef %116, i32 noundef %117)
  %119 = icmp ne i32 %118, 0
  br i1 %119, label %120, label %121

120:                                              ; preds = %114
  store i32 3, ptr %5, align 4
  store i32 1, ptr %13, align 4
  br label %130

121:                                              ; preds = %114
  %122 = load ptr, ptr %6, align 8, !tbaa !5
  %123 = getelementptr inbounds %struct.IRDA_HandleTypeDef, ptr %122, i32 0, i32 12
  store volatile i32 32, ptr %123, align 4, !tbaa !13
  br label %124

124:                                              ; preds = %121
  %125 = load ptr, ptr %6, align 8, !tbaa !5
  %126 = getelementptr inbounds %struct.IRDA_HandleTypeDef, ptr %125, i32 0, i32 11
  store i32 0, ptr %126, align 8, !tbaa !16
  br label %127

127:                                              ; preds = %124
  br label %128

128:                                              ; preds = %127
  store i32 0, ptr %5, align 4
  store i32 1, ptr %13, align 4
  br label %130

129:                                              ; preds = %4
  store i32 2, ptr %5, align 4
  store i32 1, ptr %13, align 4
  br label %130

130:                                              ; preds = %129, %128, %120, %83, %32, %25
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  %131 = load i32, ptr %5, align 4
  ret i32 %131
}

; 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: nounwind uwtable
declare hidden i32 @IRDA_WaitOnFlagUntilTimeout(ptr noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef) #0

; 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 = !{!"short", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !12, i64 84}
!14 = !{!"", !6, i64 0, !15, i64 8, !6, i64 32, !10, i64 40, !10, i64 42, !6, i64 48, !10, i64 56, !10, i64 58, !10, i64 60, !6, i64 64, !6, i64 72, !12, i64 80, !12, i64 84, !12, i64 88, !12, i64 92}
!15 = !{!"", !12, i64 0, !12, i64 4, !12, i64 8, !12, i64 12, !7, i64 16, !10, i64 18, !12, i64 20}
!16 = !{!14, !12, i64 80}
!17 = !{!14, !12, i64 92}
!18 = !{!14, !10, i64 40}
!19 = !{!14, !10, i64 42}
!20 = !{!14, !12, i64 12}
!21 = !{!14, !12, i64 16}
!22 = !{!14, !6, i64 0}
!23 = !{!24, !12, i64 40}
!24 = !{!"", !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}
!25 = !{!7, !7, i64 0}
!26 = distinct !{!26, !27}
!27 = !{!"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"

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 4) i32 @HAL_IRDA_Transmit(ptr noundef %0, ptr noundef readonly %1, i16 noundef zeroext %2, i32 noundef %3) local_unnamed_addr #0 {
  %5 = getelementptr inbounds i8, ptr %0, i64 84
  %6 = load volatile i32, ptr %5, align 4, !tbaa !5
  %7 = icmp eq i32 %6, 32
  br i1 %7, label %8, label %.loopexit

8:                                                ; preds = %4
  %9 = icmp eq ptr %1, null
  %10 = icmp eq i16 %2, 0
  %or.cond = or i1 %9, %10
  br i1 %or.cond, label %.loopexit, label %11

11:                                               ; preds = %8
  %12 = getelementptr inbounds i8, ptr %0, i64 80
  %13 = load i32, ptr %12, align 8, !tbaa !13
  %14 = icmp eq i32 %13, 1
  br i1 %14, label %.loopexit, label %15

15:                                               ; preds = %11
  store i32 1, ptr %12, align 8, !tbaa !13
  %16 = getelementptr inbounds i8, ptr %0, i64 92
  store volatile i32 0, ptr %16, align 4, !tbaa !14
  store volatile i32 33, ptr %5, align 4, !tbaa !5
  %17 = tail call i32 @HAL_GetTick() #2
  %18 = getelementptr inbounds i8, ptr %0, i64 40
  store i16 %2, ptr %18, align 8, !tbaa !15
  %19 = getelementptr inbounds i8, ptr %0, i64 42
  store volatile i16 %2, ptr %19, align 2, !tbaa !16
  %20 = getelementptr inbounds i8, ptr %0, i64 12
  %21 = load i32, ptr %20, align 4, !tbaa !17
  %22 = icmp eq i32 %21, 4096
  br i1 %22, label %23, label %27

23:                                               ; preds = %15
  %24 = getelementptr inbounds i8, ptr %0, i64 16
  %25 = load i32, ptr %24, align 8, !tbaa !18
  %26 = icmp eq i32 %25, 0
  br i1 %26, label %28, label %27

27:                                               ; preds = %23, %15
  br label %28

28:                                               ; preds = %23, %27
  %.035 = phi ptr [ %1, %27 ], [ null, %23 ]
  %.034 = phi ptr [ null, %27 ], [ %1, %23 ]
  %29 = load volatile i16, ptr %19, align 2, !tbaa !16
  %.not41 = icmp eq i16 %29, 0
  br i1 %.not41, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %28, %48
  %.143 = phi ptr [ %.2, %48 ], [ %.034, %28 ]
  %.13642 = phi ptr [ %.237, %48 ], [ %.035, %28 ]
  %30 = load volatile i16, ptr %19, align 2, !tbaa !16
  %31 = add i16 %30, -1
  store volatile i16 %31, ptr %19, align 2, !tbaa !16
  %32 = tail call i32 @IRDA_WaitOnFlagUntilTimeout(ptr noundef nonnull %0, i32 noundef 128, i32 noundef 0, i32 noundef %17, i32 noundef %3)
  %.not40 = icmp eq i32 %32, 0
  br i1 %.not40, label %33, label %.loopexit

33:                                               ; preds = %.lr.ph
  %34 = icmp eq ptr %.13642, null
  br i1 %34, label %35, label %42

35:                                               ; preds = %33
  %36 = load i16, ptr %.143, align 2, !tbaa !19
  %37 = and i16 %36, 511
  %38 = zext nneg i16 %37 to i32
  %39 = load ptr, ptr %0, align 8, !tbaa !20
  %40 = getelementptr inbounds i8, ptr %39, i64 40
  store volatile i32 %38, ptr %40, align 4, !tbaa !21
  %41 = getelementptr inbounds i8, ptr %.143, i64 2
  br label %48

42:                                               ; preds = %33
  %43 = load i8, ptr %.13642, align 1, !tbaa !23
  %44 = zext i8 %43 to i32
  %45 = load ptr, ptr %0, align 8, !tbaa !20
  %46 = getelementptr inbounds i8, ptr %45, i64 40
  store volatile i32 %44, ptr %46, align 4, !tbaa !21
  %47 = getelementptr inbounds i8, ptr %.13642, i64 1
  br label %48

48:                                               ; preds = %42, %35
  %.237 = phi ptr [ null, %35 ], [ %47, %42 ]
  %.2 = phi ptr [ %41, %35 ], [ %.143, %42 ]
  %49 = load volatile i16, ptr %19, align 2, !tbaa !16
  %.not = icmp eq i16 %49, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !24

._crit_edge:                                      ; preds = %48, %28
  %50 = tail call i32 @IRDA_WaitOnFlagUntilTimeout(ptr noundef nonnull %0, i32 noundef 64, i32 noundef 0, i32 noundef %17, i32 noundef %3)
  %.not39 = icmp eq i32 %50, 0
  br i1 %.not39, label %51, label %.loopexit

51:                                               ; preds = %._crit_edge
  store volatile i32 32, ptr %5, align 4, !tbaa !5
  store i32 0, ptr %12, align 8, !tbaa !13
  br label %.loopexit

.loopexit:                                        ; preds = %.lr.ph, %4, %._crit_edge, %11, %8, %51
  %.0 = phi i32 [ 0, %51 ], [ 1, %8 ], [ 2, %11 ], [ 3, %._crit_edge ], [ 2, %4 ], [ 3, %.lr.ph ]
  ret i32 %.0
}

declare i32 @HAL_GetTick() local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare hidden i32 @IRDA_WaitOnFlagUntilTimeout(ptr noundef, i32 noundef, i32 noundef, i32 noundef, i32 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" }
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 84}
!6 = !{!"", !7, i64 0, !10, i64 8, !7, i64 32, !12, i64 40, !12, i64 42, !7, i64 48, !12, i64 56, !12, i64 58, !12, i64 60, !7, i64 64, !7, i64 72, !11, i64 80, !11, i64 84, !11, i64 88, !11, i64 92}
!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, !8, i64 16, !12, i64 18, !11, i64 20}
!11 = !{!"int", !8, i64 0}
!12 = !{!"short", !8, i64 0}
!13 = !{!6, !11, i64 80}
!14 = !{!6, !11, i64 92}
!15 = !{!6, !12, i64 40}
!16 = !{!6, !12, i64 42}
!17 = !{!6, !11, i64 12}
!18 = !{!6, !11, i64 16}
!19 = !{!12, !12, i64 0}
!20 = !{!6, !7, i64 0}
!21 = !{!22, !11, i64 40}
!22 = !{!"", !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}
!23 = !{!8, !8, i64 0}
!24 = distinct !{!24, !25}
!25 = !{!"llvm.loop.mustprogress"}


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