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

; 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 [61 x i8], align 1
@__FUNCTION__.tls13_certificate_authorities_ext_to_bytes = external hidden unnamed_addr constant [43 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

declare void @tls_uint16_to_bytes(i16 noundef zeroext, ptr noundef, ptr noundef) #2

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

declare void @tls_uint16array_to_bytes(ptr noundef, i64 noundef, ptr noundef, ptr noundef) #2

; Function Attrs: nounwind uwtable
define dso_local i32 @tls13_certificate_authorities_ext_to_bytes(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 i32, align 4
  %11 = alloca i64, align 8
  %12 = alloca i64, align 8
  %13 = alloca ptr, align 8
  %14 = alloca i64, align 8
  %15 = alloca ptr, align 8
  %16 = alloca i64, align 8
  %17 = alloca i32, align 4
  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
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #4
  store i32 47, ptr %10, align 4, !tbaa !11
  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
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #4
  %18 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %18, ptr %15, align 8, !tbaa !5
  %19 = load i64, ptr %7, align 8, !tbaa !9
  store i64 %19, ptr %16, align 8, !tbaa !9
  store i64 0, ptr %12, align 8, !tbaa !9
  br label %20

20:                                               ; preds = %32, %4
  %21 = load i64, ptr %16, align 8, !tbaa !9
  %22 = icmp ne i64 %21, 0
  br i1 %22, label %23, label %35

23:                                               ; preds = %20
  %24 = call i32 @asn1_type_from_der(i32 noundef 48, ptr noundef %13, ptr noundef %14, ptr noundef %15, ptr noundef %16)
  %25 = icmp ne i32 %24, 1
  br i1 %25, label %26, label %32

26:                                               ; preds = %23
  br label %27

27:                                               ; preds = %26
  %28 = load ptr, ptr @stderr, align 8, !tbaa !5
  %29 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %28, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 787, ptr noundef @__FUNCTION__.tls13_certificate_authorities_ext_to_bytes) #4
  br label %30

30:                                               ; preds = %27
  br label %31

31:                                               ; preds = %30
  store i32 -1, ptr %5, align 4
  store i32 1, ptr %17, align 4
  br label %72

32:                                               ; preds = %23
  %33 = load ptr, ptr %13, align 8, !tbaa !5
  %34 = load i64, ptr %14, align 8, !tbaa !9
  call void @tls_uint16array_to_bytes(ptr noundef %33, i64 noundef %34, ptr noundef null, ptr noundef %12)
  br label %20, !llvm.loop !13

35:                                               ; preds = %20
  %36 = load i64, ptr %12, align 8, !tbaa !9
  %37 = icmp ult i64 %36, 3
  br i1 %37, label %41, label %38

38:                                               ; preds = %35
  %39 = load i64, ptr %12, align 8, !tbaa !9
  %40 = icmp ugt i64 %39, 65535
  br i1 %40, label %41, label %47

41:                                               ; preds = %38, %35
  br label %42

42:                                               ; preds = %41
  %43 = load ptr, ptr @stderr, align 8, !tbaa !5
  %44 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %43, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 793, ptr noundef @__FUNCTION__.tls13_certificate_authorities_ext_to_bytes) #4
  br label %45

45:                                               ; preds = %42
  br label %46

46:                                               ; preds = %45
  store i32 -1, ptr %5, align 4
  store i32 1, ptr %17, align 4
  br label %72

47:                                               ; preds = %38
  %48 = load i64, ptr %12, align 8, !tbaa !9
  %49 = add i64 2, %48
  store i64 %49, ptr %11, align 8, !tbaa !9
  %50 = load i32, ptr %10, align 4, !tbaa !11
  %51 = trunc i32 %50 to i16
  %52 = load ptr, ptr %8, align 8, !tbaa !5
  %53 = load ptr, ptr %9, align 8, !tbaa !5
  call void @tls_uint16_to_bytes(i16 noundef zeroext %51, ptr noundef %52, ptr noundef %53)
  %54 = load i64, ptr %11, align 8, !tbaa !9
  %55 = trunc i64 %54 to i16
  %56 = load ptr, ptr %8, align 8, !tbaa !5
  %57 = load ptr, ptr %9, align 8, !tbaa !5
  call void @tls_uint16_to_bytes(i16 noundef zeroext %55, ptr noundef %56, ptr noundef %57)
  %58 = load i64, ptr %12, align 8, !tbaa !9
  %59 = trunc i64 %58 to i16
  %60 = load ptr, ptr %8, align 8, !tbaa !5
  %61 = load ptr, ptr %9, align 8, !tbaa !5
  call void @tls_uint16_to_bytes(i16 noundef zeroext %59, ptr noundef %60, ptr noundef %61)
  br label %62

62:                                               ; preds = %65, %47
  %63 = load i64, ptr %7, align 8, !tbaa !9
  %64 = icmp ne i64 %63, 0
  br i1 %64, label %65, label %71

65:                                               ; preds = %62
  %66 = call i32 @asn1_type_from_der(i32 noundef 48, ptr noundef %13, ptr noundef %14, ptr noundef %6, ptr noundef %7)
  %67 = load ptr, ptr %13, align 8, !tbaa !5
  %68 = load i64, ptr %14, align 8, !tbaa !9
  %69 = load ptr, ptr %8, align 8, !tbaa !5
  %70 = load ptr, ptr %9, align 8, !tbaa !5
  call void @tls_uint16array_to_bytes(ptr noundef %67, i64 noundef %68, ptr noundef %69, ptr noundef %70)
  br label %62, !llvm.loop !15

71:                                               ; preds = %62
  store i32 1, ptr %5, align 4
  store i32 1, ptr %17, align 4
  br label %72

72:                                               ; preds = %71, %46, %31
  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
  %73 = load i32, ptr %5, align 4
  ret i32 %73
}

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

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 = { "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"}
!15 = distinct !{!15, !14}


; 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 [61 x i8], align 1
@__FUNCTION__.tls13_certificate_authorities_ext_to_bytes = external hidden unnamed_addr constant [43 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

declare void @tls_uint16_to_bytes(i16 noundef zeroext, ptr noundef, ptr noundef) local_unnamed_addr #2

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

declare void @tls_uint16array_to_bytes(ptr noundef, i64 noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
define dso_local range(i32 -1, 2) i32 @tls13_certificate_authorities_ext_to_bytes(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 i64, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i64, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i64, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i64 %1, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %7) #4
  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
  store ptr %0, ptr %10, align 8, !tbaa !5
  store i64 %1, ptr %11, align 8, !tbaa !9
  store i64 0, ptr %7, align 8, !tbaa !9
  %.not14 = icmp eq i64 %1, 0
  br i1 %.not14, label %.loopexit.sink.split, label %.lr.ph

.lr.ph:                                           ; preds = %4, %13
  %12 = call i32 @asn1_type_from_der(i32 noundef 48, ptr noundef nonnull %8, ptr noundef nonnull %9, ptr noundef nonnull %10, ptr noundef nonnull %11) #4
  %.not13 = icmp eq i32 %12, 1
  br i1 %.not13, label %13, label %.loopexit.sink.split

13:                                               ; preds = %.lr.ph
  %14 = load ptr, ptr %8, align 8, !tbaa !5
  %15 = load i64, ptr %9, align 8, !tbaa !9
  call void @tls_uint16array_to_bytes(ptr noundef %14, i64 noundef %15, ptr noundef null, ptr noundef nonnull %7) #4
  %.pr = load i64, ptr %11, align 8, !tbaa !9
  %.not = icmp eq i64 %.pr, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !11

._crit_edge:                                      ; preds = %13
  %.pre = load i64, ptr %7, align 8
  %16 = add i64 %.pre, -65536
  %or.cond = icmp ult i64 %16, -65533
  br i1 %or.cond, label %.loopexit.sink.split, label %17

17:                                               ; preds = %._crit_edge
  call void @tls_uint16_to_bytes(i16 noundef zeroext 47, ptr noundef %2, ptr noundef %3) #4
  %18 = trunc nuw i64 %.pre to i16
  %19 = add i16 %18, 2
  call void @tls_uint16_to_bytes(i16 noundef zeroext %19, ptr noundef %2, ptr noundef %3) #4
  %20 = load i64, ptr %7, align 8, !tbaa !9
  %21 = trunc i64 %20 to i16
  call void @tls_uint16_to_bytes(i16 noundef zeroext %21, ptr noundef %2, ptr noundef %3) #4
  br i1 %.not14, label %.loopexit, label %.lr.ph17

.lr.ph17:                                         ; preds = %17, %.lr.ph17
  %22 = call i32 @asn1_type_from_der(i32 noundef 48, ptr noundef nonnull %8, ptr noundef nonnull %9, ptr noundef nonnull %5, ptr noundef nonnull %6) #4
  %23 = load ptr, ptr %8, align 8, !tbaa !5
  %24 = load i64, ptr %9, align 8, !tbaa !9
  call void @tls_uint16array_to_bytes(ptr noundef %23, i64 noundef %24, ptr noundef %2, ptr noundef %3) #4
  %25 = load i64, ptr %6, align 8, !tbaa !9
  %.not12 = icmp eq i64 %25, 0
  br i1 %.not12, label %.loopexit, label %.lr.ph17, !llvm.loop !13

.loopexit.sink.split:                             ; preds = %.lr.ph, %._crit_edge, %4
  %.sink19 = phi i32 [ 793, %4 ], [ 793, %._crit_edge ], [ 787, %.lr.ph ]
  %26 = load ptr, ptr @stderr, align 8, !tbaa !5
  %27 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %26, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef %.sink19, ptr noundef nonnull @__FUNCTION__.tls13_certificate_authorities_ext_to_bytes) #5
  br label %.loopexit

.loopexit:                                        ; preds = %.lr.ph17, %.loopexit.sink.split, %17
  %.0 = phi i32 [ 1, %17 ], [ -1, %.loopexit.sink.split ], [ 1, %.lr.ph17 ]
  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
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %7) #4
  ret i32 %.0
}

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

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 = { "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 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}


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