; 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_ext_from_bytes = external hidden unnamed_addr constant [19 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

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

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

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

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

18:                                               ; preds = %5
  %19 = load ptr, ptr %8, align 8, !tbaa !5
  %20 = load ptr, ptr %9, align 8, !tbaa !5
  %21 = load ptr, ptr %10, align 8, !tbaa !5
  %22 = load ptr, ptr %11, align 8, !tbaa !5
  %23 = call i32 @tls_uint16array_from_bytes(ptr noundef %19, ptr noundef %20, ptr noundef %21, ptr noundef %22)
  %24 = icmp ne i32 %23, 1
  br i1 %24, label %25, label %31

25:                                               ; preds = %18, %5
  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 814, ptr noundef @__FUNCTION__.tls_ext_from_bytes) #4
  br label %29

29:                                               ; preds = %26
  br label %30

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

31:                                               ; preds = %18
  %32 = load i16, ptr %12, align 2, !tbaa !9
  %33 = zext i16 %32 to i32
  %34 = load ptr, ptr %7, align 8, !tbaa !5
  store i32 %33, ptr %34, align 4, !tbaa !11
  %35 = load i16, ptr %12, align 2, !tbaa !9
  %36 = zext i16 %35 to i32
  %37 = call ptr @tls_extension_name(i32 noundef %36)
  %38 = icmp ne ptr %37, null
  br i1 %38, label %45, label %39

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 819, ptr noundef @__FUNCTION__.tls_ext_from_bytes) #4
  br label %43

43:                                               ; preds = %40
  br label %44

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

45:                                               ; preds = %31
  store i32 1, ptr %6, align 4
  store i32 1, ptr %13, align 4
  br label %46

46:                                               ; preds = %45, %44, %30
  call void @llvm.lifetime.end.p0(i64 2, ptr %12) #4
  %47 = load i32, ptr %6, align 4
  ret i32 %47
}

declare ptr @tls_extension_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 = !{!"short", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !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 [61 x i8], align 1
@__FUNCTION__.tls_ext_from_bytes = external hidden unnamed_addr constant [19 x i8], align 1

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

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

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

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

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

; Function Attrs: nounwind uwtable
define dso_local range(i32 -1, 2) i32 @tls_ext_from_bytes(ptr nocapture noundef writeonly %0, ptr noundef %1, ptr noundef %2, ptr noundef %3, ptr noundef %4) local_unnamed_addr #3 {
  %6 = alloca i16, align 2
  call void @llvm.lifetime.start.p0(i64 2, ptr nonnull %6) #4
  %7 = call i32 @tls_uint16_from_bytes(ptr noundef nonnull %6, ptr noundef %3, ptr noundef %4) #4
  %.not = icmp eq i32 %7, 1
  br i1 %.not, label %8, label %.sink.split

8:                                                ; preds = %5
  %9 = call i32 @tls_uint16array_from_bytes(ptr noundef %1, ptr noundef %2, ptr noundef %3, ptr noundef %4) #4
  %.not7 = icmp eq i32 %9, 1
  br i1 %.not7, label %10, label %.sink.split

10:                                               ; preds = %8
  %11 = load i16, ptr %6, align 2, !tbaa !5
  %12 = zext i16 %11 to i32
  store i32 %12, ptr %0, align 4, !tbaa !9
  %13 = call ptr @tls_extension_name(i32 noundef %12) #4
  %.not8 = icmp eq ptr %13, null
  br i1 %.not8, label %.sink.split, label %16

.sink.split:                                      ; preds = %10, %8, %5
  %.sink9 = phi i32 [ 814, %5 ], [ 814, %8 ], [ 819, %10 ]
  %14 = load ptr, ptr @stderr, align 8, !tbaa !11
  %15 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %14, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef %.sink9, ptr noundef nonnull @__FUNCTION__.tls_ext_from_bytes) #5
  br label %16

16:                                               ; preds = %.sink.split, %10
  %.0 = phi i32 [ 1, %10 ], [ -1, %.sink.split ]
  call void @llvm.lifetime.end.p0(i64 2, ptr nonnull %6) #4
  ret i32 %.0
}

declare ptr @tls_extension_name(i32 noundef) local_unnamed_addr #2

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 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 = !{!"short", !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 = !{!"any pointer", !7, i64 0}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass