; LLVM IR from gem5/gem5 :: src/arch/arm/insts/crypto.ll (ZN4gem56ArmISA6Crypto8aesFFMulEhh)

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

@_ZN4gem56ArmISA6Crypto8aesFFLOGE = external dso_local constant [256 x i8], align 16
@_ZN4gem56ArmISA6Crypto8aesFFEXPE = external dso_local constant [256 x i8], align 16

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef zeroext i8 @_ZN4gem56ArmISA6Crypto8aesFFMulEhh(ptr noundef nonnull align 1 dereferenceable(1) %0, i8 noundef zeroext %1, i8 noundef zeroext %2) #0 align 2 {
  %4 = alloca i8, align 1
  %5 = alloca ptr, align 8
  %6 = alloca i8, align 1
  %7 = alloca i8, align 1
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i8 %1, ptr %6, align 1, !tbaa !9
  store i8 %2, ptr %7, align 1, !tbaa !9
  %10 = load ptr, ptr %5, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #2
  %11 = load i8, ptr %6, align 1, !tbaa !9
  %12 = zext i8 %11 to i32
  %13 = icmp eq i32 %12, 0
  br i1 %13, label %18, label %14

14:                                               ; preds = %3
  %15 = load i8, ptr %7, align 1, !tbaa !9
  %16 = zext i8 %15 to i32
  %17 = icmp eq i32 %16, 0
  br i1 %17, label %18, label %19

18:                                               ; preds = %14, %3
  store i8 0, ptr %4, align 1
  store i32 1, ptr %9, align 4
  br label %41

19:                                               ; preds = %14
  %20 = load i8, ptr %6, align 1, !tbaa !9
  %21 = zext i8 %20 to i64
  %22 = getelementptr inbounds [256 x i8], ptr @_ZN4gem56ArmISA6Crypto8aesFFLOGE, i64 0, i64 %21
  %23 = load i8, ptr %22, align 1, !tbaa !9
  %24 = zext i8 %23 to i32
  %25 = load i8, ptr %7, align 1, !tbaa !9
  %26 = zext i8 %25 to i64
  %27 = getelementptr inbounds [256 x i8], ptr @_ZN4gem56ArmISA6Crypto8aesFFLOGE, i64 0, i64 %26
  %28 = load i8, ptr %27, align 1, !tbaa !9
  %29 = zext i8 %28 to i32
  %30 = add nsw i32 %24, %29
  store i32 %30, ptr %8, align 4, !tbaa !10
  %31 = load i32, ptr %8, align 4, !tbaa !10
  %32 = icmp ugt i32 %31, 255
  br i1 %32, label %33, label %36

33:                                               ; preds = %19
  %34 = load i32, ptr %8, align 4, !tbaa !10
  %35 = sub i32 %34, 255
  store i32 %35, ptr %8, align 4, !tbaa !10
  br label %36

36:                                               ; preds = %33, %19
  %37 = load i32, ptr %8, align 4, !tbaa !10
  %38 = zext i32 %37 to i64
  %39 = getelementptr inbounds [256 x i8], ptr @_ZN4gem56ArmISA6Crypto8aesFFEXPE, i64 0, i64 %38
  %40 = load i8, ptr %39, align 1, !tbaa !9
  store i8 %40, ptr %4, align 1
  store i32 1, ptr %9, align 4
  br label %41

41:                                               ; preds = %36, %18
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  %42 = load i8, ptr %4, align 1
  ret i8 %42
}

; 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 nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

attributes #0 = { mustprogress 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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++ TBAA"}
!9 = !{!7, !7, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"int", !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"

@_ZN4gem56ArmISA6Crypto8aesFFLOGE = external dso_local local_unnamed_addr constant [256 x i8], align 16
@_ZN4gem56ArmISA6Crypto8aesFFEXPE = external dso_local local_unnamed_addr constant [256 x i8], align 16

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(none) uwtable
define dso_local noundef zeroext i8 @_ZN4gem56ArmISA6Crypto8aesFFMulEhh(ptr nocapture noundef nonnull readnone align 1 dereferenceable(1) %0, i8 noundef zeroext %1, i8 noundef zeroext %2) local_unnamed_addr #0 align 2 {
  %4 = icmp eq i8 %1, 0
  %5 = icmp eq i8 %2, 0
  %or.cond = or i1 %4, %5
  br i1 %or.cond, label %21, label %6

6:                                                ; preds = %3
  %7 = zext i8 %1 to i64
  %8 = getelementptr inbounds [256 x i8], ptr @_ZN4gem56ArmISA6Crypto8aesFFLOGE, i64 0, i64 %7
  %9 = load i8, ptr %8, align 1, !tbaa !5
  %10 = zext i8 %9 to i32
  %11 = zext i8 %2 to i64
  %12 = getelementptr inbounds [256 x i8], ptr @_ZN4gem56ArmISA6Crypto8aesFFLOGE, i64 0, i64 %11
  %13 = load i8, ptr %12, align 1, !tbaa !5
  %14 = zext i8 %13 to i32
  %15 = add nuw nsw i32 %14, %10
  %16 = icmp ugt i32 %15, 255
  %17 = add nsw i32 %15, -255
  %spec.select = select i1 %16, i32 %17, i32 %15
  %18 = zext nneg i32 %spec.select to i64
  %19 = getelementptr inbounds [256 x i8], ptr @_ZN4gem56ArmISA6Crypto8aesFFEXPE, i64 0, i64 %18
  %20 = load i8, ptr %19, align 1, !tbaa !5
  br label %21

21:                                               ; preds = %3, %6
  %.010 = phi i8 [ %20, %6 ], [ 0, %3 ]
  ret i8 %.010
}

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

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


; Effective O3 passes: GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass