; LLVM IR from dhuertas/AES :: aes (inv_mix_columns)

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

@Nb = external dso_local global i32, align 4
@__const.inv_mix_columns.a = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local void @coef_mult(ptr noundef, ptr noundef, ptr noundef) #0

; 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

; 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

; Function Attrs: nounwind uwtable
define dso_local void @inv_mix_columns(ptr noundef %0) #0 {
  %2 = alloca ptr, align 8
  %3 = alloca [4 x i8], align 1
  %4 = alloca i8, align 1
  %5 = alloca i8, align 1
  %6 = alloca [4 x i8], align 1
  %7 = alloca [4 x i8], align 1
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %3, ptr align 1 @__const.inv_mix_columns.a, i64 4, i1 false)
  call void @llvm.lifetime.start.p0(i64 1, ptr %4) #3
  call void @llvm.lifetime.start.p0(i64 1, ptr %5) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  store i8 0, ptr %5, align 1, !tbaa !9
  br label %8

8:                                                ; preds = %63, %1
  %9 = load i8, ptr %5, align 1, !tbaa !9
  %10 = zext i8 %9 to i32
  %11 = load i32, ptr @Nb, align 4, !tbaa !10
  %12 = icmp slt i32 %10, %11
  br i1 %12, label %13, label %66

13:                                               ; preds = %8
  store i8 0, ptr %4, align 1, !tbaa !9
  br label %14

14:                                               ; preds = %33, %13
  %15 = load i8, ptr %4, align 1, !tbaa !9
  %16 = zext i8 %15 to i32
  %17 = icmp slt i32 %16, 4
  br i1 %17, label %18, label %36

18:                                               ; preds = %14
  %19 = load ptr, ptr %2, align 8, !tbaa !5
  %20 = load i32, ptr @Nb, align 4, !tbaa !10
  %21 = load i8, ptr %4, align 1, !tbaa !9
  %22 = zext i8 %21 to i32
  %23 = mul nsw i32 %20, %22
  %24 = load i8, ptr %5, align 1, !tbaa !9
  %25 = zext i8 %24 to i32
  %26 = add nsw i32 %23, %25
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds i8, ptr %19, i64 %27
  %29 = load i8, ptr %28, align 1, !tbaa !9
  %30 = load i8, ptr %4, align 1, !tbaa !9
  %31 = zext i8 %30 to i64
  %32 = getelementptr inbounds [4 x i8], ptr %6, i64 0, i64 %31
  store i8 %29, ptr %32, align 1, !tbaa !9
  br label %33

33:                                               ; preds = %18
  %34 = load i8, ptr %4, align 1, !tbaa !9
  %35 = add i8 %34, 1
  store i8 %35, ptr %4, align 1, !tbaa !9
  br label %14, !llvm.loop !12

36:                                               ; preds = %14
  %37 = getelementptr inbounds [4 x i8], ptr %3, i64 0, i64 0
  %38 = getelementptr inbounds [4 x i8], ptr %6, i64 0, i64 0
  %39 = getelementptr inbounds [4 x i8], ptr %7, i64 0, i64 0
  call void @coef_mult(ptr noundef %37, ptr noundef %38, ptr noundef %39)
  store i8 0, ptr %4, align 1, !tbaa !9
  br label %40

40:                                               ; preds = %59, %36
  %41 = load i8, ptr %4, align 1, !tbaa !9
  %42 = zext i8 %41 to i32
  %43 = icmp slt i32 %42, 4
  br i1 %43, label %44, label %62

44:                                               ; preds = %40
  %45 = load i8, ptr %4, align 1, !tbaa !9
  %46 = zext i8 %45 to i64
  %47 = getelementptr inbounds [4 x i8], ptr %7, i64 0, i64 %46
  %48 = load i8, ptr %47, align 1, !tbaa !9
  %49 = load ptr, ptr %2, align 8, !tbaa !5
  %50 = load i32, ptr @Nb, align 4, !tbaa !10
  %51 = load i8, ptr %4, align 1, !tbaa !9
  %52 = zext i8 %51 to i32
  %53 = mul nsw i32 %50, %52
  %54 = load i8, ptr %5, align 1, !tbaa !9
  %55 = zext i8 %54 to i32
  %56 = add nsw i32 %53, %55
  %57 = sext i32 %56 to i64
  %58 = getelementptr inbounds i8, ptr %49, i64 %57
  store i8 %48, ptr %58, align 1, !tbaa !9
  br label %59

59:                                               ; preds = %44
  %60 = load i8, ptr %4, align 1, !tbaa !9
  %61 = add i8 %60, 1
  store i8 %61, ptr %4, align 1, !tbaa !9
  br label %40, !llvm.loop !14

62:                                               ; preds = %40
  br label %63

63:                                               ; preds = %62
  %64 = load i8, ptr %5, align 1, !tbaa !9
  %65 = add i8 %64, 1
  store i8 %65, ptr %5, align 1, !tbaa !9
  br label %8, !llvm.loop !15

66:                                               ; preds = %8
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 1, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 1, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  ret void
}

attributes #0 = { 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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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"}
!14 = distinct !{!14, !13}
!15 = distinct !{!15, !13}


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

@Nb = external dso_local local_unnamed_addr global i32, align 4
@__const.inv_mix_columns.a = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local void @coef_mult(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #0

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

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

; Function Attrs: nounwind uwtable
define dso_local void @inv_mix_columns(ptr nocapture noundef %0) local_unnamed_addr #0 {
  %2 = alloca [4 x i8], align 4
  %3 = alloca [4 x i8], align 1
  %4 = alloca [4 x i8], align 1
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %2) #2
  %5 = load i32, ptr @__const.inv_mix_columns.a, align 1
  store i32 %5, ptr %2, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %3) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %4) #2
  %6 = load i32, ptr @Nb, align 4, !tbaa !5
  %7 = icmp sgt i32 %6, 0
  br i1 %7, label %.preheader.preheader, label %._crit_edge

.preheader.preheader:                             ; preds = %1
  %8 = getelementptr inbounds i8, ptr %3, i64 1
  %9 = getelementptr inbounds i8, ptr %3, i64 2
  %10 = getelementptr inbounds i8, ptr %3, i64 3
  %11 = getelementptr inbounds i8, ptr %4, i64 1
  %12 = getelementptr inbounds i8, ptr %4, i64 2
  %13 = getelementptr inbounds i8, ptr %4, i64 3
  br label %.preheader

.preheader:                                       ; preds = %.preheader.preheader, %.preheader
  %14 = phi i32 [ %53, %.preheader ], [ %6, %.preheader.preheader ]
  %15 = phi i32 [ %52, %.preheader ], [ 0, %.preheader.preheader ]
  %.019 = phi i8 [ %51, %.preheader ], [ 0, %.preheader.preheader ]
  %16 = zext nneg i32 %15 to i64
  %17 = getelementptr inbounds i8, ptr %0, i64 %16
  %18 = load i8, ptr %17, align 1, !tbaa !9
  store i8 %18, ptr %3, align 1, !tbaa !9
  %19 = add nuw nsw i32 %14, %15
  %20 = zext nneg i32 %19 to i64
  %21 = getelementptr inbounds i8, ptr %0, i64 %20
  %22 = load i8, ptr %21, align 1, !tbaa !9
  store i8 %22, ptr %8, align 1, !tbaa !9
  %23 = shl nuw nsw i32 %14, 1
  %24 = add nuw nsw i32 %23, %15
  %25 = zext nneg i32 %24 to i64
  %26 = getelementptr inbounds i8, ptr %0, i64 %25
  %27 = load i8, ptr %26, align 1, !tbaa !9
  store i8 %27, ptr %9, align 1, !tbaa !9
  %28 = mul nsw i32 %14, 3
  %29 = add nuw nsw i32 %28, %15
  %30 = zext nneg i32 %29 to i64
  %31 = getelementptr inbounds i8, ptr %0, i64 %30
  %32 = load i8, ptr %31, align 1, !tbaa !9
  store i8 %32, ptr %10, align 1, !tbaa !9
  call void @coef_mult(ptr noundef nonnull %2, ptr noundef nonnull %3, ptr noundef nonnull %4)
  %33 = load i8, ptr %4, align 1, !tbaa !9
  store i8 %33, ptr %17, align 1, !tbaa !9
  %34 = load i8, ptr %11, align 1, !tbaa !9
  %35 = load i32, ptr @Nb, align 4, !tbaa !5
  %36 = add nsw i32 %35, %15
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds i8, ptr %0, i64 %37
  store i8 %34, ptr %38, align 1, !tbaa !9
  %39 = load i8, ptr %12, align 1, !tbaa !9
  %40 = load i32, ptr @Nb, align 4, !tbaa !5
  %41 = shl nsw i32 %40, 1
  %42 = add nsw i32 %41, %15
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds i8, ptr %0, i64 %43
  store i8 %39, ptr %44, align 1, !tbaa !9
  %45 = load i8, ptr %13, align 1, !tbaa !9
  %46 = load i32, ptr @Nb, align 4, !tbaa !5
  %47 = mul nsw i32 %46, 3
  %48 = add nsw i32 %47, %15
  %49 = sext i32 %48 to i64
  %50 = getelementptr inbounds i8, ptr %0, i64 %49
  store i8 %45, ptr %50, align 1, !tbaa !9
  %51 = add i8 %.019, 1
  %52 = zext i8 %51 to i32
  %53 = load i32, ptr @Nb, align 4, !tbaa !5
  %54 = icmp sgt i32 %53, %52
  br i1 %54, label %.preheader, label %._crit_edge, !llvm.loop !10

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

attributes #0 = { 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 = { mustprogress 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!7, !7, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass