; LLVM IR from openssl/openssl :: crypto/asn1 (tasn_fre)

; 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.ASN1_TEMPLATE_st = type { i64, i64, i64, ptr, ptr }

; Function Attrs: nounwind uwtable
declare dso_local void @ossl_asn1_item_embed_free(ptr noundef, ptr noundef, i32 noundef) #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 uwtable
define dso_local void @ossl_asn1_template_free(ptr noundef %0, ptr noundef %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  %10 = load ptr, ptr %4, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.ASN1_TEMPLATE_st, ptr %10, i32 0, i32 0
  %12 = load i64, ptr %11, align 8, !tbaa !9
  %13 = and i64 %12, 4096
  %14 = trunc i64 %13 to i32
  store i32 %14, ptr %5, align 4, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  %15 = load i32, ptr %5, align 4, !tbaa !12
  %16 = icmp ne i32 %15, 0
  br i1 %16, label %17, label %19

17:                                               ; preds = %2
  %18 = load ptr, ptr %3, align 8, !tbaa !5
  store ptr %18, ptr %6, align 8, !tbaa !5
  store ptr %6, ptr %3, align 8, !tbaa !5
  br label %19

19:                                               ; preds = %17, %2
  %20 = load ptr, ptr %4, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.ASN1_TEMPLATE_st, ptr %20, i32 0, i32 0
  %22 = load i64, ptr %21, align 8, !tbaa !9
  %23 = and i64 %22, 6
  %24 = icmp ne i64 %23, 0
  br i1 %24, label %25, label %51

25:                                               ; preds = %19
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  %26 = load ptr, ptr %3, align 8, !tbaa !5
  %27 = load ptr, ptr %26, align 8, !tbaa !5
  store ptr %27, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  store i32 0, ptr %8, align 4, !tbaa !12
  br label %28

28:                                               ; preds = %44, %25
  %29 = load i32, ptr %8, align 4, !tbaa !12
  %30 = load ptr, ptr %7, align 8, !tbaa !5
  %31 = call ptr @ossl_check_const_ASN1_VALUE_sk_type(ptr noundef %30)
  %32 = call i32 @OPENSSL_sk_num(ptr noundef %31)
  %33 = icmp slt i32 %29, %32
  br i1 %33, label %34, label %47

34:                                               ; preds = %28
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  %35 = load ptr, ptr %7, align 8, !tbaa !5
  %36 = call ptr @ossl_check_const_ASN1_VALUE_sk_type(ptr noundef %35)
  %37 = load i32, ptr %8, align 4, !tbaa !12
  %38 = call ptr @OPENSSL_sk_value(ptr noundef %36, i32 noundef %37)
  store ptr %38, ptr %9, align 8, !tbaa !5
  %39 = load ptr, ptr %4, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.ASN1_TEMPLATE_st, ptr %39, i32 0, i32 4
  %41 = load ptr, ptr %40, align 8, !tbaa !14
  %42 = call ptr %41()
  %43 = load i32, ptr %5, align 4, !tbaa !12
  call void @ossl_asn1_item_embed_free(ptr noundef %9, ptr noundef %42, i32 noundef %43)
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  br label %44

44:                                               ; preds = %34
  %45 = load i32, ptr %8, align 4, !tbaa !12
  %46 = add nsw i32 %45, 1
  store i32 %46, ptr %8, align 4, !tbaa !12
  br label %28, !llvm.loop !15

47:                                               ; preds = %28
  %48 = load ptr, ptr %7, align 8, !tbaa !5
  %49 = call ptr @ossl_check_ASN1_VALUE_sk_type(ptr noundef %48)
  call void @OPENSSL_sk_free(ptr noundef %49)
  %50 = load ptr, ptr %3, align 8, !tbaa !5
  store ptr null, ptr %50, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  br label %58

51:                                               ; preds = %19
  %52 = load ptr, ptr %3, align 8, !tbaa !5
  %53 = load ptr, ptr %4, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.ASN1_TEMPLATE_st, ptr %53, i32 0, i32 4
  %55 = load ptr, ptr %54, align 8, !tbaa !14
  %56 = call ptr %55()
  %57 = load i32, ptr %5, align 4, !tbaa !12
  call void @ossl_asn1_item_embed_free(ptr noundef %52, ptr noundef %56, i32 noundef %57)
  br label %58

58:                                               ; preds = %51, %47
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  ret void
}

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

declare i32 @OPENSSL_sk_num(ptr noundef) #2

; Function Attrs: inlinehint nounwind uwtable
declare hidden ptr @ossl_check_const_ASN1_VALUE_sk_type(ptr noundef) #3

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

declare void @OPENSSL_sk_free(ptr noundef) #2

; Function Attrs: inlinehint nounwind uwtable
declare hidden ptr @ossl_check_ASN1_VALUE_sk_type(ptr noundef) #3

attributes #0 = { 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 #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 = { inlinehint 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 }

!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, !11, i64 0}
!10 = !{!"ASN1_TEMPLATE_st", !11, i64 0, !11, i64 8, !11, i64 16, !6, i64 24, !6, i64 32}
!11 = !{!"long", !7, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"int", !7, i64 0}
!14 = !{!10, !6, i64 32}
!15 = distinct !{!15, !16}
!16 = !{!"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"

; Function Attrs: nounwind uwtable
declare dso_local void @ossl_asn1_item_embed_free(ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #0

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

; Function Attrs: nounwind uwtable
define dso_local void @ossl_asn1_template_free(ptr noundef %0, ptr nocapture noundef readonly %1) local_unnamed_addr #0 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = load i64, ptr %1, align 8, !tbaa !5
  %6 = trunc i64 %5 to i32
  %7 = and i32 %6, 4096
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #4
  %.not = icmp eq i32 %7, 0
  br i1 %.not, label %9, label %8

8:                                                ; preds = %2
  store ptr %0, ptr %3, align 8, !tbaa !11
  br label %9

9:                                                ; preds = %8, %2
  %.016 = phi ptr [ %3, %8 ], [ %0, %2 ]
  %10 = and i64 %5, 6
  %.not17 = icmp eq i64 %10, 0
  br i1 %.not17, label %27, label %11

11:                                               ; preds = %9
  %12 = load ptr, ptr %.016, align 8, !tbaa !11
  %13 = tail call ptr @ossl_check_const_ASN1_VALUE_sk_type(ptr noundef %12)
  %14 = tail call i32 @OPENSSL_sk_num(ptr noundef %13) #4
  %15 = icmp sgt i32 %14, 0
  br i1 %15, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %11
  %16 = getelementptr inbounds i8, ptr %1, i64 32
  br label %17

17:                                               ; preds = %.lr.ph, %17
  %.018 = phi i32 [ 0, %.lr.ph ], [ %22, %17 ]
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %4) #4
  %18 = call ptr @ossl_check_const_ASN1_VALUE_sk_type(ptr noundef %12)
  %19 = call ptr @OPENSSL_sk_value(ptr noundef %18, i32 noundef %.018) #4
  store ptr %19, ptr %4, align 8, !tbaa !11
  %20 = load ptr, ptr %16, align 8, !tbaa !12
  %21 = call ptr %20() #4
  call void @ossl_asn1_item_embed_free(ptr noundef nonnull %4, ptr noundef %21, i32 noundef %7)
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #4
  %22 = add nuw nsw i32 %.018, 1
  %23 = call ptr @ossl_check_const_ASN1_VALUE_sk_type(ptr noundef %12)
  %24 = call i32 @OPENSSL_sk_num(ptr noundef %23) #4
  %25 = icmp slt i32 %22, %24
  br i1 %25, label %17, label %._crit_edge, !llvm.loop !13

._crit_edge:                                      ; preds = %17, %11
  %26 = call ptr @ossl_check_ASN1_VALUE_sk_type(ptr noundef %12)
  call void @OPENSSL_sk_free(ptr noundef %26) #4
  store ptr null, ptr %.016, align 8, !tbaa !11
  br label %31

27:                                               ; preds = %9
  %28 = getelementptr inbounds i8, ptr %1, i64 32
  %29 = load ptr, ptr %28, align 8, !tbaa !12
  %30 = tail call ptr %29() #4
  call void @ossl_asn1_item_embed_free(ptr noundef %.016, ptr noundef %30, i32 noundef %7)
  br label %31

31:                                               ; preds = %27, %._crit_edge
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #4
  ret void
}

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

declare i32 @OPENSSL_sk_num(ptr noundef) local_unnamed_addr #2

; Function Attrs: inlinehint nounwind uwtable
declare hidden ptr @ossl_check_const_ASN1_VALUE_sk_type(ptr noundef) local_unnamed_addr #3

declare ptr @OPENSSL_sk_value(ptr noundef, i32 noundef) local_unnamed_addr #2

declare void @OPENSSL_sk_free(ptr noundef) local_unnamed_addr #2

; Function Attrs: inlinehint nounwind uwtable
declare hidden ptr @ossl_check_ASN1_VALUE_sk_type(ptr noundef) local_unnamed_addr #3

attributes #0 = { 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 #1 = { mustprogress 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 = { inlinehint 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 }

!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 = !{!"ASN1_TEMPLATE_st", !7, i64 0, !7, i64 8, !7, i64 16, !10, i64 24, !10, i64 32}
!7 = !{!"long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!10, !10, i64 0}
!12 = !{!6, !10, i64 32}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}


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