; LLVM IR from PacktPublishing/Demystifying-Cryptography-with-OpenSSL-3 :: Chapter10 (crl-check)

; 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"

@.str.16 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.24 = external hidden unnamed_addr constant [91 x i8], align 1
@.str.25 = external hidden unnamed_addr constant [24 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

; Function Attrs: nounwind
declare i32 @fprintf(ptr noundef, ptr 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 @verify_callback(i32 noundef %0, ptr noundef %1) #2 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca ptr, align 8
  %14 = alloca ptr, align 8
  %15 = alloca ptr, align 8
  %16 = alloca i64, align 8
  %17 = alloca i32, align 4
  store i32 %0, ptr %4, align 4, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  %18 = call i32 @SSL_get_ex_data_X509_STORE_CTX_idx()
  store i32 %18, ptr %6, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  %19 = load ptr, ptr %5, align 8, !tbaa !9
  %20 = load i32, ptr %6, align 4, !tbaa !5
  %21 = call ptr @X509_STORE_CTX_get_ex_data(ptr noundef %19, i32 noundef %20)
  store ptr %21, ptr %7, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  %22 = load ptr, ptr %7, align 8, !tbaa !9
  %23 = call ptr @SSL_get_ex_data(ptr noundef %22, i32 noundef 0)
  store ptr %23, ptr %8, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  %24 = load ptr, ptr %5, align 8, !tbaa !9
  %25 = call i32 @X509_STORE_CTX_get_error_depth(ptr noundef %24)
  store i32 %25, ptr %9, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #4
  %26 = load i32, ptr %4, align 4, !tbaa !5
  %27 = icmp ne i32 %26, 0
  br i1 %27, label %28, label %29

28:                                               ; preds = %2
  br label %32

29:                                               ; preds = %2
  %30 = load ptr, ptr %5, align 8, !tbaa !9
  %31 = call i32 @X509_STORE_CTX_get_error(ptr noundef %30)
  br label %32

32:                                               ; preds = %29, %28
  %33 = phi i32 [ 0, %28 ], [ %31, %29 ]
  store i32 %33, ptr %10, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  %34 = load i32, ptr %10, align 4, !tbaa !5
  %35 = sext i32 %34 to i64
  %36 = call ptr @X509_verify_cert_error_string(i64 noundef %35)
  store ptr %36, ptr %11, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #4
  %37 = load ptr, ptr %5, align 8, !tbaa !9
  %38 = call ptr @X509_STORE_CTX_get_current_cert(ptr noundef %37)
  store ptr %38, ptr %12, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #4
  %39 = load ptr, ptr %12, align 8, !tbaa !9
  %40 = call ptr @X509_get_subject_name(ptr noundef %39)
  store ptr %40, ptr %13, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #4
  %41 = call ptr @BIO_s_mem()
  %42 = call ptr @BIO_new(ptr noundef %41)
  store ptr %42, ptr %14, align 8, !tbaa !9
  %43 = load ptr, ptr %14, align 8, !tbaa !9
  %44 = load ptr, ptr %13, align 8, !tbaa !9
  %45 = call i32 @X509_NAME_print_ex(ptr noundef %43, ptr noundef %44, i32 noundef 0, i64 noundef 8520475)
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #4
  store ptr null, ptr %15, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #4
  %46 = load ptr, ptr %14, align 8, !tbaa !9
  %47 = call i64 @BIO_ctrl(ptr noundef %46, i32 noundef 3, i64 noundef 0, ptr noundef %15)
  store i64 %47, ptr %16, align 8, !tbaa !11
  %48 = load ptr, ptr %8, align 8, !tbaa !9
  %49 = load i32, ptr %9, align 4, !tbaa !5
  %50 = load i32, ptr %4, align 4, !tbaa !5
  %51 = load i32, ptr %10, align 4, !tbaa !5
  %52 = load ptr, ptr %11, align 8, !tbaa !9
  %53 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %48, ptr noundef @.str.24, i32 noundef %49, i32 noundef %50, i32 noundef %51, ptr noundef %52) #4
  %54 = load ptr, ptr %8, align 8, !tbaa !9
  %55 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %54, ptr noundef @.str.25) #4
  %56 = load ptr, ptr %15, align 8, !tbaa !9
  %57 = load i64, ptr %16, align 8, !tbaa !11
  %58 = load ptr, ptr %8, align 8, !tbaa !9
  %59 = call i64 @fwrite(ptr noundef %56, i64 noundef 1, i64 noundef %57, ptr noundef %58)
  %60 = load ptr, ptr %8, align 8, !tbaa !9
  %61 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %60, ptr noundef @.str.16) #4
  %62 = load ptr, ptr %14, align 8, !tbaa !9
  %63 = call i32 @BIO_free(ptr noundef %62)
  %64 = load i32, ptr %10, align 4, !tbaa !5
  %65 = icmp eq i32 %64, 3
  br i1 %65, label %66, label %67

66:                                               ; preds = %32
  store i32 1, ptr %3, align 4
  store i32 1, ptr %17, align 4
  br label %69

67:                                               ; preds = %32
  %68 = load i32, ptr %4, align 4, !tbaa !5
  store i32 %68, ptr %3, align 4
  store i32 1, ptr %17, align 4
  br label %69

69:                                               ; preds = %67, %66
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  %70 = load i32, ptr %3, align 4
  ret i32 %70
}

declare i64 @BIO_ctrl(ptr noundef, i32 noundef, i64 noundef, ptr noundef) #3

declare i32 @SSL_get_ex_data_X509_STORE_CTX_idx() #3

declare ptr @X509_STORE_CTX_get_ex_data(ptr noundef, i32 noundef) #3

declare ptr @SSL_get_ex_data(ptr noundef, i32 noundef) #3

declare ptr @X509_STORE_CTX_get_current_cert(ptr noundef) #3

declare i32 @X509_STORE_CTX_get_error_depth(ptr noundef) #3

declare ptr @X509_get_subject_name(ptr noundef) #3

declare i32 @BIO_free(ptr noundef) #3

declare i32 @X509_STORE_CTX_get_error(ptr noundef) #3

declare ptr @X509_verify_cert_error_string(i64 noundef) #3

declare ptr @BIO_new(ptr noundef) #3

declare ptr @BIO_s_mem() #3

declare i32 @X509_NAME_print_ex(ptr noundef, ptr noundef, i32 noundef, i64 noundef) #3

declare i64 @fwrite(ptr noundef, i64 noundef, i64 noundef, ptr noundef) #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nounwind "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 = { "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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"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.16 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.24 = external hidden unnamed_addr constant [91 x i8], align 1
@.str.25 = external hidden unnamed_addr constant [24 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

; Function Attrs: nofree nounwind
declare noundef i32 @fprintf(ptr nocapture noundef, ptr nocapture noundef readonly, ...) 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 noundef i32 @verify_callback(i32 noundef %0, ptr noundef %1) local_unnamed_addr #2 {
  %3 = alloca ptr, align 8
  %4 = tail call i32 @SSL_get_ex_data_X509_STORE_CTX_idx() #4
  %5 = tail call ptr @X509_STORE_CTX_get_ex_data(ptr noundef %1, i32 noundef %4) #4
  %6 = tail call ptr @SSL_get_ex_data(ptr noundef %5, i32 noundef 0) #4
  %7 = tail call i32 @X509_STORE_CTX_get_error_depth(ptr noundef %1) #4
  %.not = icmp eq i32 %0, 0
  br i1 %.not, label %8, label %11

8:                                                ; preds = %2
  %9 = tail call i32 @X509_STORE_CTX_get_error(ptr noundef %1) #4
  %10 = freeze i32 %9
  br label %11

11:                                               ; preds = %2, %8
  %.fr = phi i32 [ %10, %8 ], [ 0, %2 ]
  %12 = sext i32 %.fr to i64
  %13 = tail call ptr @X509_verify_cert_error_string(i64 noundef %12) #4
  %14 = tail call ptr @X509_STORE_CTX_get_current_cert(ptr noundef %1) #4
  %15 = tail call ptr @X509_get_subject_name(ptr noundef %14) #4
  %16 = tail call ptr @BIO_s_mem() #4
  %17 = tail call ptr @BIO_new(ptr noundef %16) #4
  %18 = tail call i32 @X509_NAME_print_ex(ptr noundef %17, ptr noundef %15, i32 noundef 0, i64 noundef 8520475) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #4
  store ptr null, ptr %3, align 8, !tbaa !5
  %19 = call i64 @BIO_ctrl(ptr noundef %17, i32 noundef 3, i64 noundef 0, ptr noundef nonnull %3) #4
  %20 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %6, ptr noundef nonnull @.str.24, i32 noundef %7, i32 noundef %0, i32 noundef %.fr, ptr noundef %13) #4
  %21 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %6, ptr noundef nonnull @.str.25) #4
  %22 = load ptr, ptr %3, align 8, !tbaa !5
  %23 = call i64 @fwrite(ptr noundef %22, i64 noundef 1, i64 noundef %19, ptr noundef %6)
  %24 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %6, ptr noundef nonnull @.str.16) #4
  %25 = call i32 @BIO_free(ptr noundef %17) #4
  %26 = icmp eq i32 %.fr, 3
  %spec.select = select i1 %26, i32 1, i32 %0
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #4
  ret i32 %spec.select
}

declare i64 @BIO_ctrl(ptr noundef, i32 noundef, i64 noundef, ptr noundef) local_unnamed_addr #3

declare i32 @SSL_get_ex_data_X509_STORE_CTX_idx() local_unnamed_addr #3

declare ptr @X509_STORE_CTX_get_ex_data(ptr noundef, i32 noundef) local_unnamed_addr #3

declare ptr @SSL_get_ex_data(ptr noundef, i32 noundef) local_unnamed_addr #3

declare ptr @X509_STORE_CTX_get_current_cert(ptr noundef) local_unnamed_addr #3

declare i32 @X509_STORE_CTX_get_error_depth(ptr noundef) local_unnamed_addr #3

declare ptr @X509_get_subject_name(ptr noundef) local_unnamed_addr #3

declare i32 @BIO_free(ptr noundef) local_unnamed_addr #3

declare i32 @X509_STORE_CTX_get_error(ptr noundef) local_unnamed_addr #3

declare ptr @X509_verify_cert_error_string(i64 noundef) local_unnamed_addr #3

declare ptr @BIO_new(ptr noundef) local_unnamed_addr #3

declare ptr @BIO_s_mem() local_unnamed_addr #3

declare i32 @X509_NAME_print_ex(ptr noundef, ptr noundef, i32 noundef, i64 noundef) local_unnamed_addr #3

; Function Attrs: nofree nounwind
declare noundef i64 @fwrite(ptr nocapture noundef, i64 noundef, i64 noundef, ptr nocapture noundef) local_unnamed_addr #1

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nofree nounwind "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 = { "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"}


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