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

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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @tls13_gcm_encrypt(ptr noundef %0, ptr noundef %1, ptr noundef %2, i32 noundef %3, ptr noundef %4, i64 noundef %5, i64 noundef %6, ptr noundef %7, ptr noundef %8) #0 {
  %10 = alloca i32, align 4
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca ptr, align 8
  %14 = alloca i32, align 4
  %15 = alloca ptr, align 8
  %16 = alloca i64, align 8
  %17 = alloca i64, align 8
  %18 = alloca ptr, align 8
  %19 = alloca ptr, align 8
  %20 = alloca [12 x i8], align 1
  %21 = alloca [5 x i8], align 1
  %22 = alloca ptr, align 8
  %23 = alloca ptr, align 8
  %24 = alloca i64, align 8
  %25 = alloca i64, align 8
  %26 = alloca i32, align 4
  store ptr %0, ptr %11, align 8, !tbaa !5
  store ptr %1, ptr %12, align 8, !tbaa !5
  store ptr %2, ptr %13, align 8, !tbaa !5
  store i32 %3, ptr %14, align 4, !tbaa !9
  store ptr %4, ptr %15, align 8, !tbaa !5
  store i64 %5, ptr %16, align 8, !tbaa !11
  store i64 %6, ptr %17, align 8, !tbaa !11
  store ptr %7, ptr %18, align 8, !tbaa !5
  store ptr %8, ptr %19, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 12, ptr %20) #7
  call void @llvm.lifetime.start.p0(i64 5, ptr %21) #7
  call void @llvm.lifetime.start.p0(i64 8, ptr %22) #7
  call void @llvm.lifetime.start.p0(i64 8, ptr %23) #7
  store ptr null, ptr %23, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %24) #7
  call void @llvm.lifetime.start.p0(i64 8, ptr %25) #7
  %27 = load i64, ptr %16, align 8, !tbaa !11
  %28 = add i64 %27, 256
  %29 = call noalias ptr @malloc(i64 noundef %28) #8
  store ptr %29, ptr %23, align 8, !tbaa !5
  %30 = icmp ne ptr %29, null
  br i1 %30, label %37, label %31

31:                                               ; preds = %9
  br label %32

32:                                               ; preds = %31
  %33 = load ptr, ptr @stderr, align 8, !tbaa !5
  %34 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %33, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 111, ptr noundef @__FUNCTION__.tls13_gcm_encrypt) #7
  br label %35

35:                                               ; preds = %32
  br label %36

36:                                               ; preds = %35
  store i32 -1, ptr %10, align 4
  store i32 1, ptr %26, align 4
  br label %100

37:                                               ; preds = %9
  %38 = getelementptr inbounds [12 x i8], ptr %20, i64 0, i64 3
  store i8 0, ptr %38, align 1, !tbaa !13
  %39 = getelementptr inbounds [12 x i8], ptr %20, i64 0, i64 2
  store i8 0, ptr %39, align 1, !tbaa !13
  %40 = getelementptr inbounds [12 x i8], ptr %20, i64 0, i64 1
  store i8 0, ptr %40, align 1, !tbaa !13
  %41 = getelementptr inbounds [12 x i8], ptr %20, i64 0, i64 0
  store i8 0, ptr %41, align 1, !tbaa !13
  %42 = getelementptr inbounds [12 x i8], ptr %20, i64 0, i64 0
  %43 = getelementptr inbounds i8, ptr %42, i64 4
  %44 = load ptr, ptr %13, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %43, ptr align 1 %44, i64 8, i1 false)
  %45 = getelementptr inbounds [12 x i8], ptr %20, i64 0, i64 0
  %46 = getelementptr inbounds [12 x i8], ptr %20, i64 0, i64 0
  %47 = load ptr, ptr %12, align 8, !tbaa !5
  call void @gmssl_memxor(ptr noundef %45, ptr noundef %46, ptr noundef %47, i64 noundef 12)
  %48 = load ptr, ptr %23, align 8, !tbaa !5
  %49 = load ptr, ptr %15, align 8, !tbaa !5
  %50 = load i64, ptr %16, align 8, !tbaa !11
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %48, ptr align 1 %49, i64 %50, i1 false)
  %51 = load i32, ptr %14, align 4, !tbaa !9
  %52 = trunc i32 %51 to i8
  %53 = load ptr, ptr %23, align 8, !tbaa !5
  %54 = load i64, ptr %16, align 8, !tbaa !11
  %55 = getelementptr inbounds i8, ptr %53, i64 %54
  store i8 %52, ptr %55, align 1, !tbaa !13
  %56 = load ptr, ptr %23, align 8, !tbaa !5
  %57 = load i64, ptr %16, align 8, !tbaa !11
  %58 = getelementptr inbounds i8, ptr %56, i64 %57
  %59 = getelementptr inbounds i8, ptr %58, i64 1
  %60 = load i64, ptr %17, align 8, !tbaa !11
  call void @llvm.memset.p0.i64(ptr align 1 %59, i8 0, i64 %60, i1 false)
  %61 = load i64, ptr %16, align 8, !tbaa !11
  %62 = add i64 %61, 1
  %63 = load i64, ptr %17, align 8, !tbaa !11
  %64 = add i64 %62, %63
  store i64 %64, ptr %24, align 8, !tbaa !11
  %65 = load i64, ptr %24, align 8, !tbaa !11
  %66 = add i64 %65, 16
  store i64 %66, ptr %25, align 8, !tbaa !11
  %67 = getelementptr inbounds [5 x i8], ptr %21, i64 0, i64 0
  store i8 23, ptr %67, align 1, !tbaa !13
  %68 = getelementptr inbounds [5 x i8], ptr %21, i64 0, i64 1
  store i8 3, ptr %68, align 1, !tbaa !13
  %69 = getelementptr inbounds [5 x i8], ptr %21, i64 0, i64 2
  store i8 3, ptr %69, align 1, !tbaa !13
  %70 = load i64, ptr %25, align 8, !tbaa !11
  %71 = lshr i64 %70, 8
  %72 = trunc i64 %71 to i8
  %73 = getelementptr inbounds [5 x i8], ptr %21, i64 0, i64 3
  store i8 %72, ptr %73, align 1, !tbaa !13
  %74 = load i64, ptr %25, align 8, !tbaa !11
  %75 = trunc i64 %74 to i8
  %76 = getelementptr inbounds [5 x i8], ptr %21, i64 0, i64 4
  store i8 %75, ptr %76, align 1, !tbaa !13
  %77 = load ptr, ptr %18, align 8, !tbaa !5
  %78 = load i64, ptr %24, align 8, !tbaa !11
  %79 = getelementptr inbounds i8, ptr %77, i64 %78
  store ptr %79, ptr %22, align 8, !tbaa !5
  %80 = load ptr, ptr %11, align 8, !tbaa !5
  %81 = getelementptr inbounds [12 x i8], ptr %20, i64 0, i64 0
  %82 = getelementptr inbounds [5 x i8], ptr %21, i64 0, i64 0
  %83 = load ptr, ptr %23, align 8, !tbaa !5
  %84 = load i64, ptr %24, align 8, !tbaa !11
  %85 = load ptr, ptr %18, align 8, !tbaa !5
  %86 = load ptr, ptr %22, align 8, !tbaa !5
  %87 = call i32 @gcm_encrypt(ptr noundef %80, ptr noundef %81, i64 noundef 12, ptr noundef %82, i64 noundef 5, ptr noundef %83, i64 noundef %84, ptr noundef %85, i64 noundef 16, ptr noundef %86)
  %88 = icmp ne i32 %87, 1
  br i1 %88, label %89, label %96

89:                                               ; preds = %37
  br label %90

90:                                               ; preds = %89
  %91 = load ptr, ptr @stderr, align 8, !tbaa !5
  %92 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %91, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 136, ptr noundef @__FUNCTION__.tls13_gcm_encrypt) #7
  br label %93

93:                                               ; preds = %90
  br label %94

94:                                               ; preds = %93
  %95 = load ptr, ptr %23, align 8, !tbaa !5
  call void @free(ptr noundef %95) #7
  store i32 -1, ptr %10, align 4
  store i32 1, ptr %26, align 4
  br label %100

96:                                               ; preds = %37
  %97 = load i64, ptr %25, align 8, !tbaa !11
  %98 = load ptr, ptr %19, align 8, !tbaa !5
  store i64 %97, ptr %98, align 8, !tbaa !11
  %99 = load ptr, ptr %23, align 8, !tbaa !5
  call void @free(ptr noundef %99) #7
  store i32 1, ptr %10, align 4
  store i32 1, ptr %26, align 4
  br label %100

100:                                              ; preds = %96, %94, %36
  call void @llvm.lifetime.end.p0(i64 8, ptr %25) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr %24) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr %23) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr %22) #7
  call void @llvm.lifetime.end.p0(i64 5, ptr %21) #7
  call void @llvm.lifetime.end.p0(i64 12, ptr %20) #7
  %101 = load i32, ptr %10, align 4
  ret i32 %101
}

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

; Function Attrs: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #3

; 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) #4

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #6

; Function Attrs: nounwind
declare void @free(ptr noundef) #1

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

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 = { 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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { nounwind allocsize(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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #5 = { "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 #6 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #7 = { nounwind }
attributes #8 = { nounwind allocsize(0) }

!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__.tls13_gcm_encrypt = external hidden unnamed_addr constant [18 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local i32 @gcm_encrypt(ptr noundef, ptr noundef, i64 noundef, ptr noundef, i64 noundef, ptr noundef, i64 noundef, ptr noundef, i64 noundef, ptr noundef) local_unnamed_addr #0

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

; Function Attrs: nounwind uwtable
define dso_local range(i32 -1, 2) i32 @tls13_gcm_encrypt(ptr noundef %0, ptr noundef %1, ptr nocapture noundef readonly %2, i32 noundef %3, ptr nocapture noundef readonly %4, i64 noundef %5, i64 noundef %6, ptr noundef %7, ptr nocapture noundef writeonly %8) local_unnamed_addr #0 {
  %10 = alloca [12 x i8], align 4
  %11 = alloca [5 x i8], align 1
  call void @llvm.lifetime.start.p0(i64 12, ptr nonnull %10) #8
  call void @llvm.lifetime.start.p0(i64 5, ptr nonnull %11) #8
  %12 = add i64 %5, 256
  %13 = tail call noalias ptr @malloc(i64 noundef %12) #9
  %.not = icmp eq ptr %13, null
  br i1 %.not, label %14, label %17

14:                                               ; preds = %9
  %15 = load ptr, ptr @stderr, align 8, !tbaa !5
  %16 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %15, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 111, ptr noundef nonnull @__FUNCTION__.tls13_gcm_encrypt) #10
  br label %39

17:                                               ; preds = %9
  %18 = getelementptr inbounds i8, ptr %10, i64 4
  store i32 0, ptr %10, align 4
  %19 = load i64, ptr %2, align 1
  store i64 %19, ptr %18, align 4
  call void @gmssl_memxor(ptr noundef nonnull %10, ptr noundef nonnull %10, ptr noundef %1, i64 noundef 12) #8
  call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 1 %13, ptr align 1 %4, i64 %5, i1 false)
  %20 = trunc i32 %3 to i8
  %21 = getelementptr inbounds i8, ptr %13, i64 %5
  store i8 %20, ptr %21, align 1, !tbaa !9
  %22 = getelementptr inbounds i8, ptr %21, i64 1
  call void @llvm.memset.p0.i64(ptr nonnull align 1 %22, i8 0, i64 %6, i1 false)
  %23 = add i64 %5, 1
  %24 = add i64 %23, %6
  %25 = add i64 %24, 16
  store i8 23, ptr %11, align 1, !tbaa !9
  %26 = getelementptr inbounds i8, ptr %11, i64 1
  store i8 3, ptr %26, align 1, !tbaa !9
  %27 = getelementptr inbounds i8, ptr %11, i64 2
  store i8 3, ptr %27, align 1, !tbaa !9
  %28 = lshr i64 %25, 8
  %29 = trunc i64 %28 to i8
  %30 = getelementptr inbounds i8, ptr %11, i64 3
  store i8 %29, ptr %30, align 1, !tbaa !9
  %31 = trunc i64 %25 to i8
  %32 = getelementptr inbounds i8, ptr %11, i64 4
  store i8 %31, ptr %32, align 1, !tbaa !9
  %33 = getelementptr inbounds i8, ptr %7, i64 %24
  %34 = call i32 @gcm_encrypt(ptr noundef %0, ptr noundef nonnull %10, i64 noundef 12, ptr noundef nonnull %11, i64 noundef 5, ptr noundef nonnull %13, i64 noundef %24, ptr noundef %7, i64 noundef 16, ptr noundef %33)
  %.not29 = icmp eq i32 %34, 1
  br i1 %.not29, label %38, label %35

35:                                               ; preds = %17
  %36 = load ptr, ptr @stderr, align 8, !tbaa !5
  %37 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %36, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 136, ptr noundef nonnull @__FUNCTION__.tls13_gcm_encrypt) #10
  call void @free(ptr noundef nonnull %13) #8
  br label %39

38:                                               ; preds = %17
  store i64 %25, ptr %8, align 8, !tbaa !10
  call void @free(ptr noundef nonnull %13) #8
  br label %39

39:                                               ; preds = %38, %35, %14
  %.0 = phi i32 [ -1, %35 ], [ 1, %38 ], [ -1, %14 ]
  call void @llvm.lifetime.end.p0(i64 5, ptr nonnull %11) #8
  call void @llvm.lifetime.end.p0(i64 12, ptr nonnull %10) #8
  ret i32 %.0
}

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

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #3

; Function Attrs: mustprogress 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) #4

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

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #6

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #7

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

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 = { 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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" "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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #5 = { "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 #6 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #7 = { mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite) "alloc-family"="malloc" "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 #8 = { nounwind }
attributes #9 = { nounwind allocsize(0) }
attributes #10 = { 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 = !{!7, !7, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"long", !7, i64 0}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,MemCpyOptPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass