; 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_encrypt = 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

; Function Attrs: nounwind uwtable
define dso_local i32 @aes_gcm_encrypt(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) #6
  %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) #6
  %30 = load ptr, ptr %19, align 8, !tbaa !5
  store ptr %30, ptr %23, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %24) #6
  %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) #6
  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) #6
  call void @llvm.lifetime.start.p0(i64 16, ptr %27) #6
  %32 = load i64, ptr %20, align 8, !tbaa !9
  %33 = icmp ugt i64 %32, 16
  br i1 %33, label %34, label %40

34:                                               ; preds = %10
  br label %35

35:                                               ; preds = %34
  %36 = load ptr, ptr @stderr, align 8, !tbaa !5
  %37 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %36, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 162, ptr noundef @__FUNCTION__.aes_gcm_encrypt) #6
  br label %38

38:                                               ; preds = %35
  br label %39

39:                                               ; preds = %38
  store i32 -1, ptr %11, align 4
  store i32 1, ptr %28, align 4
  br label %78

40:                                               ; preds = %10
  %41 = load ptr, ptr %12, align 8, !tbaa !5
  %42 = getelementptr inbounds [16 x i8], ptr %25, i64 0, i64 0
  %43 = getelementptr inbounds [16 x i8], ptr %25, i64 0, i64 0
  call void @aes_encrypt(ptr noundef %41, ptr noundef %42, ptr noundef %43)
  %44 = load i64, ptr %14, align 8, !tbaa !9
  %45 = icmp eq i64 %44, 12
  br i1 %45, label %46, label %53

46:                                               ; preds = %40
  %47 = getelementptr inbounds [16 x i8], ptr %26, i64 0, i64 0
  %48 = load ptr, ptr %13, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %47, ptr align 1 %48, i64 12, i1 false)
  %49 = getelementptr inbounds [16 x i8], ptr %26, i64 0, i64 14
  store i8 0, ptr %49, align 2, !tbaa !11
  %50 = getelementptr inbounds [16 x i8], ptr %26, i64 0, i64 13
  store i8 0, ptr %50, align 1, !tbaa !11
  %51 = getelementptr inbounds [16 x i8], ptr %26, i64 0, i64 12
  store i8 0, ptr %51, align 4, !tbaa !11
  %52 = getelementptr inbounds [16 x i8], ptr %26, i64 0, i64 15
  store i8 1, ptr %52, align 1, !tbaa !11
  br label %58

53:                                               ; preds = %40
  %54 = getelementptr inbounds [16 x i8], ptr %25, i64 0, i64 0
  %55 = load ptr, ptr %13, align 8, !tbaa !5
  %56 = load i64, ptr %14, align 8, !tbaa !9
  %57 = getelementptr inbounds [16 x i8], ptr %26, i64 0, i64 0
  call void @ghash(ptr noundef %54, ptr noundef null, i64 noundef 0, ptr noundef %55, i64 noundef %56, ptr noundef %57)
  br label %58

58:                                               ; preds = %53, %46
  %59 = load ptr, ptr %12, align 8, !tbaa !5
  %60 = getelementptr inbounds [16 x i8], ptr %26, i64 0, i64 0
  %61 = getelementptr inbounds [16 x i8], ptr %27, i64 0, i64 0
  call void @aes_encrypt(ptr noundef %59, ptr noundef %60, ptr noundef %61)
  %62 = getelementptr inbounds [16 x i8], ptr %26, i64 0, i64 0
  call void @ctr32_incr(ptr noundef %62)
  %63 = load ptr, ptr %12, align 8, !tbaa !5
  %64 = getelementptr inbounds [16 x i8], ptr %26, i64 0, i64 0
  %65 = load ptr, ptr %17, align 8, !tbaa !5
  %66 = load i64, ptr %18, align 8, !tbaa !9
  %67 = load ptr, ptr %19, align 8, !tbaa !5
  call void @aes_ctr32_encrypt(ptr noundef %63, ptr noundef %64, ptr noundef %65, i64 noundef %66, ptr noundef %67)
  %68 = getelementptr inbounds [16 x i8], ptr %25, i64 0, i64 0
  %69 = load ptr, ptr %15, align 8, !tbaa !5
  %70 = load i64, ptr %16, align 8, !tbaa !9
  %71 = load ptr, ptr %19, align 8, !tbaa !5
  %72 = load i64, ptr %18, align 8, !tbaa !9
  %73 = getelementptr inbounds [16 x i8], ptr %25, i64 0, i64 0
  call void @ghash(ptr noundef %68, ptr noundef %69, i64 noundef %70, ptr noundef %71, i64 noundef %72, ptr noundef %73)
  %74 = load ptr, ptr %21, align 8, !tbaa !5
  %75 = getelementptr inbounds [16 x i8], ptr %27, i64 0, i64 0
  %76 = getelementptr inbounds [16 x i8], ptr %25, i64 0, i64 0
  %77 = load i64, ptr %20, align 8, !tbaa !9
  call void @gmssl_memxor(ptr noundef %74, ptr noundef %75, ptr noundef %76, i64 noundef %77)
  store i32 1, ptr %11, align 4
  store i32 1, ptr %28, align 4
  br label %78

78:                                               ; preds = %58, %39
  call void @llvm.lifetime.end.p0(i64 16, ptr %27) #6
  call void @llvm.lifetime.end.p0(i64 16, ptr %26) #6
  call void @llvm.lifetime.end.p0(i64 16, ptr %25) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %24) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %23) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %22) #6
  %79 = load i32, ptr %11, align 4
  ret i32 %79
}

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

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 }

!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_encrypt = 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

; Function Attrs: nounwind uwtable
define dso_local range(i32 -1, 2) i32 @aes_gcm_encrypt(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) 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) #6
  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) #6
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %13) #6
  %14 = icmp ugt i64 %8, 16
  br i1 %14, label %15, label %18

15:                                               ; preds = %10
  %16 = load ptr, ptr @stderr, align 8, !tbaa !5
  %17 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %16, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 162, ptr noundef nonnull @__FUNCTION__.aes_gcm_encrypt) #7
  br label %24

18:                                               ; preds = %10
  call void @aes_encrypt(ptr noundef %0, ptr noundef nonnull %11, ptr noundef nonnull %11) #6
  %19 = icmp eq i64 %2, 12
  br i1 %19, label %20, label %22

20:                                               ; preds = %18
  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)
  %21 = getelementptr inbounds i8, ptr %12, i64 12
  store <4 x i8> <i8 0, i8 0, i8 0, i8 1>, ptr %21, align 4, !tbaa !9
  br label %23

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

23:                                               ; preds = %22, %20
  call void @aes_encrypt(ptr noundef %0, ptr noundef nonnull %12, ptr noundef nonnull %13) #6
  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 %7)
  call void @ghash(ptr noundef nonnull %11, ptr noundef %3, i64 noundef %4, ptr noundef %7, i64 noundef %6, ptr noundef nonnull %11) #6
  call void @gmssl_memxor(ptr noundef %9, ptr noundef nonnull %13, ptr noundef nonnull %11, i64 noundef %8) #6
  br label %24

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

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

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 = { nounwind }
attributes #7 = { 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}


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