; LLVM IR from guanzhi/GmSSL :: src (tls13)

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

@stderr = external global ptr, align 8
@.str = external hidden unnamed_addr constant [13 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [59 x i8], align 1
@__FUNCTION__.tls13_process_certificate_list = external hidden unnamed_addr constant [31 x i8], align 1

; Function Attrs: nounwind
declare i32 @fprintf(ptr noundef, ptr 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: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

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

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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @tls13_process_certificate_list(ptr noundef %0, i64 noundef %1, ptr noundef %2, ptr noundef %3) #3 {
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca i64, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i64, align 8
  %12 = alloca ptr, align 8
  %13 = alloca i64, align 8
  %14 = alloca ptr, align 8
  %15 = alloca i64, align 8
  %16 = alloca i32, align 4
  %17 = alloca i32, align 4
  %18 = alloca ptr, align 8
  %19 = alloca i64, align 8
  store ptr %0, ptr %6, align 8, !tbaa !5
  store i64 %1, ptr %7, align 8, !tbaa !9
  store ptr %2, ptr %8, align 8, !tbaa !5
  store ptr %3, ptr %9, align 8, !tbaa !5
  %20 = load ptr, ptr %9, align 8, !tbaa !5
  store i64 0, ptr %20, align 8, !tbaa !9
  br label %21

21:                                               ; preds = %86, %4
  %22 = load i64, ptr %7, align 8, !tbaa !9
  %23 = icmp ne i64 %22, 0
  br i1 %23, label %24, label %87

24:                                               ; preds = %21
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #4
  %25 = call i32 @tls_uint24array_from_bytes(ptr noundef %10, ptr noundef %11, ptr noundef %6, ptr noundef %7)
  %26 = icmp ne i32 %25, 1
  br i1 %26, label %30, label %27

27:                                               ; preds = %24
  %28 = call i32 @tls_uint16array_from_bytes(ptr noundef %12, ptr noundef %13, ptr noundef %6, ptr noundef %7)
  %29 = icmp ne i32 %28, 1
  br i1 %29, label %30, label %36

30:                                               ; preds = %27, %24
  br label %31

31:                                               ; preds = %30
  %32 = load ptr, ptr @stderr, align 8, !tbaa !5
  %33 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %32, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 1179, ptr noundef @__FUNCTION__.tls13_process_certificate_list) #4
  br label %34

34:                                               ; preds = %31
  br label %35

35:                                               ; preds = %34
  store i32 -1, ptr %5, align 4
  store i32 1, ptr %16, align 4
  br label %84

36:                                               ; preds = %27
  %37 = call i32 @x509_cert_from_der(ptr noundef %14, ptr noundef %15, ptr noundef %10, ptr noundef %11)
  %38 = icmp ne i32 %37, 1
  br i1 %38, label %49, label %39

39:                                               ; preds = %36
  %40 = load i64, ptr %11, align 8, !tbaa !9
  %41 = call i32 @asn1_length_is_zero(i64 noundef %40)
  %42 = icmp ne i32 %41, 1
  br i1 %42, label %49, label %43

43:                                               ; preds = %39
  %44 = load ptr, ptr %14, align 8, !tbaa !5
  %45 = load i64, ptr %15, align 8, !tbaa !9
  %46 = load ptr, ptr %9, align 8, !tbaa !5
  %47 = call i32 @x509_cert_to_der(ptr noundef %44, i64 noundef %45, ptr noundef %8, ptr noundef %46)
  %48 = icmp ne i32 %47, 1
  br i1 %48, label %49, label %55

49:                                               ; preds = %43, %39, %36
  br label %50

50:                                               ; preds = %49
  %51 = load ptr, ptr @stderr, align 8, !tbaa !5
  %52 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %51, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 1185, ptr noundef @__FUNCTION__.tls13_process_certificate_list) #4
  br label %53

53:                                               ; preds = %50
  br label %54

54:                                               ; preds = %53
  store i32 -1, ptr %5, align 4
  store i32 1, ptr %16, align 4
  br label %84

55:                                               ; preds = %43
  br label %56

56:                                               ; preds = %55
  %57 = load i64, ptr %13, align 8, !tbaa !9
  %58 = icmp ne i64 %57, 0
  br i1 %58, label %59, label %83

59:                                               ; preds = %56
  call void @llvm.lifetime.start.p0(i64 4, ptr %17) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %18) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %19) #4
  %60 = call i32 @tls_ext_from_bytes(ptr noundef %17, ptr noundef %18, ptr noundef %19, ptr noundef %12, ptr noundef %13)
  %61 = icmp ne i32 %60, 1
  br i1 %61, label %62, label %68

62:                                               ; preds = %59
  br label %63

63:                                               ; preds = %62
  %64 = load ptr, ptr @stderr, align 8, !tbaa !5
  %65 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %64, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 1195, ptr noundef @__FUNCTION__.tls13_process_certificate_list) #4
  br label %66

66:                                               ; preds = %63
  br label %67

67:                                               ; preds = %66
  store i32 -1, ptr %5, align 4
  store i32 1, ptr %16, align 4
  br label %82

68:                                               ; preds = %59
  %69 = load i32, ptr %17, align 4, !tbaa !11
  switch i32 %69, label %76 [
    i32 5, label %70
    i32 18, label %70
  ]

70:                                               ; preds = %68, %68
  br label %71

71:                                               ; preds = %70
  %72 = load ptr, ptr @stderr, align 8, !tbaa !5
  %73 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %72, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 1201, ptr noundef @__FUNCTION__.tls13_process_certificate_list) #4
  br label %74

74:                                               ; preds = %71
  br label %75

75:                                               ; preds = %74
  store i32 -1, ptr %5, align 4
  store i32 1, ptr %16, align 4
  br label %82

76:                                               ; preds = %68
  br label %77

77:                                               ; preds = %76
  %78 = load ptr, ptr @stderr, align 8, !tbaa !5
  %79 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %78, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 1204, ptr noundef @__FUNCTION__.tls13_process_certificate_list) #4
  br label %80

80:                                               ; preds = %77
  br label %81

81:                                               ; preds = %80
  store i32 -1, ptr %5, align 4
  store i32 1, ptr %16, align 4
  br label %82

82:                                               ; preds = %81, %75, %67
  call void @llvm.lifetime.end.p0(i64 8, ptr %19) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %18) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %17) #4
  br label %84

83:                                               ; preds = %56
  store i32 0, ptr %16, align 4
  br label %84

84:                                               ; preds = %83, %82, %54, %35
  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 8, ptr %10) #4
  %85 = load i32, ptr %16, align 4
  switch i32 %85, label %90 [
    i32 0, label %86
    i32 1, label %88
  ]

86:                                               ; preds = %84
  br label %21, !llvm.loop !13

87:                                               ; preds = %21
  store i32 1, ptr %5, align 4
  br label %88

88:                                               ; preds = %87, %84
  %89 = load i32, ptr %5, align 4
  ret i32 %89

90:                                               ; preds = %84
  unreachable
}

declare i32 @asn1_length_is_zero(i64 noundef) #2

declare i32 @x509_cert_to_der(ptr noundef, i64 noundef, ptr noundef, ptr noundef) #2

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

attributes #0 = { 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 #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 = { 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, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"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"

@stderr = external local_unnamed_addr global ptr, align 8
@.str = external hidden unnamed_addr constant [13 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [59 x i8], align 1
@__FUNCTION__.tls13_process_certificate_list = external hidden unnamed_addr constant [31 x i8], align 1

; Function Attrs: nofree nounwind
declare noundef i32 @fprintf(ptr nocapture noundef, ptr nocapture noundef readonly, ...) 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: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

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

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

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

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @tls13_process_certificate_list(ptr noundef %0, i64 noundef %1, ptr noundef %2, ptr noundef %3) local_unnamed_addr #3 {
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i64, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i64, align 8
  %12 = alloca ptr, align 8
  %13 = alloca i64, align 8
  %14 = alloca i32, align 4
  %15 = alloca ptr, align 8
  %16 = alloca i64, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i64 %1, ptr %6, align 8, !tbaa !9
  store ptr %2, ptr %7, align 8, !tbaa !5
  store i64 0, ptr %3, align 8, !tbaa !9
  %.not14 = icmp eq i64 %1, 0
  br i1 %.not14, label %.loopexit, label %.lr.ph

thread-pre-split:                                 ; preds = %35
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %13) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %12) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %11) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %10) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %9) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %8) #4
  %.pr = load i64, ptr %6, align 8, !tbaa !9
  %.not = icmp eq i64 %.pr, 0
  br i1 %.not, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %4, %thread-pre-split
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %8) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %9) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %10) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %11) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %12) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %13) #4
  %17 = call i32 @tls_uint24array_from_bytes(ptr noundef nonnull %8, ptr noundef nonnull %9, ptr noundef nonnull %5, ptr noundef nonnull %6) #4
  %.not5 = icmp eq i32 %17, 1
  br i1 %.not5, label %18, label %20

18:                                               ; preds = %.lr.ph
  %19 = call i32 @tls_uint16array_from_bytes(ptr noundef nonnull %10, ptr noundef nonnull %11, ptr noundef nonnull %5, ptr noundef nonnull %6) #4
  %.not6 = icmp eq i32 %19, 1
  br i1 %.not6, label %23, label %20

20:                                               ; preds = %.lr.ph, %18
  %21 = load ptr, ptr @stderr, align 8, !tbaa !5
  %22 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %21, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 1179, ptr noundef nonnull @__FUNCTION__.tls13_process_certificate_list) #5
  br label %.thread

23:                                               ; preds = %18
  %24 = call i32 @x509_cert_from_der(ptr noundef nonnull %12, ptr noundef nonnull %13, ptr noundef nonnull %8, ptr noundef nonnull %9) #4
  %.not7 = icmp eq i32 %24, 1
  br i1 %.not7, label %25, label %32

25:                                               ; preds = %23
  %26 = load i64, ptr %9, align 8, !tbaa !9
  %27 = call i32 @asn1_length_is_zero(i64 noundef %26) #4
  %.not8 = icmp eq i32 %27, 1
  br i1 %.not8, label %28, label %32

28:                                               ; preds = %25
  %29 = load ptr, ptr %12, align 8, !tbaa !5
  %30 = load i64, ptr %13, align 8, !tbaa !9
  %31 = call i32 @x509_cert_to_der(ptr noundef %29, i64 noundef %30, ptr noundef nonnull %7, ptr noundef nonnull %3) #4
  %.not9 = icmp eq i32 %31, 1
  br i1 %.not9, label %35, label %32

32:                                               ; preds = %23, %25, %28
  %33 = load ptr, ptr @stderr, align 8, !tbaa !5
  %34 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %33, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 1185, ptr noundef nonnull @__FUNCTION__.tls13_process_certificate_list) #5
  br label %.thread

35:                                               ; preds = %28
  %36 = load i64, ptr %11, align 8, !tbaa !9
  %.not10 = icmp eq i64 %36, 0
  br i1 %.not10, label %thread-pre-split, label %37

37:                                               ; preds = %35
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %14) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %15) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %16) #4
  %38 = call i32 @tls_ext_from_bytes(ptr noundef nonnull %14, ptr noundef nonnull %15, ptr noundef nonnull %16, ptr noundef nonnull %10, ptr noundef nonnull %11) #4
  %.not11 = icmp eq i32 %38, 1
  br i1 %.not11, label %39, label %42

39:                                               ; preds = %37
  %40 = load i32, ptr %14, align 4, !tbaa !11
  %switch.selectcmp.case1 = icmp eq i32 %40, 5
  %switch.selectcmp.case2 = icmp eq i32 %40, 18
  %switch.selectcmp = or i1 %switch.selectcmp.case1, %switch.selectcmp.case2
  %41 = select i1 %switch.selectcmp, i32 1201, i32 1204
  br label %42

42:                                               ; preds = %39, %37
  %.sink15 = phi i32 [ 1195, %37 ], [ %41, %39 ]
  %43 = load ptr, ptr @stderr, align 8, !tbaa !5
  %44 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %43, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef %.sink15, ptr noundef nonnull @__FUNCTION__.tls13_process_certificate_list) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %16) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %15) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %14) #4
  br label %.thread

.thread:                                          ; preds = %20, %32, %42
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %13) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %12) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %11) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %10) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %9) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %8) #4
  br label %.loopexit

.loopexit:                                        ; preds = %thread-pre-split, %4, %.thread
  %.3 = phi i32 [ -1, %.thread ], [ 1, %4 ], [ 1, %thread-pre-split ]
  ret i32 %.3
}

declare i32 @asn1_length_is_zero(i64 noundef) local_unnamed_addr #2

declare i32 @x509_cert_to_der(ptr noundef, i64 noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

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

attributes #0 = { 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 #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 = { 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 = { cold 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 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}


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