; LLVM IR from specinfo-ua/UAPKI :: library/common/pkix (aid)

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

@.str = external hidden unnamed_addr constant [18 x i8], align 1
@OID_RSA = external global ptr, align 8

declare ptr @get_AlgorithmIdentifier_desc() #0

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

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

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

declare i32 @asn_set_oid_from_text(ptr noundef, ptr noundef) #0

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

declare i32 @asn_create_any(ptr noundef, ptr noundef, ptr noundef) #0

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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @aid_create_rsa(ptr noundef %0) #3 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #4
  store i32 0, ptr %3, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #4
  store ptr null, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  store ptr null, ptr %5, align 8, !tbaa !5
  %6 = call noalias ptr @calloc(i64 noundef 1, i64 noundef 48) #5
  store ptr %6, ptr %4, align 8, !tbaa !5
  %7 = load ptr, ptr %4, align 8, !tbaa !5
  %8 = icmp eq ptr %7, null
  br i1 %8, label %9, label %11

9:                                                ; preds = %1
  store i32 1, ptr %3, align 4, !tbaa !9
  %10 = load i32, ptr %3, align 4, !tbaa !9
  call void @stacktrace_create(ptr noundef @.str, i64 noundef 95, i32 noundef %10, ptr noundef null)
  br label %45

11:                                               ; preds = %1
  %12 = call noalias ptr @calloc(i64 noundef 1, i64 noundef 4) #5
  store ptr %12, ptr %5, align 8, !tbaa !5
  %13 = load ptr, ptr %5, align 8, !tbaa !5
  %14 = icmp eq ptr %13, null
  br i1 %14, label %15, label %17

15:                                               ; preds = %11
  store i32 1, ptr %3, align 4, !tbaa !9
  %16 = load i32, ptr %3, align 4, !tbaa !9
  call void @stacktrace_create(ptr noundef @.str, i64 noundef 96, i32 noundef %16, ptr noundef null)
  br label %45

17:                                               ; preds = %11
  br label %18

18:                                               ; preds = %17
  %19 = load ptr, ptr @OID_RSA, align 8, !tbaa !5
  %20 = load ptr, ptr %4, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.AlgorithmIdentifier, ptr %20, i32 0, i32 0
  %22 = call i32 @asn_set_oid_from_text(ptr noundef %19, ptr noundef %21)
  store i32 %22, ptr %3, align 4, !tbaa !9
  %23 = load i32, ptr %3, align 4, !tbaa !9
  %24 = icmp ne i32 %23, 0
  br i1 %24, label %25, label %27

25:                                               ; preds = %18
  %26 = load i32, ptr %3, align 4, !tbaa !9
  call void @stacktrace_add(ptr noundef @.str, i64 noundef 97, i32 noundef %26)
  br label %45

27:                                               ; preds = %18
  br label %28

28:                                               ; preds = %27
  br label %29

29:                                               ; preds = %28
  br label %30

30:                                               ; preds = %29
  %31 = call ptr @get_NULL_desc()
  %32 = load ptr, ptr %5, align 8, !tbaa !5
  %33 = load ptr, ptr %4, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.AlgorithmIdentifier, ptr %33, i32 0, i32 1
  %35 = call i32 @asn_create_any(ptr noundef %31, ptr noundef %32, ptr noundef %34)
  store i32 %35, ptr %3, align 4, !tbaa !9
  %36 = load i32, ptr %3, align 4, !tbaa !9
  %37 = icmp ne i32 %36, 0
  br i1 %37, label %38, label %40

38:                                               ; preds = %30
  %39 = load i32, ptr %3, align 4, !tbaa !9
  call void @stacktrace_add(ptr noundef @.str, i64 noundef 98, i32 noundef %39)
  br label %45

40:                                               ; preds = %30
  br label %41

41:                                               ; preds = %40
  br label %42

42:                                               ; preds = %41
  %43 = load ptr, ptr %4, align 8, !tbaa !5
  %44 = load ptr, ptr %2, align 8, !tbaa !5
  store ptr %43, ptr %44, align 8, !tbaa !5
  store ptr null, ptr %4, align 8, !tbaa !5
  br label %45

45:                                               ; preds = %42, %38, %25, %15, %9
  %46 = call ptr @get_AlgorithmIdentifier_desc()
  %47 = load ptr, ptr %4, align 8, !tbaa !5
  call void @asn_free(ptr noundef %46, ptr noundef %47)
  %48 = call ptr @get_NULL_desc()
  %49 = load ptr, ptr %5, align 8, !tbaa !5
  call void @asn_free(ptr noundef %48, ptr noundef %49)
  %50 = load i32, ptr %3, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #4
  ret i32 %50
}

declare ptr @get_NULL_desc() #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nounwind allocsize(0,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 #3 = { 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 }
attributes #5 = { nounwind allocsize(0,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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !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 [18 x i8], align 1
@OID_RSA = external local_unnamed_addr global ptr, align 8

declare ptr @get_AlgorithmIdentifier_desc() local_unnamed_addr #0

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

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

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

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

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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @aid_create_rsa(ptr nocapture noundef writeonly %0) local_unnamed_addr #2 {
  %2 = tail call noalias dereferenceable_or_null(48) ptr @calloc(i64 noundef 1, i64 noundef 48) #3
  %3 = icmp eq ptr %2, null
  br i1 %3, label %4, label %5

4:                                                ; preds = %1
  tail call void @stacktrace_create(ptr noundef nonnull @.str, i64 noundef 95, i32 noundef 1, ptr noundef null) #4
  br label %19

5:                                                ; preds = %1
  %6 = tail call noalias dereferenceable_or_null(4) ptr @calloc(i64 noundef 1, i64 noundef 4) #3
  %7 = icmp eq ptr %6, null
  br i1 %7, label %8, label %9

8:                                                ; preds = %5
  tail call void @stacktrace_create(ptr noundef nonnull @.str, i64 noundef 96, i32 noundef 1, ptr noundef null) #4
  br label %19

9:                                                ; preds = %5
  %10 = load ptr, ptr @OID_RSA, align 8, !tbaa !5
  %11 = tail call i32 @asn_set_oid_from_text(ptr noundef %10, ptr noundef nonnull %2) #4
  %.not = icmp eq i32 %11, 0
  br i1 %.not, label %13, label %12

12:                                               ; preds = %9
  tail call void @stacktrace_add(ptr noundef nonnull @.str, i64 noundef 97, i32 noundef %11) #4
  br label %19

13:                                               ; preds = %9
  %14 = tail call ptr @get_NULL_desc() #4
  %15 = getelementptr inbounds i8, ptr %2, i64 16
  %16 = tail call i32 @asn_create_any(ptr noundef %14, ptr noundef nonnull %6, ptr noundef nonnull %15) #4
  %.not23 = icmp eq i32 %16, 0
  br i1 %.not23, label %18, label %17

17:                                               ; preds = %13
  tail call void @stacktrace_add(ptr noundef nonnull @.str, i64 noundef 98, i32 noundef %16) #4
  br label %19

18:                                               ; preds = %13
  store ptr %2, ptr %0, align 8, !tbaa !5
  br label %19

19:                                               ; preds = %18, %17, %12, %8, %4
  %.016 = phi i32 [ 1, %4 ], [ 1, %8 ], [ %11, %12 ], [ %16, %17 ], [ 0, %18 ]
  %.015 = phi ptr [ null, %4 ], [ %2, %8 ], [ %2, %12 ], [ %2, %17 ], [ null, %18 ]
  %.0 = phi ptr [ null, %4 ], [ null, %8 ], [ %6, %12 ], [ %6, %17 ], [ %6, %18 ]
  %20 = tail call ptr @get_AlgorithmIdentifier_desc() #4
  tail call void @asn_free(ptr noundef %20, ptr noundef %.015) #4
  %21 = tail call ptr @get_NULL_desc() #4
  tail call void @asn_free(ptr noundef %21, ptr noundef %.0) #4
  ret i32 %.016
}

declare ptr @get_NULL_desc() local_unnamed_addr #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 nofree nounwind willreturn allockind("alloc,zeroed") allocsize(0,1) 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 = { 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 #3 = { nounwind allocsize(0,1) }
attributes #4 = { 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/C++ TBAA"}


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