; LLVM IR from specinfo-ua/UAPKI :: library/common/pkix (extension-helper-json)

; 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.BasicConstraints = type { ptr, ptr, %struct.asn_struct_ctx_s }
%struct.asn_struct_ctx_s = type { i16, i16, i32, ptr, i64 }

@.str = external hidden unnamed_addr constant [38 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.11 = external hidden unnamed_addr constant [18 x i8], align 1

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

declare ptr @asn_decode_ba_with_alloc(ptr noundef, ptr noundef) #1

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

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

declare void @asn_free(ptr noundef, ptr noundef) #1

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN7UapkiNS15ExtensionHelper18DecodeToJsonObject16basicConstraintsEPK12ByteArray_stP13json_object_t(ptr noundef %0, ptr noundef %1) #2 {
  %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 i8, align 1
  %9 = alloca i32, align 4
  %10 = alloca i64, align 8
  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
  br label %11

11:                                               ; preds = %2
  %12 = call ptr @get_BasicConstraints_desc()
  %13 = load ptr, ptr %4, align 8, !tbaa !5
  %14 = call ptr @asn_decode_ba_with_alloc(ptr noundef %12, ptr noundef %13)
  store ptr %14, ptr %7, align 8, !tbaa !5
  %15 = icmp eq ptr null, %14
  br i1 %15, label %16, label %18

16:                                               ; preds = %11
  store i32 2, ptr %6, align 4, !tbaa !9
  %17 = load i32, ptr %6, align 4, !tbaa !9
  call void @stacktrace_add(ptr noundef @.str, i64 noundef 281, i32 noundef %17)
  br label %70

18:                                               ; preds = %11
  br label %19

19:                                               ; preds = %18
  br label %20

20:                                               ; preds = %19
  %21 = load ptr, ptr %7, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.BasicConstraints, ptr %21, i32 0, i32 0
  %23 = load ptr, ptr %22, align 8, !tbaa !11
  %24 = icmp ne ptr %23, null
  br i1 %24, label %25, label %41

25:                                               ; preds = %20
  call void @llvm.lifetime.start.p0(i64 1, ptr %8) #3
  %26 = load ptr, ptr %7, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.BasicConstraints, ptr %26, i32 0, i32 0
  %28 = load ptr, ptr %27, align 8, !tbaa !11
  %29 = icmp ne ptr %28, null
  %30 = zext i1 %29 to i8
  store i8 %30, ptr %8, align 1, !tbaa !16
  %31 = load ptr, ptr %5, align 8, !tbaa !5
  %32 = load i8, ptr %8, align 1, !tbaa !16, !range !18, !noundef !19
  %33 = trunc i8 %32 to i1
  %34 = call noundef i32 @_ZN12ParsonHelper20jsonObjectSetBooleanEP13json_object_tPKcb(ptr noundef %31, ptr noundef @.str.10, i1 noundef zeroext %33)
  %35 = icmp ne i32 %34, 0
  br i1 %35, label %36, label %37

36:                                               ; preds = %25
  store i32 4113, ptr %6, align 4, !tbaa !9
  store i32 4, ptr %9, align 4
  br label %38

37:                                               ; preds = %25
  store i32 0, ptr %9, align 4
  br label %38

38:                                               ; preds = %37, %36
  call void @llvm.lifetime.end.p0(i64 1, ptr %8) #3
  %39 = load i32, ptr %9, align 4
  switch i32 %39, label %74 [
    i32 0, label %40
    i32 4, label %70
  ]

40:                                               ; preds = %38
  br label %41

41:                                               ; preds = %40, %20
  %42 = load ptr, ptr %7, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.BasicConstraints, ptr %42, i32 0, i32 1
  %44 = load ptr, ptr %43, align 8, !tbaa !20
  %45 = icmp ne ptr %44, null
  br i1 %45, label %46, label %69

46:                                               ; preds = %41
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  store i64 0, ptr %10, align 8, !tbaa !21
  br label %47

47:                                               ; preds = %46
  %48 = load ptr, ptr %7, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.BasicConstraints, ptr %48, i32 0, i32 1
  %50 = load ptr, ptr %49, align 8, !tbaa !20
  %51 = call i32 @asn_INTEGER2long(ptr noundef %50, ptr noundef %10)
  store i32 %51, ptr %6, align 4, !tbaa !9
  %52 = load i32, ptr %6, align 4, !tbaa !9
  %53 = icmp ne i32 %52, 0
  br i1 %53, label %54, label %56

54:                                               ; preds = %47
  %55 = load i32, ptr %6, align 4, !tbaa !9
  call void @stacktrace_add(ptr noundef @.str, i64 noundef 290, i32 noundef %55)
  store i32 4, ptr %9, align 4
  br label %66

56:                                               ; preds = %47
  br label %57

57:                                               ; preds = %56
  br label %58

58:                                               ; preds = %57
  %59 = load ptr, ptr %5, align 8, !tbaa !5
  %60 = load i64, ptr %10, align 8, !tbaa !21
  %61 = trunc i64 %60 to i32
  %62 = call noundef i32 @_ZN12ParsonHelper18jsonObjectSetInt32EP13json_object_tPKci(ptr noundef %59, ptr noundef @.str.11, i32 noundef %61)
  %63 = icmp ne i32 %62, 0
  br i1 %63, label %64, label %65

64:                                               ; preds = %58
  store i32 4113, ptr %6, align 4, !tbaa !9
  store i32 4, ptr %9, align 4
  br label %66

65:                                               ; preds = %58
  store i32 0, ptr %9, align 4
  br label %66

66:                                               ; preds = %65, %64, %54
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  %67 = load i32, ptr %9, align 4
  switch i32 %67, label %74 [
    i32 0, label %68
    i32 4, label %70
  ]

68:                                               ; preds = %66
  br label %69

69:                                               ; preds = %68, %41
  br label %70

70:                                               ; preds = %69, %66, %38, %16
  %71 = call ptr @get_BasicConstraints_desc()
  %72 = load ptr, ptr %7, align 8, !tbaa !5
  call void @asn_free(ptr noundef %71, ptr noundef %72)
  %73 = load i32, ptr %6, align 4, !tbaa !9
  store i32 %73, ptr %3, align 4
  store i32 1, ptr %9, align 4
  br label %74

74:                                               ; preds = %70, %66, %38
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  %75 = load i32, ptr %3, align 4
  ret i32 %75
}

declare ptr @get_BasicConstraints_desc() #1

declare noundef i32 @_ZN12ParsonHelper20jsonObjectSetBooleanEP13json_object_tPKcb(ptr noundef, ptr noundef, i1 noundef zeroext) #1

declare i32 @asn_INTEGER2long(ptr noundef, ptr noundef) #1

declare noundef i32 @_ZN12ParsonHelper18jsonObjectSetInt32EP13json_object_tPKci(ptr noundef, ptr noundef, i32 noundef) #1

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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" }
attributes #2 = { 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 #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, !6, i64 0}
!12 = !{!"_ZTS16BasicConstraints", !6, i64 0, !6, i64 8, !13, i64 16}
!13 = !{!"_ZTS16asn_struct_ctx_s", !14, i64 0, !14, i64 2, !10, i64 4, !6, i64 8, !15, i64 16}
!14 = !{!"short", !7, i64 0}
!15 = !{!"long", !7, i64 0}
!16 = !{!17, !17, i64 0}
!17 = !{!"bool", !7, i64 0}
!18 = !{i8 0, i8 2}
!19 = !{}
!20 = !{!12, !6, i64 8}
!21 = !{!15, !15, i64 0}


; 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 [38 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.11 = external hidden unnamed_addr constant [18 x i8], align 1

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

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

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

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

declare void @asn_free(ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN7UapkiNS15ExtensionHelper18DecodeToJsonObject16basicConstraintsEPK12ByteArray_stP13json_object_t(ptr noundef %0, ptr noundef %1) local_unnamed_addr #2 {
  %3 = alloca i64, align 8
  %4 = tail call ptr @get_BasicConstraints_desc()
  %5 = tail call ptr @asn_decode_ba_with_alloc(ptr noundef %4, ptr noundef %0)
  %6 = icmp eq ptr %5, null
  br i1 %6, label %7, label %8

7:                                                ; preds = %2
  tail call void @stacktrace_add(ptr noundef nonnull @.str, i64 noundef 281, i32 noundef 2)
  br label %23

8:                                                ; preds = %2
  %9 = load ptr, ptr %5, align 8, !tbaa !5
  %.not = icmp eq ptr %9, null
  br i1 %.not, label %12, label %10

10:                                               ; preds = %8
  %11 = tail call noundef i32 @_ZN12ParsonHelper20jsonObjectSetBooleanEP13json_object_tPKcb(ptr noundef %1, ptr noundef nonnull @.str.10, i1 noundef zeroext true)
  %.not21 = icmp eq i32 %11, 0
  br i1 %.not21, label %12, label %23

12:                                               ; preds = %10, %8
  %13 = getelementptr inbounds i8, ptr %5, i64 8
  %14 = load ptr, ptr %13, align 8, !tbaa !14
  %.not22 = icmp eq ptr %14, null
  br i1 %.not22, label %23, label %15

15:                                               ; preds = %12
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #3
  store i64 0, ptr %3, align 8, !tbaa !15
  %16 = call i32 @asn_INTEGER2long(ptr noundef nonnull %14, ptr noundef nonnull %3)
  %.not23 = icmp eq i32 %16, 0
  br i1 %.not23, label %18, label %17

17:                                               ; preds = %15
  call void @stacktrace_add(ptr noundef nonnull @.str, i64 noundef 290, i32 noundef %16)
  br label %22

18:                                               ; preds = %15
  %19 = load i64, ptr %3, align 8, !tbaa !15
  %20 = trunc i64 %19 to i32
  %21 = call noundef i32 @_ZN12ParsonHelper18jsonObjectSetInt32EP13json_object_tPKci(ptr noundef %1, ptr noundef nonnull @.str.11, i32 noundef %20)
  %.not24 = icmp eq i32 %21, 0
  %.26 = select i1 %.not24, i32 0, i32 4113
  br label %22

22:                                               ; preds = %18, %17
  %.2 = phi i32 [ %16, %17 ], [ %.26, %18 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #3
  br label %23

23:                                               ; preds = %10, %22, %12, %7
  %.3 = phi i32 [ 2, %7 ], [ 4113, %10 ], [ %.2, %22 ], [ 0, %12 ]
  %24 = call ptr @get_BasicConstraints_desc()
  call void @asn_free(ptr noundef %24, ptr noundef %5)
  ret i32 %.3
}

declare ptr @get_BasicConstraints_desc() local_unnamed_addr #1

declare noundef i32 @_ZN12ParsonHelper20jsonObjectSetBooleanEP13json_object_tPKcb(ptr noundef, ptr noundef, i1 noundef zeroext) local_unnamed_addr #1

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

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

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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" }
attributes #2 = { 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 #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 = !{!"_ZTS16BasicConstraints", !7, i64 0, !7, i64 8, !10, i64 16}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"_ZTS16asn_struct_ctx_s", !11, i64 0, !11, i64 2, !12, i64 4, !7, i64 8, !13, i64 16}
!11 = !{!"short", !8, i64 0}
!12 = !{!"int", !8, i64 0}
!13 = !{!"long", !8, i64 0}
!14 = !{!6, !7, i64 8}
!15 = !{!13, !13, i64 0}


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