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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @tls_record_set_handshake_server_key_exchange_ecdhe(ptr noundef %0, ptr noundef %1, i32 noundef %2, ptr noundef %3, ptr noundef %4, i64 noundef %5) #0 {
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca i64, align 8
  %14 = alloca i32, align 4
  %15 = alloca ptr, align 8
  %16 = alloca ptr, align 8
  %17 = alloca i64, align 8
  %18 = alloca i32, align 4
  store ptr %0, ptr %8, align 8, !tbaa !5
  store ptr %1, ptr %9, align 8, !tbaa !5
  store i32 %2, ptr %10, align 4, !tbaa !9
  store ptr %3, ptr %11, align 8, !tbaa !5
  store ptr %4, ptr %12, align 8, !tbaa !5
  store i64 %5, ptr %13, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #4
  store i32 12, ptr %14, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #4
  %19 = load ptr, ptr %8, align 8, !tbaa !5
  %20 = getelementptr inbounds i8, ptr %19, i64 9
  store ptr %20, ptr %15, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #4
  %21 = load ptr, ptr %15, align 8, !tbaa !5
  %22 = getelementptr inbounds i8, ptr %21, i64 69
  store ptr %22, ptr %16, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %17) #4
  store i64 69, ptr %17, align 8, !tbaa !11
  %23 = load ptr, ptr %8, align 8, !tbaa !5
  %24 = icmp ne ptr %23, null
  br i1 %24, label %25, label %44

25:                                               ; preds = %6
  %26 = load ptr, ptr %9, align 8, !tbaa !5
  %27 = icmp ne ptr %26, null
  br i1 %27, label %28, label %44

28:                                               ; preds = %25
  %29 = load i32, ptr %10, align 4, !tbaa !9
  %30 = call ptr @tls_curve_name(i32 noundef %29)
  %31 = icmp ne ptr %30, null
  br i1 %31, label %32, label %44

32:                                               ; preds = %28
  %33 = load ptr, ptr %11, align 8, !tbaa !5
  %34 = icmp ne ptr %33, null
  br i1 %34, label %35, label %44

35:                                               ; preds = %32
  %36 = load ptr, ptr %12, align 8, !tbaa !5
  %37 = icmp ne ptr %36, null
  br i1 %37, label %38, label %44

38:                                               ; preds = %35
  %39 = load i64, ptr %13, align 8, !tbaa !11
  %40 = icmp ne i64 %39, 0
  br i1 %40, label %41, label %44

41:                                               ; preds = %38
  %42 = load i64, ptr %13, align 8, !tbaa !11
  %43 = icmp ugt i64 %42, 72
  br i1 %43, label %44, label %50

44:                                               ; preds = %41, %38, %35, %32, %28, %25, %6
  br label %45

45:                                               ; preds = %44
  %46 = load ptr, ptr @stderr, align 8, !tbaa !5
  %47 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %46, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 54, ptr noundef @__FUNCTION__.tls_record_set_handshake_server_key_exchange_ecdhe) #4
  br label %48

48:                                               ; preds = %45
  br label %49

49:                                               ; preds = %48
  store i32 -1, ptr %7, align 4
  store i32 1, ptr %18, align 4
  br label %75

50:                                               ; preds = %41
  %51 = load ptr, ptr %15, align 8, !tbaa !5
  %52 = getelementptr inbounds i8, ptr %51, i64 0
  store i8 3, ptr %52, align 1, !tbaa !13
  %53 = load i32, ptr %10, align 4, !tbaa !9
  %54 = ashr i32 %53, 8
  %55 = trunc i32 %54 to i8
  %56 = load ptr, ptr %15, align 8, !tbaa !5
  %57 = getelementptr inbounds i8, ptr %56, i64 1
  store i8 %55, ptr %57, align 1, !tbaa !13
  %58 = load i32, ptr %10, align 4, !tbaa !9
  %59 = trunc i32 %58 to i8
  %60 = load ptr, ptr %15, align 8, !tbaa !5
  %61 = getelementptr inbounds i8, ptr %60, i64 2
  store i8 %59, ptr %61, align 1, !tbaa !13
  %62 = load ptr, ptr %15, align 8, !tbaa !5
  %63 = getelementptr inbounds i8, ptr %62, i64 3
  store i8 65, ptr %63, align 1, !tbaa !13
  %64 = load ptr, ptr %11, align 8, !tbaa !5
  %65 = load ptr, ptr %15, align 8, !tbaa !5
  %66 = getelementptr inbounds i8, ptr %65, i64 4
  %67 = call i32 @sm2_z256_point_to_uncompressed_octets(ptr noundef %64, ptr noundef %66)
  call void @tls_uint16_to_bytes(i16 noundef zeroext 1800, ptr noundef %16, ptr noundef %17)
  %68 = load ptr, ptr %12, align 8, !tbaa !5
  %69 = load i64, ptr %13, align 8, !tbaa !11
  call void @tls_uint16array_to_bytes(ptr noundef %68, i64 noundef %69, ptr noundef %16, ptr noundef %17)
  %70 = load ptr, ptr %8, align 8, !tbaa !5
  %71 = load ptr, ptr %9, align 8, !tbaa !5
  %72 = load i32, ptr %14, align 4, !tbaa !9
  %73 = load i64, ptr %17, align 8, !tbaa !11
  %74 = call i32 @tls_record_set_handshake(ptr noundef %70, ptr noundef %71, i32 noundef %72, ptr noundef null, i64 noundef %73)
  store i32 1, ptr %7, align 4
  store i32 1, ptr %18, align 4
  br label %75

75:                                               ; preds = %50, %49
  call void @llvm.lifetime.end.p0(i64 8, ptr %17) #4
  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 4, ptr %14) #4
  %76 = load i32, ptr %7, align 4
  ret i32 %76
}

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

declare ptr @tls_curve_name(i32 noundef) #2

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

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

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

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

declare i32 @tls_record_set_handshake(ptr noundef, ptr noundef, i32 noundef, ptr noundef, i64 noundef) #2

; 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 = { "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 "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 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!7, !7, i64 0}


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

; Function Attrs: nounwind uwtable
define dso_local range(i32 -1, 2) i32 @tls_record_set_handshake_server_key_exchange_ecdhe(ptr noundef %0, ptr noundef %1, i32 noundef %2, ptr noundef %3, ptr noundef %4, i64 noundef %5) local_unnamed_addr #0 {
  %7 = alloca ptr, align 8
  %8 = alloca i64, align 8
  %9 = getelementptr inbounds i8, ptr %0, i64 9
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %7) #4
  %10 = getelementptr inbounds i8, ptr %0, i64 78
  store ptr %10, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %8) #4
  store i64 69, ptr %8, align 8, !tbaa !9
  %11 = icmp ne ptr %0, null
  %12 = icmp ne ptr %1, null
  %or.cond = and i1 %11, %12
  br i1 %or.cond, label %13, label %20

13:                                               ; preds = %6
  %14 = tail call ptr @tls_curve_name(i32 noundef %2) #4
  %15 = icmp eq ptr %14, null
  %16 = icmp eq ptr %3, null
  %or.cond3.not39 = or i1 %16, %15
  %17 = icmp eq ptr %4, null
  %or.cond5.not36 = or i1 %17, %or.cond3.not39
  %18 = add i64 %5, -73
  %19 = icmp ult i64 %18, -72
  %or.cond9 = or i1 %19, %or.cond5.not36
  br i1 %or.cond9, label %20, label %23

20:                                               ; preds = %6, %13
  %21 = load ptr, ptr @stderr, align 8, !tbaa !5
  %22 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %21, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 54, ptr noundef nonnull @__FUNCTION__.tls_record_set_handshake_server_key_exchange_ecdhe) #5
  br label %34

23:                                               ; preds = %13
  store i8 3, ptr %9, align 1, !tbaa !11
  %24 = lshr i32 %2, 8
  %25 = trunc i32 %24 to i8
  %26 = getelementptr inbounds i8, ptr %0, i64 10
  store i8 %25, ptr %26, align 1, !tbaa !11
  %27 = trunc i32 %2 to i8
  %28 = getelementptr inbounds i8, ptr %0, i64 11
  store i8 %27, ptr %28, align 1, !tbaa !11
  %29 = getelementptr inbounds i8, ptr %0, i64 12
  store i8 65, ptr %29, align 1, !tbaa !11
  %30 = getelementptr inbounds i8, ptr %0, i64 13
  %31 = tail call i32 @sm2_z256_point_to_uncompressed_octets(ptr noundef nonnull %3, ptr noundef nonnull %30) #4
  call void @tls_uint16_to_bytes(i16 noundef zeroext 1800, ptr noundef nonnull %7, ptr noundef nonnull %8) #4
  call void @tls_uint16array_to_bytes(ptr noundef nonnull %4, i64 noundef %5, ptr noundef nonnull %7, ptr noundef nonnull %8) #4
  %32 = load i64, ptr %8, align 8, !tbaa !9
  %33 = call i32 @tls_record_set_handshake(ptr noundef nonnull %0, ptr noundef nonnull %1, i32 noundef 12, ptr noundef null, i64 noundef %32) #4
  br label %34

34:                                               ; preds = %23, %20
  %.0 = phi i32 [ -1, %20 ], [ 1, %23 ]
  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
}

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

declare ptr @tls_curve_name(i32 noundef) local_unnamed_addr #2

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

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

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

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

declare i32 @tls_record_set_handshake(ptr noundef, ptr noundef, i32 noundef, ptr noundef, i64 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) #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 = { 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 = { 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 #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 = !{!7, !7, i64 0}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass