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

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

@xBlockAllocatedBit = external hidden global i64, align 8
@xFreeBytesRemaining = external hidden global i64, align 8
@xNumberOfSuccessfulFrees = external hidden global i64, align 8

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

declare void @vTaskSuspendAll() #1

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

; Function Attrs: nounwind uwtable
declare hidden void @prvInsertBlockIntoFreeList(ptr noundef) #3

declare i64 @xTaskResumeAll() #1

; 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
define dso_local void @vPortFree(ptr noundef %0) #3 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #4
  %5 = load ptr, ptr %2, align 8, !tbaa !5
  store ptr %5, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #4
  %6 = load ptr, ptr %2, align 8, !tbaa !5
  %7 = icmp ne ptr %6, null
  br i1 %7, label %8, label %63

8:                                                ; preds = %1
  %9 = load ptr, ptr %3, align 8, !tbaa !5
  %10 = getelementptr inbounds i8, ptr %9, i64 -16
  store ptr %10, ptr %3, align 8, !tbaa !5
  %11 = load ptr, ptr %3, align 8, !tbaa !5
  store ptr %11, ptr %4, align 8, !tbaa !5
  %12 = load ptr, ptr %4, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.A_BLOCK_LINK, ptr %12, i32 0, i32 1
  %14 = load i64, ptr %13, align 8, !tbaa !9
  %15 = load i64, ptr @xBlockAllocatedBit, align 8, !tbaa !12
  %16 = and i64 %14, %15
  %17 = icmp ne i64 %16, 0
  %18 = zext i1 %17 to i32
  %19 = icmp eq i32 %18, 0
  br i1 %19, label %20, label %22

20:                                               ; preds = %8
  call void @vPortRaiseBASEPRI()
  br label %21

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

22:                                               ; preds = %8
  %23 = load ptr, ptr %4, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.A_BLOCK_LINK, ptr %23, i32 0, i32 0
  %25 = load ptr, ptr %24, align 8, !tbaa !13
  %26 = icmp eq ptr %25, null
  %27 = zext i1 %26 to i32
  %28 = icmp eq i32 %27, 0
  br i1 %28, label %29, label %31

29:                                               ; preds = %22
  call void @vPortRaiseBASEPRI()
  br label %30

30:                                               ; preds = %30, %29
  br label %30

31:                                               ; preds = %22
  %32 = load ptr, ptr %4, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.A_BLOCK_LINK, ptr %32, i32 0, i32 1
  %34 = load i64, ptr %33, align 8, !tbaa !9
  %35 = load i64, ptr @xBlockAllocatedBit, align 8, !tbaa !12
  %36 = and i64 %34, %35
  %37 = icmp ne i64 %36, 0
  br i1 %37, label %38, label %61

38:                                               ; preds = %31
  %39 = load ptr, ptr %4, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.A_BLOCK_LINK, ptr %39, i32 0, i32 0
  %41 = load ptr, ptr %40, align 8, !tbaa !13
  %42 = icmp eq ptr %41, null
  br i1 %42, label %43, label %59

43:                                               ; preds = %38
  %44 = load i64, ptr @xBlockAllocatedBit, align 8, !tbaa !12
  %45 = xor i64 %44, -1
  %46 = load ptr, ptr %4, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.A_BLOCK_LINK, ptr %46, i32 0, i32 1
  %48 = load i64, ptr %47, align 8, !tbaa !9
  %49 = and i64 %48, %45
  store i64 %49, ptr %47, align 8, !tbaa !9
  call void @vTaskSuspendAll()
  %50 = load ptr, ptr %4, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.A_BLOCK_LINK, ptr %50, i32 0, i32 1
  %52 = load i64, ptr %51, align 8, !tbaa !9
  %53 = load i64, ptr @xFreeBytesRemaining, align 8, !tbaa !12
  %54 = add i64 %53, %52
  store i64 %54, ptr @xFreeBytesRemaining, align 8, !tbaa !12
  %55 = load ptr, ptr %4, align 8, !tbaa !5
  call void @prvInsertBlockIntoFreeList(ptr noundef %55)
  %56 = load i64, ptr @xNumberOfSuccessfulFrees, align 8, !tbaa !12
  %57 = add i64 %56, 1
  store i64 %57, ptr @xNumberOfSuccessfulFrees, align 8, !tbaa !12
  %58 = call i64 @xTaskResumeAll()
  br label %60

59:                                               ; preds = %38
  br label %60

60:                                               ; preds = %59, %43
  br label %62

61:                                               ; preds = %31
  br label %62

62:                                               ; preds = %61, %60
  br label %63

63:                                               ; preds = %62, %1
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #4
  ret void
}

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 = { 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 #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, !11, i64 8}
!10 = !{!"A_BLOCK_LINK", !6, i64 0, !11, i64 8}
!11 = !{!"long", !7, i64 0}
!12 = !{!11, !11, i64 0}
!13 = !{!10, !6, i64 0}


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

@xBlockAllocatedBit = external hidden local_unnamed_addr global i64, align 8
@xFreeBytesRemaining = external hidden local_unnamed_addr global i64, align 8
@xNumberOfSuccessfulFrees = external hidden local_unnamed_addr global i64, align 8

declare void @vTaskSuspendAll() local_unnamed_addr #0

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

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

declare i64 @xTaskResumeAll() local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @vPortFree(ptr noundef %0) local_unnamed_addr #2 {
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %23, label %2

2:                                                ; preds = %1
  %3 = getelementptr inbounds i8, ptr %0, i64 -16
  %4 = getelementptr inbounds i8, ptr %0, i64 -8
  %5 = load i64, ptr %4, align 8, !tbaa !5
  %6 = load i64, ptr @xBlockAllocatedBit, align 8, !tbaa !11
  %7 = and i64 %6, %5
  %.not11 = icmp eq i64 %7, 0
  br i1 %.not11, label %8, label %10

8:                                                ; preds = %2
  tail call void @vPortRaiseBASEPRI()
  br label %9

9:                                                ; preds = %9, %8
  br label %9

10:                                               ; preds = %2
  %11 = load ptr, ptr %3, align 8, !tbaa !12
  %.not12 = icmp eq ptr %11, null
  br i1 %.not12, label %14, label %12

12:                                               ; preds = %10
  tail call void @vPortRaiseBASEPRI()
  br label %13

13:                                               ; preds = %13, %12
  br label %13

14:                                               ; preds = %10
  %15 = xor i64 %6, -1
  %16 = and i64 %5, %15
  store i64 %16, ptr %4, align 8, !tbaa !5
  tail call void @vTaskSuspendAll() #3
  %17 = load i64, ptr %4, align 8, !tbaa !5
  %18 = load i64, ptr @xFreeBytesRemaining, align 8, !tbaa !11
  %19 = add i64 %18, %17
  store i64 %19, ptr @xFreeBytesRemaining, align 8, !tbaa !11
  tail call void @prvInsertBlockIntoFreeList(ptr noundef nonnull %3)
  %20 = load i64, ptr @xNumberOfSuccessfulFrees, align 8, !tbaa !11
  %21 = add i64 %20, 1
  store i64 %21, ptr @xNumberOfSuccessfulFrees, align 8, !tbaa !11
  %22 = tail call i64 @xTaskResumeAll() #3
  br label %23

23:                                               ; preds = %14, %1
  ret void
}

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 = { 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 = { 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, !10, i64 8}
!6 = !{!"A_BLOCK_LINK", !7, i64 0, !10, i64 8}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"long", !8, i64 0}
!11 = !{!10, !10, i64 0}
!12 = !{!6, !7, i64 0}


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