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

; 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.__I2C_HandleTypeDef = type { ptr, %struct.I2C_InitTypeDef, ptr, i16, i16, i32, i32, ptr, ptr, ptr, i32, i32, i32, i32, i32 }
%struct.I2C_InitTypeDef = type { i32, i32, i32, i32, i32, i32, i32, i32 }
%struct.I2C_TypeDef = type { i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32 }

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

declare i32 @HAL_GetTick() #1

; Function Attrs: nounwind uwtable
declare hidden void @I2C_TransferConfig(ptr noundef, i16 noundef zeroext, i8 noundef zeroext, i32 noundef, i32 noundef) #2

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

; Function Attrs: nounwind uwtable
declare hidden i32 @I2C_Master_ISR_IT(ptr noundef, i32 noundef, i32 noundef) #2

; Function Attrs: nounwind uwtable
declare hidden void @I2C_Enable_IRQ(ptr noundef, i16 noundef zeroext) #2

; Function Attrs: nounwind uwtable
declare hidden i32 @I2C_RequestMemoryRead(ptr noundef, i16 noundef zeroext, i16 noundef zeroext, i16 noundef zeroext, i32 noundef, i32 noundef) #2

; Function Attrs: nounwind uwtable
define dso_local i32 @HAL_I2C_Mem_Read_IT(ptr noundef %0, i16 noundef zeroext %1, i16 noundef zeroext %2, i16 noundef zeroext %3, ptr noundef %4, i16 noundef zeroext %5) #2 {
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca i16, align 2
  %10 = alloca i16, align 2
  %11 = alloca i16, align 2
  %12 = alloca ptr, align 8
  %13 = alloca i16, align 2
  %14 = alloca i32, align 4
  %15 = alloca i32, align 4
  %16 = alloca i32, align 4
  store ptr %0, ptr %8, align 8, !tbaa !5
  store i16 %1, ptr %9, align 2, !tbaa !9
  store i16 %2, ptr %10, align 2, !tbaa !9
  store i16 %3, ptr %11, align 2, !tbaa !9
  store ptr %4, ptr %12, align 8, !tbaa !5
  store i16 %5, ptr %13, align 2, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #3
  %17 = load ptr, ptr %8, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.__I2C_HandleTypeDef, ptr %17, i32 0, i32 11
  %19 = load volatile i32, ptr %18, align 4, !tbaa !11
  %20 = icmp eq i32 %19, 32
  br i1 %20, label %21, label %116

21:                                               ; preds = %6
  %22 = load ptr, ptr %12, align 8, !tbaa !5
  %23 = icmp eq ptr %22, null
  br i1 %23, label %28, label %24

24:                                               ; preds = %21
  %25 = load i16, ptr %13, align 2, !tbaa !9
  %26 = zext i16 %25 to i32
  %27 = icmp eq i32 %26, 0
  br i1 %27, label %28, label %31

28:                                               ; preds = %24, %21
  %29 = load ptr, ptr %8, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.__I2C_HandleTypeDef, ptr %29, i32 0, i32 13
  store volatile i32 512, ptr %30, align 4, !tbaa !15
  store i32 1, ptr %7, align 4
  store i32 1, ptr %16, align 4
  br label %117

31:                                               ; preds = %24
  %32 = load ptr, ptr %8, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.__I2C_HandleTypeDef, ptr %32, i32 0, i32 0
  %34 = load ptr, ptr %33, align 8, !tbaa !16
  %35 = getelementptr inbounds %struct.I2C_TypeDef, ptr %34, i32 0, i32 6
  %36 = load volatile i32, ptr %35, align 4, !tbaa !17
  %37 = zext i32 %36 to i64
  %38 = and i64 %37, 32768
  %39 = icmp eq i64 %38, 32768
  %40 = zext i1 %39 to i64
  %41 = select i1 %39, i32 1, i32 0
  %42 = icmp eq i32 %41, 1
  br i1 %42, label %43, label %44

43:                                               ; preds = %31
  store i32 2, ptr %7, align 4
  store i32 1, ptr %16, align 4
  br label %117

44:                                               ; preds = %31
  br label %45

45:                                               ; preds = %44
  %46 = load ptr, ptr %8, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.__I2C_HandleTypeDef, ptr %46, i32 0, i32 10
  %48 = load i32, ptr %47, align 8, !tbaa !19
  %49 = icmp eq i32 %48, 1
  br i1 %49, label %50, label %51

50:                                               ; preds = %45
  store i32 2, ptr %7, align 4
  store i32 1, ptr %16, align 4
  br label %117

51:                                               ; preds = %45
  %52 = load ptr, ptr %8, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.__I2C_HandleTypeDef, ptr %52, i32 0, i32 10
  store i32 1, ptr %53, align 8, !tbaa !19
  br label %54

54:                                               ; preds = %51
  br label %55

55:                                               ; preds = %54
  br label %56

56:                                               ; preds = %55
  %57 = call i32 @HAL_GetTick()
  store i32 %57, ptr %14, align 4, !tbaa !20
  %58 = load ptr, ptr %8, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.__I2C_HandleTypeDef, ptr %58, i32 0, i32 11
  store volatile i32 34, ptr %59, align 4, !tbaa !11
  %60 = load ptr, ptr %8, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.__I2C_HandleTypeDef, ptr %60, i32 0, i32 12
  store volatile i32 64, ptr %61, align 8, !tbaa !21
  %62 = load ptr, ptr %8, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.__I2C_HandleTypeDef, ptr %62, i32 0, i32 13
  store volatile i32 0, ptr %63, align 4, !tbaa !15
  %64 = load ptr, ptr %12, align 8, !tbaa !5
  %65 = load ptr, ptr %8, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.__I2C_HandleTypeDef, ptr %65, i32 0, i32 2
  store ptr %64, ptr %66, align 8, !tbaa !22
  %67 = load i16, ptr %13, align 2, !tbaa !9
  %68 = load ptr, ptr %8, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.__I2C_HandleTypeDef, ptr %68, i32 0, i32 4
  store volatile i16 %67, ptr %69, align 2, !tbaa !23
  %70 = load ptr, ptr %8, align 8, !tbaa !5
  %71 = getelementptr inbounds %struct.__I2C_HandleTypeDef, ptr %70, i32 0, i32 5
  store volatile i32 -65536, ptr %71, align 4, !tbaa !24
  %72 = load ptr, ptr %8, align 8, !tbaa !5
  %73 = getelementptr inbounds %struct.__I2C_HandleTypeDef, ptr %72, i32 0, i32 7
  store ptr @I2C_Master_ISR_IT, ptr %73, align 8, !tbaa !25
  %74 = load ptr, ptr %8, align 8, !tbaa !5
  %75 = getelementptr inbounds %struct.__I2C_HandleTypeDef, ptr %74, i32 0, i32 4
  %76 = load volatile i16, ptr %75, align 2, !tbaa !23
  %77 = zext i16 %76 to i32
  %78 = icmp ugt i32 %77, 255
  br i1 %78, label %79, label %82

79:                                               ; preds = %56
  %80 = load ptr, ptr %8, align 8, !tbaa !5
  %81 = getelementptr inbounds %struct.__I2C_HandleTypeDef, ptr %80, i32 0, i32 3
  store i16 255, ptr %81, align 8, !tbaa !26
  store i32 16777216, ptr %15, align 4, !tbaa !20
  br label %88

82:                                               ; preds = %56
  %83 = load ptr, ptr %8, align 8, !tbaa !5
  %84 = getelementptr inbounds %struct.__I2C_HandleTypeDef, ptr %83, i32 0, i32 4
  %85 = load volatile i16, ptr %84, align 2, !tbaa !23
  %86 = load ptr, ptr %8, align 8, !tbaa !5
  %87 = getelementptr inbounds %struct.__I2C_HandleTypeDef, ptr %86, i32 0, i32 3
  store i16 %85, ptr %87, align 8, !tbaa !26
  store i32 33554432, ptr %15, align 4, !tbaa !20
  br label %88

88:                                               ; preds = %82, %79
  %89 = load ptr, ptr %8, align 8, !tbaa !5
  %90 = load i16, ptr %9, align 2, !tbaa !9
  %91 = load i16, ptr %10, align 2, !tbaa !9
  %92 = load i16, ptr %11, align 2, !tbaa !9
  %93 = load i32, ptr %14, align 4, !tbaa !20
  %94 = call i32 @I2C_RequestMemoryRead(ptr noundef %89, i16 noundef zeroext %90, i16 noundef zeroext %91, i16 noundef zeroext %92, i32 noundef 25, i32 noundef %93)
  %95 = icmp ne i32 %94, 0
  br i1 %95, label %96, label %102

96:                                               ; preds = %88
  br label %97

97:                                               ; preds = %96
  %98 = load ptr, ptr %8, align 8, !tbaa !5
  %99 = getelementptr inbounds %struct.__I2C_HandleTypeDef, ptr %98, i32 0, i32 10
  store i32 0, ptr %99, align 8, !tbaa !19
  br label %100

100:                                              ; preds = %97
  br label %101

101:                                              ; preds = %100
  store i32 1, ptr %7, align 4
  store i32 1, ptr %16, align 4
  br label %117

102:                                              ; preds = %88
  %103 = load ptr, ptr %8, align 8, !tbaa !5
  %104 = load i16, ptr %9, align 2, !tbaa !9
  %105 = load ptr, ptr %8, align 8, !tbaa !5
  %106 = getelementptr inbounds %struct.__I2C_HandleTypeDef, ptr %105, i32 0, i32 3
  %107 = load i16, ptr %106, align 8, !tbaa !26
  %108 = trunc i16 %107 to i8
  %109 = load i32, ptr %15, align 4, !tbaa !20
  call void @I2C_TransferConfig(ptr noundef %103, i16 noundef zeroext %104, i8 noundef zeroext %108, i32 noundef %109, i32 noundef -2147474432)
  br label %110

110:                                              ; preds = %102
  %111 = load ptr, ptr %8, align 8, !tbaa !5
  %112 = getelementptr inbounds %struct.__I2C_HandleTypeDef, ptr %111, i32 0, i32 10
  store i32 0, ptr %112, align 8, !tbaa !19
  br label %113

113:                                              ; preds = %110
  br label %114

114:                                              ; preds = %113
  %115 = load ptr, ptr %8, align 8, !tbaa !5
  call void @I2C_Enable_IRQ(ptr noundef %115, i16 noundef zeroext 2)
  store i32 0, ptr %7, align 4
  store i32 1, ptr %16, align 4
  br label %117

116:                                              ; preds = %6
  store i32 2, ptr %7, align 4
  store i32 1, ptr %16, align 4
  br label %117

117:                                              ; preds = %116, %114, %101, %50, %43, %28
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #3
  %118 = load i32, ptr %7, align 4
  ret i32 %118
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 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 #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, !14, i64 92}
!12 = !{!"__I2C_HandleTypeDef", !6, i64 0, !13, i64 8, !6, i64 40, !10, i64 48, !10, i64 50, !14, i64 52, !14, i64 56, !6, i64 64, !6, i64 72, !6, i64 80, !14, i64 88, !14, i64 92, !14, i64 96, !14, i64 100, !14, i64 104}
!13 = !{!"", !14, i64 0, !14, i64 4, !14, i64 8, !14, i64 12, !14, i64 16, !14, i64 20, !14, i64 24, !14, i64 28}
!14 = !{!"int", !7, i64 0}
!15 = !{!12, !14, i64 100}
!16 = !{!12, !6, i64 0}
!17 = !{!18, !14, i64 24}
!18 = !{!"", !14, i64 0, !14, i64 4, !14, i64 8, !14, i64 12, !14, i64 16, !14, i64 20, !14, i64 24, !14, i64 28, !14, i64 32, !14, i64 36, !14, i64 40}
!19 = !{!12, !14, i64 88}
!20 = !{!14, !14, i64 0}
!21 = !{!12, !14, i64 96}
!22 = !{!12, !6, i64 40}
!23 = !{!12, !10, i64 50}
!24 = !{!12, !14, i64 52}
!25 = !{!12, !6, i64 64}
!26 = !{!12, !10, i64 48}


; 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"

declare i32 @HAL_GetTick() local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare hidden void @I2C_TransferConfig(ptr noundef, i16 noundef zeroext, i8 noundef zeroext, i32 noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare hidden i32 @I2C_Master_ISR_IT(ptr noundef, i32 noundef, i32 noundef) #1

; Function Attrs: nounwind uwtable
declare hidden void @I2C_Enable_IRQ(ptr noundef, i16 noundef zeroext) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare hidden i32 @I2C_RequestMemoryRead(ptr noundef, i16 noundef zeroext, i16 noundef zeroext, i16 noundef zeroext, i32 noundef, i32 noundef) local_unnamed_addr #1

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

10:                                               ; preds = %6
  %11 = icmp eq ptr %4, null
  %12 = icmp eq i16 %5, 0
  %or.cond = or i1 %11, %12
  br i1 %or.cond, label %13, label %15

13:                                               ; preds = %10
  %14 = getelementptr inbounds i8, ptr %0, i64 100
  store volatile i32 512, ptr %14, align 4, !tbaa !13
  br label %43

15:                                               ; preds = %10
  %16 = load ptr, ptr %0, align 8, !tbaa !14
  %17 = getelementptr inbounds i8, ptr %16, i64 24
  %18 = load volatile i32, ptr %17, align 4, !tbaa !15
  %19 = and i32 %18, 32768
  %.not = icmp eq i32 %19, 0
  br i1 %.not, label %20, label %43

20:                                               ; preds = %15
  %21 = getelementptr inbounds i8, ptr %0, i64 88
  %22 = load i32, ptr %21, align 8, !tbaa !17
  %23 = icmp eq i32 %22, 1
  br i1 %23, label %43, label %24

24:                                               ; preds = %20
  store i32 1, ptr %21, align 8, !tbaa !17
  %25 = tail call i32 @HAL_GetTick() #2
  store volatile i32 34, ptr %7, align 4, !tbaa !5
  %26 = getelementptr inbounds i8, ptr %0, i64 96
  store volatile i32 64, ptr %26, align 8, !tbaa !18
  %27 = getelementptr inbounds i8, ptr %0, i64 100
  store volatile i32 0, ptr %27, align 4, !tbaa !13
  %28 = getelementptr inbounds i8, ptr %0, i64 40
  store ptr %4, ptr %28, align 8, !tbaa !19
  %29 = getelementptr inbounds i8, ptr %0, i64 50
  store volatile i16 %5, ptr %29, align 2, !tbaa !20
  %30 = getelementptr inbounds i8, ptr %0, i64 52
  store volatile i32 -65536, ptr %30, align 4, !tbaa !21
  %31 = getelementptr inbounds i8, ptr %0, i64 64
  store ptr @I2C_Master_ISR_IT, ptr %31, align 8, !tbaa !22
  %32 = load volatile i16, ptr %29, align 2, !tbaa !20
  %33 = icmp ugt i16 %32, 255
  br i1 %33, label %36, label %34

34:                                               ; preds = %24
  %35 = load volatile i16, ptr %29, align 2, !tbaa !20
  br label %36

36:                                               ; preds = %24, %34
  %.sink = phi i16 [ %35, %34 ], [ 255, %24 ]
  %.0 = phi i32 [ 33554432, %34 ], [ 16777216, %24 ]
  %37 = getelementptr inbounds i8, ptr %0, i64 48
  store i16 %.sink, ptr %37, align 8
  %38 = tail call i32 @I2C_RequestMemoryRead(ptr noundef nonnull %0, i16 noundef zeroext %1, i16 noundef zeroext %2, i16 noundef zeroext %3, i32 noundef 25, i32 noundef %25)
  %.not36 = icmp eq i32 %38, 0
  br i1 %.not36, label %40, label %39

39:                                               ; preds = %36
  store i32 0, ptr %21, align 8, !tbaa !17
  br label %43

40:                                               ; preds = %36
  %41 = load i16, ptr %37, align 8, !tbaa !23
  %42 = trunc i16 %41 to i8
  tail call void @I2C_TransferConfig(ptr noundef nonnull %0, i16 noundef zeroext %1, i8 noundef zeroext %42, i32 noundef %.0, i32 noundef -2147474432)
  store i32 0, ptr %21, align 8, !tbaa !17
  tail call void @I2C_Enable_IRQ(ptr noundef nonnull %0, i16 noundef zeroext 2)
  br label %43

43:                                               ; preds = %6, %20, %15, %40, %39, %13
  %.034 = phi i32 [ 1, %13 ], [ 1, %39 ], [ 0, %40 ], [ 2, %15 ], [ 2, %20 ], [ 2, %6 ]
  ret i32 %.034
}

attributes #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 = { 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 #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 92}
!6 = !{!"__I2C_HandleTypeDef", !7, i64 0, !10, i64 8, !7, i64 40, !12, i64 48, !12, i64 50, !11, i64 52, !11, i64 56, !7, i64 64, !7, i64 72, !7, i64 80, !11, i64 88, !11, i64 92, !11, i64 96, !11, i64 100, !11, i64 104}
!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 = !{!"int", !8, i64 0}
!12 = !{!"short", !8, i64 0}
!13 = !{!6, !11, i64 100}
!14 = !{!6, !7, i64 0}
!15 = !{!16, !11, i64 24}
!16 = !{!"", !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}
!17 = !{!6, !11, i64 88}
!18 = !{!6, !11, i64 96}
!19 = !{!6, !7, i64 40}
!20 = !{!6, !12, i64 50}
!21 = !{!6, !11, i64 52}
!22 = !{!6, !7, i64 64}
!23 = !{!6, !12, i64 48}


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