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

; 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._QCBOREncodeContext = type { %struct.useful_out_buf, i8, %struct.__QCBORTrackNesting }
%struct.useful_out_buf = type { %struct.q_useful_buf, i64, i16, i8 }
%struct.q_useful_buf = type { ptr, i64 }
%struct.__QCBORTrackNesting = type { [16 x %struct.anon], ptr }
%struct.anon = type { i32, i16, i8 }

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

; Function Attrs: nounwind uwtable
define dso_local void @QCBOREncode_AddType7(ptr noundef %0, i64 noundef %1, i64 noundef %2) #1 {
  %4 = alloca ptr, align 8
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i64 %1, ptr %5, align 8, !tbaa !9
  store i64 %2, ptr %6, align 8, !tbaa !9
  %7 = load ptr, ptr %4, align 8, !tbaa !5
  %8 = getelementptr inbounds %struct._QCBOREncodeContext, ptr %7, i32 0, i32 1
  %9 = load i8, ptr %8, align 8, !tbaa !11
  %10 = zext i8 %9 to i32
  %11 = icmp eq i32 %10, 0
  br i1 %11, label %12, label %26

12:                                               ; preds = %3
  %13 = load ptr, ptr %4, align 8, !tbaa !5
  %14 = load i64, ptr %5, align 8, !tbaa !9
  %15 = trunc i64 %14 to i32
  %16 = load i64, ptr %6, align 8, !tbaa !9
  %17 = load ptr, ptr %4, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct._QCBOREncodeContext, ptr %17, i32 0, i32 0
  %19 = call i64 @UsefulOutBuf_GetEndPosition(ptr noundef %18)
  call void @InsertEncodedTypeAndNumber(ptr noundef %13, i8 noundef zeroext 7, i32 noundef %15, i64 noundef %16, i64 noundef %19)
  %20 = load ptr, ptr %4, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct._QCBOREncodeContext, ptr %20, i32 0, i32 2
  %22 = call i32 @Nesting_Increment(ptr noundef %21)
  %23 = trunc i32 %22 to i8
  %24 = load ptr, ptr %4, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct._QCBOREncodeContext, ptr %24, i32 0, i32 1
  store i8 %23, ptr %25, align 8, !tbaa !11
  br label %26

26:                                               ; preds = %12, %3
  ret void
}

; Function Attrs: nounwind uwtable
declare hidden void @InsertEncodedTypeAndNumber(ptr noundef, i8 noundef zeroext, i32 noundef, i64 noundef, i64 noundef) #1

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

attributes #0 = { 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 #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" }

!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, !7, i64 32}
!12 = !{!"_QCBOREncodeContext", !13, i64 0, !7, i64 32, !16, i64 40}
!13 = !{!"useful_out_buf", !14, i64 0, !10, i64 16, !15, i64 24, !7, i64 26}
!14 = !{!"q_useful_buf", !6, i64 0, !10, i64 8}
!15 = !{!"short", !7, i64 0}
!16 = !{!"__QCBORTrackNesting", !7, i64 0, !6, i64 128}


; 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: inlinehint nounwind uwtable
declare hidden i32 @Nesting_Increment(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @QCBOREncode_AddType7(ptr noundef %0, i64 noundef %1, i64 noundef %2) local_unnamed_addr #1 {
  %4 = getelementptr inbounds i8, ptr %0, i64 32
  %5 = load i8, ptr %4, align 8, !tbaa !5
  %6 = icmp eq i8 %5, 0
  br i1 %6, label %7, label %13

7:                                                ; preds = %3
  %8 = trunc i64 %1 to i32
  %9 = tail call i64 @UsefulOutBuf_GetEndPosition(ptr noundef nonnull %0)
  tail call void @InsertEncodedTypeAndNumber(ptr noundef nonnull %0, i8 noundef zeroext 7, i32 noundef %8, i64 noundef %2, i64 noundef %9)
  %10 = getelementptr inbounds i8, ptr %0, i64 40
  %11 = tail call i32 @Nesting_Increment(ptr noundef nonnull %10)
  %12 = trunc i32 %11 to i8
  store i8 %12, ptr %4, align 8, !tbaa !5
  br label %13

13:                                               ; preds = %7, %3
  ret void
}

; Function Attrs: nounwind uwtable
declare hidden void @InsertEncodedTypeAndNumber(ptr noundef, i8 noundef zeroext, i32 noundef, i64 noundef, i64 noundef) local_unnamed_addr #1

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

attributes #0 = { 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 #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" }

!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 32}
!6 = !{!"_QCBOREncodeContext", !7, i64 0, !10, i64 32, !14, i64 40}
!7 = !{!"useful_out_buf", !8, i64 0, !12, i64 16, !13, i64 24, !10, i64 26}
!8 = !{!"q_useful_buf", !9, i64 0, !12, i64 8}
!9 = !{!"any pointer", !10, i64 0}
!10 = !{!"omnipotent char", !11, i64 0}
!11 = !{!"Simple C/C++ TBAA"}
!12 = !{!"long", !10, i64 0}
!13 = !{!"short", !10, i64 0}
!14 = !{!"__QCBORTrackNesting", !10, i64 0, !9, i64 128}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,InstCombinePass,SROAPass,TailCallElimPass