; LLVM IR from openssl/openssl :: crypto/ct (ct_sct_ctx)

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

@.str = external hidden unnamed_addr constant [72 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 @CRYPTO_free(ptr noundef, ptr 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

; Function Attrs: nounwind uwtable
define dso_local i32 @SCT_CTX_set1_cert(ptr noundef %0, ptr noundef %1, ptr noundef %2) #2 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  %15 = alloca i32, align 4
  %16 = alloca i32, align 4
  %17 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  store ptr null, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  store ptr null, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  store ptr null, ptr %10, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  store i32 0, ptr %11, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #3
  store i32 0, ptr %12, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #3
  store i32 -1, ptr %13, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %16) #3
  %18 = load ptr, ptr %6, align 8, !tbaa !5
  %19 = call i32 @ct_x509_get_ext(ptr noundef %18, i32 noundef 952, ptr noundef %14)
  store i32 %19, ptr %16, align 4, !tbaa !9
  %20 = load i32, ptr %14, align 4, !tbaa !9
  %21 = icmp ne i32 %20, 0
  br i1 %21, label %22, label %23

22:                                               ; preds = %3
  br label %102

23:                                               ; preds = %3
  %24 = load i32, ptr %16, align 4, !tbaa !9
  %25 = icmp eq i32 %24, -1
  br i1 %25, label %26, label %37

26:                                               ; preds = %23
  %27 = load ptr, ptr %7, align 8, !tbaa !5
  %28 = icmp ne ptr %27, null
  br i1 %28, label %29, label %30

29:                                               ; preds = %26
  br label %102

30:                                               ; preds = %26
  %31 = load ptr, ptr %6, align 8, !tbaa !5
  %32 = call i32 @i2d_X509(ptr noundef %31, ptr noundef %8)
  store i32 %32, ptr %11, align 4, !tbaa !9
  %33 = load i32, ptr %11, align 4, !tbaa !9
  %34 = icmp slt i32 %33, 0
  br i1 %34, label %35, label %36

35:                                               ; preds = %30
  br label %102

36:                                               ; preds = %30
  br label %37

37:                                               ; preds = %36, %23
  %38 = load ptr, ptr %6, align 8, !tbaa !5
  %39 = call i32 @ct_x509_get_ext(ptr noundef %38, i32 noundef 951, ptr noundef %15)
  store i32 %39, ptr %13, align 4, !tbaa !9
  %40 = load i32, ptr %15, align 4, !tbaa !9
  %41 = icmp ne i32 %40, 0
  br i1 %41, label %42, label %43

42:                                               ; preds = %37
  br label %102

43:                                               ; preds = %37
  %44 = load i32, ptr %13, align 4, !tbaa !9
  %45 = icmp sge i32 %44, 0
  br i1 %45, label %46, label %50

46:                                               ; preds = %43
  %47 = load i32, ptr %16, align 4, !tbaa !9
  %48 = icmp sge i32 %47, 0
  br i1 %48, label %49, label %50

49:                                               ; preds = %46
  br label %102

50:                                               ; preds = %46, %43
  %51 = load i32, ptr %13, align 4, !tbaa !9
  %52 = icmp eq i32 %51, -1
  br i1 %52, label %53, label %55

53:                                               ; preds = %50
  %54 = load i32, ptr %16, align 4, !tbaa !9
  store i32 %54, ptr %13, align 4, !tbaa !9
  br label %55

55:                                               ; preds = %53, %50
  %56 = load i32, ptr %13, align 4, !tbaa !9
  %57 = icmp sge i32 %56, 0
  br i1 %57, label %58, label %80

58:                                               ; preds = %55
  %59 = load ptr, ptr %6, align 8, !tbaa !5
  %60 = call ptr @X509_dup(ptr noundef %59)
  store ptr %60, ptr %10, align 8, !tbaa !5
  %61 = load ptr, ptr %10, align 8, !tbaa !5
  %62 = icmp eq ptr %61, null
  br i1 %62, label %63, label %64

63:                                               ; preds = %58
  br label %102

64:                                               ; preds = %58
  %65 = load ptr, ptr %10, align 8, !tbaa !5
  %66 = load i32, ptr %13, align 4, !tbaa !9
  %67 = call ptr @X509_delete_ext(ptr noundef %65, i32 noundef %66)
  call void @X509_EXTENSION_free(ptr noundef %67)
  %68 = load ptr, ptr %10, align 8, !tbaa !5
  %69 = load ptr, ptr %7, align 8, !tbaa !5
  %70 = call i32 @ct_x509_cert_fixup(ptr noundef %68, ptr noundef %69)
  %71 = icmp ne i32 %70, 0
  br i1 %71, label %73, label %72

72:                                               ; preds = %64
  br label %102

73:                                               ; preds = %64
  %74 = load ptr, ptr %10, align 8, !tbaa !5
  %75 = call i32 @i2d_re_X509_tbs(ptr noundef %74, ptr noundef %9)
  store i32 %75, ptr %12, align 4, !tbaa !9
  %76 = load i32, ptr %12, align 4, !tbaa !9
  %77 = icmp sle i32 %76, 0
  br i1 %77, label %78, label %79

78:                                               ; preds = %73
  br label %102

79:                                               ; preds = %73
  br label %80

80:                                               ; preds = %79, %55
  %81 = load ptr, ptr %10, align 8, !tbaa !5
  call void @X509_free(ptr noundef %81)
  %82 = load ptr, ptr %5, align 8, !tbaa !5
  %83 = getelementptr inbounds %struct.sct_ctx_st, ptr %82, i32 0, i32 5
  %84 = load ptr, ptr %83, align 8, !tbaa !11
  call void @CRYPTO_free(ptr noundef %84, ptr noundef @.str, i32 noundef 185)
  %85 = load ptr, ptr %8, align 8, !tbaa !5
  %86 = load ptr, ptr %5, align 8, !tbaa !5
  %87 = getelementptr inbounds %struct.sct_ctx_st, ptr %86, i32 0, i32 5
  store ptr %85, ptr %87, align 8, !tbaa !11
  %88 = load i32, ptr %11, align 4, !tbaa !9
  %89 = sext i32 %88 to i64
  %90 = load ptr, ptr %5, align 8, !tbaa !5
  %91 = getelementptr inbounds %struct.sct_ctx_st, ptr %90, i32 0, i32 6
  store i64 %89, ptr %91, align 8, !tbaa !14
  %92 = load ptr, ptr %5, align 8, !tbaa !5
  %93 = getelementptr inbounds %struct.sct_ctx_st, ptr %92, i32 0, i32 7
  %94 = load ptr, ptr %93, align 8, !tbaa !15
  call void @CRYPTO_free(ptr noundef %94, ptr noundef @.str, i32 noundef 189)
  %95 = load ptr, ptr %9, align 8, !tbaa !5
  %96 = load ptr, ptr %5, align 8, !tbaa !5
  %97 = getelementptr inbounds %struct.sct_ctx_st, ptr %96, i32 0, i32 7
  store ptr %95, ptr %97, align 8, !tbaa !15
  %98 = load i32, ptr %12, align 4, !tbaa !9
  %99 = sext i32 %98 to i64
  %100 = load ptr, ptr %5, align 8, !tbaa !5
  %101 = getelementptr inbounds %struct.sct_ctx_st, ptr %100, i32 0, i32 8
  store i64 %99, ptr %101, align 8, !tbaa !16
  store i32 1, ptr %4, align 4
  store i32 1, ptr %17, align 4
  br label %106

102:                                              ; preds = %78, %72, %63, %49, %42, %35, %29, %22
  %103 = load ptr, ptr %8, align 8, !tbaa !5
  call void @CRYPTO_free(ptr noundef %103, ptr noundef @.str, i32 noundef 195)
  %104 = load ptr, ptr %9, align 8, !tbaa !5
  call void @CRYPTO_free(ptr noundef %104, ptr noundef @.str, i32 noundef 196)
  %105 = load ptr, ptr %10, align 8, !tbaa !5
  call void @X509_free(ptr noundef %105)
  store i32 0, ptr %4, align 4
  store i32 1, ptr %17, align 4
  br label %106

106:                                              ; preds = %102, %80
  call void @llvm.lifetime.end.p0(i64 4, ptr %16) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  %107 = load i32, ptr %4, align 4
  ret i32 %107
}

; Function Attrs: nounwind uwtable
declare hidden i32 @ct_x509_get_ext(ptr noundef, i32 noundef, ptr noundef) #2

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

declare ptr @X509_dup(ptr noundef) #1

declare void @X509_EXTENSION_free(ptr noundef) #1

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

; Function Attrs: nounwind uwtable
declare hidden i32 @ct_x509_cert_fixup(ptr noundef, ptr noundef) #2

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

declare void @X509_free(ptr 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 = { 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 }

!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}
!11 = !{!12, !6, i64 40}
!12 = !{!"sct_ctx_st", !6, i64 0, !6, i64 8, !13, i64 16, !6, i64 24, !13, i64 32, !6, i64 40, !13, i64 48, !6, i64 56, !13, i64 64, !13, i64 72, !6, i64 80, !6, i64 88}
!13 = !{!"long", !7, i64 0}
!14 = !{!12, !13, i64 48}
!15 = !{!12, !6, i64 56}
!16 = !{!12, !13, i64 64}


; 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 [72 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 void @CRYPTO_free(ptr noundef, ptr 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

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 2) i32 @SCT_CTX_set1_cert(ptr nocapture noundef %0, ptr noundef %1, ptr noundef %2) local_unnamed_addr #2 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %4) #3
  store ptr null, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %5) #3
  store ptr null, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %6) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %7) #3
  %8 = call i32 @ct_x509_get_ext(ptr noundef %1, i32 noundef 952, ptr noundef nonnull %6)
  %9 = load i32, ptr %6, align 4, !tbaa !9
  %.not = icmp eq i32 %9, 0
  br i1 %.not, label %10, label %45

10:                                               ; preds = %3
  %11 = icmp eq i32 %8, -1
  br i1 %11, label %12, label %16

12:                                               ; preds = %10
  %.not39 = icmp eq ptr %2, null
  br i1 %.not39, label %13, label %45

13:                                               ; preds = %12
  %14 = call i32 @i2d_X509(ptr noundef %1, ptr noundef nonnull %4) #3
  %15 = icmp slt i32 %14, 0
  br i1 %15, label %45, label %16

16:                                               ; preds = %13, %10
  %.032 = phi i32 [ %14, %13 ], [ 0, %10 ]
  %17 = call i32 @ct_x509_get_ext(ptr noundef %1, i32 noundef 951, ptr noundef nonnull %7)
  %18 = load i32, ptr %7, align 4, !tbaa !9
  %.not40 = icmp eq i32 %18, 0
  br i1 %.not40, label %19, label %45

19:                                               ; preds = %16
  %20 = icmp sgt i32 %17, -1
  %21 = icmp sgt i32 %8, -1
  %or.cond = select i1 %20, i1 %21, i1 false
  br i1 %or.cond, label %45, label %22

22:                                               ; preds = %19
  %23 = icmp eq i32 %17, -1
  %spec.select = select i1 %23, i32 %8, i32 %17
  %24 = icmp sgt i32 %spec.select, -1
  br i1 %24, label %25, label %34

25:                                               ; preds = %22
  %26 = call ptr @X509_dup(ptr noundef %1) #3
  %27 = icmp eq ptr %26, null
  br i1 %27, label %45, label %28

28:                                               ; preds = %25
  %29 = call ptr @X509_delete_ext(ptr noundef nonnull %26, i32 noundef %spec.select) #3
  call void @X509_EXTENSION_free(ptr noundef %29) #3
  %30 = call i32 @ct_x509_cert_fixup(ptr noundef nonnull %26, ptr noundef %2)
  %.not41 = icmp eq i32 %30, 0
  br i1 %.not41, label %45, label %31

31:                                               ; preds = %28
  %32 = call i32 @i2d_re_X509_tbs(ptr noundef nonnull %26, ptr noundef nonnull %5) #3
  %33 = icmp slt i32 %32, 1
  br i1 %33, label %45, label %34

34:                                               ; preds = %31, %22
  %.033 = phi ptr [ %26, %31 ], [ null, %22 ]
  %.031 = phi i32 [ %32, %31 ], [ 0, %22 ]
  call void @X509_free(ptr noundef %.033) #3
  %35 = getelementptr inbounds i8, ptr %0, i64 40
  %36 = load ptr, ptr %35, align 8, !tbaa !11
  call void @CRYPTO_free(ptr noundef %36, ptr noundef nonnull @.str, i32 noundef 185) #3
  %37 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %37, ptr %35, align 8, !tbaa !11
  %38 = zext nneg i32 %.032 to i64
  %39 = getelementptr inbounds i8, ptr %0, i64 48
  store i64 %38, ptr %39, align 8, !tbaa !14
  %40 = getelementptr inbounds i8, ptr %0, i64 56
  %41 = load ptr, ptr %40, align 8, !tbaa !15
  call void @CRYPTO_free(ptr noundef %41, ptr noundef nonnull @.str, i32 noundef 189) #3
  %42 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %42, ptr %40, align 8, !tbaa !15
  %43 = zext nneg i32 %.031 to i64
  %44 = getelementptr inbounds i8, ptr %0, i64 64
  store i64 %43, ptr %44, align 8, !tbaa !16
  br label %48

45:                                               ; preds = %31, %28, %25, %19, %16, %13, %12, %3
  %.1 = phi ptr [ null, %3 ], [ null, %12 ], [ null, %13 ], [ null, %16 ], [ null, %19 ], [ null, %25 ], [ %26, %31 ], [ %26, %28 ]
  %46 = load ptr, ptr %4, align 8, !tbaa !5
  call void @CRYPTO_free(ptr noundef %46, ptr noundef nonnull @.str, i32 noundef 195) #3
  %47 = load ptr, ptr %5, align 8, !tbaa !5
  call void @CRYPTO_free(ptr noundef %47, ptr noundef nonnull @.str, i32 noundef 196) #3
  call void @X509_free(ptr noundef %.1) #3
  br label %48

48:                                               ; preds = %45, %34
  %.0 = phi i32 [ 0, %45 ], [ 1, %34 ]
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %7) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %5) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #3
  ret i32 %.0
}

; Function Attrs: nounwind uwtable
declare hidden i32 @ct_x509_get_ext(ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #2

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

declare ptr @X509_dup(ptr noundef) local_unnamed_addr #1

declare void @X509_EXTENSION_free(ptr noundef) local_unnamed_addr #1

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

; Function Attrs: nounwind uwtable
declare hidden i32 @ct_x509_cert_fixup(ptr noundef, ptr noundef) local_unnamed_addr #2

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

declare void @X509_free(ptr 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 = { 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 }

!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}
!11 = !{!12, !6, i64 40}
!12 = !{!"sct_ctx_st", !6, i64 0, !6, i64 8, !13, i64 16, !6, i64 24, !13, i64 32, !6, i64 40, !13, i64 48, !6, i64 56, !13, i64 64, !13, i64 72, !6, i64 80, !6, i64 88}
!13 = !{!"long", !7, i64 0}
!14 = !{!12, !13, i64 48}
!15 = !{!12, !6, i64 56}
!16 = !{!12, !13, i64 64}


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