; LLVM IR from specinfo-ua/UAPKI :: library/common/pkix (uapki-ns-util)

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

@.str = external hidden unnamed_addr constant [30 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 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 i32 @asn_OCTSTRING2ba(ptr noundef, ptr noundef) #1

; Function Attrs: mustprogress uwtable
declare dso_local noundef ptr @_ZN7UapkiNS4Util23extensionFromExtensionsEPK10ExtensionsPKc(ptr noundef, ptr noundef) #2

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

15:                                               ; preds = %4
  %16 = load ptr, ptr %7, align 8, !tbaa !5
  %17 = icmp ne ptr %16, null
  br i1 %17, label %18, label %21

18:                                               ; preds = %15
  %19 = load ptr, ptr %9, align 8, !tbaa !5
  %20 = icmp ne ptr %19, null
  br i1 %20, label %22, label %21

21:                                               ; preds = %18, %15, %4
  store i32 4101, ptr %5, align 4
  store i32 1, ptr %11, align 4
  br label %61

22:                                               ; preds = %18
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #3
  %23 = load ptr, ptr %6, align 8, !tbaa !5
  %24 = load ptr, ptr %7, align 8, !tbaa !5
  %25 = call noundef ptr @_ZN7UapkiNS4Util23extensionFromExtensionsEPK10ExtensionsPKc(ptr noundef %23, ptr noundef %24)
  store ptr %25, ptr %12, align 8, !tbaa !5
  %26 = load ptr, ptr %12, align 8, !tbaa !5
  %27 = icmp ne ptr %26, null
  br i1 %27, label %29, label %28

28:                                               ; preds = %22
  store i32 4150, ptr %10, align 4, !tbaa !9
  br label %59

29:                                               ; preds = %22
  %30 = load ptr, ptr %8, align 8, !tbaa !5
  %31 = icmp ne ptr %30, null
  br i1 %31, label %32, label %46

32:                                               ; preds = %29
  %33 = load ptr, ptr %8, align 8, !tbaa !5
  store i8 0, ptr %33, align 1, !tbaa !11
  %34 = load ptr, ptr %12, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.Extension, ptr %34, i32 0, i32 1
  %36 = load ptr, ptr %35, align 8, !tbaa !13
  %37 = icmp ne ptr %36, null
  br i1 %37, label %38, label %45

38:                                               ; preds = %32
  %39 = load ptr, ptr %12, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.Extension, ptr %39, i32 0, i32 1
  %41 = load ptr, ptr %40, align 8, !tbaa !13
  %42 = icmp ne ptr %41, null
  %43 = load ptr, ptr %8, align 8, !tbaa !5
  %44 = zext i1 %42 to i8
  store i8 %44, ptr %43, align 1, !tbaa !11
  br label %45

45:                                               ; preds = %38, %32
  br label %46

46:                                               ; preds = %45, %29
  br label %47

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

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

56:                                               ; preds = %47
  br label %57

57:                                               ; preds = %56
  br label %58

58:                                               ; preds = %57
  br label %59

59:                                               ; preds = %58, %54, %28
  %60 = load i32, ptr %10, align 4, !tbaa !9
  store i32 %60, ptr %5, align 4
  store i32 1, ptr %11, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #3
  br label %61

61:                                               ; preds = %59, %21
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  %62 = load i32, ptr %5, align 4
  ret i32 %62
}

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, !12, i64 0}
!12 = !{!"bool", !7, i64 0}
!13 = !{!14, !6, i64 16}
!14 = !{!"_ZTS9Extension", !15, i64 0, !6, i64 16, !16, i64 24, !17, i64 64}
!15 = !{!"_ZTS21ASN__PRIMITIVE_TYPE_s", !6, i64 0, !10, i64 8}
!16 = !{!"_ZTS12OCTET_STRING", !6, i64 0, !10, i64 8, !17, i64 16}
!17 = !{!"_ZTS16asn_struct_ctx_s", !18, i64 0, !18, i64 2, !10, i64 4, !6, i64 8, !19, i64 16}
!18 = !{!"short", !7, i64 0}
!19 = !{!"long", !7, 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 [30 x i8], align 1

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

declare i32 @asn_OCTSTRING2ba(ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
declare dso_local noundef ptr @_ZN7UapkiNS4Util23extensionFromExtensionsEPK10ExtensionsPKc(ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN7UapkiNS4Util23extnValueFromExtensionsEPK10ExtensionsPKcPbPP12ByteArray_st(ptr noundef %0, ptr noundef %1, ptr noundef writeonly %2, ptr noundef %3) local_unnamed_addr #1 {
  %5 = icmp ne ptr %0, null
  %6 = icmp ne ptr %1, null
  %or.cond = and i1 %5, %6
  %7 = icmp ne ptr %3, null
  %or.cond3 = and i1 %or.cond, %7
  br i1 %or.cond3, label %8, label %18

8:                                                ; preds = %4
  %9 = tail call noundef ptr @_ZN7UapkiNS4Util23extensionFromExtensionsEPK10ExtensionsPKc(ptr noundef nonnull %0, ptr noundef nonnull %1)
  %.not = icmp eq ptr %9, null
  br i1 %.not, label %18, label %10

10:                                               ; preds = %8
  %.not26 = icmp eq ptr %2, null
  br i1 %.not26, label %14, label %11

11:                                               ; preds = %10
  %12 = getelementptr inbounds i8, ptr %9, i64 16
  %13 = load ptr, ptr %12, align 8, !tbaa !5
  %.not27 = icmp ne ptr %13, null
  %spec.store.select = zext i1 %.not27 to i8
  store i8 %spec.store.select, ptr %2, align 1
  br label %14

14:                                               ; preds = %11, %10
  %15 = getelementptr inbounds i8, ptr %9, i64 24
  %16 = tail call i32 @asn_OCTSTRING2ba(ptr noundef nonnull %15, ptr noundef nonnull %3)
  %.not28 = icmp eq i32 %16, 0
  br i1 %.not28, label %18, label %17

17:                                               ; preds = %14
  tail call void @stacktrace_add(ptr noundef nonnull @.str, i64 noundef 398, i32 noundef %16)
  br label %18

18:                                               ; preds = %17, %14, %8, %4
  %.0 = phi i32 [ 4101, %4 ], [ %16, %17 ], [ 0, %14 ], [ 4150, %8 ]
  ret i32 %.0
}

attributes #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 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, !8, i64 16}
!6 = !{!"_ZTS9Extension", !7, i64 0, !8, i64 16, !12, i64 24, !13, i64 64}
!7 = !{!"_ZTS21ASN__PRIMITIVE_TYPE_s", !8, i64 0, !11, i64 8}
!8 = !{!"any pointer", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C++ TBAA"}
!11 = !{!"int", !9, i64 0}
!12 = !{!"_ZTS12OCTET_STRING", !8, i64 0, !11, i64 8, !13, i64 16}
!13 = !{!"_ZTS16asn_struct_ctx_s", !14, i64 0, !14, i64 2, !11, i64 4, !8, i64 8, !15, i64 16}
!14 = !{!"short", !9, i64 0}
!15 = !{!"long", !9, i64 0}


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