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

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

; Function Attrs: nounwind uwtable
declare dso_local i32 @gcm_decrypt(ptr noundef, ptr noundef, i64 noundef, ptr noundef, i64 noundef, ptr noundef, i64 noundef, ptr noundef, i64 noundef, ptr noundef) #1

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #3

declare void @gmssl_memxor(ptr noundef, ptr noundef, ptr noundef, i64 noundef) #4

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

; Function Attrs: nounwind uwtable
define dso_local i32 @tls13_gcm_decrypt(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3, i64 noundef %4, ptr noundef %5, ptr noundef %6, ptr noundef %7) #1 {
  %9 = alloca i32, align 4
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca ptr, align 8
  %14 = alloca i64, align 8
  %15 = alloca ptr, align 8
  %16 = alloca ptr, align 8
  %17 = alloca ptr, align 8
  %18 = alloca [12 x i8], align 1
  %19 = alloca [5 x i8], align 1
  %20 = alloca i64, align 8
  %21 = alloca ptr, align 8
  %22 = alloca i32, align 4
  store ptr %0, ptr %10, align 8, !tbaa !5
  store ptr %1, ptr %11, align 8, !tbaa !5
  store ptr %2, ptr %12, align 8, !tbaa !5
  store ptr %3, ptr %13, align 8, !tbaa !5
  store i64 %4, ptr %14, align 8, !tbaa !9
  store ptr %5, ptr %15, align 8, !tbaa !5
  store ptr %6, ptr %16, align 8, !tbaa !5
  store ptr %7, ptr %17, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 12, ptr %18) #5
  call void @llvm.lifetime.start.p0(i64 5, ptr %19) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %20) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %21) #5
  %23 = getelementptr inbounds [12 x i8], ptr %18, i64 0, i64 3
  store i8 0, ptr %23, align 1, !tbaa !11
  %24 = getelementptr inbounds [12 x i8], ptr %18, i64 0, i64 2
  store i8 0, ptr %24, align 1, !tbaa !11
  %25 = getelementptr inbounds [12 x i8], ptr %18, i64 0, i64 1
  store i8 0, ptr %25, align 1, !tbaa !11
  %26 = getelementptr inbounds [12 x i8], ptr %18, i64 0, i64 0
  store i8 0, ptr %26, align 1, !tbaa !11
  %27 = getelementptr inbounds [12 x i8], ptr %18, i64 0, i64 0
  %28 = getelementptr inbounds i8, ptr %27, i64 4
  %29 = load ptr, ptr %12, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %28, ptr align 1 %29, i64 8, i1 false)
  %30 = getelementptr inbounds [12 x i8], ptr %18, i64 0, i64 0
  %31 = getelementptr inbounds [12 x i8], ptr %18, i64 0, i64 0
  %32 = load ptr, ptr %11, align 8, !tbaa !5
  call void @gmssl_memxor(ptr noundef %30, ptr noundef %31, ptr noundef %32, i64 noundef 12)
  %33 = getelementptr inbounds [5 x i8], ptr %19, i64 0, i64 0
  store i8 23, ptr %33, align 1, !tbaa !11
  %34 = getelementptr inbounds [5 x i8], ptr %19, i64 0, i64 1
  store i8 3, ptr %34, align 1, !tbaa !11
  %35 = getelementptr inbounds [5 x i8], ptr %19, i64 0, i64 2
  store i8 3, ptr %35, align 1, !tbaa !11
  %36 = load i64, ptr %14, align 8, !tbaa !9
  %37 = lshr i64 %36, 8
  %38 = trunc i64 %37 to i8
  %39 = getelementptr inbounds [5 x i8], ptr %19, i64 0, i64 3
  store i8 %38, ptr %39, align 1, !tbaa !11
  %40 = load i64, ptr %14, align 8, !tbaa !9
  %41 = trunc i64 %40 to i8
  %42 = getelementptr inbounds [5 x i8], ptr %19, i64 0, i64 4
  store i8 %41, ptr %42, align 1, !tbaa !11
  %43 = load i64, ptr %14, align 8, !tbaa !9
  %44 = icmp ult i64 %43, 16
  br i1 %44, label %45, label %51

45:                                               ; preds = %8
  br label %46

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

49:                                               ; preds = %46
  br label %50

50:                                               ; preds = %49
  store i32 -1, ptr %9, align 4
  store i32 1, ptr %22, align 4
  br label %107

51:                                               ; preds = %8
  %52 = load i64, ptr %14, align 8, !tbaa !9
  %53 = sub i64 %52, 16
  store i64 %53, ptr %20, align 8, !tbaa !9
  %54 = load ptr, ptr %13, align 8, !tbaa !5
  %55 = load i64, ptr %20, align 8, !tbaa !9
  %56 = getelementptr inbounds i8, ptr %54, i64 %55
  store ptr %56, ptr %21, align 8, !tbaa !5
  %57 = load ptr, ptr %10, align 8, !tbaa !5
  %58 = getelementptr inbounds [12 x i8], ptr %18, i64 0, i64 0
  %59 = getelementptr inbounds [5 x i8], ptr %19, i64 0, i64 0
  %60 = load ptr, ptr %13, align 8, !tbaa !5
  %61 = load i64, ptr %20, align 8, !tbaa !9
  %62 = load ptr, ptr %21, align 8, !tbaa !5
  %63 = load ptr, ptr %16, align 8, !tbaa !5
  %64 = call i32 @gcm_decrypt(ptr noundef %57, ptr noundef %58, i64 noundef 12, ptr noundef %59, i64 noundef 5, ptr noundef %60, i64 noundef %61, ptr noundef %62, i64 noundef 16, ptr noundef %63)
  %65 = icmp ne i32 %64, 1
  br i1 %65, label %66, label %72

66:                                               ; preds = %51
  br label %67

67:                                               ; preds = %66
  %68 = load ptr, ptr @stderr, align 8, !tbaa !5
  %69 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %68, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 175, ptr noundef @__FUNCTION__.tls13_gcm_decrypt) #5
  br label %70

70:                                               ; preds = %67
  br label %71

71:                                               ; preds = %70
  store i32 -1, ptr %9, align 4
  store i32 1, ptr %22, align 4
  br label %107

72:                                               ; preds = %51
  %73 = load ptr, ptr %15, align 8, !tbaa !5
  store i32 0, ptr %73, align 4, !tbaa !12
  br label %74

74:                                               ; preds = %92, %72
  %75 = load i64, ptr %20, align 8, !tbaa !9
  %76 = add i64 %75, -1
  store i64 %76, ptr %20, align 8, !tbaa !9
  %77 = icmp ne i64 %75, 0
  br i1 %77, label %78, label %93

78:                                               ; preds = %74
  %79 = load ptr, ptr %16, align 8, !tbaa !5
  %80 = load i64, ptr %20, align 8, !tbaa !9
  %81 = getelementptr inbounds i8, ptr %79, i64 %80
  %82 = load i8, ptr %81, align 1, !tbaa !11
  %83 = zext i8 %82 to i32
  %84 = icmp ne i32 %83, 0
  br i1 %84, label %85, label %92

85:                                               ; preds = %78
  %86 = load ptr, ptr %16, align 8, !tbaa !5
  %87 = load i64, ptr %20, align 8, !tbaa !9
  %88 = getelementptr inbounds i8, ptr %86, i64 %87
  %89 = load i8, ptr %88, align 1, !tbaa !11
  %90 = zext i8 %89 to i32
  %91 = load ptr, ptr %15, align 8, !tbaa !5
  store i32 %90, ptr %91, align 4, !tbaa !12
  br label %93

92:                                               ; preds = %78
  br label %74, !llvm.loop !14

93:                                               ; preds = %85, %74
  %94 = load i64, ptr %20, align 8, !tbaa !9
  %95 = load ptr, ptr %17, align 8, !tbaa !5
  store i64 %94, ptr %95, align 8, !tbaa !9
  %96 = load ptr, ptr %15, align 8, !tbaa !5
  %97 = load i32, ptr %96, align 4, !tbaa !12
  %98 = call ptr @tls_record_type_name(i32 noundef %97)
  %99 = icmp ne ptr %98, null
  br i1 %99, label %106, label %100

100:                                              ; preds = %93
  br label %101

101:                                              ; preds = %100
  %102 = load ptr, ptr @stderr, align 8, !tbaa !5
  %103 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %102, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 188, ptr noundef @__FUNCTION__.tls13_gcm_decrypt) #5
  br label %104

104:                                              ; preds = %101
  br label %105

105:                                              ; preds = %104
  store i32 -1, ptr %9, align 4
  store i32 1, ptr %22, align 4
  br label %107

106:                                              ; preds = %93
  store i32 1, ptr %9, align 4
  store i32 1, ptr %22, align 4
  br label %107

107:                                              ; preds = %106, %105, %71, %50
  call void @llvm.lifetime.end.p0(i64 8, ptr %21) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %20) #5
  call void @llvm.lifetime.end.p0(i64 5, ptr %19) #5
  call void @llvm.lifetime.end.p0(i64 12, ptr %18) #5
  %108 = load i32, ptr %9, align 4
  ret i32 %108
}

declare ptr @tls_record_type_name(i32 noundef) #4

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 = { 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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { "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 }

!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}
!12 = !{!13, !13, i64 0}
!13 = !{!"int", !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 [59 x i8], align 1
@__FUNCTION__.tls13_gcm_decrypt = external hidden unnamed_addr constant [18 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
declare dso_local i32 @gcm_decrypt(ptr noundef, ptr noundef, i64 noundef, ptr noundef, i64 noundef, ptr noundef, i64 noundef, ptr noundef, i64 noundef, ptr noundef) local_unnamed_addr #1

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

declare void @gmssl_memxor(ptr noundef, ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #3

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

; Function Attrs: nounwind uwtable
define dso_local range(i32 -1, 2) i32 @tls13_gcm_decrypt(ptr noundef %0, ptr noundef %1, ptr nocapture noundef readonly %2, ptr noundef %3, i64 noundef %4, ptr nocapture noundef writeonly %5, ptr noundef %6, ptr nocapture noundef writeonly %7) local_unnamed_addr #1 {
  %9 = alloca [12 x i8], align 4
  %10 = alloca [5 x i8], align 1
  call void @llvm.lifetime.start.p0(i64 12, ptr nonnull %9) #4
  call void @llvm.lifetime.start.p0(i64 5, ptr nonnull %10) #4
  %11 = getelementptr inbounds i8, ptr %9, i64 4
  store i32 0, ptr %9, align 4
  %12 = load i64, ptr %2, align 1
  store i64 %12, ptr %11, align 4
  call void @gmssl_memxor(ptr noundef nonnull %9, ptr noundef nonnull %9, ptr noundef %1, i64 noundef 12) #4
  store i8 23, ptr %10, align 1, !tbaa !5
  %13 = getelementptr inbounds i8, ptr %10, i64 1
  store i8 3, ptr %13, align 1, !tbaa !5
  %14 = getelementptr inbounds i8, ptr %10, i64 2
  store i8 3, ptr %14, align 1, !tbaa !5
  %15 = lshr i64 %4, 8
  %16 = trunc i64 %15 to i8
  %17 = getelementptr inbounds i8, ptr %10, i64 3
  store i8 %16, ptr %17, align 1, !tbaa !5
  %18 = trunc i64 %4 to i8
  %19 = getelementptr inbounds i8, ptr %10, i64 4
  store i8 %18, ptr %19, align 1, !tbaa !5
  %20 = icmp ult i64 %4, 16
  br i1 %20, label %.sink.split, label %21

21:                                               ; preds = %8
  %22 = add i64 %4, -16
  %23 = getelementptr inbounds i8, ptr %3, i64 %22
  %24 = call i32 @gcm_decrypt(ptr noundef %0, ptr noundef nonnull %9, i64 noundef 12, ptr noundef nonnull %10, i64 noundef 5, ptr noundef %3, i64 noundef %22, ptr noundef %23, i64 noundef 16, ptr noundef %6)
  %.not = icmp eq i32 %24, 1
  br i1 %.not, label %25, label %.sink.split

25:                                               ; preds = %21
  store i32 0, ptr %5, align 4, !tbaa !8
  br label %26

26:                                               ; preds = %28, %25
  %.023 = phi i64 [ %22, %25 ], [ %27, %28 ]
  %27 = add i64 %.023, -1
  %.not26 = icmp eq i64 %.023, 0
  br i1 %.not26, label %.loopexit, label %28

28:                                               ; preds = %26
  %29 = getelementptr inbounds i8, ptr %6, i64 %27
  %30 = load i8, ptr %29, align 1, !tbaa !5
  %.not27 = icmp eq i8 %30, 0
  br i1 %.not27, label %26, label %31, !llvm.loop !10

31:                                               ; preds = %28
  %32 = zext i8 %30 to i32
  store i32 %32, ptr %5, align 4, !tbaa !8
  br label %.loopexit

.loopexit:                                        ; preds = %26, %31
  %33 = phi i32 [ %32, %31 ], [ 0, %26 ]
  store i64 %27, ptr %7, align 8, !tbaa !12
  %34 = call ptr @tls_record_type_name(i32 noundef %33) #4
  %.not28 = icmp eq ptr %34, null
  br i1 %.not28, label %.sink.split, label %37

.sink.split:                                      ; preds = %.loopexit, %21, %8
  %.sink35 = phi i32 [ 168, %8 ], [ 175, %21 ], [ 188, %.loopexit ]
  %35 = load ptr, ptr @stderr, align 8, !tbaa !14
  %36 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %35, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef %.sink35, ptr noundef nonnull @__FUNCTION__.tls13_gcm_decrypt) #5
  br label %37

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

declare ptr @tls_record_type_name(i32 noundef) local_unnamed_addr #3

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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 }
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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = !{!9, !9, i64 0}
!9 = !{!"int", !6, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}
!12 = !{!13, !13, i64 0}
!13 = !{!"long", !6, i64 0}
!14 = !{!15, !15, i64 0}
!15 = !{!"any pointer", !6, i64 0}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopSimplifyPass,LoopUnrollPass,MemCpyOptPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass