; 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_ec_point_formats_ext_to_bytes = external hidden unnamed_addr constant [34 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i32 @tls_ec_point_formats_ext_to_bytes(ptr noundef %0, i64 noundef %1, ptr noundef %2, ptr noundef %3) #0 {
  %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 11, 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 %23

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

20:                                               ; preds = %17
  %21 = load ptr, ptr %9, align 8, !tbaa !5
  %22 = icmp ne ptr %21, null
  br i1 %22, label %29, label %23

23:                                               ; preds = %20, %17, %4
  br label %24

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

27:                                               ; preds = %24
  br label %28

28:                                               ; preds = %27
  store i32 -1, ptr %5, align 4
  store i32 1, ptr %14, align 4
  br label %86

29:                                               ; preds = %20
  %30 = load i64, ptr %7, align 8, !tbaa !9
  %31 = mul i64 1, %30
  store i64 %31, ptr %12, align 8, !tbaa !9
  %32 = load i64, ptr %12, align 8, !tbaa !9
  %33 = icmp ult i64 %32, 1
  br i1 %33, label %37, label %34

34:                                               ; preds = %29
  %35 = load i64, ptr %12, align 8, !tbaa !9
  %36 = icmp ugt i64 %35, 255
  br i1 %36, label %37, label %43

37:                                               ; preds = %34, %29
  br label %38

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

41:                                               ; preds = %38
  br label %42

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

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

57:                                               ; preds = %82, %43
  %58 = load i64, ptr %13, align 8, !tbaa !9
  %59 = load i64, ptr %7, align 8, !tbaa !9
  %60 = icmp ult i64 %58, %59
  br i1 %60, label %61, label %85

61:                                               ; preds = %57
  %62 = load ptr, ptr %6, align 8, !tbaa !5
  %63 = load i64, ptr %13, align 8, !tbaa !9
  %64 = getelementptr inbounds i32, ptr %62, i64 %63
  %65 = load i32, ptr %64, align 4, !tbaa !13
  %66 = call ptr @tls_ec_point_format_name(i32 noundef %65)
  %67 = icmp ne ptr %66, null
  br i1 %67, label %74, label %68

68:                                               ; preds = %61
  br label %69

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

72:                                               ; preds = %69
  br label %73

73:                                               ; preds = %72
  store i32 -1, ptr %5, align 4
  store i32 1, ptr %14, align 4
  br label %86

74:                                               ; preds = %61
  %75 = load ptr, ptr %6, align 8, !tbaa !5
  %76 = load i64, ptr %13, align 8, !tbaa !9
  %77 = getelementptr inbounds i32, ptr %75, i64 %76
  %78 = load i32, ptr %77, align 4, !tbaa !13
  %79 = trunc i32 %78 to i8
  %80 = load ptr, ptr %8, align 8, !tbaa !5
  %81 = load ptr, ptr %9, align 8, !tbaa !5
  call void @tls_uint8_to_bytes(i8 noundef zeroext %79, ptr noundef %80, ptr noundef %81)
  br label %82

82:                                               ; preds = %74
  %83 = load i64, ptr %13, align 8, !tbaa !9
  %84 = add i64 %83, 1
  store i64 %84, ptr %13, align 8, !tbaa !9
  br label %57, !llvm.loop !15

85:                                               ; preds = %57
  store i32 1, ptr %5, align 4
  store i32 1, ptr %14, align 4
  br label %86

86:                                               ; preds = %85, %73, %42, %28
  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
  %87 = load i32, ptr %5, align 4
  ret i32 %87
}

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

; Function Attrs: nounwind
declare i32 @fprintf(ptr noundef, ptr noundef, ...) #2

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

declare void @tls_uint8_to_bytes(i8 noundef zeroext, ptr noundef, ptr noundef) #3

declare ptr @tls_ec_point_format_name(i32 noundef) #3

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

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

!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_ec_point_formats_ext_to_bytes = external hidden unnamed_addr constant [34 x i8], align 1

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

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

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

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

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

.loopexit.sink.split:                             ; preds = %14, %8, %4
  %.sink35 = phi i32 [ 50, %4 ], [ 55, %8 ], [ 65, %14 ]
  %22 = load ptr, ptr @stderr, align 8, !tbaa !11
  %23 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %22, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef %.sink35, ptr noundef nonnull @__FUNCTION__.tls_ec_point_formats_ext_to_bytes) #4
  br label %.loopexit

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

; 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

declare void @tls_uint8_to_bytes(i8 noundef zeroext, ptr noundef, ptr noundef) local_unnamed_addr #2

declare ptr @tls_ec_point_format_name(i32 noundef) 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 = { 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 }
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