; 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_supported_groups_ext_to_bytes = external hidden unnamed_addr constant [34 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_supported_groups_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 i16, align 2
  %11 = alloca i64, align 8
  %12 = alloca i64, align 8
  %13 = alloca i64, align 8
  %14 = 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 2, ptr %10) #4
  store i16 10, ptr %10, align 2, !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
  %15 = load ptr, ptr %6, align 8, !tbaa !5
  %16 = icmp ne ptr %15, null
  br i1 %16, label %17, label %20

17:                                               ; preds = %4
  %18 = load i64, ptr %7, align 8, !tbaa !9
  %19 = icmp ne i64 %18, 0
  br i1 %19, label %26, label %20

20:                                               ; preds = %17, %4
  br label %21

21:                                               ; preds = %20
  %22 = load ptr, ptr @stderr, align 8, !tbaa !5
  %23 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %22, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 160, ptr noundef @__FUNCTION__.tls_supported_groups_ext_to_bytes) #4
  br label %24

24:                                               ; preds = %21
  br label %25

25:                                               ; preds = %24
  store i32 -1, ptr %5, align 4
  store i32 1, ptr %14, align 4
  br label %89

26:                                               ; preds = %17
  %27 = load ptr, ptr %9, align 8, !tbaa !5
  %28 = icmp ne ptr %27, null
  br i1 %28, label %35, label %29

29:                                               ; preds = %26
  br label %30

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

33:                                               ; preds = %30
  br label %34

34:                                               ; preds = %33
  store i32 -1, ptr %5, align 4
  store i32 1, ptr %14, align 4
  br label %89

35:                                               ; preds = %26
  %36 = load i64, ptr %7, align 8, !tbaa !9
  %37 = icmp ugt i64 %36, 32767
  br i1 %37, label %38, label %44

38:                                               ; preds = %35
  br label %39

39:                                               ; preds = %38
  %40 = load ptr, ptr @stderr, align 8, !tbaa !5
  %41 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %40, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 169, ptr noundef @__FUNCTION__.tls_supported_groups_ext_to_bytes) #4
  br label %42

42:                                               ; preds = %39
  br label %43

43:                                               ; preds = %42
  store i32 -1, ptr %5, align 4
  store i32 1, ptr %14, align 4
  br label %89

44:                                               ; preds = %35
  %45 = load i64, ptr %7, align 8, !tbaa !9
  %46 = mul i64 2, %45
  store i64 %46, ptr %12, align 8, !tbaa !9
  %47 = load i64, ptr %12, align 8, !tbaa !9
  %48 = add i64 2, %47
  store i64 %48, ptr %11, align 8, !tbaa !9
  %49 = load i16, ptr %10, align 2, !tbaa !11
  %50 = load ptr, ptr %8, align 8, !tbaa !5
  %51 = load ptr, ptr %9, align 8, !tbaa !5
  call void @tls_uint16_to_bytes(i16 noundef zeroext %49, ptr noundef %50, ptr noundef %51)
  %52 = load i64, ptr %11, align 8, !tbaa !9
  %53 = trunc i64 %52 to i16
  %54 = load ptr, ptr %8, align 8, !tbaa !5
  %55 = load ptr, ptr %9, align 8, !tbaa !5
  call void @tls_uint16_to_bytes(i16 noundef zeroext %53, ptr noundef %54, ptr noundef %55)
  %56 = load i64, ptr %12, align 8, !tbaa !9
  %57 = trunc i64 %56 to i16
  %58 = load ptr, ptr %8, align 8, !tbaa !5
  %59 = load ptr, ptr %9, align 8, !tbaa !5
  call void @tls_uint16_to_bytes(i16 noundef zeroext %57, ptr noundef %58, ptr noundef %59)
  store i64 0, ptr %13, align 8, !tbaa !9
  br label %60

60:                                               ; preds = %85, %44
  %61 = load i64, ptr %13, align 8, !tbaa !9
  %62 = load i64, ptr %7, align 8, !tbaa !9
  %63 = icmp ult i64 %61, %62
  br i1 %63, label %64, label %88

64:                                               ; preds = %60
  %65 = load ptr, ptr %6, align 8, !tbaa !5
  %66 = load i64, ptr %13, align 8, !tbaa !9
  %67 = getelementptr inbounds i32, ptr %65, i64 %66
  %68 = load i32, ptr %67, align 4, !tbaa !13
  %69 = call ptr @tls_curve_name(i32 noundef %68)
  %70 = icmp ne ptr %69, null
  br i1 %70, label %77, label %71

71:                                               ; preds = %64
  br label %72

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

75:                                               ; preds = %72
  br label %76

76:                                               ; preds = %75
  store i32 -1, ptr %5, align 4
  store i32 1, ptr %14, align 4
  br label %89

77:                                               ; preds = %64
  %78 = load ptr, ptr %6, align 8, !tbaa !5
  %79 = load i64, ptr %13, align 8, !tbaa !9
  %80 = getelementptr inbounds i32, ptr %78, i64 %79
  %81 = load i32, ptr %80, align 4, !tbaa !13
  %82 = trunc i32 %81 to i16
  %83 = load ptr, ptr %8, align 8, !tbaa !5
  %84 = load ptr, ptr %9, align 8, !tbaa !5
  call void @tls_uint16_to_bytes(i16 noundef zeroext %82, ptr noundef %83, ptr noundef %84)
  br label %85

85:                                               ; preds = %77
  %86 = load i64, ptr %13, align 8, !tbaa !9
  %87 = add i64 %86, 1
  store i64 %87, ptr %13, align 8, !tbaa !9
  br label %60, !llvm.loop !15

88:                                               ; preds = %60
  store i32 1, ptr %5, align 4
  store i32 1, ptr %14, align 4
  br label %89

89:                                               ; preds = %88, %76, %43, %34, %25
  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 2, ptr %10) #4
  %90 = load i32, ptr %5, align 4
  ret i32 %90
}

declare ptr @tls_curve_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 = !{!"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 = !{!"short", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"int", !7, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"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_supported_groups_ext_to_bytes = external hidden unnamed_addr constant [34 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_supported_groups_ext_to_bytes(ptr noundef readonly %0, i64 noundef %1, ptr noundef %2, ptr noundef %3) local_unnamed_addr #2 {
  %5 = icmp ne ptr %0, null
  %6 = icmp ne i64 %1, 0
  %or.cond = and i1 %5, %6
  br i1 %or.cond, label %7, label %.loopexit.sink.split

7:                                                ; preds = %4
  %.not = icmp eq ptr %3, null
  br i1 %.not, label %.loopexit.sink.split, label %8

8:                                                ; preds = %7
  %9 = icmp ugt i64 %1, 32767
  br i1 %9, label %.loopexit.sink.split, label %10

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

13:                                               ; preds = %10, %17
  %.030 = phi i64 [ 0, %10 ], [ %20, %17 ]
  %14 = getelementptr inbounds i32, ptr %0, i64 %.030
  %15 = load i32, ptr %14, align 4, !tbaa !5
  %16 = tail call ptr @tls_curve_name(i32 noundef %15) #3
  %.not29 = icmp eq ptr %16, null
  br i1 %.not29, label %.loopexit.sink.split, label %17

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

.loopexit.sink.split:                             ; preds = %13, %8, %7, %4
  %.sink31 = phi i32 [ 160, %4 ], [ 164, %7 ], [ 169, %8 ], [ 180, %13 ]
  %21 = load ptr, ptr @stderr, align 8, !tbaa !11
  %22 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %21, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef %.sink31, ptr noundef nonnull @__FUNCTION__.tls_supported_groups_ext_to_bytes) #4
  br label %.loopexit

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

declare ptr @tls_curve_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