; 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__.tls_signature_algorithms_ext_to_bytes_ex = external hidden unnamed_addr constant [41 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

; Function Attrs: nounwind uwtable
define dso_local i32 @tls_signature_algorithms_ext_to_bytes_ex(i32 noundef %0, ptr noundef %1, i64 noundef %2, ptr noundef %3, ptr noundef %4) #3 {
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca i64, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca i64, align 8
  %13 = alloca i64, align 8
  %14 = alloca i64, align 8
  %15 = alloca i32, align 4
  store i32 %0, ptr %7, align 4, !tbaa !5
  store ptr %1, ptr %8, align 8, !tbaa !9
  store i64 %2, ptr %9, align 8, !tbaa !11
  store ptr %3, ptr %10, align 8, !tbaa !9
  store ptr %4, ptr %11, align 8, !tbaa !9
  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
  %16 = load ptr, ptr %8, align 8, !tbaa !9
  %17 = icmp ne ptr %16, null
  br i1 %17, label %18, label %24

18:                                               ; preds = %5
  %19 = load i64, ptr %9, align 8, !tbaa !11
  %20 = icmp ne i64 %19, 0
  br i1 %20, label %21, label %24

21:                                               ; preds = %18
  %22 = load ptr, ptr %11, align 8, !tbaa !9
  %23 = icmp ne ptr %22, null
  br i1 %23, label %30, label %24

24:                                               ; preds = %21, %18, %5
  br label %25

25:                                               ; preds = %24
  %26 = load ptr, ptr @stderr, align 8, !tbaa !9
  %27 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %26, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 276, ptr noundef @__FUNCTION__.tls_signature_algorithms_ext_to_bytes_ex) #4
  br label %28

28:                                               ; preds = %25
  br label %29

29:                                               ; preds = %28
  store i32 -1, ptr %6, align 4
  store i32 1, ptr %15, align 4
  br label %85

30:                                               ; preds = %21
  %31 = load i64, ptr %9, align 8, !tbaa !11
  %32 = icmp ugt i64 %31, 32767
  br i1 %32, label %33, label %39

33:                                               ; preds = %30
  br label %34

34:                                               ; preds = %33
  %35 = load ptr, ptr @stderr, align 8, !tbaa !9
  %36 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %35, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 280, ptr noundef @__FUNCTION__.tls_signature_algorithms_ext_to_bytes_ex) #4
  br label %37

37:                                               ; preds = %34
  br label %38

38:                                               ; preds = %37
  store i32 -1, ptr %6, align 4
  store i32 1, ptr %15, align 4
  br label %85

39:                                               ; preds = %30
  %40 = load i64, ptr %9, align 8, !tbaa !11
  %41 = mul i64 2, %40
  store i64 %41, ptr %13, align 8, !tbaa !11
  %42 = load i64, ptr %13, align 8, !tbaa !11
  %43 = add i64 2, %42
  store i64 %43, ptr %12, align 8, !tbaa !11
  %44 = load i32, ptr %7, align 4, !tbaa !5
  %45 = trunc i32 %44 to i16
  %46 = load ptr, ptr %10, align 8, !tbaa !9
  %47 = load ptr, ptr %11, align 8, !tbaa !9
  call void @tls_uint16_to_bytes(i16 noundef zeroext %45, ptr noundef %46, ptr noundef %47)
  %48 = load i64, ptr %12, align 8, !tbaa !11
  %49 = trunc i64 %48 to i16
  %50 = load ptr, ptr %10, align 8, !tbaa !9
  %51 = load ptr, ptr %11, align 8, !tbaa !9
  call void @tls_uint16_to_bytes(i16 noundef zeroext %49, ptr noundef %50, ptr noundef %51)
  %52 = load i64, ptr %13, align 8, !tbaa !11
  %53 = trunc i64 %52 to i16
  %54 = load ptr, ptr %10, align 8, !tbaa !9
  %55 = load ptr, ptr %11, align 8, !tbaa !9
  call void @tls_uint16_to_bytes(i16 noundef zeroext %53, ptr noundef %54, ptr noundef %55)
  store i64 0, ptr %14, align 8, !tbaa !11
  br label %56

56:                                               ; preds = %81, %39
  %57 = load i64, ptr %14, align 8, !tbaa !11
  %58 = load i64, ptr %9, align 8, !tbaa !11
  %59 = icmp ult i64 %57, %58
  br i1 %59, label %60, label %84

60:                                               ; preds = %56
  %61 = load ptr, ptr %8, align 8, !tbaa !9
  %62 = load i64, ptr %14, align 8, !tbaa !11
  %63 = getelementptr inbounds i32, ptr %61, i64 %62
  %64 = load i32, ptr %63, align 4, !tbaa !5
  %65 = call ptr @tls_signature_scheme_name(i32 noundef %64)
  %66 = icmp ne ptr %65, null
  br i1 %66, label %73, label %67

67:                                               ; preds = %60
  br label %68

68:                                               ; preds = %67
  %69 = load ptr, ptr @stderr, align 8, !tbaa !9
  %70 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %69, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 291, ptr noundef @__FUNCTION__.tls_signature_algorithms_ext_to_bytes_ex) #4
  br label %71

71:                                               ; preds = %68
  br label %72

72:                                               ; preds = %71
  store i32 -1, ptr %6, align 4
  store i32 1, ptr %15, align 4
  br label %85

73:                                               ; preds = %60
  %74 = load ptr, ptr %8, align 8, !tbaa !9
  %75 = load i64, ptr %14, align 8, !tbaa !11
  %76 = getelementptr inbounds i32, ptr %74, i64 %75
  %77 = load i32, ptr %76, align 4, !tbaa !5
  %78 = trunc i32 %77 to i16
  %79 = load ptr, ptr %10, align 8, !tbaa !9
  %80 = load ptr, ptr %11, align 8, !tbaa !9
  call void @tls_uint16_to_bytes(i16 noundef zeroext %78, ptr noundef %79, ptr noundef %80)
  br label %81

81:                                               ; preds = %73
  %82 = load i64, ptr %14, align 8, !tbaa !11
  %83 = add i64 %82, 1
  store i64 %83, ptr %14, align 8, !tbaa !11
  br label %56, !llvm.loop !13

84:                                               ; preds = %56
  store i32 1, ptr %6, align 4
  store i32 1, ptr %15, align 4
  br label %85

85:                                               ; preds = %84, %72, %38, %29
  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
  %86 = load i32, ptr %6, align 4
  ret i32 %86
}

declare ptr @tls_signature_scheme_name(i32 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 = !{!"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}
!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 [61 x i8], align 1
@__FUNCTION__.tls_signature_algorithms_ext_to_bytes_ex = external hidden unnamed_addr constant [41 x i8], align 1

; Function Attrs: nofree nounwind
declare noundef i32 @fprintf(ptr nocapture noundef, ptr nocapture noundef readonly, ...) local_unnamed_addr #0

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

; Function Attrs: nounwind uwtable
define dso_local range(i32 -1, 2) i32 @tls_signature_algorithms_ext_to_bytes_ex(i32 noundef %0, ptr noundef readonly %1, i64 noundef %2, ptr noundef %3, ptr noundef %4) local_unnamed_addr #2 {
  %6 = icmp ne ptr %1, null
  %7 = icmp ne i64 %2, 0
  %or.cond = and i1 %6, %7
  %8 = icmp ne ptr %4, null
  %or.cond3 = and i1 %or.cond, %8
  br i1 %or.cond3, label %9, label %.loopexit.sink.split

9:                                                ; preds = %5
  %10 = icmp ugt i64 %2, 32767
  br i1 %10, label %.loopexit.sink.split, label %11

11:                                               ; preds = %9
  %12 = trunc i32 %0 to i16
  tail call void @tls_uint16_to_bytes(i16 noundef zeroext %12, ptr noundef %3, ptr noundef nonnull %4) #3
  %.tr = trunc nuw i64 %2 to i16
  %13 = shl nuw i16 %.tr, 1
  %14 = add i16 %13, 2
  tail call void @tls_uint16_to_bytes(i16 noundef zeroext %14, ptr noundef %3, ptr noundef nonnull %4) #3
  tail call void @tls_uint16_to_bytes(i16 noundef zeroext %13, ptr noundef %3, ptr noundef nonnull %4) #3
  br label %15

15:                                               ; preds = %11, %19
  %.031 = phi i64 [ 0, %11 ], [ %22, %19 ]
  %16 = getelementptr inbounds i32, ptr %1, i64 %.031
  %17 = load i32, ptr %16, align 4, !tbaa !5
  %18 = tail call ptr @tls_signature_scheme_name(i32 noundef %17) #3
  %.not = icmp eq ptr %18, null
  br i1 %.not, label %.loopexit.sink.split, label %19

19:                                               ; preds = %15
  %20 = load i32, ptr %16, align 4, !tbaa !5
  %21 = trunc i32 %20 to i16
  tail call void @tls_uint16_to_bytes(i16 noundef zeroext %21, ptr noundef %3, ptr noundef nonnull %4) #3
  %22 = add nuw i64 %.031, 1
  %exitcond.not = icmp eq i64 %22, %2
  br i1 %exitcond.not, label %.loopexit, label %15, !llvm.loop !9

.loopexit.sink.split:                             ; preds = %15, %9, %5
  %.sink32 = phi i32 [ 276, %5 ], [ 280, %9 ], [ 291, %15 ]
  %23 = load ptr, ptr @stderr, align 8, !tbaa !11
  %24 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %23, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef %.sink32, ptr noundef nonnull @__FUNCTION__.tls_signature_algorithms_ext_to_bytes_ex) #4
  br label %.loopexit

.loopexit:                                        ; preds = %19, %.loopexit.sink.split
  %.027 = phi i32 [ -1, %.loopexit.sink.split ], [ 1, %19 ]
  ret i32 %.027
}

declare ptr @tls_signature_scheme_name(i32 noundef) local_unnamed_addr #1

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 = { "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 }
attributes #4 = { 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!12, !12, i64 0}
!12 = !{!"any pointer", !7, i64 0}


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