; LLVM IR from specinfo-ua/UAPKI :: library/uapki/src/api (library-list-providers)

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

@.str = external hidden unnamed_addr constant [10 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [37 x i8], align 1

; Function Attrs: mustprogress uwtable
define dso_local i32 @uapki_list_providers(ptr noundef %0, ptr noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca i64, align 8
  %9 = alloca i64, align 8
  %10 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  store i32 0, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  store ptr null, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  %11 = call noundef i64 @_ZN11CmProviders5countEv()
  store i64 %11, ptr %8, align 8, !tbaa !11
  %12 = load ptr, ptr %5, align 8, !tbaa !5
  %13 = call ptr @json_value_init_array()
  %14 = call i32 @json_object_set_value(ptr noundef %12, ptr noundef @.str, ptr noundef %13)
  %15 = icmp ne i32 %14, 0
  br i1 %15, label %16, label %17

16:                                               ; preds = %2
  store i32 4113, ptr %6, align 4, !tbaa !9
  br label %51

17:                                               ; preds = %2
  %18 = load ptr, ptr %5, align 8, !tbaa !5
  %19 = call ptr @json_object_get_array(ptr noundef %18, ptr noundef @.str)
  store ptr %19, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  store i64 0, ptr %9, align 8, !tbaa !11
  br label %20

20:                                               ; preds = %45, %17
  %21 = load i64, ptr %9, align 8, !tbaa !11
  %22 = load i64, ptr %8, align 8, !tbaa !11
  %23 = icmp ult i64 %21, %22
  br i1 %23, label %25, label %24

24:                                               ; preds = %20
  store i32 3, ptr %10, align 4
  br label %48

25:                                               ; preds = %20
  %26 = load ptr, ptr %7, align 8, !tbaa !5
  %27 = call ptr @json_value_init_object()
  %28 = call i32 @json_array_append_value(ptr noundef %26, ptr noundef %27)
  %29 = icmp ne i32 %28, 0
  br i1 %29, label %30, label %31

30:                                               ; preds = %25
  store i32 4113, ptr %6, align 4, !tbaa !9
  store i32 2, ptr %10, align 4
  br label %48

31:                                               ; preds = %25
  br label %32

32:                                               ; preds = %31
  %33 = load i64, ptr %9, align 8, !tbaa !11
  %34 = load ptr, ptr %7, align 8, !tbaa !5
  %35 = load i64, ptr %9, align 8, !tbaa !11
  %36 = call ptr @json_array_get_object(ptr noundef %34, i64 noundef %35)
  %37 = call noundef i32 @_ZN11CmProviders7getInfoEmP13json_object_t(i64 noundef %33, ptr noundef %36)
  store i32 %37, ptr %6, align 4, !tbaa !9
  %38 = load i32, ptr %6, align 4, !tbaa !9
  %39 = icmp ne i32 %38, 0
  br i1 %39, label %40, label %42

40:                                               ; preds = %32
  %41 = load i32, ptr %6, align 4, !tbaa !9
  call void @stacktrace_add(ptr noundef @.str.1, i64 noundef 44, i32 noundef %41)
  store i32 2, ptr %10, align 4
  br label %48

42:                                               ; preds = %32
  br label %43

43:                                               ; preds = %42
  br label %44

44:                                               ; preds = %43
  br label %45

45:                                               ; preds = %44
  %46 = load i64, ptr %9, align 8, !tbaa !11
  %47 = add i64 %46, 1
  store i64 %47, ptr %9, align 8, !tbaa !11
  br label %20, !llvm.loop !13

48:                                               ; preds = %40, %30, %24
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  %49 = load i32, ptr %10, align 4
  switch i32 %49, label %53 [
    i32 3, label %50
    i32 2, label %51
  ]

50:                                               ; preds = %48
  br label %51

51:                                               ; preds = %50, %48, %16
  %52 = load i32, ptr %6, align 4, !tbaa !9
  store i32 %52, ptr %3, align 4
  store i32 1, ptr %10, align 4
  br label %53

53:                                               ; preds = %51, %48
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  %54 = load i32, ptr %3, align 4
  ret i32 %54
}

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

declare noundef i64 @_ZN11CmProviders5countEv() #2

declare i32 @json_object_set_value(ptr noundef, ptr noundef, ptr noundef) #2

declare ptr @json_value_init_array() #2

declare ptr @json_object_get_array(ptr noundef, ptr noundef) #2

declare i32 @json_array_append_value(ptr noundef, ptr noundef) #2

declare ptr @json_value_init_object() #2

declare noundef i32 @_ZN11CmProviders7getInfoEmP13json_object_t(i64 noundef, ptr noundef) #2

declare ptr @json_array_get_object(ptr noundef, i64 noundef) #2

declare void @stacktrace_add(ptr noundef, i64 noundef, i32 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 = { 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 = { "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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}


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

@.str = external hidden unnamed_addr constant [10 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [37 x i8], align 1

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @uapki_list_providers(ptr nocapture noundef readnone %0, ptr noundef %1) local_unnamed_addr #0 {
  %3 = tail call noundef i64 @_ZN11CmProviders5countEv()
  %4 = tail call ptr @json_value_init_array()
  %5 = tail call i32 @json_object_set_value(ptr noundef %1, ptr noundef nonnull @.str, ptr noundef %4)
  %.not = icmp eq i32 %5, 0
  br i1 %.not, label %6, label %.loopexit

6:                                                ; preds = %2
  %7 = tail call ptr @json_object_get_array(ptr noundef %1, ptr noundef nonnull @.str)
  %.not23 = icmp eq i64 %3, 0
  br i1 %.not23, label %.loopexit, label %.lr.ph

8:                                                ; preds = %12
  %9 = add nuw i64 %.01320, 1
  %exitcond.not = icmp eq i64 %9, %3
  br i1 %exitcond.not, label %.loopexit, label %.lr.ph, !llvm.loop !5

.lr.ph:                                           ; preds = %6, %8
  %.01320 = phi i64 [ %9, %8 ], [ 0, %6 ]
  %10 = tail call ptr @json_value_init_object()
  %11 = tail call i32 @json_array_append_value(ptr noundef %7, ptr noundef %10)
  %.not18 = icmp eq i32 %11, 0
  br i1 %.not18, label %12, label %.loopexit

12:                                               ; preds = %.lr.ph
  %13 = tail call ptr @json_array_get_object(ptr noundef %7, i64 noundef %.01320)
  %14 = tail call noundef i32 @_ZN11CmProviders7getInfoEmP13json_object_t(i64 noundef %.01320, ptr noundef %13)
  %.not19 = icmp eq i32 %14, 0
  br i1 %.not19, label %8, label %15

15:                                               ; preds = %12
  tail call void @stacktrace_add(ptr noundef nonnull @.str.1, i64 noundef 44, i32 noundef %14)
  br label %.loopexit

.loopexit:                                        ; preds = %8, %.lr.ph, %6, %2, %15
  %.2 = phi i32 [ 4113, %2 ], [ %14, %15 ], [ 0, %6 ], [ 0, %8 ], [ 4113, %.lr.ph ]
  ret i32 %.2
}

declare noundef i64 @_ZN11CmProviders5countEv() local_unnamed_addr #1

declare i32 @json_object_set_value(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

declare ptr @json_value_init_array() local_unnamed_addr #1

declare ptr @json_object_get_array(ptr noundef, ptr noundef) local_unnamed_addr #1

declare i32 @json_array_append_value(ptr noundef, ptr noundef) local_unnamed_addr #1

declare ptr @json_value_init_object() local_unnamed_addr #1

declare noundef i32 @_ZN11CmProviders7getInfoEmP13json_object_t(i64 noundef, ptr noundef) local_unnamed_addr #1

declare ptr @json_array_get_object(ptr noundef, i64 noundef) local_unnamed_addr #1

declare void @stacktrace_add(ptr noundef, i64 noundef, i32 noundef) local_unnamed_addr #1

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 = { "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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}


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