; LLVM IR from Seeed-Studio/Seeed_Arduino_edgeimpulse :: src/QCBOR/src (qcbor_decode)

; 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._QCBORItem = type { i8, i8, i8, i8, i8, i8, %union.anon, %union.anon.1, i64 }
%union.anon = type { %struct.q_useful_buf_c }
%struct.q_useful_buf_c = type { ptr, i64 }
%union.anon.1 = type { %struct.q_useful_buf_c }
%struct._QCBORDecodeContext = type { %struct.useful_input_buf, i8, i8, %struct.__QCBORDecodeNesting, %struct.QCORInternalAllocator, i32, i32, ptr }
%struct.useful_input_buf = type { %struct.q_useful_buf_c, i64, i16, i8 }
%struct.__QCBORDecodeNesting = type { [16 x %struct.anon], ptr }
%struct.anon = type { i16, i8 }
%struct.QCORInternalAllocator = type { ptr, ptr }

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

18:                                               ; preds = %3
  br label %102

19:                                               ; preds = %3
  %20 = load ptr, ptr %6, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct._QCBORItem, ptr %20, i32 0, i32 0
  %22 = load i8, ptr %21, align 8, !tbaa !11
  %23 = zext i8 %22 to i32
  %24 = icmp eq i32 %23, 31
  br i1 %24, label %25, label %26

25:                                               ; preds = %19
  store i32 19, ptr %8, align 4, !tbaa !9
  br label %102

26:                                               ; preds = %19
  %27 = load ptr, ptr %5, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct._QCBORDecodeContext, ptr %27, i32 0, i32 3
  %29 = call zeroext i8 @DecodeNesting_GetLevel(ptr noundef %28)
  %30 = load ptr, ptr %6, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct._QCBORItem, ptr %30, i32 0, i32 1
  store i8 %29, ptr %31, align 1, !tbaa !14
  %32 = load ptr, ptr %6, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct._QCBORItem, ptr %32, i32 0, i32 0
  %34 = load i8, ptr %33, align 8, !tbaa !11
  %35 = call i32 @IsMapOrArray(i8 noundef zeroext %34)
  %36 = icmp ne i32 %35, 0
  br i1 %36, label %37, label %42

37:                                               ; preds = %26
  %38 = load ptr, ptr %5, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct._QCBORDecodeContext, ptr %38, i32 0, i32 3
  %40 = load ptr, ptr %6, align 8, !tbaa !5
  %41 = call i32 @DecodeNesting_Descend(ptr noundef %39, ptr noundef %40)
  store i32 %41, ptr %8, align 4, !tbaa !9
  br label %45

42:                                               ; preds = %26
  %43 = load ptr, ptr %5, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct._QCBORDecodeContext, ptr %43, i32 0, i32 3
  call void @DecodeNesting_DecrementCount(ptr noundef %44)
  br label %45

45:                                               ; preds = %42, %37
  %46 = load i32, ptr %8, align 4, !tbaa !9
  %47 = icmp ne i32 %46, 0
  br i1 %47, label %48, label %49

48:                                               ; preds = %45
  br label %102

49:                                               ; preds = %45
  %50 = load ptr, ptr %5, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct._QCBORDecodeContext, ptr %50, i32 0, i32 3
  %52 = call i32 @DecodeNesting_IsNested(ptr noundef %51)
  %53 = icmp ne i32 %52, 0
  br i1 %53, label %54, label %96

54:                                               ; preds = %49
  %55 = load ptr, ptr %5, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct._QCBORDecodeContext, ptr %55, i32 0, i32 3
  %57 = call i32 @DecodeNesting_IsIndefiniteLength(ptr noundef %56)
  %58 = icmp ne i32 %57, 0
  br i1 %58, label %59, label %96

59:                                               ; preds = %54
  br label %60

60:                                               ; preds = %94, %59
  %61 = load ptr, ptr %5, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct._QCBORDecodeContext, ptr %61, i32 0, i32 0
  %63 = call i64 @UsefulInputBuf_BytesUnconsumed(ptr noundef %62)
  %64 = icmp ne i64 %63, 0
  br i1 %64, label %65, label %95

65:                                               ; preds = %60
  call void @llvm.lifetime.start.p0(i64 48, ptr %9) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  %66 = load ptr, ptr %5, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct._QCBORDecodeContext, ptr %66, i32 0, i32 0
  %68 = call i64 @UsefulInputBuf_Tell(ptr noundef %67)
  store i64 %68, ptr %10, align 8, !tbaa !15
  %69 = load ptr, ptr %5, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct._QCBORDecodeContext, ptr %69, i32 0, i32 0
  %71 = call i32 @GetNext_Item(ptr noundef %70, ptr noundef %9, ptr noundef null)
  store i32 %71, ptr %8, align 4, !tbaa !9
  %72 = load i32, ptr %8, align 4, !tbaa !9
  %73 = icmp ne i32 %72, 0
  br i1 %73, label %74, label %75

74:                                               ; preds = %65
  store i32 2, ptr %11, align 4
  br label %92

75:                                               ; preds = %65
  %76 = getelementptr inbounds %struct._QCBORItem, ptr %9, i32 0, i32 0
  %77 = load i8, ptr %76, align 8, !tbaa !11
  %78 = zext i8 %77 to i32
  %79 = icmp ne i32 %78, 31
  br i1 %79, label %80, label %84

80:                                               ; preds = %75
  %81 = load ptr, ptr %5, align 8, !tbaa !5
  %82 = getelementptr inbounds %struct._QCBORDecodeContext, ptr %81, i32 0, i32 0
  %83 = load i64, ptr %10, align 8, !tbaa !15
  call void @UsefulInputBuf_Seek(ptr noundef %82, i64 noundef %83)
  store i32 4, ptr %11, align 4
  br label %92

84:                                               ; preds = %75
  %85 = load ptr, ptr %5, align 8, !tbaa !5
  %86 = getelementptr inbounds %struct._QCBORDecodeContext, ptr %85, i32 0, i32 3
  %87 = call i32 @DecodeNesting_BreakAscend(ptr noundef %86)
  store i32 %87, ptr %8, align 4, !tbaa !9
  %88 = load i32, ptr %8, align 4, !tbaa !9
  %89 = icmp ne i32 %88, 0
  br i1 %89, label %90, label %91

90:                                               ; preds = %84
  store i32 2, ptr %11, align 4
  br label %92

91:                                               ; preds = %84
  store i32 0, ptr %11, align 4
  br label %92

92:                                               ; preds = %91, %90, %80, %74
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 48, ptr %9) #3
  %93 = load i32, ptr %11, align 4
  switch i32 %93, label %104 [
    i32 0, label %94
    i32 4, label %95
    i32 2, label %102
  ]

94:                                               ; preds = %92
  br label %60, !llvm.loop !16

95:                                               ; preds = %92, %60
  br label %96

96:                                               ; preds = %95, %54, %49
  %97 = load ptr, ptr %5, align 8, !tbaa !5
  %98 = getelementptr inbounds %struct._QCBORDecodeContext, ptr %97, i32 0, i32 3
  %99 = call zeroext i8 @DecodeNesting_GetLevel(ptr noundef %98)
  %100 = load ptr, ptr %6, align 8, !tbaa !5
  %101 = getelementptr inbounds %struct._QCBORItem, ptr %100, i32 0, i32 5
  store i8 %99, ptr %101, align 1, !tbaa !18
  br label %102

102:                                              ; preds = %96, %92, %48, %25, %18
  %103 = load i32, ptr %8, align 4, !tbaa !9
  store i32 %103, ptr %4, align 4
  store i32 1, ptr %11, align 4
  br label %104

104:                                              ; preds = %102, %92
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  %105 = load i32, ptr %4, align 4
  ret i32 %105
}

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @GetNext_MapEntry(ptr noundef, ptr noundef, ptr noundef) #2

; Function Attrs: inlinehint nounwind uwtable
declare hidden zeroext i8 @DecodeNesting_GetLevel(ptr noundef) #2

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @IsMapOrArray(i8 noundef zeroext) #2

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @DecodeNesting_Descend(ptr noundef, ptr noundef) #2

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @DecodeNesting_IsNested(ptr noundef) #2

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @DecodeNesting_IsIndefiniteLength(ptr noundef) #2

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

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

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @UsefulInputBuf_Seek(ptr noundef, i64 noundef) #2

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @DecodeNesting_BreakAscend(ptr noundef) #2

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

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" }
attributes #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { inlinehint 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 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !7, i64 0}
!12 = !{!"_QCBORItem", !7, i64 0, !7, i64 1, !7, i64 2, !7, i64 3, !7, i64 4, !7, i64 5, !7, i64 8, !7, i64 24, !13, i64 40}
!13 = !{!"long", !7, i64 0}
!14 = !{!12, !7, i64 1}
!15 = !{!13, !13, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}
!18 = !{!12, !7, i64 5}


; 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._QCBORItem = type { i8, i8, i8, i8, i8, i8, %union.anon, %union.anon.1, i64 }
%union.anon = type { %struct.q_useful_buf_c }
%struct.q_useful_buf_c = type { ptr, i64 }
%union.anon.1 = type { %struct.q_useful_buf_c }

; Function Attrs: nounwind uwtable
define dso_local i32 @QCBORDecode_GetNextWithTags(ptr noundef %0, ptr noundef %1, ptr noundef %2) local_unnamed_addr #0 {
  %4 = alloca %struct._QCBORItem, align 8
  %5 = tail call i32 @GetNext_MapEntry(ptr noundef %0, ptr noundef %1, ptr noundef %2)
  %.not = icmp eq i32 %5, 0
  br i1 %.not, label %6, label %32

6:                                                ; preds = %3
  %7 = load i8, ptr %1, align 8, !tbaa !5
  %8 = icmp eq i8 %7, 31
  br i1 %8, label %32, label %9

9:                                                ; preds = %6
  %10 = getelementptr inbounds i8, ptr %0, i64 40
  %11 = tail call zeroext i8 @DecodeNesting_GetLevel(ptr noundef nonnull %10)
  %12 = getelementptr inbounds i8, ptr %1, i64 1
  store i8 %11, ptr %12, align 1, !tbaa !10
  %13 = load i8, ptr %1, align 8, !tbaa !5
  %14 = tail call i32 @IsMapOrArray(i8 noundef zeroext %13)
  %.not34 = icmp eq i32 %14, 0
  br i1 %.not34, label %.thread, label %15

.thread:                                          ; preds = %9
  tail call void @DecodeNesting_DecrementCount(ptr noundef nonnull %10)
  br label %17

15:                                               ; preds = %9
  %16 = tail call i32 @DecodeNesting_Descend(ptr noundef nonnull %10, ptr noundef nonnull %1)
  %.not35 = icmp eq i32 %16, 0
  br i1 %.not35, label %17, label %32

17:                                               ; preds = %.thread, %15
  %18 = tail call i32 @DecodeNesting_IsNested(ptr noundef nonnull %10)
  %.not36 = icmp eq i32 %18, 0
  br i1 %.not36, label %.loopexit, label %19

19:                                               ; preds = %17
  %20 = tail call i32 @DecodeNesting_IsIndefiniteLength(ptr noundef nonnull %10)
  %.not37 = icmp eq i32 %20, 0
  br i1 %.not37, label %.loopexit, label %.preheader

.preheader:                                       ; preds = %19
  %21 = tail call i64 @UsefulInputBuf_BytesUnconsumed(ptr noundef %0)
  %.not3852 = icmp eq i64 %21, 0
  br i1 %.not3852, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %.preheader, %28
  call void @llvm.lifetime.start.p0(i64 48, ptr nonnull %4) #3
  %22 = call i64 @UsefulInputBuf_Tell(ptr noundef %0)
  %23 = call i32 @GetNext_Item(ptr noundef %0, ptr noundef nonnull %4, ptr noundef null)
  %.not39 = icmp eq i32 %23, 0
  br i1 %.not39, label %24, label %.thread45

24:                                               ; preds = %.lr.ph
  %25 = load i8, ptr %4, align 8, !tbaa !5
  %.not40 = icmp eq i8 %25, 31
  br i1 %.not40, label %26, label %.thread48

.thread48:                                        ; preds = %24
  call void @UsefulInputBuf_Seek(ptr noundef %0, i64 noundef %22)
  call void @llvm.lifetime.end.p0(i64 48, ptr nonnull %4) #3
  br label %.loopexit

26:                                               ; preds = %24
  %27 = call i32 @DecodeNesting_BreakAscend(ptr noundef nonnull %10)
  %.not41 = icmp eq i32 %27, 0
  br i1 %.not41, label %28, label %.thread45

.thread45:                                        ; preds = %.lr.ph, %26
  %.2.ph = phi i32 [ %27, %26 ], [ %23, %.lr.ph ]
  call void @llvm.lifetime.end.p0(i64 48, ptr nonnull %4) #3
  br label %32

28:                                               ; preds = %26
  call void @llvm.lifetime.end.p0(i64 48, ptr nonnull %4) #3
  %29 = call i64 @UsefulInputBuf_BytesUnconsumed(ptr noundef %0)
  %.not38 = icmp eq i64 %29, 0
  br i1 %.not38, label %.loopexit, label %.lr.ph

.loopexit:                                        ; preds = %28, %.preheader, %.thread48, %19, %17
  %30 = call zeroext i8 @DecodeNesting_GetLevel(ptr noundef nonnull %10)
  %31 = getelementptr inbounds i8, ptr %1, i64 5
  store i8 %30, ptr %31, align 1, !tbaa !11
  br label %32

32:                                               ; preds = %.thread45, %.loopexit, %3, %15, %6
  %.026 = phi i32 [ %5, %3 ], [ %16, %15 ], [ 0, %.loopexit ], [ 19, %6 ], [ %.2.ph, %.thread45 ]
  ret i32 %.026
}

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @GetNext_MapEntry(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: inlinehint nounwind uwtable
declare hidden zeroext i8 @DecodeNesting_GetLevel(ptr noundef) local_unnamed_addr #2

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @IsMapOrArray(i8 noundef zeroext) local_unnamed_addr #2

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @DecodeNesting_Descend(ptr noundef, ptr noundef) local_unnamed_addr #2

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @DecodeNesting_IsNested(ptr noundef) local_unnamed_addr #2

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @DecodeNesting_IsIndefiniteLength(ptr noundef) local_unnamed_addr #2

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

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

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

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @DecodeNesting_BreakAscend(ptr noundef) local_unnamed_addr #2

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

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" }
attributes #1 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { inlinehint 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, !7, i64 0}
!6 = !{!"_QCBORItem", !7, i64 0, !7, i64 1, !7, i64 2, !7, i64 3, !7, i64 4, !7, i64 5, !7, i64 8, !7, i64 24, !9, i64 40}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!"long", !7, i64 0}
!10 = !{!6, !7, i64 1}
!11 = !{!6, !7, i64 5}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass