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

; 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 [57 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [16 x i8], align 1
@__FUNCTION__.tls_record_send = external hidden unnamed_addr constant [16 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [22 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

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

12:                                               ; preds = %3
  br label %13

13:                                               ; preds = %12
  %14 = load ptr, ptr @stderr, align 8, !tbaa !5
  %15 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %14, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 1461, ptr noundef @__FUNCTION__.tls_record_send) #5
  br label %16

16:                                               ; preds = %13
  br label %17

17:                                               ; preds = %16
  store i32 -1, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %106

18:                                               ; preds = %3
  %19 = load i64, ptr %6, align 8, !tbaa !9
  %20 = icmp ult i64 %19, 5
  br i1 %20, label %21, label %27

21:                                               ; preds = %18
  br label %22

22:                                               ; preds = %21
  %23 = load ptr, ptr @stderr, align 8, !tbaa !5
  %24 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %23, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 1465, ptr noundef @__FUNCTION__.tls_record_send) #5
  br label %25

25:                                               ; preds = %22
  br label %26

26:                                               ; preds = %25
  store i32 -1, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %106

27:                                               ; preds = %18
  %28 = load ptr, ptr %5, align 8, !tbaa !5
  %29 = getelementptr inbounds i8, ptr %28, i64 3
  %30 = load i8, ptr %29, align 1, !tbaa !13
  %31 = zext i8 %30 to i16
  %32 = zext i16 %31 to i32
  %33 = shl i32 %32, 8
  %34 = load ptr, ptr %5, align 8, !tbaa !5
  %35 = getelementptr inbounds i8, ptr %34, i64 4
  %36 = load i8, ptr %35, align 1, !tbaa !13
  %37 = zext i8 %36 to i32
  %38 = or i32 %33, %37
  %39 = add nsw i32 5, %38
  %40 = sext i32 %39 to i64
  %41 = load i64, ptr %6, align 8, !tbaa !9
  %42 = icmp ne i64 %40, %41
  br i1 %42, label %43, label %49

43:                                               ; preds = %27
  br label %44

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

47:                                               ; preds = %44
  br label %48

48:                                               ; preds = %47
  store i32 -1, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %106

49:                                               ; preds = %27
  br label %50

50:                                               ; preds = %104, %49
  %51 = load i64, ptr %6, align 8, !tbaa !9
  %52 = icmp ne i64 %51, 0
  br i1 %52, label %53, label %105

53:                                               ; preds = %50
  %54 = load i32, ptr %7, align 4, !tbaa !11
  %55 = load ptr, ptr %5, align 8, !tbaa !5
  %56 = load i64, ptr %6, align 8, !tbaa !9
  %57 = call i64 @send(i32 noundef %54, ptr noundef %55, i64 noundef %56, i32 noundef 0)
  store i64 %57, ptr %8, align 8, !tbaa !9
  %58 = icmp sgt i64 %57, 0
  br i1 %58, label %59, label %66

59:                                               ; preds = %53
  %60 = load i64, ptr %8, align 8, !tbaa !9
  %61 = load ptr, ptr %5, align 8, !tbaa !5
  %62 = getelementptr inbounds i8, ptr %61, i64 %60
  store ptr %62, ptr %5, align 8, !tbaa !5
  %63 = load i64, ptr %8, align 8, !tbaa !9
  %64 = load i64, ptr %6, align 8, !tbaa !9
  %65 = sub i64 %64, %63
  store i64 %65, ptr %6, align 8, !tbaa !9
  br label %104

66:                                               ; preds = %53
  %67 = load i64, ptr %8, align 8, !tbaa !9
  %68 = icmp eq i64 %67, 0
  br i1 %68, label %69, label %86

69:                                               ; preds = %66
  %70 = call ptr @__errno_location() #6
  %71 = load i32, ptr %70, align 4, !tbaa !11
  %72 = icmp eq i32 %71, 11
  br i1 %72, label %77, label %73

73:                                               ; preds = %69
  %74 = call ptr @__errno_location() #6
  %75 = load i32, ptr %74, align 4, !tbaa !11
  %76 = icmp eq i32 %75, 11
  br i1 %76, label %77, label %79

77:                                               ; preds = %73, %69
  %78 = call i32 @usleep(i32 noundef 1000)
  br label %85

79:                                               ; preds = %73
  br label %80

80:                                               ; preds = %79
  %81 = load ptr, ptr @stderr, align 8, !tbaa !5
  %82 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %81, ptr noundef @.str.4, ptr noundef @.str.1, i32 noundef 1482, ptr noundef @__FUNCTION__.tls_record_send, ptr noundef @.str.9) #5
  br label %83

83:                                               ; preds = %80
  br label %84

84:                                               ; preds = %83
  store i32 0, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %106

85:                                               ; preds = %77
  br label %103

86:                                               ; preds = %66
  %87 = call ptr @__errno_location() #6
  %88 = load i32, ptr %87, align 4, !tbaa !11
  %89 = icmp eq i32 %88, 11
  br i1 %89, label %94, label %90

90:                                               ; preds = %86
  %91 = call ptr @__errno_location() #6
  %92 = load i32, ptr %91, align 4, !tbaa !11
  %93 = icmp eq i32 %92, 11
  br i1 %93, label %94, label %96

94:                                               ; preds = %90, %86
  %95 = call i32 @usleep(i32 noundef 1000)
  br label %102

96:                                               ; preds = %90
  br label %97

97:                                               ; preds = %96
  %98 = load ptr, ptr @stderr, align 8, !tbaa !5
  %99 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %98, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 1489, ptr noundef @__FUNCTION__.tls_record_send) #5
  br label %100

100:                                              ; preds = %97
  br label %101

101:                                              ; preds = %100
  store i32 -1, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %106

102:                                              ; preds = %94
  br label %103

103:                                              ; preds = %102, %85
  br label %104

104:                                              ; preds = %103, %59
  br label %50, !llvm.loop !14

105:                                              ; preds = %50
  store i32 1, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %106

106:                                              ; preds = %105, %101, %84, %48, %26, %17
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #5
  %107 = load i32, ptr %4, align 4
  ret i32 %107
}

declare i64 @send(i32 noundef, ptr noundef, i64 noundef, i32 noundef) #3

; Function Attrs: nounwind willreturn memory(none)
declare ptr @__errno_location() #4

declare i32 @usleep(i32 noundef) #3

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 = { 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 #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 willreturn memory(none) "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 #5 = { nounwind }
attributes #6 = { nounwind willreturn memory(none) }

!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 = !{!"int", !7, i64 0}
!13 = !{!7, !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"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 [57 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [16 x i8], align 1
@__FUNCTION__.tls_record_send = external hidden unnamed_addr constant [16 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [22 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: nounwind uwtable
define dso_local range(i32 -1, 2) i32 @tls_record_send(ptr noundef %0, i64 noundef %1, i32 noundef %2) local_unnamed_addr #1 {
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %4, label %7

4:                                                ; preds = %3
  %5 = load ptr, ptr @stderr, align 8, !tbaa !5
  %6 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %5, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 1461, ptr noundef nonnull @__FUNCTION__.tls_record_send) #4
  br label %.loopexit

7:                                                ; preds = %3
  %8 = icmp ult i64 %1, 5
  br i1 %8, label %9, label %12

9:                                                ; preds = %7
  %10 = load ptr, ptr @stderr, align 8, !tbaa !5
  %11 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %10, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 1465, ptr noundef nonnull @__FUNCTION__.tls_record_send) #4
  br label %.loopexit

12:                                               ; preds = %7
  %13 = getelementptr inbounds i8, ptr %0, i64 3
  %14 = load i8, ptr %13, align 1, !tbaa !9
  %15 = zext i8 %14 to i64
  %16 = shl nuw nsw i64 %15, 8
  %17 = getelementptr inbounds i8, ptr %0, i64 4
  %18 = load i8, ptr %17, align 1, !tbaa !9
  %19 = zext i8 %18 to i64
  %20 = or disjoint i64 %16, %19
  %21 = add nuw nsw i64 %20, 5
  %.not21 = icmp eq i64 %21, %1
  br i1 %.not21, label %.preheader, label %22

22:                                               ; preds = %12
  %23 = load ptr, ptr @stderr, align 8, !tbaa !5
  %24 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %23, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 1469, ptr noundef nonnull @__FUNCTION__.tls_record_send) #4
  br label %.loopexit

.preheader:                                       ; preds = %12, %47
  %.01424 = phi ptr [ %.1, %47 ], [ %0, %12 ]
  %.01523 = phi i64 [ %.116, %47 ], [ %1, %12 ]
  %25 = tail call i64 @send(i32 noundef %2, ptr noundef %.01424, i64 noundef %.01523, i32 noundef 0) #5
  %26 = icmp sgt i64 %25, 0
  br i1 %26, label %27, label %30

27:                                               ; preds = %.preheader
  %28 = getelementptr inbounds i8, ptr %.01424, i64 %25
  %29 = sub i64 %.01523, %25
  br label %47

30:                                               ; preds = %.preheader
  %31 = icmp eq i64 %25, 0
  %32 = tail call ptr @__errno_location() #6
  %33 = load i32, ptr %32, align 4, !tbaa !10
  %34 = icmp eq i32 %33, 11
  br i1 %31, label %35, label %41

35:                                               ; preds = %30
  br i1 %34, label %36, label %38

36:                                               ; preds = %35
  %37 = tail call i32 @usleep(i32 noundef 1000) #5
  br label %47

38:                                               ; preds = %35
  %39 = load ptr, ptr @stderr, align 8, !tbaa !5
  %40 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %39, ptr noundef nonnull @.str.4, ptr noundef nonnull @.str.1, i32 noundef 1482, ptr noundef nonnull @__FUNCTION__.tls_record_send, ptr noundef nonnull @.str.9) #4
  br label %.loopexit

41:                                               ; preds = %30
  br i1 %34, label %42, label %44

42:                                               ; preds = %41
  %43 = tail call i32 @usleep(i32 noundef 1000) #5
  br label %47

44:                                               ; preds = %41
  %45 = load ptr, ptr @stderr, align 8, !tbaa !5
  %46 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %45, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 1489, ptr noundef nonnull @__FUNCTION__.tls_record_send) #4
  br label %.loopexit

47:                                               ; preds = %36, %42, %27
  %.116 = phi i64 [ %29, %27 ], [ %.01523, %36 ], [ %.01523, %42 ]
  %.1 = phi ptr [ %28, %27 ], [ %.01424, %36 ], [ %.01424, %42 ]
  %.not22 = icmp eq i64 %.116, 0
  br i1 %.not22, label %.loopexit, label %.preheader, !llvm.loop !12

.loopexit:                                        ; preds = %47, %44, %38, %22, %9, %4
  %.0 = phi i32 [ -1, %9 ], [ -1, %22 ], [ 0, %38 ], [ -1, %44 ], [ -1, %4 ], [ 1, %47 ]
  ret i32 %.0
}

declare i64 @send(i32 noundef, ptr noundef, i64 noundef, i32 noundef) local_unnamed_addr #2

; Function Attrs: mustprogress nofree nosync nounwind willreturn memory(none)
declare ptr @__errno_location() local_unnamed_addr #3

declare i32 @usleep(i32 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 = { 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 #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 = { mustprogress nofree nosync nounwind willreturn memory(none) "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 = { cold nounwind }
attributes #5 = { nounwind }
attributes #6 = { nounwind willreturn memory(none) }

!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 = !{!7, !7, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"int", !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}


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