; LLVM IR from whoiswelliton/Computer_Engineering_UTFPR-PB :: Embedded_Systems/TIVA Connected TM4C1294XL Projects/00 - freeRTOS10_on_TIVA (xStreamBufferReceive)

; 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.StreamBufferDef_t = type { i64, i64, i64, i64, ptr, ptr, ptr, i8 }

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

; Function Attrs: alwaysinline nounwind uwtable
declare hidden void @vPortRaiseBASEPRI() #1

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

declare void @vPortEnterCritical() #2

declare void @vPortExitCritical() #2

; Function Attrs: nounwind uwtable
declare hidden i64 @prvBytesInBuffer(ptr noundef) #3

declare i64 @xTaskGenericNotifyStateClear(ptr noundef, i64 noundef) #2

declare ptr @xTaskGetCurrentTaskHandle() #2

declare i64 @xTaskGenericNotifyWait(i64 noundef, i32 noundef, i32 noundef, ptr noundef, i32 noundef) #2

declare void @vTaskSuspendAll() #2

declare i64 @xTaskGenericNotify(ptr noundef, i64 noundef, i32 noundef, i32 noundef, ptr noundef) #2

declare i64 @xTaskResumeAll() #2

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

16:                                               ; preds = %4
  call void @vPortRaiseBASEPRI()
  br label %17

17:                                               ; preds = %17, %16
  br label %17

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

21:                                               ; preds = %18
  call void @vPortRaiseBASEPRI()
  br label %22

22:                                               ; preds = %22, %21
  br label %22

23:                                               ; preds = %18
  %24 = load ptr, ptr %9, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.StreamBufferDef_t, ptr %24, i32 0, i32 7
  %26 = load i8, ptr %25, align 8, !tbaa !13
  %27 = zext i8 %26 to i32
  %28 = and i32 %27, 1
  %29 = icmp ne i32 %28, 0
  br i1 %29, label %30, label %31

30:                                               ; preds = %23
  store i64 8, ptr %12, align 8, !tbaa !9
  br label %32

31:                                               ; preds = %23
  store i64 0, ptr %12, align 8, !tbaa !9
  br label %32

32:                                               ; preds = %31, %30
  %33 = load i32, ptr %8, align 4, !tbaa !11
  %34 = icmp ne i32 %33, 0
  br i1 %34, label %35, label %69

35:                                               ; preds = %32
  call void @vPortEnterCritical()
  %36 = load ptr, ptr %9, align 8, !tbaa !5
  %37 = call i64 @prvBytesInBuffer(ptr noundef %36)
  store i64 %37, ptr %11, align 8, !tbaa !9
  %38 = load i64, ptr %11, align 8, !tbaa !9
  %39 = load i64, ptr %12, align 8, !tbaa !9
  %40 = icmp ule i64 %38, %39
  br i1 %40, label %41, label %55

41:                                               ; preds = %35
  %42 = call i64 @xTaskGenericNotifyStateClear(ptr noundef null, i64 noundef 0)
  %43 = load ptr, ptr %9, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.StreamBufferDef_t, ptr %43, i32 0, i32 4
  %45 = load volatile ptr, ptr %44, align 8, !tbaa !15
  %46 = icmp eq ptr %45, null
  %47 = zext i1 %46 to i32
  %48 = icmp eq i32 %47, 0
  br i1 %48, label %49, label %51

49:                                               ; preds = %41
  call void @vPortRaiseBASEPRI()
  br label %50

50:                                               ; preds = %50, %49
  br label %50

51:                                               ; preds = %41
  %52 = call ptr @xTaskGetCurrentTaskHandle()
  %53 = load ptr, ptr %9, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.StreamBufferDef_t, ptr %53, i32 0, i32 4
  store volatile ptr %52, ptr %54, align 8, !tbaa !15
  br label %56

55:                                               ; preds = %35
  br label %56

56:                                               ; preds = %55, %51
  call void @vPortExitCritical()
  %57 = load i64, ptr %11, align 8, !tbaa !9
  %58 = load i64, ptr %12, align 8, !tbaa !9
  %59 = icmp ule i64 %57, %58
  br i1 %59, label %60, label %67

60:                                               ; preds = %56
  %61 = load i32, ptr %8, align 4, !tbaa !11
  %62 = call i64 @xTaskGenericNotifyWait(i64 noundef 0, i32 noundef 0, i32 noundef 0, ptr noundef null, i32 noundef %61)
  %63 = load ptr, ptr %9, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.StreamBufferDef_t, ptr %63, i32 0, i32 4
  store volatile ptr null, ptr %64, align 8, !tbaa !15
  %65 = load ptr, ptr %9, align 8, !tbaa !5
  %66 = call i64 @prvBytesInBuffer(ptr noundef %65)
  store i64 %66, ptr %11, align 8, !tbaa !9
  br label %68

67:                                               ; preds = %56
  br label %68

68:                                               ; preds = %67, %60
  br label %72

69:                                               ; preds = %32
  %70 = load ptr, ptr %9, align 8, !tbaa !5
  %71 = call i64 @prvBytesInBuffer(ptr noundef %70)
  store i64 %71, ptr %11, align 8, !tbaa !9
  br label %72

72:                                               ; preds = %69, %68
  %73 = load i64, ptr %11, align 8, !tbaa !9
  %74 = load i64, ptr %12, align 8, !tbaa !9
  %75 = icmp ugt i64 %73, %74
  br i1 %75, label %76, label %101

76:                                               ; preds = %72
  %77 = load ptr, ptr %9, align 8, !tbaa !5
  %78 = load ptr, ptr %6, align 8, !tbaa !5
  %79 = load i64, ptr %7, align 8, !tbaa !9
  %80 = load i64, ptr %11, align 8, !tbaa !9
  %81 = load i64, ptr %12, align 8, !tbaa !9
  %82 = call i64 @prvReadMessageFromBuffer(ptr noundef %77, ptr noundef %78, i64 noundef %79, i64 noundef %80, i64 noundef %81)
  store i64 %82, ptr %10, align 8, !tbaa !9
  %83 = load i64, ptr %10, align 8, !tbaa !9
  %84 = icmp ne i64 %83, 0
  br i1 %84, label %85, label %99

85:                                               ; preds = %76
  call void @vTaskSuspendAll()
  %86 = load ptr, ptr %9, align 8, !tbaa !5
  %87 = getelementptr inbounds %struct.StreamBufferDef_t, ptr %86, i32 0, i32 5
  %88 = load volatile ptr, ptr %87, align 8, !tbaa !16
  %89 = icmp ne ptr %88, null
  br i1 %89, label %90, label %97

90:                                               ; preds = %85
  %91 = load ptr, ptr %9, align 8, !tbaa !5
  %92 = getelementptr inbounds %struct.StreamBufferDef_t, ptr %91, i32 0, i32 5
  %93 = load volatile ptr, ptr %92, align 8, !tbaa !16
  %94 = call i64 @xTaskGenericNotify(ptr noundef %93, i64 noundef 0, i32 noundef 0, i32 noundef 0, ptr noundef null)
  %95 = load ptr, ptr %9, align 8, !tbaa !5
  %96 = getelementptr inbounds %struct.StreamBufferDef_t, ptr %95, i32 0, i32 5
  store volatile ptr null, ptr %96, align 8, !tbaa !16
  br label %97

97:                                               ; preds = %90, %85
  %98 = call i64 @xTaskResumeAll()
  br label %100

99:                                               ; preds = %76
  br label %100

100:                                              ; preds = %99, %97
  br label %102

101:                                              ; preds = %72
  br label %102

102:                                              ; preds = %101, %100
  %103 = load i64, ptr %10, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  ret i64 %103
}

; Function Attrs: nounwind uwtable
declare hidden i64 @prvReadMessageFromBuffer(ptr noundef, ptr noundef, i64 noundef, i64 noundef, i64 noundef) #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { alwaysinline 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 = { "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 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 #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 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !7, i64 56}
!14 = !{!"StreamBufferDef_t", !10, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !7, i64 56}
!15 = !{!14, !6, i64 32}
!16 = !{!14, !6, i64 40}


; 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: alwaysinline nounwind uwtable
declare hidden void @vPortRaiseBASEPRI() local_unnamed_addr #0

declare void @vPortEnterCritical() local_unnamed_addr #1

declare void @vPortExitCritical() local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare hidden i64 @prvBytesInBuffer(ptr noundef) local_unnamed_addr #2

declare i64 @xTaskGenericNotifyStateClear(ptr noundef, i64 noundef) local_unnamed_addr #1

declare ptr @xTaskGetCurrentTaskHandle() local_unnamed_addr #1

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

declare void @vTaskSuspendAll() local_unnamed_addr #1

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

declare i64 @xTaskResumeAll() local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local i64 @xStreamBufferReceive(ptr noundef %0, ptr noundef %1, i64 noundef %2, i32 noundef %3) local_unnamed_addr #2 {
  %5 = icmp eq ptr %1, null
  br i1 %5, label %6, label %8

6:                                                ; preds = %4
  tail call void @vPortRaiseBASEPRI()
  br label %7

7:                                                ; preds = %7, %6
  br label %7

8:                                                ; preds = %4
  %9 = icmp eq ptr %0, null
  br i1 %9, label %10, label %12

10:                                               ; preds = %8
  tail call void @vPortRaiseBASEPRI()
  br label %11

11:                                               ; preds = %11, %10
  br label %11

12:                                               ; preds = %8
  %13 = getelementptr inbounds i8, ptr %0, i64 56
  %14 = load i8, ptr %13, align 8, !tbaa !5
  %15 = shl i8 %14, 3
  %16 = and i8 %15, 8
  %. = zext nneg i8 %16 to i64
  %.not34 = icmp eq i32 %3, 0
  br i1 %.not34, label %29, label %17

17:                                               ; preds = %12
  tail call void @vPortEnterCritical() #3
  %18 = tail call i64 @prvBytesInBuffer(ptr noundef nonnull %0)
  %.not35 = icmp ugt i64 %18, %.
  br i1 %.not35, label %.critedge, label %19

19:                                               ; preds = %17
  %20 = tail call i64 @xTaskGenericNotifyStateClear(ptr noundef null, i64 noundef 0) #3
  %21 = getelementptr inbounds i8, ptr %0, i64 32
  %22 = load volatile ptr, ptr %21, align 8, !tbaa !11
  %.not36 = icmp eq ptr %22, null
  br i1 %.not36, label %25, label %23

23:                                               ; preds = %19
  tail call void @vPortRaiseBASEPRI()
  br label %24

24:                                               ; preds = %24, %23
  br label %24

25:                                               ; preds = %19
  %26 = tail call ptr @xTaskGetCurrentTaskHandle() #3
  store volatile ptr %26, ptr %21, align 8, !tbaa !11
  tail call void @vPortExitCritical() #3
  %27 = tail call i64 @xTaskGenericNotifyWait(i64 noundef 0, i32 noundef 0, i32 noundef 0, ptr noundef null, i32 noundef %3) #3
  store volatile ptr null, ptr %21, align 8, !tbaa !11
  %28 = tail call i64 @prvBytesInBuffer(ptr noundef nonnull %0)
  br label %31

29:                                               ; preds = %12
  %30 = tail call i64 @prvBytesInBuffer(ptr noundef nonnull %0)
  br label %31

.critedge:                                        ; preds = %17
  tail call void @vPortExitCritical() #3
  br label %31

31:                                               ; preds = %.critedge, %25, %29
  %.027 = phi i64 [ %28, %25 ], [ %30, %29 ], [ %18, %.critedge ]
  %32 = icmp ugt i64 %.027, %.
  br i1 %32, label %33, label %43

33:                                               ; preds = %31
  %34 = tail call i64 @prvReadMessageFromBuffer(ptr noundef nonnull %0, ptr noundef nonnull %1, i64 noundef %2, i64 noundef %.027, i64 noundef %.)
  %.not37 = icmp eq i64 %34, 0
  br i1 %.not37, label %43, label %35

35:                                               ; preds = %33
  tail call void @vTaskSuspendAll() #3
  %36 = getelementptr inbounds i8, ptr %0, i64 40
  %37 = load volatile ptr, ptr %36, align 8, !tbaa !12
  %.not38 = icmp eq ptr %37, null
  br i1 %.not38, label %41, label %38

38:                                               ; preds = %35
  %39 = load volatile ptr, ptr %36, align 8, !tbaa !12
  %40 = tail call i64 @xTaskGenericNotify(ptr noundef %39, i64 noundef 0, i32 noundef 0, i32 noundef 0, ptr noundef null) #3
  store volatile ptr null, ptr %36, align 8, !tbaa !12
  br label %41

41:                                               ; preds = %38, %35
  %42 = tail call i64 @xTaskResumeAll() #3
  br label %43

43:                                               ; preds = %31, %41, %33
  %.028 = phi i64 [ %34, %41 ], [ 0, %33 ], [ 0, %31 ]
  ret i64 %.028
}

; Function Attrs: nounwind uwtable
declare hidden i64 @prvReadMessageFromBuffer(ptr noundef, ptr noundef, i64 noundef, i64 noundef, i64 noundef) local_unnamed_addr #2

attributes #0 = { alwaysinline 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 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, !8, i64 56}
!6 = !{!"StreamBufferDef_t", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !10, i64 32, !10, i64 40, !10, i64 48, !8, i64 56}
!7 = !{!"long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!6, !10, i64 32}
!12 = !{!6, !10, i64 40}


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