; LLVM IR from tleonhardt/practical_cryptography_engineering :: mbedtls (x509_crt)

; 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.mbedtls_x509_crl = type { %struct.mbedtls_asn1_buf, %struct.mbedtls_asn1_buf, i32, %struct.mbedtls_asn1_buf, %struct.mbedtls_asn1_buf, %struct.mbedtls_asn1_named_data, %struct.mbedtls_x509_time, %struct.mbedtls_x509_time, %struct.mbedtls_x509_crl_entry, %struct.mbedtls_asn1_buf, %struct.mbedtls_asn1_buf, %struct.mbedtls_asn1_buf, i32, i32, ptr, ptr }
%struct.mbedtls_asn1_named_data = type { %struct.mbedtls_asn1_buf, %struct.mbedtls_asn1_buf, ptr, i8 }
%struct.mbedtls_x509_time = type { i32, i32, i32, i32, i32, i32 }
%struct.mbedtls_x509_crl_entry = type { %struct.mbedtls_asn1_buf, %struct.mbedtls_asn1_buf, %struct.mbedtls_x509_time, %struct.mbedtls_asn1_buf, ptr }
%struct.mbedtls_asn1_buf = type { i32, i64, ptr }
%struct.mbedtls_x509_crt = type { %struct.mbedtls_asn1_buf, %struct.mbedtls_asn1_buf, i32, %struct.mbedtls_asn1_buf, %struct.mbedtls_asn1_buf, %struct.mbedtls_asn1_buf, %struct.mbedtls_asn1_buf, %struct.mbedtls_asn1_named_data, %struct.mbedtls_asn1_named_data, %struct.mbedtls_x509_time, %struct.mbedtls_x509_time, %struct.mbedtls_pk_context, %struct.mbedtls_asn1_buf, %struct.mbedtls_asn1_buf, %struct.mbedtls_asn1_buf, %struct.mbedtls_asn1_sequence, i32, i32, i32, i32, %struct.mbedtls_asn1_sequence, i8, %struct.mbedtls_asn1_buf, i32, i32, ptr, ptr }
%struct.mbedtls_pk_context = type { ptr, ptr }
%struct.mbedtls_asn1_sequence = type { %struct.mbedtls_asn1_buf, ptr }

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

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

; Function Attrs: nounwind willreturn memory(read)
declare i32 @memcmp(ptr noundef, ptr noundef, i64 noundef) #1

; Function Attrs: nounwind uwtable
define dso_local i32 @mbedtls_x509_crt_is_revoked(ptr noundef %0, ptr noundef %1) #2 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  %8 = load ptr, ptr %5, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct.mbedtls_x509_crl, ptr %8, i32 0, i32 8
  store ptr %9, ptr %6, align 8, !tbaa !5
  br label %10

10:                                               ; preds = %53, %2
  %11 = load ptr, ptr %6, align 8, !tbaa !5
  %12 = icmp ne ptr %11, null
  br i1 %12, label %13, label %19

13:                                               ; preds = %10
  %14 = load ptr, ptr %6, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.mbedtls_x509_crl_entry, ptr %14, i32 0, i32 1
  %16 = getelementptr inbounds %struct.mbedtls_asn1_buf, ptr %15, i32 0, i32 1
  %17 = load i64, ptr %16, align 8, !tbaa !9
  %18 = icmp ne i64 %17, 0
  br label %19

19:                                               ; preds = %13, %10
  %20 = phi i1 [ false, %10 ], [ %18, %13 ]
  br i1 %20, label %21, label %57

21:                                               ; preds = %19
  %22 = load ptr, ptr %4, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.mbedtls_x509_crt, ptr %22, i32 0, i32 3
  %24 = getelementptr inbounds %struct.mbedtls_asn1_buf, ptr %23, i32 0, i32 1
  %25 = load i64, ptr %24, align 8, !tbaa !15
  %26 = load ptr, ptr %6, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.mbedtls_x509_crl_entry, ptr %26, i32 0, i32 1
  %28 = getelementptr inbounds %struct.mbedtls_asn1_buf, ptr %27, i32 0, i32 1
  %29 = load i64, ptr %28, align 8, !tbaa !9
  %30 = icmp eq i64 %25, %29
  br i1 %30, label %31, label %53

31:                                               ; preds = %21
  %32 = load ptr, ptr %4, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.mbedtls_x509_crt, ptr %32, i32 0, i32 3
  %34 = getelementptr inbounds %struct.mbedtls_asn1_buf, ptr %33, i32 0, i32 2
  %35 = load ptr, ptr %34, align 8, !tbaa !20
  %36 = load ptr, ptr %6, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.mbedtls_x509_crl_entry, ptr %36, i32 0, i32 1
  %38 = getelementptr inbounds %struct.mbedtls_asn1_buf, ptr %37, i32 0, i32 2
  %39 = load ptr, ptr %38, align 8, !tbaa !21
  %40 = load ptr, ptr %4, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.mbedtls_x509_crt, ptr %40, i32 0, i32 3
  %42 = getelementptr inbounds %struct.mbedtls_asn1_buf, ptr %41, i32 0, i32 1
  %43 = load i64, ptr %42, align 8, !tbaa !15
  %44 = call i32 @memcmp(ptr noundef %35, ptr noundef %39, i64 noundef %43) #5
  %45 = icmp eq i32 %44, 0
  br i1 %45, label %46, label %53

46:                                               ; preds = %31
  %47 = load ptr, ptr %6, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.mbedtls_x509_crl_entry, ptr %47, i32 0, i32 2
  %49 = call i32 @mbedtls_x509_time_is_past(ptr noundef %48)
  %50 = icmp ne i32 %49, 0
  br i1 %50, label %51, label %52

51:                                               ; preds = %46
  store i32 1, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %58

52:                                               ; preds = %46
  br label %53

53:                                               ; preds = %52, %31, %21
  %54 = load ptr, ptr %6, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.mbedtls_x509_crl_entry, ptr %54, i32 0, i32 4
  %56 = load ptr, ptr %55, align 8, !tbaa !22
  store ptr %56, ptr %6, align 8, !tbaa !5
  br label %10, !llvm.loop !23

57:                                               ; preds = %19
  store i32 0, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %58

58:                                               ; preds = %57, %51
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  %59 = load i32, ptr %3, align 4
  ret i32 %59
}

declare i32 @mbedtls_x509_time_is_past(ptr noundef) #3

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

!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, !13, i64 32}
!10 = !{!"mbedtls_x509_crl_entry", !11, i64 0, !11, i64 24, !14, i64 48, !11, i64 72, !6, i64 96}
!11 = !{!"mbedtls_asn1_buf", !12, i64 0, !13, i64 8, !6, i64 16}
!12 = !{!"int", !7, i64 0}
!13 = !{!"long", !7, i64 0}
!14 = !{!"mbedtls_x509_time", !12, i64 0, !12, i64 4, !12, i64 8, !12, i64 12, !12, i64 16, !12, i64 20}
!15 = !{!16, !13, i64 64}
!16 = !{!"mbedtls_x509_crt", !11, i64 0, !11, i64 24, !12, i64 48, !11, i64 56, !11, i64 80, !11, i64 104, !11, i64 128, !17, i64 152, !17, i64 216, !14, i64 280, !14, i64 304, !18, i64 328, !11, i64 344, !11, i64 368, !11, i64 392, !19, i64 416, !12, i64 448, !12, i64 452, !12, i64 456, !12, i64 460, !19, i64 464, !7, i64 496, !11, i64 504, !12, i64 528, !12, i64 532, !6, i64 536, !6, i64 544}
!17 = !{!"mbedtls_asn1_named_data", !11, i64 0, !11, i64 24, !6, i64 48, !7, i64 56}
!18 = !{!"", !6, i64 0, !6, i64 8}
!19 = !{!"mbedtls_asn1_sequence", !11, i64 0, !6, i64 24}
!20 = !{!16, !6, i64 72}
!21 = !{!10, !6, i64 40}
!22 = !{!10, !6, i64 96}
!23 = distinct !{!23, !24}
!24 = !{!"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
define dso_local range(i32 0, 2) i32 @mbedtls_x509_crt_is_revoked(ptr nocapture noundef readonly %0, ptr noundef %1) local_unnamed_addr #0 {
  %3 = getelementptr inbounds i8, ptr %1, i64 216
  %4 = getelementptr inbounds i8, ptr %0, i64 64
  %5 = getelementptr inbounds i8, ptr %0, i64 72
  br label %6

6:                                                ; preds = %2, %20
  %.015 = phi ptr [ %3, %2 ], [ %22, %20 ]
  %7 = getelementptr inbounds i8, ptr %.015, i64 32
  %8 = load i64, ptr %7, align 8, !tbaa !5
  %.not13 = icmp eq i64 %8, 0
  br i1 %.not13, label %.critedge, label %9

9:                                                ; preds = %6
  %10 = load i64, ptr %4, align 8, !tbaa !14
  %11 = icmp eq i64 %10, %8
  br i1 %11, label %12, label %20

12:                                               ; preds = %9
  %13 = load ptr, ptr %5, align 8, !tbaa !19
  %14 = getelementptr inbounds i8, ptr %.015, i64 40
  %15 = load ptr, ptr %14, align 8, !tbaa !20
  %bcmp = tail call i32 @bcmp(ptr %13, ptr %15, i64 %8)
  %16 = icmp eq i32 %bcmp, 0
  br i1 %16, label %17, label %20

17:                                               ; preds = %12
  %18 = getelementptr inbounds i8, ptr %.015, i64 48
  %19 = tail call i32 @mbedtls_x509_time_is_past(ptr noundef nonnull %18) #3
  %.not14 = icmp eq i32 %19, 0
  br i1 %.not14, label %20, label %.critedge

20:                                               ; preds = %17, %12, %9
  %21 = getelementptr inbounds i8, ptr %.015, i64 96
  %22 = load ptr, ptr %21, align 8, !tbaa !21
  %.not = icmp eq ptr %22, null
  br i1 %.not, label %.critedge, label %6, !llvm.loop !22

.critedge:                                        ; preds = %6, %20, %17
  %.010 = phi i32 [ 1, %17 ], [ 0, %20 ], [ 0, %6 ]
  ret i32 %.010
}

declare i32 @mbedtls_x509_time_is_past(ptr noundef) local_unnamed_addr #1

; Function Attrs: nofree nounwind willreturn memory(argmem: read)
declare i32 @bcmp(ptr nocapture, ptr nocapture, i64) local_unnamed_addr #2

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 = { "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 = { nofree nounwind willreturn memory(argmem: read) }
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, !11, i64 32}
!6 = !{!"mbedtls_x509_crl_entry", !7, i64 0, !7, i64 24, !13, i64 48, !7, i64 72, !12, i64 96}
!7 = !{!"mbedtls_asn1_buf", !8, i64 0, !11, i64 8, !12, i64 16}
!8 = !{!"int", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C/C++ TBAA"}
!11 = !{!"long", !9, i64 0}
!12 = !{!"any pointer", !9, i64 0}
!13 = !{!"mbedtls_x509_time", !8, i64 0, !8, i64 4, !8, i64 8, !8, i64 12, !8, i64 16, !8, i64 20}
!14 = !{!15, !11, i64 64}
!15 = !{!"mbedtls_x509_crt", !7, i64 0, !7, i64 24, !8, i64 48, !7, i64 56, !7, i64 80, !7, i64 104, !7, i64 128, !16, i64 152, !16, i64 216, !13, i64 280, !13, i64 304, !17, i64 328, !7, i64 344, !7, i64 368, !7, i64 392, !18, i64 416, !8, i64 448, !8, i64 452, !8, i64 456, !8, i64 460, !18, i64 464, !9, i64 496, !7, i64 504, !8, i64 528, !8, i64 532, !12, i64 536, !12, i64 544}
!16 = !{!"mbedtls_asn1_named_data", !7, i64 0, !7, i64 24, !12, i64 48, !9, i64 56}
!17 = !{!"", !12, i64 0, !12, i64 8}
!18 = !{!"mbedtls_asn1_sequence", !7, i64 0, !12, i64 24}
!19 = !{!15, !12, i64 72}
!20 = !{!6, !12, i64 40}
!21 = !{!6, !12, i64 96}
!22 = distinct !{!22, !23}
!23 = !{!"llvm.loop.mustprogress"}


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