; LLVM IR from square/subzero :: core/external-crypto/modes (cmac)

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

@c_xor = external hidden constant [4 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

; 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 @gf_mulx2(ptr noundef %0) #1 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #2
  %5 = load ptr, ptr %2, align 8, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %5, i64 0
  %7 = load i8, ptr %6, align 1, !tbaa !9
  %8 = zext i8 %7 to i32
  %9 = ashr i32 %8, 6
  store i32 %9, ptr %4, align 4, !tbaa !10
  store i32 0, ptr %3, align 4, !tbaa !10
  br label %10

10:                                               ; preds = %35, %1
  %11 = load i32, ptr %3, align 4, !tbaa !10
  %12 = icmp slt i32 %11, 15
  br i1 %12, label %13, label %38

13:                                               ; preds = %10
  %14 = load ptr, ptr %2, align 8, !tbaa !5
  %15 = load i32, ptr %3, align 4, !tbaa !10
  %16 = sext i32 %15 to i64
  %17 = getelementptr inbounds i8, ptr %14, i64 %16
  %18 = load i8, ptr %17, align 1, !tbaa !9
  %19 = zext i8 %18 to i32
  %20 = shl i32 %19, 2
  %21 = load ptr, ptr %2, align 8, !tbaa !5
  %22 = load i32, ptr %3, align 4, !tbaa !10
  %23 = add nsw i32 %22, 1
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds i8, ptr %21, i64 %24
  %26 = load i8, ptr %25, align 1, !tbaa !9
  %27 = zext i8 %26 to i32
  %28 = ashr i32 %27, 6
  %29 = or i32 %20, %28
  %30 = trunc i32 %29 to i8
  %31 = load ptr, ptr %2, align 8, !tbaa !5
  %32 = load i32, ptr %3, align 4, !tbaa !10
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds i8, ptr %31, i64 %33
  store i8 %30, ptr %34, align 1, !tbaa !9
  br label %35

35:                                               ; preds = %13
  %36 = load i32, ptr %3, align 4, !tbaa !10
  %37 = add nsw i32 %36, 1
  store i32 %37, ptr %3, align 4, !tbaa !10
  br label %10, !llvm.loop !12

38:                                               ; preds = %10
  %39 = load i32, ptr %4, align 4, !tbaa !10
  %40 = ashr i32 %39, 1
  %41 = load ptr, ptr %2, align 8, !tbaa !5
  %42 = getelementptr inbounds i8, ptr %41, i64 14
  %43 = load i8, ptr %42, align 1, !tbaa !9
  %44 = zext i8 %43 to i32
  %45 = xor i32 %44, %40
  %46 = trunc i32 %45 to i8
  store i8 %46, ptr %42, align 1, !tbaa !9
  %47 = load ptr, ptr %2, align 8, !tbaa !5
  %48 = getelementptr inbounds i8, ptr %47, i64 15
  %49 = load i8, ptr %48, align 1, !tbaa !9
  %50 = zext i8 %49 to i32
  %51 = shl i32 %50, 2
  %52 = load i32, ptr %4, align 4, !tbaa !10
  %53 = sext i32 %52 to i64
  %54 = getelementptr inbounds [4 x i8], ptr @c_xor, i64 0, i64 %53
  %55 = load i8, ptr %54, align 1, !tbaa !9
  %56 = zext i8 %55 to i32
  %57 = xor i32 %51, %56
  %58 = trunc i32 %57 to i8
  %59 = load ptr, ptr %2, align 8, !tbaa !5
  %60 = getelementptr inbounds i8, ptr %59, i64 15
  store i8 %58, ptr %60, align 1, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #2
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { 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 = !{!"int", !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"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"

@c_xor = external hidden local_unnamed_addr constant [4 x i8], align 1

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: readwrite) uwtable
define dso_local void @gf_mulx2(ptr nocapture noundef %0) local_unnamed_addr #0 {
  %2 = getelementptr inbounds i8, ptr %0, i64 8
  %3 = load <8 x i8>, ptr %0, align 1, !tbaa !5
  %4 = shufflevector <8 x i8> %3, <8 x i8> poison, <8 x i32> <i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 poison>
  %5 = getelementptr inbounds i8, ptr %0, i64 12
  %6 = load i8, ptr %5, align 1, !tbaa !5
  %7 = load <4 x i8>, ptr %2, align 1, !tbaa !5
  %8 = shufflevector <4 x i8> %7, <4 x i8> poison, <8 x i32> <i32 0, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison>
  %9 = shufflevector <8 x i8> %4, <8 x i8> %8, <8 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 8>
  %10 = tail call <8 x i8> @llvm.fshl.v8i8(<8 x i8> %3, <8 x i8> %9, <8 x i8> <i8 2, i8 2, i8 2, i8 2, i8 2, i8 2, i8 2, i8 2>)
  store <8 x i8> %10, ptr %0, align 1, !tbaa !5
  %11 = shufflevector <4 x i8> %7, <4 x i8> poison, <4 x i32> <i32 1, i32 2, i32 3, i32 poison>
  %12 = insertelement <4 x i8> %11, i8 %6, i64 3
  %13 = tail call <4 x i8> @llvm.fshl.v4i8(<4 x i8> %7, <4 x i8> %12, <4 x i8> <i8 2, i8 2, i8 2, i8 2>)
  store <4 x i8> %13, ptr %2, align 1, !tbaa !5
  %14 = getelementptr inbounds i8, ptr %0, i64 13
  %15 = load i8, ptr %14, align 1, !tbaa !5
  %16 = tail call i8 @llvm.fshl.i8(i8 %6, i8 %15, i8 2)
  store i8 %16, ptr %5, align 1, !tbaa !5
  %17 = getelementptr inbounds i8, ptr %0, i64 14
  %18 = load i8, ptr %17, align 1, !tbaa !5
  %19 = tail call i8 @llvm.fshl.i8(i8 %15, i8 %18, i8 2)
  store i8 %19, ptr %14, align 1, !tbaa !5
  %20 = getelementptr inbounds i8, ptr %0, i64 15
  %21 = load i8, ptr %20, align 1, !tbaa !5
  %22 = tail call i8 @llvm.fshl.i8(i8 %18, i8 %21, i8 2)
  %23 = extractelement <8 x i8> %3, i64 0
  %24 = lshr i8 %23, 6
  %25 = lshr i8 %23, 7
  %26 = xor i8 %22, %25
  store i8 %26, ptr %17, align 1, !tbaa !5
  %27 = shl i8 %21, 2
  %28 = zext nneg i8 %24 to i64
  %29 = getelementptr inbounds [4 x i8], ptr @c_xor, i64 0, i64 %28
  %30 = load i8, ptr %29, align 1, !tbaa !5
  %31 = xor i8 %27, %30
  store i8 %31, ptr %20, align 1, !tbaa !5
  ret void
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i8 @llvm.fshl.i8(i8, i8, i8) #1

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare <8 x i8> @llvm.fshl.v8i8(<8 x i8>, <8 x i8>, <8 x i8>) #1

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare <4 x i8> @llvm.fshl.v4i8(<4 x i8>, <4 x i8>, <4 x i8>) #1

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: readwrite) 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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }

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


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LoopRotatePass,PostOrderFunctionAttrsPass,ReassociatePass,SLPVectorizerPass,SROAPass,SimplifyCFGPass,TailCallElimPass