; LLVM IR from tensorflow/tflite-micro :: tensorflow/lite/core/c (common)

; 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.TfLiteTensor = type { i32, %union.TfLitePtrUnion, ptr, %struct.TfLiteQuantizationParams, i32, i64, ptr, ptr, ptr, i32, i8, i8, %struct.TfLiteQuantization, ptr, ptr }
%union.TfLitePtrUnion = type { ptr }
%struct.TfLiteQuantizationParams = type { float, i32 }
%struct.TfLiteQuantization = type { i32, ptr }

; Function Attrs: nounwind
declare void @free(ptr noundef) #0

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

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

; Function Attrs: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #2

; Function Attrs: mustprogress nounwind uwtable
define dso_local i32 @TfLiteTensorResizeMaybeCopy(i64 noundef %0, ptr noundef %1, i1 noundef zeroext %2) #3 {
  %4 = alloca i32, align 4
  %5 = alloca i64, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i8, align 1
  %8 = alloca i64, align 8
  %9 = alloca i32, align 4
  store i64 %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !9
  %10 = zext i1 %2 to i8
  store i8 %10, ptr %7, align 1, !tbaa !11
  %11 = load ptr, ptr %6, align 8, !tbaa !9
  %12 = getelementptr inbounds %struct.TfLiteTensor, ptr %11, i32 0, i32 4
  %13 = load i32, ptr %12, align 8, !tbaa !13
  %14 = icmp ne i32 %13, 4
  br i1 %14, label %15, label %21

15:                                               ; preds = %3
  %16 = load ptr, ptr %6, align 8, !tbaa !9
  %17 = getelementptr inbounds %struct.TfLiteTensor, ptr %16, i32 0, i32 4
  %18 = load i32, ptr %17, align 8, !tbaa !13
  %19 = icmp ne i32 %18, 5
  br i1 %19, label %20, label %21

20:                                               ; preds = %15
  store i32 0, ptr %4, align 4
  br label %74

21:                                               ; preds = %15, %3
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #5
  %22 = load i64, ptr %5, align 8, !tbaa !5
  %23 = add i64 %22, 16
  store i64 %23, ptr %8, align 8, !tbaa !5
  %24 = load ptr, ptr %6, align 8, !tbaa !9
  %25 = getelementptr inbounds %struct.TfLiteTensor, ptr %24, i32 0, i32 1
  %26 = load ptr, ptr %25, align 8, !tbaa !22
  %27 = icmp ne ptr %26, null
  br i1 %27, label %33, label %28

28:                                               ; preds = %21
  %29 = load i64, ptr %8, align 8, !tbaa !5
  %30 = call noalias ptr @malloc(i64 noundef %29) #6
  %31 = load ptr, ptr %6, align 8, !tbaa !9
  %32 = getelementptr inbounds %struct.TfLiteTensor, ptr %31, i32 0, i32 1
  store ptr %30, ptr %32, align 8, !tbaa !22
  br label %60

33:                                               ; preds = %21
  %34 = load i64, ptr %5, align 8, !tbaa !5
  %35 = load ptr, ptr %6, align 8, !tbaa !9
  %36 = getelementptr inbounds %struct.TfLiteTensor, ptr %35, i32 0, i32 5
  %37 = load i64, ptr %36, align 8, !tbaa !23
  %38 = icmp ugt i64 %34, %37
  br i1 %38, label %39, label %59

39:                                               ; preds = %33
  %40 = load i8, ptr %7, align 1, !tbaa !11, !range !24, !noundef !25
  %41 = trunc i8 %40 to i1
  br i1 %41, label %42, label %50

42:                                               ; preds = %39
  %43 = load ptr, ptr %6, align 8, !tbaa !9
  %44 = getelementptr inbounds %struct.TfLiteTensor, ptr %43, i32 0, i32 1
  %45 = load ptr, ptr %44, align 8, !tbaa !22
  %46 = load i64, ptr %8, align 8, !tbaa !5
  %47 = call ptr @realloc(ptr noundef %45, i64 noundef %46) #7
  %48 = load ptr, ptr %6, align 8, !tbaa !9
  %49 = getelementptr inbounds %struct.TfLiteTensor, ptr %48, i32 0, i32 1
  store ptr %47, ptr %49, align 8, !tbaa !22
  br label %58

50:                                               ; preds = %39
  %51 = load ptr, ptr %6, align 8, !tbaa !9
  %52 = getelementptr inbounds %struct.TfLiteTensor, ptr %51, i32 0, i32 1
  %53 = load ptr, ptr %52, align 8, !tbaa !22
  call void @free(ptr noundef %53) #5
  %54 = load i64, ptr %8, align 8, !tbaa !5
  %55 = call noalias ptr @malloc(i64 noundef %54) #6
  %56 = load ptr, ptr %6, align 8, !tbaa !9
  %57 = getelementptr inbounds %struct.TfLiteTensor, ptr %56, i32 0, i32 1
  store ptr %55, ptr %57, align 8, !tbaa !22
  br label %58

58:                                               ; preds = %50, %42
  br label %59

59:                                               ; preds = %58, %33
  br label %60

60:                                               ; preds = %59, %28
  %61 = load i64, ptr %5, align 8, !tbaa !5
  %62 = load ptr, ptr %6, align 8, !tbaa !9
  %63 = getelementptr inbounds %struct.TfLiteTensor, ptr %62, i32 0, i32 5
  store i64 %61, ptr %63, align 8, !tbaa !23
  %64 = load ptr, ptr %6, align 8, !tbaa !9
  %65 = getelementptr inbounds %struct.TfLiteTensor, ptr %64, i32 0, i32 1
  %66 = load ptr, ptr %65, align 8, !tbaa !22
  %67 = icmp eq ptr %66, null
  br i1 %67, label %68, label %72

68:                                               ; preds = %60
  %69 = load i64, ptr %5, align 8, !tbaa !5
  %70 = icmp ne i64 %69, 0
  br i1 %70, label %71, label %72

71:                                               ; preds = %68
  store i32 1, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %73

72:                                               ; preds = %68, %60
  store i32 0, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %73

73:                                               ; preds = %72, %71
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #5
  br label %74

74:                                               ; preds = %73, %20
  %75 = load i32, ptr %4, align 4
  ret i32 %75
}

; Function Attrs: nounwind allocsize(1)
declare ptr @realloc(ptr noundef, i64 noundef) #4

attributes #0 = { nounwind "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 = { nounwind allocsize(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 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 allocsize(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 #5 = { nounwind }
attributes #6 = { nounwind allocsize(0) }
attributes #7 = { nounwind allocsize(1) }

!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 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"bool", !7, i64 0}
!13 = !{!14, !19, i64 32}
!14 = !{!"_ZTS12TfLiteTensor", !15, i64 0, !7, i64 8, !10, i64 16, !16, i64 24, !19, i64 32, !6, i64 40, !10, i64 48, !10, i64 56, !10, i64 64, !18, i64 72, !12, i64 76, !12, i64 77, !20, i64 80, !10, i64 96, !10, i64 104}
!15 = !{!"_ZTS10TfLiteType", !7, i64 0}
!16 = !{!"_ZTS24TfLiteQuantizationParams", !17, i64 0, !18, i64 4}
!17 = !{!"float", !7, i64 0}
!18 = !{!"int", !7, i64 0}
!19 = !{!"_ZTS20TfLiteAllocationType", !7, i64 0}
!20 = !{!"_ZTS18TfLiteQuantization", !21, i64 0, !10, i64 8}
!21 = !{!"_ZTS22TfLiteQuantizationType", !7, i64 0}
!22 = !{!7, !7, i64 0}
!23 = !{!14, !6, i64 40}
!24 = !{i8 0, i8 2}
!25 = !{}


; 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: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nounwind willreturn uwtable
define dso_local range(i32 0, 2) i32 @TfLiteTensorResizeMaybeCopy(i64 noundef %0, ptr nocapture noundef %1, i1 noundef zeroext %2) local_unnamed_addr #2 {
  %4 = getelementptr inbounds i8, ptr %1, i64 32
  %5 = load i32, ptr %4, align 8, !tbaa !5
  %6 = and i32 %5, -2
  %switch = icmp eq i32 %6, 4
  br i1 %switch, label %7, label %27

7:                                                ; preds = %3
  %8 = add i64 %0, 16
  %9 = getelementptr inbounds i8, ptr %1, i64 8
  %10 = load ptr, ptr %9, align 8, !tbaa !19
  %.not23 = icmp eq ptr %10, null
  br i1 %.not23, label %11, label %13

11:                                               ; preds = %7
  %12 = tail call noalias ptr @malloc(i64 noundef %8) #4
  br label %.sink.split

13:                                               ; preds = %7
  %14 = getelementptr inbounds i8, ptr %1, i64 40
  %15 = load i64, ptr %14, align 8, !tbaa !20
  %16 = icmp ult i64 %15, %0
  br i1 %16, label %17, label %23

17:                                               ; preds = %13
  br i1 %2, label %18, label %20

18:                                               ; preds = %17
  %19 = tail call ptr @realloc(ptr noundef nonnull %10, i64 noundef %8) #5
  br label %.sink.split

20:                                               ; preds = %17
  tail call void @free(ptr noundef nonnull %10) #6
  %21 = tail call noalias ptr @malloc(i64 noundef %8) #4
  br label %.sink.split

.sink.split:                                      ; preds = %11, %18, %20
  %.sink = phi ptr [ %21, %20 ], [ %19, %18 ], [ %12, %11 ]
  store ptr %.sink, ptr %9, align 8, !tbaa !19
  %22 = icmp eq ptr %.sink, null
  br label %23

23:                                               ; preds = %.sink.split, %13
  %24 = phi i1 [ false, %13 ], [ %22, %.sink.split ]
  %25 = getelementptr inbounds i8, ptr %1, i64 40
  store i64 %0, ptr %25, align 8, !tbaa !20
  %26 = icmp ne i64 %0, 0
  %or.cond = and i1 %26, %24
  %. = zext i1 %or.cond to i32
  br label %27

27:                                               ; preds = %3, %23
  %.1 = phi i32 [ %., %23 ], [ 0, %3 ]
  ret i32 %.1
}

; Function Attrs: mustprogress nounwind willreturn allockind("realloc") allocsize(1) memory(argmem: readwrite, inaccessiblemem: readwrite)
declare noalias noundef ptr @realloc(ptr allocptr nocapture noundef, i64 noundef) local_unnamed_addr #3

attributes #0 = { mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite) "alloc-family"="malloc" "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 nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" "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 = { mustprogress nounwind willreturn 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 nounwind willreturn allockind("realloc") allocsize(1) memory(argmem: readwrite, inaccessiblemem: readwrite) "alloc-family"="malloc" "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 allocsize(0) }
attributes #5 = { nounwind allocsize(1) }
attributes #6 = { 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, !14, i64 32}
!6 = !{!"_ZTS12TfLiteTensor", !7, i64 0, !8, i64 8, !10, i64 16, !11, i64 24, !14, i64 32, !15, i64 40, !10, i64 48, !10, i64 56, !10, i64 64, !13, i64 72, !16, i64 76, !16, i64 77, !17, i64 80, !10, i64 96, !10, i64 104}
!7 = !{!"_ZTS10TfLiteType", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!"_ZTS24TfLiteQuantizationParams", !12, i64 0, !13, i64 4}
!12 = !{!"float", !8, i64 0}
!13 = !{!"int", !8, i64 0}
!14 = !{!"_ZTS20TfLiteAllocationType", !8, i64 0}
!15 = !{!"long", !8, i64 0}
!16 = !{!"bool", !8, i64 0}
!17 = !{!"_ZTS18TfLiteQuantization", !18, i64 0, !10, i64 8}
!18 = !{!"_ZTS22TfLiteQuantizationType", !8, i64 0}
!19 = !{!8, !8, i64 0}
!20 = !{!6, !15, i64 40}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass