; LLVM IR from reazon-research/OpenArm :: control/canfd_control/Drivers/STM32H7xx_HAL_Driver/Src (stm32h7xx_hal_i2c)

; 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, 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: nounwind uwtable
declare hidden void @I2C_TransferConfig(ptr noundef, i16 noundef zeroext, i8 noundef zeroext, i32 noundef, i32 noundef) #0

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

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

; 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) #0 {
  %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
  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
  %14 = load ptr, ptr %8, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.__I2C_HandleTypeDef, ptr %14, i32 0, i32 11
  %16 = load volatile i32, ptr %15, align 4, !tbaa !11
  %17 = icmp eq i32 %16, 32
  br i1 %17, label %18, label %121

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

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

25:                                               ; preds = %21, %18
  %26 = load ptr, ptr %8, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.__I2C_HandleTypeDef, ptr %26, i32 0, i32 13
  store volatile i32 512, ptr %27, align 4, !tbaa !15
  store i32 1, ptr %7, align 4
  br label %122

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

40:                                               ; preds = %28
  store i32 2, ptr %7, align 4
  br label %122

41:                                               ; preds = %28
  br label %42

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

47:                                               ; preds = %42
  store i32 2, ptr %7, align 4
  br label %122

48:                                               ; preds = %42
  %49 = load ptr, ptr %8, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.__I2C_HandleTypeDef, ptr %49, i32 0, i32 10
  store i32 1, ptr %50, align 8, !tbaa !19
  br label %51

51:                                               ; preds = %48
  br label %52

52:                                               ; preds = %51
  %53 = load ptr, ptr %8, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.__I2C_HandleTypeDef, ptr %53, i32 0, i32 11
  store volatile i32 34, ptr %54, align 4, !tbaa !11
  %55 = load ptr, ptr %8, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.__I2C_HandleTypeDef, ptr %55, i32 0, i32 12
  store volatile i32 64, ptr %56, align 8, !tbaa !20
  %57 = load ptr, ptr %8, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.__I2C_HandleTypeDef, ptr %57, i32 0, i32 13
  store volatile i32 0, ptr %58, align 4, !tbaa !15
  %59 = load ptr, ptr %12, align 8, !tbaa !5
  %60 = load ptr, ptr %8, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.__I2C_HandleTypeDef, ptr %60, i32 0, i32 2
  store ptr %59, ptr %61, align 8, !tbaa !21
  %62 = load i16, ptr %13, align 2, !tbaa !9
  %63 = load ptr, ptr %8, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.__I2C_HandleTypeDef, ptr %63, i32 0, i32 4
  store volatile i16 %62, ptr %64, align 2, !tbaa !22
  %65 = load ptr, ptr %8, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.__I2C_HandleTypeDef, ptr %65, i32 0, i32 5
  store volatile i32 -65536, ptr %66, align 4, !tbaa !23
  %67 = load ptr, ptr %8, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct.__I2C_HandleTypeDef, ptr %67, i32 0, i32 7
  store ptr @I2C_Mem_ISR_IT, ptr %68, align 8, !tbaa !24
  %69 = load i16, ptr %9, align 2, !tbaa !9
  %70 = zext i16 %69 to i32
  %71 = load ptr, ptr %8, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct.__I2C_HandleTypeDef, ptr %71, i32 0, i32 15
  store volatile i32 %70, ptr %72, align 4, !tbaa !25
  %73 = load i16, ptr %11, align 2, !tbaa !9
  %74 = zext i16 %73 to i32
  %75 = icmp eq i32 %74, 1
  br i1 %75, label %76, label %89

76:                                               ; preds = %52
  %77 = load i16, ptr %10, align 2, !tbaa !9
  %78 = zext i16 %77 to i32
  %79 = and i32 %78, 255
  %80 = trunc i32 %79 to i16
  %81 = trunc i16 %80 to i8
  %82 = zext i8 %81 to i32
  %83 = load ptr, ptr %8, align 8, !tbaa !5
  %84 = getelementptr inbounds %struct.__I2C_HandleTypeDef, ptr %83, i32 0, i32 0
  %85 = load ptr, ptr %84, align 8, !tbaa !16
  %86 = getelementptr inbounds %struct.I2C_TypeDef, ptr %85, i32 0, i32 10
  store volatile i32 %82, ptr %86, align 4, !tbaa !26
  %87 = load ptr, ptr %8, align 8, !tbaa !5
  %88 = getelementptr inbounds %struct.__I2C_HandleTypeDef, ptr %87, i32 0, i32 16
  store volatile i32 -1, ptr %88, align 8, !tbaa !27
  br label %111

89:                                               ; preds = %52
  %90 = load i16, ptr %10, align 2, !tbaa !9
  %91 = zext i16 %90 to i32
  %92 = and i32 %91, 65280
  %93 = trunc i32 %92 to i16
  %94 = zext i16 %93 to i32
  %95 = ashr i32 %94, 8
  %96 = trunc i32 %95 to i16
  %97 = trunc i16 %96 to i8
  %98 = zext i8 %97 to i32
  %99 = load ptr, ptr %8, align 8, !tbaa !5
  %100 = getelementptr inbounds %struct.__I2C_HandleTypeDef, ptr %99, i32 0, i32 0
  %101 = load ptr, ptr %100, align 8, !tbaa !16
  %102 = getelementptr inbounds %struct.I2C_TypeDef, ptr %101, i32 0, i32 10
  store volatile i32 %98, ptr %102, align 4, !tbaa !26
  %103 = load i16, ptr %10, align 2, !tbaa !9
  %104 = zext i16 %103 to i32
  %105 = and i32 %104, 255
  %106 = trunc i32 %105 to i16
  %107 = trunc i16 %106 to i8
  %108 = zext i8 %107 to i32
  %109 = load ptr, ptr %8, align 8, !tbaa !5
  %110 = getelementptr inbounds %struct.__I2C_HandleTypeDef, ptr %109, i32 0, i32 16
  store volatile i32 %108, ptr %110, align 8, !tbaa !27
  br label %111

111:                                              ; preds = %89, %76
  %112 = load ptr, ptr %8, align 8, !tbaa !5
  %113 = load i16, ptr %9, align 2, !tbaa !9
  %114 = load i16, ptr %11, align 2, !tbaa !9
  %115 = trunc i16 %114 to i8
  call void @I2C_TransferConfig(ptr noundef %112, i16 noundef zeroext %113, i8 noundef zeroext %115, i32 noundef 0, i32 noundef -2147475456)
  br label %116

116:                                              ; preds = %111
  %117 = load ptr, ptr %8, align 8, !tbaa !5
  %118 = getelementptr inbounds %struct.__I2C_HandleTypeDef, ptr %117, i32 0, i32 10
  store i32 0, ptr %118, align 8, !tbaa !19
  br label %119

119:                                              ; preds = %116
  %120 = load ptr, ptr %8, align 8, !tbaa !5
  call void @I2C_Enable_IRQ(ptr noundef %120, i16 noundef zeroext 3)
  store i32 0, ptr %7, align 4
  br label %122

121:                                              ; preds = %6
  store i32 2, ptr %7, align 4
  br label %122

122:                                              ; preds = %121, %119, %47, %40, %25
  %123 = load i32, ptr %7, align 4
  ret i32 %123
}

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, !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, !14, i64 108, !14, i64 112}
!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 = !{!12, !14, i64 96}
!21 = !{!12, !6, i64 40}
!22 = !{!12, !10, i64 50}
!23 = !{!12, !14, i64 52}
!24 = !{!12, !6, i64 64}
!25 = !{!12, !14, i64 108}
!26 = !{!18, !14, i64 40}
!27 = !{!12, !14, i64 112}


; 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
declare hidden void @I2C_TransferConfig(ptr noundef, i16 noundef zeroext, i8 noundef zeroext, i32 noundef, i32 noundef) local_unnamed_addr #0

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

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

; 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 #0 {
  %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 %46

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 %46

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 %46

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 %46, label %24

24:                                               ; preds = %20
  store i32 1, ptr %21, align 8, !tbaa !17
  store volatile i32 34, ptr %7, align 4, !tbaa !5
  %25 = getelementptr inbounds i8, ptr %0, i64 96
  store volatile i32 64, ptr %25, align 8, !tbaa !18
  %26 = getelementptr inbounds i8, ptr %0, i64 100
  store volatile i32 0, ptr %26, align 4, !tbaa !13
  %27 = getelementptr inbounds i8, ptr %0, i64 40
  store ptr %4, ptr %27, align 8, !tbaa !19
  %28 = getelementptr inbounds i8, ptr %0, i64 50
  store volatile i16 %5, ptr %28, align 2, !tbaa !20
  %29 = getelementptr inbounds i8, ptr %0, i64 52
  store volatile i32 -65536, ptr %29, align 4, !tbaa !21
  %30 = getelementptr inbounds i8, ptr %0, i64 64
  store ptr @I2C_Mem_ISR_IT, ptr %30, align 8, !tbaa !22
  %31 = zext i16 %1 to i32
  %32 = getelementptr inbounds i8, ptr %0, i64 108
  store volatile i32 %31, ptr %32, align 4, !tbaa !23
  %33 = icmp eq i16 %3, 1
  %34 = getelementptr inbounds i8, ptr %16, i64 40
  br i1 %33, label %35, label %38

35:                                               ; preds = %24
  %36 = and i16 %2, 255
  %37 = zext nneg i16 %36 to i32
  store volatile i32 %37, ptr %34, align 4, !tbaa !24
  br label %43

38:                                               ; preds = %24
  %39 = lshr i16 %2, 8
  %40 = zext nneg i16 %39 to i32
  store volatile i32 %40, ptr %34, align 4, !tbaa !24
  %41 = and i16 %2, 255
  %42 = zext nneg i16 %41 to i32
  br label %43

43:                                               ; preds = %38, %35
  %.sink = phi i32 [ %42, %38 ], [ -1, %35 ]
  %44 = getelementptr inbounds i8, ptr %0, i64 112
  store volatile i32 %.sink, ptr %44, align 8, !tbaa !25
  %45 = trunc i16 %3 to i8
  tail call void @I2C_TransferConfig(ptr noundef nonnull %0, i16 noundef zeroext %1, i8 noundef zeroext %45, i32 noundef 0, i32 noundef -2147475456)
  store i32 0, ptr %21, align 8, !tbaa !17
  tail call void @I2C_Enable_IRQ(ptr noundef nonnull %0, i16 noundef zeroext 3)
  br label %46

46:                                               ; preds = %6, %20, %15, %43, %13
  %.0 = phi i32 [ 1, %13 ], [ 0, %43 ], [ 2, %15 ], [ 2, %20 ], [ 2, %6 ]
  ret i32 %.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 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, !11, i64 108, !11, i64 112}
!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, !11, i64 108}
!24 = !{!16, !11, i64 40}
!25 = !{!6, !11, i64 112}


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