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

; 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 [63 x i8], align 1
@__FUNCTION__.aes_gcm_decrypt = external hidden unnamed_addr constant [16 x i8], align 1

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

declare void @aes_encrypt(ptr noundef, 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 nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #2

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

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

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

declare void @ghash(ptr noundef, ptr noundef, i64 noundef, ptr noundef, i64 noundef, ptr noundef) #0

; Function Attrs: nounwind uwtable
declare hidden void @ctr32_incr(ptr noundef) #5

; Function Attrs: nounwind uwtable
declare hidden void @aes_ctr32_encrypt(ptr noundef, ptr noundef, ptr noundef, i64 noundef, ptr noundef) #5

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

37:                                               ; preds = %10
  %38 = getelementptr inbounds [16 x i8], ptr %26, i64 0, i64 0
  %39 = load ptr, ptr %13, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %38, ptr align 1 %39, i64 12, i1 false)
  %40 = getelementptr inbounds [16 x i8], ptr %26, i64 0, i64 14
  store i8 0, ptr %40, align 2, !tbaa !11
  %41 = getelementptr inbounds [16 x i8], ptr %26, i64 0, i64 13
  store i8 0, ptr %41, align 1, !tbaa !11
  %42 = getelementptr inbounds [16 x i8], ptr %26, i64 0, i64 12
  store i8 0, ptr %42, align 4, !tbaa !11
  %43 = getelementptr inbounds [16 x i8], ptr %26, i64 0, i64 15
  store i8 1, ptr %43, align 1, !tbaa !11
  br label %49

44:                                               ; preds = %10
  %45 = getelementptr inbounds [16 x i8], ptr %25, i64 0, i64 0
  %46 = load ptr, ptr %13, align 8, !tbaa !5
  %47 = load i64, ptr %14, align 8, !tbaa !9
  %48 = getelementptr inbounds [16 x i8], ptr %26, i64 0, i64 0
  call void @ghash(ptr noundef %45, ptr noundef null, i64 noundef 0, ptr noundef %46, i64 noundef %47, ptr noundef %48)
  br label %49

49:                                               ; preds = %44, %37
  %50 = getelementptr inbounds [16 x i8], ptr %25, i64 0, i64 0
  %51 = load ptr, ptr %15, align 8, !tbaa !5
  %52 = load i64, ptr %16, align 8, !tbaa !9
  %53 = load ptr, ptr %17, align 8, !tbaa !5
  %54 = load i64, ptr %18, align 8, !tbaa !9
  %55 = getelementptr inbounds [16 x i8], ptr %25, i64 0, i64 0
  call void @ghash(ptr noundef %50, ptr noundef %51, i64 noundef %52, ptr noundef %53, i64 noundef %54, ptr noundef %55)
  %56 = load ptr, ptr %12, align 8, !tbaa !5
  %57 = getelementptr inbounds [16 x i8], ptr %26, i64 0, i64 0
  %58 = getelementptr inbounds [16 x i8], ptr %27, i64 0, i64 0
  call void @aes_encrypt(ptr noundef %56, ptr noundef %57, ptr noundef %58)
  %59 = getelementptr inbounds [16 x i8], ptr %27, i64 0, i64 0
  %60 = getelementptr inbounds [16 x i8], ptr %27, i64 0, i64 0
  %61 = getelementptr inbounds [16 x i8], ptr %25, i64 0, i64 0
  %62 = load i64, ptr %20, align 8, !tbaa !9
  call void @gmssl_memxor(ptr noundef %59, ptr noundef %60, ptr noundef %61, i64 noundef %62)
  %63 = getelementptr inbounds [16 x i8], ptr %27, i64 0, i64 0
  %64 = load ptr, ptr %19, align 8, !tbaa !5
  %65 = load i64, ptr %20, align 8, !tbaa !9
  %66 = call i32 @memcmp(ptr noundef %63, ptr noundef %64, i64 noundef %65) #8
  %67 = icmp ne i32 %66, 0
  br i1 %67, label %68, label %74

68:                                               ; preds = %49
  br label %69

69:                                               ; preds = %68
  %70 = load ptr, ptr @stderr, align 8, !tbaa !5
  %71 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %70, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 211, ptr noundef @__FUNCTION__.aes_gcm_decrypt) #7
  br label %72

72:                                               ; preds = %69
  br label %73

73:                                               ; preds = %72
  store i32 -1, ptr %11, align 4
  store i32 1, ptr %28, align 4
  br label %81

74:                                               ; preds = %49
  %75 = getelementptr inbounds [16 x i8], ptr %26, i64 0, i64 0
  call void @ctr32_incr(ptr noundef %75)
  %76 = load ptr, ptr %12, align 8, !tbaa !5
  %77 = getelementptr inbounds [16 x i8], ptr %26, i64 0, i64 0
  %78 = load ptr, ptr %17, align 8, !tbaa !5
  %79 = load i64, ptr %18, align 8, !tbaa !9
  %80 = load ptr, ptr %21, align 8, !tbaa !5
  call void @aes_ctr32_encrypt(ptr noundef %76, ptr noundef %77, ptr noundef %78, i64 noundef %79, ptr noundef %80)
  store i32 1, ptr %11, align 4
  store i32 1, ptr %28, align 4
  br label %81

81:                                               ; preds = %74, %73
  call void @llvm.lifetime.end.p0(i64 16, ptr %27) #7
  call void @llvm.lifetime.end.p0(i64 16, ptr %26) #7
  call void @llvm.lifetime.end.p0(i64 16, 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
  %82 = load i32, ptr %11, align 4
  ret i32 %82
}

; Function Attrs: nounwind willreturn memory(read)
declare i32 @memcmp(ptr noundef, ptr noundef, i64 noundef) #6

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

!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}


; 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 [63 x i8], align 1
@__FUNCTION__.aes_gcm_decrypt = external hidden unnamed_addr constant [16 x i8], align 1

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

declare void @aes_encrypt(ptr noundef, ptr noundef, ptr noundef) 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 nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #2

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

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

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

declare void @ghash(ptr noundef, ptr noundef, i64 noundef, ptr noundef, i64 noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare hidden void @ctr32_incr(ptr noundef) local_unnamed_addr #5

; Function Attrs: nounwind uwtable
declare hidden void @aes_ctr32_encrypt(ptr noundef, ptr noundef, ptr noundef, i64 noundef, ptr noundef) local_unnamed_addr #5

; Function Attrs: nounwind uwtable
define dso_local range(i32 -1, 2) i32 @aes_gcm_decrypt(ptr noundef %0, ptr noundef %1, i64 noundef %2, ptr noundef %3, i64 noundef %4, ptr noundef %5, i64 noundef %6, ptr nocapture noundef readonly %7, i64 noundef %8, ptr noundef %9) local_unnamed_addr #5 {
  %11 = alloca [16 x i8], align 16
  %12 = alloca [16 x i8], align 16
  %13 = alloca [16 x i8], align 16
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %11) #7
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(16) %11, i8 0, i64 16, i1 false)
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %12) #7
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %13) #7
  call void @aes_encrypt(ptr noundef %0, ptr noundef nonnull %11, ptr noundef nonnull %11) #7
  %14 = icmp eq i64 %2, 12
  br i1 %14, label %15, label %17

15:                                               ; preds = %10
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 16 dereferenceable(12) %12, ptr noundef nonnull align 1 dereferenceable(12) %1, i64 12, i1 false)
  %16 = getelementptr inbounds i8, ptr %12, i64 12
  store <4 x i8> <i8 0, i8 0, i8 0, i8 1>, ptr %16, align 4, !tbaa !5
  br label %18

17:                                               ; preds = %10
  call void @ghash(ptr noundef nonnull %11, ptr noundef null, i64 noundef 0, ptr noundef %1, i64 noundef %2, ptr noundef nonnull %12) #7
  br label %18

18:                                               ; preds = %17, %15
  call void @ghash(ptr noundef nonnull %11, ptr noundef %3, i64 noundef %4, ptr noundef %5, i64 noundef %6, ptr noundef nonnull %11) #7
  call void @aes_encrypt(ptr noundef %0, ptr noundef nonnull %12, ptr noundef nonnull %13) #7
  call void @gmssl_memxor(ptr noundef nonnull %13, ptr noundef nonnull %13, ptr noundef nonnull %11, i64 noundef %8) #7
  %bcmp = call i32 @bcmp(ptr nonnull %13, ptr %7, i64 %8)
  %.not = icmp eq i32 %bcmp, 0
  br i1 %.not, label %22, label %19

19:                                               ; preds = %18
  %20 = load ptr, ptr @stderr, align 8, !tbaa !8
  %21 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %20, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 211, ptr noundef nonnull @__FUNCTION__.aes_gcm_decrypt) #8
  br label %23

22:                                               ; preds = %18
  call void @ctr32_incr(ptr noundef nonnull %12)
  call void @aes_ctr32_encrypt(ptr noundef %0, ptr noundef nonnull %12, ptr noundef %5, i64 noundef %6, ptr noundef %9)
  br label %23

23:                                               ; preds = %22, %19
  %.0 = phi i32 [ -1, %19 ], [ 1, %22 ]
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %13) #7
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %12) #7
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %11) #7
  ret i32 %.0
}

; Function Attrs: nofree nounwind willreturn memory(argmem: read)
declare i32 @bcmp(ptr nocapture, ptr nocapture, i64) local_unnamed_addr #6

attributes #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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #4 = { 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 #5 = { 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 #6 = { nofree nounwind willreturn memory(argmem: read) }
attributes #7 = { nounwind }
attributes #8 = { 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 = !{!"any pointer", !6, i64 0}


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