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

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

; 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_divx(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 15
  %7 = load i8, ptr %6, align 1, !tbaa !9
  %8 = zext i8 %7 to i32
  store i32 %8, ptr %4, align 4, !tbaa !10
  store i32 15, ptr %3, align 4, !tbaa !10
  br label %9

9:                                                ; preds = %34, %1
  %10 = load i32, ptr %3, align 4, !tbaa !10
  %11 = icmp sgt i32 %10, 0
  br i1 %11, label %12, label %37

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

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

37:                                               ; preds = %9
  %38 = load ptr, ptr %2, align 8, !tbaa !5
  %39 = getelementptr inbounds i8, ptr %38, i64 0
  %40 = load i8, ptr %39, align 1, !tbaa !9
  %41 = zext i8 %40 to i32
  %42 = ashr i32 %41, 1
  %43 = load i32, ptr %4, align 4, !tbaa !10
  %44 = and i32 %43, 1
  %45 = icmp ne i32 %44, 0
  %46 = zext i1 %45 to i64
  %47 = select i1 %45, i32 128, i32 0
  %48 = xor i32 %42, %47
  %49 = trunc i32 %48 to i8
  %50 = load ptr, ptr %2, align 8, !tbaa !5
  %51 = getelementptr inbounds i8, ptr %50, i64 0
  store i8 %49, ptr %51, align 1, !tbaa !9
  %52 = load i32, ptr %4, align 4, !tbaa !10
  %53 = and i32 %52, 1
  %54 = icmp ne i32 %53, 0
  %55 = zext i1 %54 to i64
  %56 = select i1 %54, i32 67, i32 0
  %57 = load ptr, ptr %2, align 8, !tbaa !5
  %58 = getelementptr inbounds i8, ptr %57, i64 15
  %59 = load i8, ptr %58, align 1, !tbaa !9
  %60 = zext i8 %59 to i32
  %61 = xor i32 %60, %56
  %62 = trunc i32 %61 to i8
  store i8 %62, ptr %58, 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"

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: readwrite) uwtable
define dso_local void @gf_divx(ptr nocapture noundef %0) local_unnamed_addr #0 {
  %2 = getelementptr inbounds i8, ptr %0, i64 15
  %3 = load i8, ptr %2, align 1, !tbaa !5
  %4 = getelementptr i8, ptr %0, i64 14
  %5 = load i8, ptr %4, align 1, !tbaa !5
  %6 = tail call i8 @llvm.fshl.i8(i8 %5, i8 %3, i8 7)
  %7 = getelementptr inbounds i8, ptr %0, i64 14
  %8 = getelementptr i8, ptr %0, i64 13
  %9 = load i8, ptr %8, align 1, !tbaa !5
  %10 = tail call i8 @llvm.fshl.i8(i8 %9, i8 %5, i8 7)
  store i8 %10, ptr %7, align 1, !tbaa !5
  %11 = getelementptr inbounds i8, ptr %0, i64 13
  %12 = getelementptr i8, ptr %0, i64 12
  %13 = load i8, ptr %12, align 1, !tbaa !5
  %14 = tail call i8 @llvm.fshl.i8(i8 %13, i8 %9, i8 7)
  store i8 %14, ptr %11, align 1, !tbaa !5
  %15 = getelementptr inbounds i8, ptr %0, i64 12
  %16 = getelementptr i8, ptr %0, i64 8
  %17 = getelementptr inbounds i8, ptr %0, i64 8
  %18 = and i8 %3, 1
  %.not = icmp eq i8 %18, 0
  %19 = load <8 x i8>, ptr %0, align 1, !tbaa !5
  %20 = load <4 x i8>, ptr %16, align 1, !tbaa !5
  %21 = extractelement <4 x i8> %20, i64 3
  %22 = tail call i8 @llvm.fshl.i8(i8 %21, i8 %13, i8 7)
  store i8 %22, ptr %15, align 1, !tbaa !5
  %23 = shufflevector <8 x i8> %19, <8 x i8> poison, <4 x i32> <i32 7, i32 poison, i32 poison, i32 poison>
  %24 = shufflevector <4 x i8> %23, <4 x i8> %20, <4 x i32> <i32 0, i32 4, i32 5, i32 6>
  %25 = tail call <4 x i8> @llvm.fshl.v4i8(<4 x i8> %24, <4 x i8> %20, <4 x i8> <i8 7, i8 7, i8 7, i8 7>)
  store <4 x i8> %25, ptr %17, align 1, !tbaa !5
  %26 = insertelement <8 x i8> poison, i8 %3, i64 0
  %27 = shufflevector <8 x i8> %26, <8 x i8> %19, <8 x i32> <i32 0, i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14>
  %28 = tail call <8 x i8> @llvm.fshl.v8i8(<8 x i8> %27, <8 x i8> %19, <8 x i8> <i8 7, i8 7, i8 7, i8 7, i8 7, i8 7, i8 7, i8 7>)
  store <8 x i8> %28, ptr %0, align 1, !tbaa !5
  %29 = select i1 %.not, i8 0, i8 67
  %30 = xor i8 %6, %29
  store i8 %30, ptr %2, 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: DSEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LoopRotatePass,PostOrderFunctionAttrsPass,ReassociatePass,SLPVectorizerPass,SROAPass,SimplifyCFGPass,TailCallElimPass