; LLVM IR from tensorflow/tensorflow :: tensorflow/lite/python/testdata (test_delegate)

; 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.TfLiteDelegate = type { ptr, ptr, ptr, ptr, ptr, i64, ptr }
%class.anon = type { i8 }

@_ZN6tflite12_GLOBAL__N_121num_delegates_createdE = external hidden global i32, align 4
@.str = external hidden unnamed_addr constant [16 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1
@_ZN6tflite12_GLOBAL__N_115options_counterE = external hidden global i32, align 4
@.str.2 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [20 x i8], align 1

; Function Attrs: mustprogress uwtable
define dso_local ptr @tflite_plugin_create_delegate(ptr noundef %0, ptr noundef %1, i64 noundef %2, ptr noundef %3) #0 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i64, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca ptr, align 8
  %14 = alloca %struct.TfLiteDelegate, align 8
  %15 = alloca %class.anon, align 1
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store i64 %2, ptr %8, align 8, !tbaa !9
  store ptr %3, ptr %9, align 8, !tbaa !5
  %16 = load i32, ptr @_ZN6tflite12_GLOBAL__N_121num_delegates_createdE, align 4, !tbaa !11
  %17 = add nsw i32 %16, 1
  store i32 %17, ptr @_ZN6tflite12_GLOBAL__N_121num_delegates_createdE, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #8
  store i32 0, ptr %10, align 4, !tbaa !11
  br label %18

18:                                               ; preds = %61, %4
  %19 = load i32, ptr %10, align 4, !tbaa !11
  %20 = sext i32 %19 to i64
  %21 = load i64, ptr %8, align 8, !tbaa !9
  %22 = icmp ult i64 %20, %21
  br i1 %22, label %24, label %23

23:                                               ; preds = %18
  store i32 2, ptr %11, align 4
  br label %64

24:                                               ; preds = %18
  %25 = load ptr, ptr %6, align 8, !tbaa !5
  %26 = load i32, ptr %10, align 4, !tbaa !11
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds ptr, ptr %25, i64 %27
  %29 = load ptr, ptr %28, align 8, !tbaa !5
  %30 = call i32 @strcmp(ptr noundef @.str, ptr noundef %29) #9
  %31 = icmp eq i32 %30, 0
  br i1 %31, label %32, label %45

32:                                               ; preds = %24
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #8
  %33 = load ptr, ptr %7, align 8, !tbaa !5
  %34 = load i32, ptr %10, align 4, !tbaa !11
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds ptr, ptr %33, i64 %35
  %37 = load ptr, ptr %36, align 8, !tbaa !5
  %38 = call i32 (ptr, ptr, ...) @__isoc99_sscanf(ptr noundef %37, ptr noundef @.str.1, ptr noundef %12) #8
  %39 = icmp eq i32 %38, 1
  br i1 %39, label %40, label %44

40:                                               ; preds = %32
  %41 = load i32, ptr %12, align 4, !tbaa !11
  %42 = load i32, ptr @_ZN6tflite12_GLOBAL__N_115options_counterE, align 4, !tbaa !11
  %43 = add nsw i32 %42, %41
  store i32 %43, ptr @_ZN6tflite12_GLOBAL__N_115options_counterE, align 4, !tbaa !11
  br label %44

44:                                               ; preds = %40, %32
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #8
  br label %60

45:                                               ; preds = %24
  %46 = load ptr, ptr %6, align 8, !tbaa !5
  %47 = load i32, ptr %10, align 4, !tbaa !11
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds ptr, ptr %46, i64 %48
  %50 = load ptr, ptr %49, align 8, !tbaa !5
  %51 = call i32 @strcmp(ptr noundef @.str.2, ptr noundef %50) #9
  %52 = icmp eq i32 %51, 0
  br i1 %52, label %53, label %59

53:                                               ; preds = %45
  %54 = load ptr, ptr %9, align 8, !tbaa !5
  %55 = icmp ne ptr %54, null
  br i1 %55, label %56, label %58

56:                                               ; preds = %53
  %57 = load ptr, ptr %9, align 8, !tbaa !5
  call void %57(ptr noundef @.str.3)
  br label %58

58:                                               ; preds = %56, %53
  store ptr null, ptr %5, align 8
  store i32 1, ptr %11, align 4
  br label %64

59:                                               ; preds = %45
  br label %60

60:                                               ; preds = %59, %44
  br label %61

61:                                               ; preds = %60
  %62 = load i32, ptr %10, align 4, !tbaa !11
  %63 = add nsw i32 %62, 1
  store i32 %63, ptr %10, align 4, !tbaa !11
  br label %18, !llvm.loop !13

64:                                               ; preds = %58, %23
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #8
  %65 = load i32, ptr %11, align 4
  switch i32 %65, label %77 [
    i32 2, label %66
    i32 1, label %75
  ]

66:                                               ; preds = %64
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #8
  %67 = call noalias noundef nonnull ptr @_Znwm(i64 noundef 56) #10
  store ptr %67, ptr %13, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 56, ptr %14) #8
  call void @TfLiteDelegateCreate(ptr dead_on_unwind writable sret(%struct.TfLiteDelegate) align 8 %14)
  %68 = load ptr, ptr %13, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %68, ptr align 8 %14, i64 56, i1 false), !tbaa.struct !15
  call void @llvm.lifetime.end.p0(i64 56, ptr %14) #8
  call void @llvm.lifetime.start.p0(i64 1, ptr %15) #8
  %69 = call noundef ptr @"_ZZ29tflite_plugin_create_delegateENK3$_0cvPF12TfLiteStatusP13TfLiteContextP14TfLiteDelegateEEv"(ptr noundef nonnull align 1 dereferenceable(1) %15) #8
  %70 = load ptr, ptr %13, align 8, !tbaa !5
  %71 = getelementptr inbounds %struct.TfLiteDelegate, ptr %70, i32 0, i32 1
  store ptr %69, ptr %71, align 8, !tbaa !16
  call void @llvm.lifetime.end.p0(i64 1, ptr %15) #8
  %72 = load ptr, ptr %13, align 8, !tbaa !5
  %73 = getelementptr inbounds %struct.TfLiteDelegate, ptr %72, i32 0, i32 5
  store i64 0, ptr %73, align 8, !tbaa !18
  %74 = load ptr, ptr %13, align 8, !tbaa !5
  store ptr %74, ptr %5, align 8
  store i32 1, ptr %11, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #8
  br label %75

75:                                               ; preds = %66, %64
  %76 = load ptr, ptr %5, align 8
  ret ptr %76

77:                                               ; preds = %64
  unreachable
}

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

; Function Attrs: nounwind willreturn memory(read)
declare i32 @strcmp(ptr noundef, ptr noundef) #2

; Function Attrs: nounwind
declare i32 @__isoc99_sscanf(ptr noundef, ptr noundef, ...) #3

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

; Function Attrs: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znwm(i64 noundef) #4

declare void @TfLiteDelegateCreate(ptr dead_on_unwind writable sret(%struct.TfLiteDelegate) align 8) #5

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #6

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare hidden noundef ptr @"_ZZ29tflite_plugin_create_delegateENK3$_0cvPF12TfLiteStatusP13TfLiteContextP14TfLiteDelegateEEv"(ptr noundef nonnull align 1 dereferenceable(1)) #7 align 2

attributes #0 = { mustprogress 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 = { nounwind willreturn memory(read) "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 "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 = { nobuiltin 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 #5 = { "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 #6 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #7 = { inlinehint 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 #8 = { nounwind }
attributes #9 = { nounwind willreturn memory(read) }
attributes #10 = { builtin allocsize(0) }

!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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = !{i64 0, i64 8, !5, i64 8, i64 8, !5, i64 16, i64 8, !5, i64 24, i64 8, !5, i64 32, i64 8, !5, i64 40, i64 8, !9, i64 48, i64 8, !5}
!16 = !{!17, !6, i64 8}
!17 = !{!"_ZTS14TfLiteDelegate", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !10, i64 40, !6, i64 48}
!18 = !{!17, !10, 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"

%struct.TfLiteDelegate = type { ptr, ptr, ptr, ptr, ptr, i64, ptr }
%class.anon = type { i8 }

@_ZN6tflite12_GLOBAL__N_121num_delegates_createdE = external hidden local_unnamed_addr global i32, align 4
@.str = external hidden unnamed_addr constant [16 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1
@_ZN6tflite12_GLOBAL__N_115options_counterE = external hidden local_unnamed_addr global i32, align 4
@.str.2 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [20 x i8], align 1

; Function Attrs: mustprogress uwtable
define dso_local noundef ptr @tflite_plugin_create_delegate(ptr nocapture noundef readonly %0, ptr nocapture noundef readonly %1, i64 noundef %2, ptr noundef readonly %3) local_unnamed_addr #0 {
  %5 = alloca i32, align 4
  %6 = alloca %struct.TfLiteDelegate, align 8
  %7 = alloca %class.anon, align 1
  %8 = load i32, ptr @_ZN6tflite12_GLOBAL__N_121num_delegates_createdE, align 4, !tbaa !5
  %9 = add nsw i32 %8, 1
  store i32 %9, ptr @_ZN6tflite12_GLOBAL__N_121num_delegates_createdE, align 4, !tbaa !5
  %.not23 = icmp eq i64 %2, 0
  br i1 %.not23, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %4, %29
  %indvars.iv = phi i64 [ %indvars.iv.next, %29 ], [ 0, %4 ]
  %10 = getelementptr inbounds ptr, ptr %0, i64 %indvars.iv
  %11 = load ptr, ptr %10, align 8, !tbaa !9
  %12 = call i32 @strcmp(ptr noundef nonnull dereferenceable(1) @.str, ptr noundef nonnull dereferenceable(1) %11) #8
  %13 = icmp eq i32 %12, 0
  br i1 %13, label %14, label %24

14:                                               ; preds = %.lr.ph
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %5) #9
  %15 = getelementptr inbounds ptr, ptr %1, i64 %indvars.iv
  %16 = load ptr, ptr %15, align 8, !tbaa !9
  %17 = call i32 (ptr, ptr, ...) @__isoc99_sscanf(ptr noundef %16, ptr noundef nonnull @.str.1, ptr noundef nonnull %5) #9
  %18 = icmp eq i32 %17, 1
  br i1 %18, label %19, label %23

19:                                               ; preds = %14
  %20 = load i32, ptr %5, align 4, !tbaa !5
  %21 = load i32, ptr @_ZN6tflite12_GLOBAL__N_115options_counterE, align 4, !tbaa !5
  %22 = add nsw i32 %21, %20
  store i32 %22, ptr @_ZN6tflite12_GLOBAL__N_115options_counterE, align 4, !tbaa !5
  br label %23

23:                                               ; preds = %19, %14
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %5) #9
  br label %29

24:                                               ; preds = %.lr.ph
  %25 = call i32 @strcmp(ptr noundef nonnull dereferenceable(1) @.str.2, ptr noundef nonnull dereferenceable(1) %11) #8
  %26 = icmp eq i32 %25, 0
  br i1 %26, label %27, label %29

27:                                               ; preds = %24
  %.not = icmp eq ptr %3, null
  br i1 %.not, label %.thread, label %28

28:                                               ; preds = %27
  call void %3(ptr noundef nonnull @.str.3)
  br label %.thread

29:                                               ; preds = %23, %24
  %indvars.iv.next = add nuw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %2
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !11

._crit_edge:                                      ; preds = %29, %4
  %30 = call noalias noundef nonnull dereferenceable(56) ptr @_Znwm(i64 noundef 56) #10
  call void @llvm.lifetime.start.p0(i64 56, ptr nonnull %6) #9
  call void @TfLiteDelegateCreate(ptr dead_on_unwind nonnull writable sret(%struct.TfLiteDelegate) align 8 %6)
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(56) %30, ptr noundef nonnull align 8 dereferenceable(56) %6, i64 56, i1 false), !tbaa.struct !13
  call void @llvm.lifetime.end.p0(i64 56, ptr nonnull %6) #9
  call void @llvm.lifetime.start.p0(i64 1, ptr nonnull %7) #9
  %31 = call noundef ptr @"_ZZ29tflite_plugin_create_delegateENK3$_0cvPF12TfLiteStatusP13TfLiteContextP14TfLiteDelegateEEv"(ptr noundef nonnull align 1 dereferenceable(1) %7) #9
  %32 = getelementptr inbounds i8, ptr %30, i64 8
  store ptr %31, ptr %32, align 8, !tbaa !16
  call void @llvm.lifetime.end.p0(i64 1, ptr nonnull %7) #9
  %33 = getelementptr inbounds i8, ptr %30, i64 40
  store i64 0, ptr %33, align 8, !tbaa !18
  br label %.thread

.thread:                                          ; preds = %27, %28, %._crit_edge
  %.1 = phi ptr [ %30, %._crit_edge ], [ null, %28 ], [ null, %27 ]
  ret ptr %.1
}

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

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare i32 @strcmp(ptr nocapture noundef, ptr nocapture noundef) local_unnamed_addr #2

; Function Attrs: nofree nounwind
declare noundef i32 @__isoc99_sscanf(ptr nocapture noundef readonly, ptr nocapture noundef readonly, ...) local_unnamed_addr #3

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

; Function Attrs: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znwm(i64 noundef) local_unnamed_addr #4

declare void @TfLiteDelegateCreate(ptr dead_on_unwind writable sret(%struct.TfLiteDelegate) align 8) local_unnamed_addr #5

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #6

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare hidden noundef ptr @"_ZZ29tflite_plugin_create_delegateENK3$_0cvPF12TfLiteStatusP13TfLiteContextP14TfLiteDelegateEEv"(ptr noundef nonnull align 1 dereferenceable(1)) local_unnamed_addr #7 align 2

attributes #0 = { mustprogress 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 = { mustprogress nofree nounwind willreturn memory(argmem: read) "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 = { nofree 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 #4 = { nobuiltin 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 #5 = { "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 #6 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #7 = { inlinehint 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 #8 = { nounwind willreturn memory(read) }
attributes #9 = { nounwind }
attributes #10 = { builtin allocsize(0) }

!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 = !{!"int", !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 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{i64 0, i64 8, !9, i64 8, i64 8, !9, i64 16, i64 8, !9, i64 24, i64 8, !9, i64 32, i64 8, !9, i64 40, i64 8, !14, i64 48, i64 8, !9}
!14 = !{!15, !15, i64 0}
!15 = !{!"long", !7, i64 0}
!16 = !{!17, !10, i64 8}
!17 = !{!"_ZTS14TfLiteDelegate", !10, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !10, i64 32, !15, i64 40, !10, i64 48}
!18 = !{!17, !15, i64 40}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass