; 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__.tls_client_key_shares_from_bytes = external hidden unnamed_addr constant [33 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_uint16_from_bytes(ptr noundef, ptr noundef, ptr noundef) #2

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

; Function Attrs: nounwind uwtable
define dso_local i32 @tls_client_key_shares_from_bytes(ptr noundef %0, ptr noundef %1, ptr noundef %2) #3 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i64, align 8
  %10 = alloca i16, align 2
  %11 = alloca ptr, align 8
  %12 = alloca i64, align 8
  %13 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  %14 = load ptr, ptr %6, align 8, !tbaa !5
  %15 = load ptr, ptr %7, align 8, !tbaa !5
  %16 = call i32 @tls_uint16array_from_bytes(ptr noundef %8, ptr noundef %9, ptr noundef %14, ptr noundef %15)
  br label %17

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

20:                                               ; preds = %17
  call void @llvm.lifetime.start.p0(i64 2, 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
  %21 = call i32 @tls_uint16_from_bytes(ptr noundef %10, ptr noundef %8, ptr noundef %9)
  %22 = call i32 @tls_uint16array_from_bytes(ptr noundef %11, ptr noundef %12, ptr noundef %8, ptr noundef %9)
  %23 = load i64, ptr %12, align 8, !tbaa !9
  %24 = icmp ne i64 %23, 65
  br i1 %24, label %25, label %31

25:                                               ; preds = %20
  br label %26

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

29:                                               ; preds = %26
  br label %30

30:                                               ; preds = %29
  store i32 -1, ptr %4, align 4
  store i32 1, ptr %13, align 4
  br label %46

31:                                               ; preds = %20
  %32 = load i16, ptr %10, align 2, !tbaa !11
  %33 = zext i16 %32 to i32
  switch i32 %33, label %39 [
    i32 41, label %34
  ]

34:                                               ; preds = %31
  %35 = load ptr, ptr %5, align 8, !tbaa !5
  %36 = load ptr, ptr %11, align 8, !tbaa !5
  %37 = load i64, ptr %12, align 8, !tbaa !9
  %38 = call i32 @sm2_z256_point_from_octets(ptr noundef %35, ptr noundef %36, i64 noundef %37)
  br label %45

39:                                               ; preds = %31
  br label %40

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

43:                                               ; preds = %40
  br label %44

44:                                               ; preds = %43
  store i32 -1, ptr %4, align 4
  store i32 1, ptr %13, align 4
  br label %46

45:                                               ; preds = %34
  store i32 0, ptr %13, align 4
  br label %46

46:                                               ; preds = %45, %44, %30
  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
  %47 = load i32, ptr %13, align 4
  switch i32 %47, label %50 [
    i32 0, label %48
  ]

48:                                               ; preds = %46
  br label %17, !llvm.loop !13

49:                                               ; preds = %17
  store i32 1, ptr %4, align 4
  store i32 1, ptr %13, align 4
  br label %50

50:                                               ; preds = %49, %46
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  %51 = load i32, ptr %4, align 4
  ret i32 %51
}

declare i32 @sm2_z256_point_from_octets(ptr noundef, ptr noundef, i64 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 = !{!"short", !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__.tls_client_key_shares_from_bytes = external hidden unnamed_addr constant [33 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_uint16_from_bytes(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

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

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @tls_client_key_shares_from_bytes(ptr noundef %0, ptr noundef %1, ptr noundef %2) local_unnamed_addr #3 {
  %4 = alloca ptr, align 8
  %5 = alloca i64, align 8
  %6 = alloca i16, align 2
  %7 = alloca ptr, align 8
  %8 = alloca i64, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %4) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %5) #4
  %9 = call i32 @tls_uint16array_from_bytes(ptr noundef nonnull %4, ptr noundef nonnull %5, ptr noundef %1, ptr noundef %2) #4
  %10 = load i64, ptr %5, align 8, !tbaa !5
  %.not8 = icmp eq i64 %10, 0
  br i1 %.not8, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %3, %16
  call void @llvm.lifetime.start.p0(i64 2, ptr nonnull %6) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %7) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %8) #4
  %11 = call i32 @tls_uint16_from_bytes(ptr noundef nonnull %6, ptr noundef nonnull %4, ptr noundef nonnull %5) #4
  %12 = call i32 @tls_uint16array_from_bytes(ptr noundef nonnull %7, ptr noundef nonnull %8, ptr noundef nonnull %4, ptr noundef nonnull %5) #4
  %13 = load i64, ptr %8, align 8, !tbaa !5
  %.not7 = icmp eq i64 %13, 65
  br i1 %.not7, label %14, label %.critedge

14:                                               ; preds = %.lr.ph
  %15 = load i16, ptr %6, align 2, !tbaa !9
  %cond = icmp eq i16 %15, 41
  br i1 %cond, label %16, label %.critedge

16:                                               ; preds = %14
  %17 = load ptr, ptr %7, align 8, !tbaa !11
  %18 = call i32 @sm2_z256_point_from_octets(ptr noundef %0, ptr noundef %17, i64 noundef 65) #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
  call void @llvm.lifetime.end.p0(i64 2, ptr nonnull %6) #4
  %19 = load i64, ptr %5, align 8, !tbaa !5
  %.not = icmp eq i64 %19, 0
  br i1 %.not, label %.loopexit, label %.lr.ph, !llvm.loop !13

.critedge:                                        ; preds = %14, %.lr.ph
  %.sink9 = phi i32 [ 714, %.lr.ph ], [ 723, %14 ]
  %20 = load ptr, ptr @stderr, align 8, !tbaa !11
  %21 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %20, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef %.sink9, ptr noundef nonnull @__FUNCTION__.tls_client_key_shares_from_bytes) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %8) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %7) #4
  call void @llvm.lifetime.end.p0(i64 2, ptr nonnull %6) #4
  br label %.loopexit

.loopexit:                                        ; preds = %16, %3, %.critedge
  %.2 = phi i32 [ -1, %.critedge ], [ 1, %3 ], [ 1, %16 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %5) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #4
  ret i32 %.2
}

declare i32 @sm2_z256_point_from_octets(ptr noundef, ptr noundef, i64 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 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"short", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"any pointer", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}


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