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

; 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"

%struct.GHASH_CTX = type { [2 x i64], [2 x i64], i64, i64, [16 x i8], i64 }

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

declare void @gf128_from_bytes(ptr noundef, ptr noundef) #1

declare void @gf128_set_zero(ptr noundef) #1

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #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 @gf128_add(ptr noundef, ptr noundef, ptr noundef) #1

declare void @gf128_mul(ptr noundef, ptr noundef, ptr noundef) #1

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

; Function Attrs: nounwind uwtable
define dso_local void @ghash_init(ptr noundef %0, ptr noundef %1, ptr noundef %2, i64 noundef %3) #4 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i64, align 8
  %9 = alloca [2 x i64], align 16
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !5
  store i64 %3, ptr %8, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 16, ptr %9) #5
  %10 = load ptr, ptr %5, align 8, !tbaa !5
  call void @llvm.memset.p0.i64(ptr align 8 %10, i8 0, i64 72, i1 false)
  %11 = load ptr, ptr %5, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.GHASH_CTX, ptr %11, i32 0, i32 0
  %13 = getelementptr inbounds [2 x i64], ptr %12, i64 0, i64 0
  %14 = load ptr, ptr %6, align 8, !tbaa !5
  call void @gf128_from_bytes(ptr noundef %13, ptr noundef %14)
  %15 = load ptr, ptr %5, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.GHASH_CTX, ptr %15, i32 0, i32 1
  %17 = getelementptr inbounds [2 x i64], ptr %16, i64 0, i64 0
  call void @gf128_set_zero(ptr noundef %17)
  %18 = load i64, ptr %8, align 8, !tbaa !9
  %19 = load ptr, ptr %5, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.GHASH_CTX, ptr %19, i32 0, i32 2
  store i64 %18, ptr %20, align 8, !tbaa !11
  %21 = load ptr, ptr %5, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.GHASH_CTX, ptr %21, i32 0, i32 3
  store i64 0, ptr %22, align 8, !tbaa !13
  br label %23

23:                                               ; preds = %49, %4
  %24 = load i64, ptr %8, align 8, !tbaa !9
  %25 = icmp ne i64 %24, 0
  br i1 %25, label %26, label %66

26:                                               ; preds = %23
  %27 = load i64, ptr %8, align 8, !tbaa !9
  %28 = icmp uge i64 %27, 16
  br i1 %28, label %29, label %36

29:                                               ; preds = %26
  %30 = getelementptr inbounds [2 x i64], ptr %9, i64 0, i64 0
  %31 = load ptr, ptr %7, align 8, !tbaa !5
  call void @gf128_from_bytes(ptr noundef %30, ptr noundef %31)
  %32 = load ptr, ptr %7, align 8, !tbaa !5
  %33 = getelementptr inbounds i8, ptr %32, i64 16
  store ptr %33, ptr %7, align 8, !tbaa !5
  %34 = load i64, ptr %8, align 8, !tbaa !9
  %35 = sub i64 %34, 16
  store i64 %35, ptr %8, align 8, !tbaa !9
  br label %49

36:                                               ; preds = %26
  %37 = load ptr, ptr %5, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.GHASH_CTX, ptr %37, i32 0, i32 4
  %39 = getelementptr inbounds [16 x i8], ptr %38, i64 0, i64 0
  call void @llvm.memset.p0.i64(ptr align 8 %39, i8 0, i64 16, i1 false)
  %40 = load ptr, ptr %5, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.GHASH_CTX, ptr %40, i32 0, i32 4
  %42 = getelementptr inbounds [16 x i8], ptr %41, i64 0, i64 0
  %43 = load ptr, ptr %7, align 8, !tbaa !5
  %44 = load i64, ptr %8, align 8, !tbaa !9
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %42, ptr align 1 %43, i64 %44, i1 false)
  %45 = getelementptr inbounds [2 x i64], ptr %9, i64 0, i64 0
  %46 = load ptr, ptr %5, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.GHASH_CTX, ptr %46, i32 0, i32 4
  %48 = getelementptr inbounds [16 x i8], ptr %47, i64 0, i64 0
  call void @gf128_from_bytes(ptr noundef %45, ptr noundef %48)
  store i64 0, ptr %8, align 8, !tbaa !9
  br label %49

49:                                               ; preds = %36, %29
  %50 = load ptr, ptr %5, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.GHASH_CTX, ptr %50, i32 0, i32 1
  %52 = getelementptr inbounds [2 x i64], ptr %51, i64 0, i64 0
  %53 = load ptr, ptr %5, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.GHASH_CTX, ptr %53, i32 0, i32 1
  %55 = getelementptr inbounds [2 x i64], ptr %54, i64 0, i64 0
  %56 = getelementptr inbounds [2 x i64], ptr %9, i64 0, i64 0
  call void @gf128_add(ptr noundef %52, ptr noundef %55, ptr noundef %56)
  %57 = load ptr, ptr %5, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.GHASH_CTX, ptr %57, i32 0, i32 1
  %59 = getelementptr inbounds [2 x i64], ptr %58, i64 0, i64 0
  %60 = load ptr, ptr %5, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.GHASH_CTX, ptr %60, i32 0, i32 1
  %62 = getelementptr inbounds [2 x i64], ptr %61, i64 0, i64 0
  %63 = load ptr, ptr %5, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.GHASH_CTX, ptr %63, i32 0, i32 0
  %65 = getelementptr inbounds [2 x i64], ptr %64, i64 0, i64 0
  call void @gf128_mul(ptr noundef %59, ptr noundef %62, ptr noundef %65)
  br label %23, !llvm.loop !14

66:                                               ; preds = %23
  call void @llvm.lifetime.end.p0(i64 16, ptr %9) #5
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { "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 nounwind willreturn memory(argmem: write) }
attributes #3 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { 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 #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 = !{!12, !10, i64 32}
!12 = !{!"", !7, i64 0, !7, i64 16, !10, i64 32, !10, i64 40, !7, i64 48, !10, i64 64}
!13 = !{!12, !10, i64 40}
!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"

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

declare void @gf128_from_bytes(ptr noundef, ptr noundef) local_unnamed_addr #1

declare void @gf128_set_zero(ptr noundef) local_unnamed_addr #1

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

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

declare void @gf128_add(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

declare void @gf128_mul(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

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

; Function Attrs: nounwind uwtable
define dso_local void @ghash_init(ptr noundef %0, ptr noundef %1, ptr noundef %2, i64 noundef %3) local_unnamed_addr #4 {
  %5 = alloca [2 x i64], align 16
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %5) #5
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(72) %0, i8 0, i64 72, i1 false)
  tail call void @gf128_from_bytes(ptr noundef %0, ptr noundef %1) #5
  %6 = getelementptr inbounds i8, ptr %0, i64 16
  tail call void @gf128_set_zero(ptr noundef nonnull %6) #5
  %7 = getelementptr inbounds i8, ptr %0, i64 32
  store i64 %3, ptr %7, align 8, !tbaa !5
  %8 = getelementptr inbounds i8, ptr %0, i64 40
  store i64 0, ptr %8, align 8, !tbaa !10
  %.not23 = icmp eq i64 %3, 0
  br i1 %.not23, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %4
  %9 = getelementptr inbounds i8, ptr %0, i64 48
  br label %10

10:                                               ; preds = %.lr.ph, %16
  %.025 = phi i64 [ %3, %.lr.ph ], [ %.1, %16 ]
  %.02124 = phi ptr [ %2, %.lr.ph ], [ %.122, %16 ]
  %11 = icmp ugt i64 %.025, 15
  br i1 %11, label %12, label %15

12:                                               ; preds = %10
  call void @gf128_from_bytes(ptr noundef nonnull %5, ptr noundef %.02124) #5
  %13 = getelementptr inbounds i8, ptr %.02124, i64 16
  %14 = add i64 %.025, -16
  br label %16

15:                                               ; preds = %10
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %9, i8 0, i64 16, i1 false)
  call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 8 %9, ptr align 1 %.02124, i64 %.025, i1 false)
  call void @gf128_from_bytes(ptr noundef nonnull %5, ptr noundef nonnull %9) #5
  br label %16

16:                                               ; preds = %15, %12
  %.122 = phi ptr [ %13, %12 ], [ %.02124, %15 ]
  %.1 = phi i64 [ %14, %12 ], [ 0, %15 ]
  call void @gf128_add(ptr noundef nonnull %6, ptr noundef nonnull %6, ptr noundef nonnull %5) #5
  call void @gf128_mul(ptr noundef nonnull %6, ptr noundef nonnull %6, ptr noundef %0) #5
  %.not = icmp eq i64 %.1, 0
  br i1 %.not, label %._crit_edge, label %10, !llvm.loop !11

._crit_edge:                                      ; preds = %16, %4
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %5) #5
  ret void
}

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { "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 nounwind willreturn memory(argmem: write) }
attributes #3 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { 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 #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, !9, i64 32}
!6 = !{!"", !7, i64 0, !7, i64 16, !9, i64 32, !9, i64 40, !7, i64 48, !9, i64 64}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!"long", !7, i64 0}
!10 = !{!6, !9, i64 40}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


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