; LLVM IR from ctlst-tech/catpilot :: bsp/mcu/periph/can/stm32 (can)

; 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.can_frame_t = type { %struct.can_header_t, [8 x i8], ptr }
%struct.can_header_t = type { i32, i32, i32 }
%struct.can_t = type { [32 x i8], [32 x i8], %struct.FDCAN_HandleTypeDef, ptr, ptr, i32, i32, i32, i32, i32, i32, %struct.can_private_t }
%struct.FDCAN_HandleTypeDef = type { ptr, ptr, %struct.FDCAN_InitTypeDef, %struct.FDCAN_MsgRamAddressTypeDef, i32, i32, i32, i32 }
%struct.FDCAN_InitTypeDef = type { i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32 }
%struct.FDCAN_MsgRamAddressTypeDef = type { i32, i32, i32, i32, i32, i32, i32, i32, i32, i32 }
%struct.can_private_t = type { i32, i32, ptr, ptr, ptr, ptr, i32, i8, i32, [32 x ptr], ptr, ptr }
%struct.can_channel_t = type { ptr, ptr, i32, i32, i32, i32, ptr, ptr }

@.str.1 = external hidden unnamed_addr constant [16 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [19 x i8], align 1

; 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 i32 @printf_(ptr noundef, ...) #1

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

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #3

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

; Function Attrs: nounwind uwtable
define dso_local void @can_read_thread(ptr noundef %0) #2 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca %struct.can_frame_t, align 8
  %5 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #4
  %6 = load ptr, ptr %2, align 8, !tbaa !5
  store ptr %6, ptr %3, align 8, !tbaa !5
  br label %7

7:                                                ; preds = %99, %1
  br label %8

8:                                                ; preds = %7
  call void @llvm.lifetime.start.p0(i64 32, ptr %4) #4
  call void @llvm.memset.p0.i64(ptr align 8 %4, i8 0, i64 32, i1 false)
  %9 = load ptr, ptr %3, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct.can_frame_t, ptr %4, i32 0, i32 0
  %11 = getelementptr inbounds %struct.can_frame_t, ptr %4, i32 0, i32 1
  %12 = getelementptr inbounds [8 x i8], ptr %11, i64 0, i64 0
  %13 = call i32 @can_receive(ptr noundef %9, ptr noundef %10, ptr noundef %12)
  %14 = icmp ne i32 %13, 0
  br i1 %14, label %99, label %15

15:                                               ; preds = %8
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  store i32 0, ptr %5, align 4, !tbaa !9
  br label %16

16:                                               ; preds = %95, %15
  %17 = load i32, ptr %5, align 4, !tbaa !9
  %18 = icmp slt i32 %17, 32
  br i1 %18, label %19, label %28

19:                                               ; preds = %16
  %20 = load ptr, ptr %3, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.can_t, ptr %20, i32 0, i32 11
  %22 = getelementptr inbounds %struct.can_private_t, ptr %21, i32 0, i32 9
  %23 = load i32, ptr %5, align 4, !tbaa !9
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds [32 x ptr], ptr %22, i64 0, i64 %24
  %26 = load ptr, ptr %25, align 8, !tbaa !5
  %27 = icmp ne ptr %26, null
  br label %28

28:                                               ; preds = %19, %16
  %29 = phi i1 [ false, %16 ], [ %27, %19 ]
  br i1 %29, label %31, label %30

30:                                               ; preds = %28
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  br label %98

31:                                               ; preds = %28
  %32 = load ptr, ptr %3, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.can_t, ptr %32, i32 0, i32 11
  %34 = getelementptr inbounds %struct.can_private_t, ptr %33, i32 0, i32 9
  %35 = load i32, ptr %5, align 4, !tbaa !9
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds [32 x ptr], ptr %34, i64 0, i64 %36
  %38 = load ptr, ptr %37, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.can_channel_t, ptr %38, i32 0, i32 3
  %40 = load i32, ptr %39, align 4, !tbaa !11
  %41 = getelementptr inbounds %struct.can_frame_t, ptr %4, i32 0, i32 0
  %42 = getelementptr inbounds %struct.can_header_t, ptr %41, i32 0, i32 0
  %43 = load i32, ptr %42, align 8, !tbaa !13
  %44 = icmp ule i32 %40, %43
  br i1 %44, label %45, label %94

45:                                               ; preds = %31
  %46 = load ptr, ptr %3, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.can_t, ptr %46, i32 0, i32 11
  %48 = getelementptr inbounds %struct.can_private_t, ptr %47, i32 0, i32 9
  %49 = load i32, ptr %5, align 4, !tbaa !9
  %50 = sext i32 %49 to i64
  %51 = getelementptr inbounds [32 x ptr], ptr %48, i64 0, i64 %50
  %52 = load ptr, ptr %51, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.can_channel_t, ptr %52, i32 0, i32 4
  %54 = load i32, ptr %53, align 8, !tbaa !16
  %55 = getelementptr inbounds %struct.can_frame_t, ptr %4, i32 0, i32 0
  %56 = getelementptr inbounds %struct.can_header_t, ptr %55, i32 0, i32 0
  %57 = load i32, ptr %56, align 8, !tbaa !13
  %58 = icmp uge i32 %54, %57
  br i1 %58, label %59, label %94

59:                                               ; preds = %45
  %60 = load ptr, ptr %3, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.can_t, ptr %60, i32 0, i32 11
  %62 = getelementptr inbounds %struct.can_private_t, ptr %61, i32 0, i32 9
  %63 = load i32, ptr %5, align 4, !tbaa !9
  %64 = sext i32 %63 to i64
  %65 = getelementptr inbounds [32 x ptr], ptr %62, i64 0, i64 %64
  %66 = load ptr, ptr %65, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.can_channel_t, ptr %66, i32 0, i32 7
  %68 = load ptr, ptr %67, align 8, !tbaa !17
  %69 = call i64 @xQueueGenericSend(ptr noundef %68, ptr noundef %4, i32 noundef 0, i64 noundef 0)
  %70 = icmp ne i64 %69, 0
  br i1 %70, label %93, label %71

71:                                               ; preds = %59
  %72 = load ptr, ptr %3, align 8, !tbaa !5
  %73 = getelementptr inbounds %struct.can_t, ptr %72, i32 0, i32 10
  %74 = load i32, ptr %73, align 4, !tbaa !18
  %75 = icmp eq i32 %74, 2
  br i1 %75, label %76, label %82

76:                                               ; preds = %71
  %77 = load ptr, ptr %3, align 8, !tbaa !5
  %78 = getelementptr inbounds %struct.can_t, ptr %77, i32 0, i32 0
  %79 = getelementptr inbounds [32 x i8], ptr %78, i64 0, i64 0
  %80 = call i32 (ptr, ...) @printf_(ptr noundef @.str.1, ptr noundef %79)
  %81 = call i32 (ptr, ...) @printf_(ptr noundef @.str.5)
  br label %82

82:                                               ; preds = %76, %71
  %83 = load ptr, ptr %3, align 8, !tbaa !5
  %84 = getelementptr inbounds %struct.can_t, ptr %83, i32 0, i32 11
  %85 = getelementptr inbounds %struct.can_private_t, ptr %84, i32 0, i32 9
  %86 = load i32, ptr %5, align 4, !tbaa !9
  %87 = sext i32 %86 to i64
  %88 = getelementptr inbounds [32 x ptr], ptr %85, i64 0, i64 %87
  %89 = load ptr, ptr %88, align 8, !tbaa !5
  %90 = getelementptr inbounds %struct.can_channel_t, ptr %89, i32 0, i32 7
  %91 = load ptr, ptr %90, align 8, !tbaa !17
  %92 = call i64 @xQueueReceive(ptr noundef %91, ptr noundef %4, i32 noundef -1)
  br label %93

93:                                               ; preds = %82, %59
  br label %94

94:                                               ; preds = %93, %45, %31
  br label %95

95:                                               ; preds = %94
  %96 = load i32, ptr %5, align 4, !tbaa !9
  %97 = add nsw i32 %96, 1
  store i32 %97, ptr %5, align 4, !tbaa !9
  br label %16, !llvm.loop !25

98:                                               ; preds = %30
  br label %99

99:                                               ; preds = %98, %8
  call void @llvm.lifetime.end.p0(i64 32, ptr %4) #4
  br label %7
}

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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #4 = { 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 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 20}
!12 = !{!"", !6, i64 0, !6, i64 8, !10, i64 16, !10, i64 20, !10, i64 24, !10, i64 28, !6, i64 32, !6, i64 40}
!13 = !{!14, !10, i64 0}
!14 = !{!"", !15, i64 0, !7, i64 12, !6, i64 24}
!15 = !{!"", !10, i64 0, !10, i64 4, !10, i64 8}
!16 = !{!12, !10, i64 24}
!17 = !{!12, !6, i64 40}
!18 = !{!19, !10, i64 284}
!19 = !{!"", !7, i64 0, !7, i64 32, !20, i64 64, !6, i64 248, !6, i64 256, !10, i64 264, !10, i64 268, !10, i64 272, !10, i64 276, !10, i64 280, !10, i64 284, !23, i64 288}
!20 = !{!"", !6, i64 0, !6, i64 8, !21, i64 16, !22, i64 124, !10, i64 164, !10, i64 168, !10, i64 172, !10, i64 176}
!21 = !{!"", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20, !10, i64 24, !10, i64 28, !10, i64 32, !10, i64 36, !10, i64 40, !10, i64 44, !10, i64 48, !10, i64 52, !10, i64 56, !10, i64 60, !10, i64 64, !10, i64 68, !10, i64 72, !10, i64 76, !10, i64 80, !10, i64 84, !10, i64 88, !10, i64 92, !10, i64 96, !10, i64 100, !10, i64 104}
!22 = !{!"", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20, !10, i64 24, !10, i64 28, !10, i64 32, !10, i64 36}
!23 = !{!"", !10, i64 0, !10, i64 4, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !10, i64 40, !24, i64 44, !10, i64 48, !7, i64 56, !6, i64 312, !6, i64 320}
!24 = !{!"_Bool", !7, i64 0}
!25 = distinct !{!25, !26}
!26 = !{!"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"

%struct.can_frame_t = type { %struct.can_header_t, [8 x i8], ptr }
%struct.can_header_t = type { i32, i32, i32 }

@.str.1 = external hidden unnamed_addr constant [16 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [19 x i8], align 1

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

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

declare i32 @printf_(ptr noundef, ...) local_unnamed_addr #1

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

; Function Attrs: nounwind uwtable
declare dso_local i32 @can_receive(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #3

declare i64 @xQueueReceive(ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: noreturn nounwind uwtable
define dso_local void @can_read_thread(ptr noundef %0) local_unnamed_addr #4 {
  %2 = alloca %struct.can_frame_t, align 8
  %3 = getelementptr inbounds i8, ptr %2, i64 12
  %4 = getelementptr inbounds i8, ptr %0, i64 344
  %5 = getelementptr inbounds i8, ptr %0, i64 284
  br label %6

6:                                                ; preds = %.critedge, %1
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %2) #5
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(32) %2, i8 0, i64 32, i1 false)
  %7 = call i32 @can_receive(ptr noundef %0, ptr noundef nonnull %2, ptr noundef nonnull %3)
  %.not = icmp eq i32 %7, 0
  br i1 %.not, label %.preheader, label %.critedge

.preheader:                                       ; preds = %6, %32
  %indvars.iv = phi i64 [ %indvars.iv.next, %32 ], [ 0, %6 ]
  %8 = getelementptr inbounds [32 x ptr], ptr %4, i64 0, i64 %indvars.iv
  %9 = load ptr, ptr %8, align 8, !tbaa !5
  %.not17 = icmp eq ptr %9, null
  br i1 %.not17, label %.critedge, label %10

10:                                               ; preds = %.preheader
  %11 = getelementptr inbounds i8, ptr %9, i64 20
  %12 = load i32, ptr %11, align 4, !tbaa !9
  %13 = load i32, ptr %2, align 8, !tbaa !12
  %.not18 = icmp ugt i32 %12, %13
  br i1 %.not18, label %32, label %14

14:                                               ; preds = %10
  %15 = getelementptr inbounds i8, ptr %9, i64 24
  %16 = load i32, ptr %15, align 8, !tbaa !15
  %.not19 = icmp ult i32 %16, %13
  br i1 %.not19, label %32, label %17

17:                                               ; preds = %14
  %18 = getelementptr inbounds i8, ptr %9, i64 40
  %19 = load ptr, ptr %18, align 8, !tbaa !16
  %20 = call i64 @xQueueGenericSend(ptr noundef %19, ptr noundef nonnull %2, i32 noundef 0, i64 noundef 0) #5
  %.not20 = icmp eq i64 %20, 0
  br i1 %.not20, label %21, label %32

21:                                               ; preds = %17
  %22 = load i32, ptr %5, align 4, !tbaa !17
  %23 = icmp eq i32 %22, 2
  br i1 %23, label %24, label %27

24:                                               ; preds = %21
  %25 = call i32 (ptr, ...) @printf_(ptr noundef nonnull @.str.1, ptr noundef nonnull %0) #5
  %26 = call i32 (ptr, ...) @printf_(ptr noundef nonnull @.str.5) #5
  br label %27

27:                                               ; preds = %24, %21
  %28 = load ptr, ptr %8, align 8, !tbaa !5
  %29 = getelementptr inbounds i8, ptr %28, i64 40
  %30 = load ptr, ptr %29, align 8, !tbaa !16
  %31 = call i64 @xQueueReceive(ptr noundef %30, ptr noundef nonnull %2, i32 noundef -1) #5
  br label %32

32:                                               ; preds = %10, %14, %27, %17
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, 32
  br i1 %exitcond.not, label %.critedge, label %.preheader, !llvm.loop !24

.critedge:                                        ; preds = %.preheader, %32, %6
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %2) #5
  br label %6
}

attributes #0 = { mustprogress 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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #4 = { noreturn 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 #5 = { 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, !11, i64 20}
!10 = !{!"", !6, i64 0, !6, i64 8, !11, i64 16, !11, i64 20, !11, i64 24, !11, i64 28, !6, i64 32, !6, i64 40}
!11 = !{!"int", !7, i64 0}
!12 = !{!13, !11, i64 0}
!13 = !{!"", !14, i64 0, !7, i64 12, !6, i64 24}
!14 = !{!"", !11, i64 0, !11, i64 4, !11, i64 8}
!15 = !{!10, !11, i64 24}
!16 = !{!10, !6, i64 40}
!17 = !{!18, !11, i64 284}
!18 = !{!"", !7, i64 0, !7, i64 32, !19, i64 64, !6, i64 248, !6, i64 256, !11, i64 264, !11, i64 268, !11, i64 272, !11, i64 276, !11, i64 280, !11, i64 284, !22, i64 288}
!19 = !{!"", !6, i64 0, !6, i64 8, !20, i64 16, !21, i64 124, !11, i64 164, !11, i64 168, !11, i64 172, !11, i64 176}
!20 = !{!"", !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, !11, i64 48, !11, i64 52, !11, i64 56, !11, i64 60, !11, i64 64, !11, i64 68, !11, i64 72, !11, i64 76, !11, i64 80, !11, i64 84, !11, i64 88, !11, i64 92, !11, i64 96, !11, i64 100, !11, i64 104}
!21 = !{!"", !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}
!22 = !{!"", !11, i64 0, !11, i64 4, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !11, i64 40, !23, i64 44, !11, i64 48, !7, i64 56, !6, i64 312, !6, i64 320}
!23 = !{!"_Bool", !7, i64 0}
!24 = distinct !{!24, !25}
!25 = !{!"llvm.loop.mustprogress"}


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