; LLVM IR from ctlst-tech/catpilot :: bsp/mcu/periph/i2c/stm32 (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_t = type { %struct.__I2C_HandleTypeDef, ptr, ptr, %struct.dma_t, %struct.dma_t, i32, i32, %struct.i2c_private_t }
%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.dma_t = type { %struct.__DMA_HandleTypeDef, i32, %struct.dma_private_t }
%struct.__DMA_HandleTypeDef = type { ptr, %struct.DMA_InitTypeDef, i32, i32, ptr, ptr, ptr, ptr, ptr, ptr, ptr, i32, i32, i32, ptr, ptr, i32, ptr, ptr, i32 }
%struct.DMA_InitTypeDef = type { i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32 }
%struct.dma_private_t = type { i32 }
%struct.i2c_private_t = type { i32, i32, ptr, ptr, ptr, i32 }

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

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

declare i64 @xQueueSemaphoreTake(ptr noundef, i32 noundef) #1

declare i64 @xQueueGenericSend(ptr noundef, ptr noundef, i32 noundef, i64 noundef) #1

; Function Attrs: nounwind uwtable
define dso_local i32 @i2c_receive(ptr noundef %0, i8 noundef zeroext %1, ptr noundef %2, i16 noundef zeroext %3) #2 {
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca i8, align 1
  %8 = alloca ptr, align 8
  %9 = alloca i16, align 2
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store i8 %1, ptr %7, align 1, !tbaa !9
  store ptr %2, ptr %8, align 8, !tbaa !5
  store i16 %3, ptr %9, align 2, !tbaa !10
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  store i32 0, ptr %10, align 4, !tbaa !12
  %12 = load i16, ptr %9, align 2, !tbaa !10
  %13 = zext i16 %12 to i32
  %14 = icmp eq i32 %13, 0
  br i1 %14, label %15, label %16

15:                                               ; preds = %4
  store i32 22, ptr %5, align 4
  store i32 1, ptr %11, align 4
  br label %74

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

19:                                               ; preds = %16
  store i32 22, ptr %5, align 4
  store i32 1, ptr %11, align 4
  br label %74

20:                                               ; preds = %16
  %21 = load ptr, ptr %6, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.i2c_t, ptr %21, i32 0, i32 7
  %23 = getelementptr inbounds %struct.i2c_private_t, ptr %22, i32 0, i32 3
  %24 = load ptr, ptr %23, align 8, !tbaa !14
  %25 = load ptr, ptr %6, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.i2c_t, ptr %25, i32 0, i32 5
  %27 = load i32, ptr %26, align 8, !tbaa !23
  %28 = mul i32 %27, 1000
  %29 = udiv i32 %28, 1000
  %30 = call i64 @xQueueSemaphoreTake(ptr noundef %24, i32 noundef %29)
  %31 = icmp eq i64 %30, 0
  br i1 %31, label %32, label %33

32:                                               ; preds = %20
  store i32 116, ptr %5, align 4
  store i32 1, ptr %11, align 4
  br label %74

33:                                               ; preds = %20
  %34 = load ptr, ptr %6, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.i2c_t, ptr %34, i32 0, i32 7
  %36 = getelementptr inbounds %struct.i2c_private_t, ptr %35, i32 0, i32 2
  %37 = load ptr, ptr %36, align 8, !tbaa !24
  %38 = call i64 @xQueueSemaphoreTake(ptr noundef %37, i32 noundef 0)
  %39 = load ptr, ptr %6, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.i2c_t, ptr %39, i32 0, i32 7
  %41 = getelementptr inbounds %struct.i2c_private_t, ptr %40, i32 0, i32 5
  store i32 2, ptr %41, align 8, !tbaa !25
  %42 = load ptr, ptr %6, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.i2c_t, ptr %42, i32 0, i32 0
  %44 = load i8, ptr %7, align 1, !tbaa !9
  %45 = zext i8 %44 to i16
  %46 = load ptr, ptr %8, align 8, !tbaa !5
  %47 = load i16, ptr %9, align 2, !tbaa !10
  %48 = call i32 @HAL_I2C_Master_Receive_DMA(ptr noundef %43, i16 noundef zeroext %45, ptr noundef %46, i16 noundef zeroext %47)
  store i32 %48, ptr %10, align 4, !tbaa !12
  %49 = load i32, ptr %10, align 4, !tbaa !12
  %50 = icmp eq i32 %49, 0
  br i1 %50, label %51, label %64

51:                                               ; preds = %33
  %52 = load ptr, ptr %6, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.i2c_t, ptr %52, i32 0, i32 7
  %54 = getelementptr inbounds %struct.i2c_private_t, ptr %53, i32 0, i32 2
  %55 = load ptr, ptr %54, align 8, !tbaa !24
  %56 = load ptr, ptr %6, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.i2c_t, ptr %56, i32 0, i32 5
  %58 = load i32, ptr %57, align 8, !tbaa !23
  %59 = mul i32 %58, 1000
  %60 = udiv i32 %59, 1000
  %61 = call i64 @xQueueSemaphoreTake(ptr noundef %55, i32 noundef %60)
  %62 = icmp ne i64 %61, 0
  br i1 %62, label %64, label %63

63:                                               ; preds = %51
  store i32 116, ptr %10, align 4, !tbaa !12
  br label %64

64:                                               ; preds = %63, %51, %33
  %65 = load ptr, ptr %6, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.i2c_t, ptr %65, i32 0, i32 7
  %67 = getelementptr inbounds %struct.i2c_private_t, ptr %66, i32 0, i32 5
  store i32 0, ptr %67, align 8, !tbaa !25
  %68 = load ptr, ptr %6, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.i2c_t, ptr %68, i32 0, i32 7
  %70 = getelementptr inbounds %struct.i2c_private_t, ptr %69, i32 0, i32 3
  %71 = load ptr, ptr %70, align 8, !tbaa !14
  %72 = call i64 @xQueueGenericSend(ptr noundef %71, ptr noundef null, i32 noundef 0, i64 noundef 0)
  %73 = load i32, ptr %10, align 4, !tbaa !12
  store i32 %73, ptr %5, align 4
  store i32 1, ptr %11, align 4
  br label %74

74:                                               ; preds = %64, %32, %19, %15
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  %75 = load i32, ptr %5, align 4
  ret i32 %75
}

declare i32 @HAL_I2C_Master_Receive_DMA(ptr noundef, i16 noundef zeroext, ptr noundef, i16 noundef zeroext) #1

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 = !{!7, !7, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"short", !7, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"int", !7, i64 0}
!14 = !{!15, !6, i64 536}
!15 = !{!"", !16, i64 0, !6, i64 112, !6, i64 120, !18, i64 128, !18, i64 320, !13, i64 512, !13, i64 516, !22, i64 520}
!16 = !{!"__I2C_HandleTypeDef", !6, i64 0, !17, i64 8, !6, i64 40, !11, i64 48, !11, i64 50, !13, i64 52, !13, i64 56, !6, i64 64, !6, i64 72, !6, i64 80, !13, i64 88, !13, i64 92, !13, i64 96, !13, i64 100, !13, i64 104}
!17 = !{!"", !13, i64 0, !13, i64 4, !13, i64 8, !13, i64 12, !13, i64 16, !13, i64 20, !13, i64 24, !13, i64 28}
!18 = !{!"", !19, i64 0, !13, i64 184, !21, i64 188}
!19 = !{!"__DMA_HandleTypeDef", !6, i64 0, !20, i64 8, !13, i64 56, !13, i64 60, !6, i64 64, !6, i64 72, !6, i64 80, !6, i64 88, !6, i64 96, !6, i64 104, !6, i64 112, !13, i64 120, !13, i64 124, !13, i64 128, !6, i64 136, !6, i64 144, !13, i64 152, !6, i64 160, !6, i64 168, !13, i64 176}
!20 = !{!"", !13, i64 0, !13, i64 4, !13, i64 8, !13, i64 12, !13, i64 16, !13, i64 20, !13, i64 24, !13, i64 28, !13, i64 32, !13, i64 36, !13, i64 40, !13, i64 44}
!21 = !{!"", !13, i64 0}
!22 = !{!"", !13, i64 0, !13, i64 4, !6, i64 8, !6, i64 16, !6, i64 24, !13, i64 32}
!23 = !{!15, !13, i64 512}
!24 = !{!15, !6, i64 528}
!25 = !{!15, !13, i64 552}


; 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 i64 @xQueueSemaphoreTake(ptr noundef, i32 noundef) local_unnamed_addr #0

declare i64 @xQueueGenericSend(ptr noundef, ptr noundef, i32 noundef, i64 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local i32 @i2c_receive(ptr noundef %0, i8 noundef zeroext %1, ptr noundef %2, i16 noundef zeroext %3) local_unnamed_addr #1 {
  %5 = icmp eq i16 %3, 0
  %6 = icmp eq ptr %2, null
  %or.cond = or i1 %6, %5
  br i1 %or.cond, label %33, label %7

7:                                                ; preds = %4
  %8 = getelementptr inbounds i8, ptr %0, i64 536
  %9 = load ptr, ptr %8, align 8, !tbaa !5
  %10 = getelementptr inbounds i8, ptr %0, i64 512
  %11 = load i32, ptr %10, align 8, !tbaa !19
  %12 = mul i32 %11, 1000
  %13 = udiv i32 %12, 1000
  %14 = tail call i64 @xQueueSemaphoreTake(ptr noundef %9, i32 noundef %13) #2
  %15 = icmp eq i64 %14, 0
  br i1 %15, label %33, label %16

16:                                               ; preds = %7
  %17 = getelementptr inbounds i8, ptr %0, i64 528
  %18 = load ptr, ptr %17, align 8, !tbaa !20
  %19 = tail call i64 @xQueueSemaphoreTake(ptr noundef %18, i32 noundef 0) #2
  %20 = getelementptr inbounds i8, ptr %0, i64 552
  store i32 2, ptr %20, align 8, !tbaa !21
  %21 = zext i8 %1 to i16
  %22 = tail call i32 @HAL_I2C_Master_Receive_DMA(ptr noundef nonnull %0, i16 noundef zeroext %21, ptr noundef nonnull %2, i16 noundef zeroext %3) #2
  %23 = icmp eq i32 %22, 0
  br i1 %23, label %24, label %30

24:                                               ; preds = %16
  %25 = load ptr, ptr %17, align 8, !tbaa !20
  %26 = load i32, ptr %10, align 8, !tbaa !19
  %27 = mul i32 %26, 1000
  %28 = udiv i32 %27, 1000
  %29 = tail call i64 @xQueueSemaphoreTake(ptr noundef %25, i32 noundef %28) #2
  %.not = icmp eq i64 %29, 0
  %spec.select = select i1 %.not, i32 116, i32 0
  br label %30

30:                                               ; preds = %24, %16
  %.0 = phi i32 [ %22, %16 ], [ %spec.select, %24 ]
  store i32 0, ptr %20, align 8, !tbaa !21
  %31 = load ptr, ptr %8, align 8, !tbaa !5
  %32 = tail call i64 @xQueueGenericSend(ptr noundef %31, ptr noundef null, i32 noundef 0, i64 noundef 0) #2
  br label %33

33:                                               ; preds = %7, %4, %30
  %.016 = phi i32 [ %.0, %30 ], [ 22, %4 ], [ 116, %7 ]
  ret i32 %.016
}

declare i32 @HAL_I2C_Master_Receive_DMA(ptr noundef, i16 noundef zeroext, ptr noundef, i16 noundef zeroext) local_unnamed_addr #0

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, !8, i64 536}
!6 = !{!"", !7, i64 0, !8, i64 112, !8, i64 120, !14, i64 128, !14, i64 320, !12, i64 512, !12, i64 516, !18, i64 520}
!7 = !{!"__I2C_HandleTypeDef", !8, i64 0, !11, i64 8, !8, i64 40, !13, i64 48, !13, i64 50, !12, i64 52, !12, i64 56, !8, i64 64, !8, i64 72, !8, i64 80, !12, i64 88, !12, i64 92, !12, i64 96, !12, i64 100, !12, i64 104}
!8 = !{!"any pointer", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C/C++ TBAA"}
!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 = !{!"int", !9, i64 0}
!13 = !{!"short", !9, i64 0}
!14 = !{!"", !15, i64 0, !12, i64 184, !17, i64 188}
!15 = !{!"__DMA_HandleTypeDef", !8, i64 0, !16, i64 8, !12, i64 56, !12, i64 60, !8, i64 64, !8, i64 72, !8, i64 80, !8, i64 88, !8, i64 96, !8, i64 104, !8, i64 112, !12, i64 120, !12, i64 124, !12, i64 128, !8, i64 136, !8, i64 144, !12, i64 152, !8, i64 160, !8, i64 168, !12, i64 176}
!16 = !{!"", !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}
!17 = !{!"", !12, i64 0}
!18 = !{!"", !12, i64 0, !12, i64 4, !8, i64 8, !8, i64 16, !8, i64 24, !12, i64 32}
!19 = !{!6, !12, i64 512}
!20 = !{!6, !8, i64 528}
!21 = !{!6, !12, i64 552}


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