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

@.str = external hidden unnamed_addr constant [14 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [59 x i8], align 1
@__PRETTY_FUNCTION__.ghash_update = external hidden unnamed_addr constant [56 x i8], align 1

; 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

; 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

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_update(ptr noundef %0, ptr noundef %1, i64 noundef %2) #3 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca [2 x i64], align 16
  %8 = alloca i64, align 8
  %9 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store i64 %2, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 16, ptr %7) #5
  %10 = load ptr, ptr %4, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.GHASH_CTX, ptr %10, i32 0, i32 5
  %12 = load i64, ptr %11, align 8, !tbaa !11
  %13 = icmp ult i64 %12, 16
  br i1 %13, label %14, label %15

14:                                               ; preds = %3
  br label %16

15:                                               ; preds = %3
  call void @__assert_fail(ptr noundef @.str, ptr noundef @.str.1, i32 noundef 114, ptr noundef @__PRETTY_FUNCTION__.ghash_update) #6
  unreachable

16:                                               ; preds = %14
  %17 = load i64, ptr %6, align 8, !tbaa !9
  %18 = load ptr, ptr %4, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.GHASH_CTX, ptr %18, i32 0, i32 3
  %20 = load i64, ptr %19, align 8, !tbaa !13
  %21 = add i64 %20, %17
  store i64 %21, ptr %19, align 8, !tbaa !13
  %22 = load ptr, ptr %4, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.GHASH_CTX, ptr %22, i32 0, i32 5
  %24 = load i64, ptr %23, align 8, !tbaa !11
  %25 = icmp ne i64 %24, 0
  br i1 %25, label %26, label %89

26:                                               ; preds = %16
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #5
  %27 = load ptr, ptr %4, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.GHASH_CTX, ptr %27, i32 0, i32 5
  %29 = load i64, ptr %28, align 8, !tbaa !11
  %30 = sub i64 16, %29
  store i64 %30, ptr %8, align 8, !tbaa !9
  %31 = load i64, ptr %6, align 8, !tbaa !9
  %32 = load i64, ptr %8, align 8, !tbaa !9
  %33 = icmp ult i64 %31, %32
  br i1 %33, label %34, label %49

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

49:                                               ; preds = %26
  %50 = load ptr, ptr %4, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.GHASH_CTX, ptr %50, i32 0, i32 4
  %52 = getelementptr inbounds [16 x i8], ptr %51, i64 0, i64 0
  %53 = load ptr, ptr %4, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.GHASH_CTX, ptr %53, i32 0, i32 5
  %55 = load i64, ptr %54, align 8, !tbaa !11
  %56 = getelementptr inbounds i8, ptr %52, i64 %55
  %57 = load ptr, ptr %5, align 8, !tbaa !5
  %58 = load i64, ptr %8, align 8, !tbaa !9
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %56, ptr align 1 %57, i64 %58, i1 false)
  %59 = getelementptr inbounds [2 x i64], ptr %7, i64 0, i64 0
  %60 = load ptr, ptr %4, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.GHASH_CTX, ptr %60, i32 0, i32 4
  %62 = getelementptr inbounds [16 x i8], ptr %61, i64 0, i64 0
  call void @gf128_from_bytes(ptr noundef %59, ptr noundef %62)
  %63 = load ptr, ptr %4, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.GHASH_CTX, ptr %63, i32 0, i32 1
  %65 = getelementptr inbounds [2 x i64], ptr %64, i64 0, i64 0
  %66 = load ptr, ptr %4, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.GHASH_CTX, ptr %66, i32 0, i32 1
  %68 = getelementptr inbounds [2 x i64], ptr %67, i64 0, i64 0
  %69 = getelementptr inbounds [2 x i64], ptr %7, i64 0, i64 0
  call void @gf128_add(ptr noundef %65, ptr noundef %68, ptr noundef %69)
  %70 = load ptr, ptr %4, align 8, !tbaa !5
  %71 = getelementptr inbounds %struct.GHASH_CTX, ptr %70, i32 0, i32 1
  %72 = getelementptr inbounds [2 x i64], ptr %71, i64 0, i64 0
  %73 = load ptr, ptr %4, align 8, !tbaa !5
  %74 = getelementptr inbounds %struct.GHASH_CTX, ptr %73, i32 0, i32 1
  %75 = getelementptr inbounds [2 x i64], ptr %74, i64 0, i64 0
  %76 = load ptr, ptr %4, align 8, !tbaa !5
  %77 = getelementptr inbounds %struct.GHASH_CTX, ptr %76, i32 0, i32 0
  %78 = getelementptr inbounds [2 x i64], ptr %77, i64 0, i64 0
  call void @gf128_mul(ptr noundef %72, ptr noundef %75, ptr noundef %78)
  %79 = load i64, ptr %8, align 8, !tbaa !9
  %80 = load ptr, ptr %5, align 8, !tbaa !5
  %81 = getelementptr inbounds i8, ptr %80, i64 %79
  store ptr %81, ptr %5, align 8, !tbaa !5
  %82 = load i64, ptr %8, align 8, !tbaa !9
  %83 = load i64, ptr %6, align 8, !tbaa !9
  %84 = sub i64 %83, %82
  store i64 %84, ptr %6, align 8, !tbaa !9
  br label %85

85:                                               ; preds = %49
  store i32 0, ptr %9, align 4
  br label %86

86:                                               ; preds = %85, %34
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #5
  %87 = load i32, ptr %9, align 4
  switch i32 %87, label %129 [
    i32 0, label %88
  ]

88:                                               ; preds = %86
  br label %89

89:                                               ; preds = %88, %16
  br label %90

90:                                               ; preds = %93, %89
  %91 = load i64, ptr %6, align 8, !tbaa !9
  %92 = icmp uge i64 %91, 16
  br i1 %92, label %93, label %116

93:                                               ; preds = %90
  %94 = getelementptr inbounds [2 x i64], ptr %7, i64 0, i64 0
  %95 = load ptr, ptr %5, align 8, !tbaa !5
  call void @gf128_from_bytes(ptr noundef %94, ptr noundef %95)
  %96 = load ptr, ptr %4, align 8, !tbaa !5
  %97 = getelementptr inbounds %struct.GHASH_CTX, ptr %96, i32 0, i32 1
  %98 = getelementptr inbounds [2 x i64], ptr %97, i64 0, i64 0
  %99 = load ptr, ptr %4, align 8, !tbaa !5
  %100 = getelementptr inbounds %struct.GHASH_CTX, ptr %99, i32 0, i32 1
  %101 = getelementptr inbounds [2 x i64], ptr %100, i64 0, i64 0
  %102 = getelementptr inbounds [2 x i64], ptr %7, i64 0, i64 0
  call void @gf128_add(ptr noundef %98, ptr noundef %101, ptr noundef %102)
  %103 = load ptr, ptr %4, align 8, !tbaa !5
  %104 = getelementptr inbounds %struct.GHASH_CTX, ptr %103, i32 0, i32 1
  %105 = getelementptr inbounds [2 x i64], ptr %104, i64 0, i64 0
  %106 = load ptr, ptr %4, align 8, !tbaa !5
  %107 = getelementptr inbounds %struct.GHASH_CTX, ptr %106, i32 0, i32 1
  %108 = getelementptr inbounds [2 x i64], ptr %107, i64 0, i64 0
  %109 = load ptr, ptr %4, align 8, !tbaa !5
  %110 = getelementptr inbounds %struct.GHASH_CTX, ptr %109, i32 0, i32 0
  %111 = getelementptr inbounds [2 x i64], ptr %110, i64 0, i64 0
  call void @gf128_mul(ptr noundef %105, ptr noundef %108, ptr noundef %111)
  %112 = load ptr, ptr %5, align 8, !tbaa !5
  %113 = getelementptr inbounds i8, ptr %112, i64 16
  store ptr %113, ptr %5, align 8, !tbaa !5
  %114 = load i64, ptr %6, align 8, !tbaa !9
  %115 = sub i64 %114, 16
  store i64 %115, ptr %6, align 8, !tbaa !9
  br label %90, !llvm.loop !14

116:                                              ; preds = %90
  %117 = load i64, ptr %6, align 8, !tbaa !9
  %118 = load ptr, ptr %4, align 8, !tbaa !5
  %119 = getelementptr inbounds %struct.GHASH_CTX, ptr %118, i32 0, i32 5
  store i64 %117, ptr %119, align 8, !tbaa !11
  %120 = load i64, ptr %6, align 8, !tbaa !9
  %121 = icmp ne i64 %120, 0
  br i1 %121, label %122, label %128

122:                                              ; preds = %116
  %123 = load ptr, ptr %4, align 8, !tbaa !5
  %124 = getelementptr inbounds %struct.GHASH_CTX, ptr %123, i32 0, i32 4
  %125 = getelementptr inbounds [16 x i8], ptr %124, i64 0, i64 0
  %126 = load ptr, ptr %5, align 8, !tbaa !5
  %127 = load i64, ptr %6, align 8, !tbaa !9
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %125, ptr align 1 %126, i64 %127, i1 false)
  br label %128

128:                                              ; preds = %122, %116
  store i32 0, ptr %9, align 4
  br label %129

129:                                              ; preds = %128, %86
  call void @llvm.lifetime.end.p0(i64 16, ptr %7) #5
  %130 = load i32, ptr %9, align 4
  switch i32 %130, label %132 [
    i32 0, label %131
    i32 1, label %131
  ]

131:                                              ; preds = %129, %129
  ret void

132:                                              ; preds = %129
  unreachable
}

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #4

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: readwrite) }
attributes #3 = { 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 #4 = { noreturn 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 }
attributes #6 = { noreturn 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 64}
!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"

@.str = external hidden unnamed_addr constant [14 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [59 x i8], align 1
@__PRETTY_FUNCTION__.ghash_update = external hidden unnamed_addr constant [56 x i8], align 1

; 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

; 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

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_update(ptr noundef %0, ptr noundef %1, i64 noundef %2) local_unnamed_addr #3 {
  %4 = alloca [2 x i64], align 16
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %4) #5
  %5 = getelementptr inbounds i8, ptr %0, i64 64
  %6 = load i64, ptr %5, align 8, !tbaa !5
  %7 = icmp ult i64 %6, 16
  br i1 %7, label %9, label %8

8:                                                ; preds = %3
  tail call void @__assert_fail(ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 114, ptr noundef nonnull @__PRETTY_FUNCTION__.ghash_update) #6
  unreachable

9:                                                ; preds = %3
  %10 = getelementptr inbounds i8, ptr %0, i64 40
  %11 = load i64, ptr %10, align 8, !tbaa !10
  %12 = add i64 %11, %2
  store i64 %12, ptr %10, align 8, !tbaa !10
  %.not = icmp eq i64 %6, 0
  br i1 %.not, label %23, label %13

13:                                               ; preds = %9
  %14 = sub nuw nsw i64 16, %6
  %.not50 = icmp ugt i64 %14, %2
  %15 = getelementptr inbounds i8, ptr %0, i64 48
  %16 = getelementptr inbounds i8, ptr %15, i64 %6
  br i1 %.not50, label %.thread, label %19

.thread:                                          ; preds = %13
  tail call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 1 %16, ptr align 1 %1, i64 %2, i1 false)
  %17 = load i64, ptr %5, align 8, !tbaa !5
  %18 = add i64 %17, %2
  store i64 %18, ptr %5, align 8, !tbaa !5
  br label %32

19:                                               ; preds = %13
  tail call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 1 %16, ptr align 1 %1, i64 %14, i1 false)
  call void @gf128_from_bytes(ptr noundef nonnull %4, ptr noundef nonnull %15) #5
  %20 = getelementptr inbounds i8, ptr %0, i64 16
  call void @gf128_add(ptr noundef nonnull %20, ptr noundef nonnull %20, ptr noundef nonnull %4) #5
  call void @gf128_mul(ptr noundef nonnull %20, ptr noundef nonnull %20, ptr noundef nonnull %0) #5
  %21 = getelementptr inbounds i8, ptr %1, i64 %14
  %22 = sub i64 %2, %14
  br label %23

23:                                               ; preds = %19, %9
  %.144 = phi i64 [ %22, %19 ], [ %2, %9 ]
  %.1 = phi ptr [ %21, %19 ], [ %1, %9 ]
  %24 = icmp ugt i64 %.144, 15
  br i1 %24, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %23
  %25 = getelementptr inbounds i8, ptr %0, i64 16
  br label %26

26:                                               ; preds = %.lr.ph, %26
  %.255 = phi ptr [ %.1, %.lr.ph ], [ %27, %26 ]
  %.24554 = phi i64 [ %.144, %.lr.ph ], [ %28, %26 ]
  call void @gf128_from_bytes(ptr noundef nonnull %4, ptr noundef %.255) #5
  call void @gf128_add(ptr noundef nonnull %25, ptr noundef nonnull %25, ptr noundef nonnull %4) #5
  call void @gf128_mul(ptr noundef nonnull %25, ptr noundef nonnull %25, ptr noundef %0) #5
  %27 = getelementptr inbounds i8, ptr %.255, i64 16
  %28 = add i64 %.24554, -16
  %29 = icmp ugt i64 %28, 15
  br i1 %29, label %26, label %._crit_edge, !llvm.loop !11

._crit_edge:                                      ; preds = %26, %23
  %.245.lcssa = phi i64 [ %.144, %23 ], [ %28, %26 ]
  %.2.lcssa = phi ptr [ %.1, %23 ], [ %27, %26 ]
  store i64 %.245.lcssa, ptr %5, align 8, !tbaa !5
  %.not51 = icmp eq i64 %.245.lcssa, 0
  br i1 %.not51, label %32, label %30

30:                                               ; preds = %._crit_edge
  %31 = getelementptr inbounds i8, ptr %0, i64 48
  call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 8 %31, ptr align 1 %.2.lcssa, i64 %.245.lcssa, i1 false)
  br label %32

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

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #4

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: readwrite) }
attributes #3 = { 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 #4 = { noreturn 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 }
attributes #6 = { noreturn 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 64}
!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: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass