; 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__.tls13_server_hello_extensions_get = external hidden unnamed_addr constant [34 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 @tls13_server_hello_extensions_get(ptr noundef %0, i64 noundef %1, ptr noundef %2) #3 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i16, align 2
  %9 = alloca i16, align 2
  %10 = alloca ptr, align 8
  %11 = alloca i64, align 8
  %12 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i64 %1, ptr %6, align 8, !tbaa !9
  store ptr %2, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 2, ptr %8) #4
  br label %13

13:                                               ; preds = %60, %3
  %14 = load i64, ptr %6, align 8, !tbaa !9
  %15 = icmp ne i64 %14, 0
  br i1 %15, label %16, label %61

16:                                               ; preds = %13
  call void @llvm.lifetime.start.p0(i64 2, ptr %9) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  %17 = call i32 @tls_uint16_from_bytes(ptr noundef %9, ptr noundef %5, ptr noundef %6)
  %18 = call i32 @tls_uint16array_from_bytes(ptr noundef %10, ptr noundef %11, ptr noundef %5, ptr noundef %6)
  %19 = load i16, ptr %9, align 2, !tbaa !11
  %20 = zext i16 %19 to i32
  switch i32 %20, label %57 [
    i32 43, label %21
    i32 51, label %44
  ]

21:                                               ; preds = %16
  %22 = call i32 @tls_uint16_from_bytes(ptr noundef %8, ptr noundef %10, ptr noundef %11)
  %23 = icmp ne i32 %22, 1
  br i1 %23, label %27, label %24

24:                                               ; preds = %21
  %25 = load i64, ptr %11, align 8, !tbaa !9
  %26 = icmp ugt i64 %25, 0
  br i1 %26, label %27, label %33

27:                                               ; preds = %24, %21
  br label %28

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

31:                                               ; preds = %28
  br label %32

32:                                               ; preds = %31
  store i32 -1, ptr %4, align 4
  store i32 1, ptr %12, align 4
  br label %58

33:                                               ; preds = %24
  %34 = load i16, ptr %8, align 2, !tbaa !11
  %35 = zext i16 %34 to i32
  %36 = icmp ne i32 %35, 772
  br i1 %36, label %37, label %43

37:                                               ; preds = %33
  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 751, ptr noundef @__FUNCTION__.tls13_server_hello_extensions_get) #4
  br label %41

41:                                               ; preds = %38
  br label %42

42:                                               ; preds = %41
  store i32 -1, ptr %4, align 4
  store i32 1, ptr %12, align 4
  br label %58

43:                                               ; preds = %33
  br label %57

44:                                               ; preds = %16
  %45 = load ptr, ptr %10, align 8, !tbaa !5
  %46 = load i64, ptr %11, align 8, !tbaa !9
  %47 = load ptr, ptr %7, align 8, !tbaa !5
  %48 = call i32 @tls13_process_server_key_share(ptr noundef %45, i64 noundef %46, ptr noundef %47)
  %49 = icmp ne i32 %48, 1
  br i1 %49, label %50, label %56

50:                                               ; preds = %44
  br label %51

51:                                               ; preds = %50
  %52 = load ptr, ptr @stderr, align 8, !tbaa !5
  %53 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %52, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 757, ptr noundef @__FUNCTION__.tls13_server_hello_extensions_get) #4
  br label %54

54:                                               ; preds = %51
  br label %55

55:                                               ; preds = %54
  store i32 -1, ptr %4, align 4
  store i32 1, ptr %12, align 4
  br label %58

56:                                               ; preds = %44
  br label %57

57:                                               ; preds = %56, %43, %16
  store i32 0, ptr %12, align 4
  br label %58

58:                                               ; preds = %57, %55, %42, %32
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 2, ptr %9) #4
  %59 = load i32, ptr %12, align 4
  switch i32 %59, label %62 [
    i32 0, label %60
  ]

60:                                               ; preds = %58
  br label %13, !llvm.loop !13

61:                                               ; preds = %13
  store i32 1, ptr %4, align 4
  store i32 1, ptr %12, align 4
  br label %62

62:                                               ; preds = %61, %58
  call void @llvm.lifetime.end.p0(i64 2, ptr %8) #4
  %63 = load i32, ptr %4, align 4
  ret i32 %63
}

declare i32 @tls13_process_server_key_share(ptr noundef, i64 noundef, ptr 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__.tls13_server_hello_extensions_get = 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

; 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 @tls13_server_hello_extensions_get(ptr noundef %0, i64 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 i16, align 2
  %8 = alloca ptr, align 8
  %9 = alloca i64, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i64 %1, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 2, ptr nonnull %6) #4
  %.not6 = icmp eq i64 %1, 0
  br i1 %.not6, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %3, %24
  call void @llvm.lifetime.start.p0(i64 2, ptr nonnull %7) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %8) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %9) #4
  %10 = call i32 @tls_uint16_from_bytes(ptr noundef nonnull %7, ptr noundef nonnull %4, ptr noundef nonnull %5) #4
  %11 = call i32 @tls_uint16array_from_bytes(ptr noundef nonnull %8, ptr noundef nonnull %9, ptr noundef nonnull %4, ptr noundef nonnull %5) #4
  %12 = load i16, ptr %7, align 2, !tbaa !11
  switch i16 %12, label %24 [
    i16 43, label %13
    i16 51, label %20
  ]

13:                                               ; preds = %.lr.ph
  %14 = call i32 @tls_uint16_from_bytes(ptr noundef nonnull %6, ptr noundef nonnull %8, ptr noundef nonnull %9) #4
  %15 = icmp ne i32 %14, 1
  %16 = load i64, ptr %9, align 8
  %17 = icmp ne i64 %16, 0
  %or.cond = select i1 %15, i1 true, i1 %17
  br i1 %or.cond, label %.critedge, label %18

18:                                               ; preds = %13
  %19 = load i16, ptr %6, align 2, !tbaa !11
  %.not5 = icmp eq i16 %19, 772
  br i1 %.not5, label %24, label %.critedge

20:                                               ; preds = %.lr.ph
  %21 = load ptr, ptr %8, align 8, !tbaa !5
  %22 = load i64, ptr %9, align 8, !tbaa !9
  %23 = call i32 @tls13_process_server_key_share(ptr noundef %21, i64 noundef %22, ptr noundef %2) #4
  %.not4 = icmp eq i32 %23, 1
  br i1 %.not4, label %24, label %.critedge

24:                                               ; preds = %.lr.ph, %18, %20
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %9) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %8) #4
  call void @llvm.lifetime.end.p0(i64 2, ptr nonnull %7) #4
  %.pr = load i64, ptr %5, align 8, !tbaa !9
  %.not = icmp eq i64 %.pr, 0
  br i1 %.not, label %.loopexit, label %.lr.ph, !llvm.loop !13

.critedge:                                        ; preds = %20, %18, %13
  %.sink7 = phi i32 [ 747, %13 ], [ 751, %18 ], [ 757, %20 ]
  %25 = load ptr, ptr @stderr, align 8, !tbaa !5
  %26 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %25, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef %.sink7, ptr noundef nonnull @__FUNCTION__.tls13_server_hello_extensions_get) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %9) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %8) #4
  call void @llvm.lifetime.end.p0(i64 2, ptr nonnull %7) #4
  br label %.loopexit

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

declare i32 @tls13_process_server_key_share(ptr noundef, i64 noundef, ptr 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 = !{!"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"}


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