; LLVM IR from louk78/crypto_project :: aes (AES_decrypt)

; 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.aes_ctx_t = type { [4 x [4 x i8]], i32, i32, [0 x i8] }

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

; Function Attrs: nounwind uwtable
declare hidden void @add_roundkey(ptr noundef, i32 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 @AES_decrypt(ptr noundef %0, ptr noundef %1, ptr noundef %2) #1 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store ptr %2, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #2
  store i32 0, ptr %7, align 4, !tbaa !9
  br label %9

9:                                                ; preds = %28, %3
  %10 = load i32, ptr %7, align 4, !tbaa !9
  %11 = icmp slt i32 %10, 16
  br i1 %11, label %12, label %31

12:                                               ; preds = %9
  %13 = load ptr, ptr %5, align 8, !tbaa !5
  %14 = load i32, ptr %7, align 4, !tbaa !9
  %15 = sext i32 %14 to i64
  %16 = getelementptr inbounds i8, ptr %13, i64 %15
  %17 = load i8, ptr %16, align 1, !tbaa !11
  %18 = load ptr, ptr %4, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.aes_ctx_t, ptr %18, i32 0, i32 0
  %20 = load i32, ptr %7, align 4, !tbaa !9
  %21 = srem i32 %20, 4
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds [4 x [4 x i8]], ptr %19, i64 0, i64 %22
  %24 = load i32, ptr %7, align 4, !tbaa !9
  %25 = sdiv i32 %24, 4
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds [4 x i8], ptr %23, i64 0, i64 %26
  store i8 %17, ptr %27, align 1, !tbaa !11
  br label %28

28:                                               ; preds = %12
  %29 = load i32, ptr %7, align 4, !tbaa !9
  %30 = add nsw i32 %29, 1
  store i32 %30, ptr %7, align 4, !tbaa !9
  br label %9, !llvm.loop !12

31:                                               ; preds = %9
  %32 = load ptr, ptr %4, align 8, !tbaa !5
  %33 = load ptr, ptr %4, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.aes_ctx_t, ptr %33, i32 0, i32 1
  %35 = load i32, ptr %34, align 4, !tbaa !14
  call void @add_roundkey(ptr noundef %32, i32 noundef %35)
  %36 = load ptr, ptr %4, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.aes_ctx_t, ptr %36, i32 0, i32 1
  %38 = load i32, ptr %37, align 4, !tbaa !14
  %39 = sub nsw i32 %38, 1
  store i32 %39, ptr %8, align 4, !tbaa !9
  br label %40

40:                                               ; preds = %49, %31
  %41 = load i32, ptr %8, align 4, !tbaa !9
  %42 = icmp sgt i32 %41, 0
  br i1 %42, label %43, label %52

43:                                               ; preds = %40
  %44 = load ptr, ptr %4, align 8, !tbaa !5
  call void @inv_shift_rows(ptr noundef %44)
  %45 = load ptr, ptr %4, align 8, !tbaa !5
  call void @inv_sub_bytes(ptr noundef %45)
  %46 = load ptr, ptr %4, align 8, !tbaa !5
  %47 = load i32, ptr %8, align 4, !tbaa !9
  call void @add_roundkey(ptr noundef %46, i32 noundef %47)
  %48 = load ptr, ptr %4, align 8, !tbaa !5
  call void @inv_mix_columns(ptr noundef %48)
  br label %49

49:                                               ; preds = %43
  %50 = load i32, ptr %8, align 4, !tbaa !9
  %51 = add nsw i32 %50, -1
  store i32 %51, ptr %8, align 4, !tbaa !9
  br label %40, !llvm.loop !16

52:                                               ; preds = %40
  %53 = load ptr, ptr %4, align 8, !tbaa !5
  call void @inv_shift_rows(ptr noundef %53)
  %54 = load ptr, ptr %4, align 8, !tbaa !5
  call void @inv_sub_bytes(ptr noundef %54)
  %55 = load ptr, ptr %4, align 8, !tbaa !5
  call void @add_roundkey(ptr noundef %55, i32 noundef 0)
  store i32 0, ptr %7, align 4, !tbaa !9
  br label %56

56:                                               ; preds = %75, %52
  %57 = load i32, ptr %7, align 4, !tbaa !9
  %58 = icmp slt i32 %57, 16
  br i1 %58, label %59, label %78

59:                                               ; preds = %56
  %60 = load ptr, ptr %4, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.aes_ctx_t, ptr %60, i32 0, i32 0
  %62 = load i32, ptr %7, align 4, !tbaa !9
  %63 = srem i32 %62, 4
  %64 = sext i32 %63 to i64
  %65 = getelementptr inbounds [4 x [4 x i8]], ptr %61, i64 0, i64 %64
  %66 = load i32, ptr %7, align 4, !tbaa !9
  %67 = sdiv i32 %66, 4
  %68 = sext i32 %67 to i64
  %69 = getelementptr inbounds [4 x i8], ptr %65, i64 0, i64 %68
  %70 = load i8, ptr %69, align 1, !tbaa !11
  %71 = load ptr, ptr %6, align 8, !tbaa !5
  %72 = load i32, ptr %7, align 4, !tbaa !9
  %73 = sext i32 %72 to i64
  %74 = getelementptr inbounds i8, ptr %71, i64 %73
  store i8 %70, ptr %74, align 1, !tbaa !11
  br label %75

75:                                               ; preds = %59
  %76 = load i32, ptr %7, align 4, !tbaa !9
  %77 = add nsw i32 %76, 1
  store i32 %77, ptr %7, align 4, !tbaa !9
  br label %56, !llvm.loop !17

78:                                               ; preds = %56
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  ret void
}

; Function Attrs: nounwind uwtable
declare hidden void @inv_shift_rows(ptr noundef) #1

; Function Attrs: nounwind uwtable
declare hidden void @inv_sub_bytes(ptr noundef) #1

; Function Attrs: nounwind uwtable
declare hidden void @inv_mix_columns(ptr noundef) #1

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 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = !{!15, !10, i64 16}
!15 = !{!"", !7, i64 0, !10, i64 16, !10, i64 20, !7, i64 24}
!16 = distinct !{!16, !13}
!17 = distinct !{!17, !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"

; Function Attrs: nounwind uwtable
declare hidden void @add_roundkey(ptr noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @AES_decrypt(ptr noundef %0, ptr nocapture noundef readonly %1, ptr nocapture noundef writeonly %2) local_unnamed_addr #0 {
  %4 = load i8, ptr %1, align 1, !tbaa !5
  store i8 %4, ptr %0, align 1, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %1, i64 1
  %6 = load i8, ptr %5, align 1, !tbaa !5
  %7 = getelementptr inbounds i8, ptr %0, i64 4
  store i8 %6, ptr %7, align 1, !tbaa !5
  %8 = getelementptr inbounds i8, ptr %1, i64 2
  %9 = load i8, ptr %8, align 1, !tbaa !5
  %10 = getelementptr inbounds i8, ptr %0, i64 8
  store i8 %9, ptr %10, align 1, !tbaa !5
  %11 = getelementptr inbounds i8, ptr %1, i64 3
  %12 = load i8, ptr %11, align 1, !tbaa !5
  %13 = getelementptr inbounds i8, ptr %0, i64 12
  store i8 %12, ptr %13, align 1, !tbaa !5
  %14 = getelementptr inbounds i8, ptr %1, i64 4
  %15 = load i8, ptr %14, align 1, !tbaa !5
  %16 = getelementptr inbounds i8, ptr %0, i64 1
  store i8 %15, ptr %16, align 1, !tbaa !5
  %17 = getelementptr inbounds i8, ptr %1, i64 5
  %18 = load i8, ptr %17, align 1, !tbaa !5
  %19 = getelementptr inbounds i8, ptr %0, i64 5
  store i8 %18, ptr %19, align 1, !tbaa !5
  %20 = getelementptr inbounds i8, ptr %1, i64 6
  %21 = load i8, ptr %20, align 1, !tbaa !5
  %22 = getelementptr inbounds i8, ptr %0, i64 9
  store i8 %21, ptr %22, align 1, !tbaa !5
  %23 = getelementptr inbounds i8, ptr %1, i64 7
  %24 = load i8, ptr %23, align 1, !tbaa !5
  %25 = getelementptr inbounds i8, ptr %0, i64 13
  store i8 %24, ptr %25, align 1, !tbaa !5
  %26 = getelementptr inbounds i8, ptr %1, i64 8
  %27 = load i8, ptr %26, align 1, !tbaa !5
  %28 = getelementptr inbounds i8, ptr %0, i64 2
  store i8 %27, ptr %28, align 1, !tbaa !5
  %29 = getelementptr inbounds i8, ptr %1, i64 9
  %30 = load i8, ptr %29, align 1, !tbaa !5
  %31 = getelementptr inbounds i8, ptr %0, i64 6
  store i8 %30, ptr %31, align 1, !tbaa !5
  %32 = getelementptr inbounds i8, ptr %1, i64 10
  %33 = load i8, ptr %32, align 1, !tbaa !5
  %34 = getelementptr inbounds i8, ptr %0, i64 10
  store i8 %33, ptr %34, align 1, !tbaa !5
  %35 = getelementptr inbounds i8, ptr %1, i64 11
  %36 = load i8, ptr %35, align 1, !tbaa !5
  %37 = getelementptr inbounds i8, ptr %0, i64 14
  store i8 %36, ptr %37, align 1, !tbaa !5
  %38 = getelementptr inbounds i8, ptr %1, i64 12
  %39 = load i8, ptr %38, align 1, !tbaa !5
  %40 = getelementptr inbounds i8, ptr %0, i64 3
  store i8 %39, ptr %40, align 1, !tbaa !5
  %41 = getelementptr inbounds i8, ptr %1, i64 13
  %42 = load i8, ptr %41, align 1, !tbaa !5
  %43 = getelementptr inbounds i8, ptr %0, i64 7
  store i8 %42, ptr %43, align 1, !tbaa !5
  %44 = getelementptr inbounds i8, ptr %1, i64 14
  %45 = load i8, ptr %44, align 1, !tbaa !5
  %46 = getelementptr inbounds i8, ptr %0, i64 11
  store i8 %45, ptr %46, align 1, !tbaa !5
  %47 = getelementptr inbounds i8, ptr %1, i64 15
  %48 = load i8, ptr %47, align 1, !tbaa !5
  %49 = getelementptr inbounds i8, ptr %0, i64 15
  store i8 %48, ptr %49, align 1, !tbaa !5
  %50 = getelementptr inbounds i8, ptr %0, i64 16
  %51 = load i32, ptr %50, align 4, !tbaa !8
  tail call void @add_roundkey(ptr noundef nonnull %0, i32 noundef %51)
  %52 = load i32, ptr %50, align 4, !tbaa !8
  %53 = icmp sgt i32 %52, 1
  br i1 %53, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %3, %.lr.ph
  %.0.in28 = phi i32 [ %.0, %.lr.ph ], [ %52, %3 ]
  %.0 = add nsw i32 %.0.in28, -1
  tail call void @inv_shift_rows(ptr noundef nonnull %0)
  tail call void @inv_sub_bytes(ptr noundef nonnull %0)
  tail call void @add_roundkey(ptr noundef nonnull %0, i32 noundef %.0)
  tail call void @inv_mix_columns(ptr noundef nonnull %0)
  %54 = icmp ugt i32 %.0.in28, 2
  br i1 %54, label %.lr.ph, label %._crit_edge, !llvm.loop !11

._crit_edge:                                      ; preds = %.lr.ph, %3
  tail call void @inv_shift_rows(ptr noundef nonnull %0)
  tail call void @inv_sub_bytes(ptr noundef nonnull %0)
  tail call void @add_roundkey(ptr noundef nonnull %0, i32 noundef 0)
  %55 = load i8, ptr %0, align 1, !tbaa !5
  store i8 %55, ptr %2, align 1, !tbaa !5
  %56 = load i8, ptr %7, align 1, !tbaa !5
  %57 = getelementptr inbounds i8, ptr %2, i64 1
  store i8 %56, ptr %57, align 1, !tbaa !5
  %58 = load i8, ptr %10, align 1, !tbaa !5
  %59 = getelementptr inbounds i8, ptr %2, i64 2
  store i8 %58, ptr %59, align 1, !tbaa !5
  %60 = load i8, ptr %13, align 1, !tbaa !5
  %61 = getelementptr inbounds i8, ptr %2, i64 3
  store i8 %60, ptr %61, align 1, !tbaa !5
  %62 = load i8, ptr %16, align 1, !tbaa !5
  %63 = getelementptr inbounds i8, ptr %2, i64 4
  store i8 %62, ptr %63, align 1, !tbaa !5
  %64 = load i8, ptr %19, align 1, !tbaa !5
  %65 = getelementptr inbounds i8, ptr %2, i64 5
  store i8 %64, ptr %65, align 1, !tbaa !5
  %66 = load i8, ptr %22, align 1, !tbaa !5
  %67 = getelementptr inbounds i8, ptr %2, i64 6
  store i8 %66, ptr %67, align 1, !tbaa !5
  %68 = load i8, ptr %25, align 1, !tbaa !5
  %69 = getelementptr inbounds i8, ptr %2, i64 7
  store i8 %68, ptr %69, align 1, !tbaa !5
  %70 = load i8, ptr %28, align 1, !tbaa !5
  %71 = getelementptr inbounds i8, ptr %2, i64 8
  store i8 %70, ptr %71, align 1, !tbaa !5
  %72 = load i8, ptr %31, align 1, !tbaa !5
  %73 = getelementptr inbounds i8, ptr %2, i64 9
  store i8 %72, ptr %73, align 1, !tbaa !5
  %74 = load i8, ptr %34, align 1, !tbaa !5
  %75 = getelementptr inbounds i8, ptr %2, i64 10
  store i8 %74, ptr %75, align 1, !tbaa !5
  %76 = load i8, ptr %37, align 1, !tbaa !5
  %77 = getelementptr inbounds i8, ptr %2, i64 11
  store i8 %76, ptr %77, align 1, !tbaa !5
  %78 = load i8, ptr %40, align 1, !tbaa !5
  %79 = getelementptr inbounds i8, ptr %2, i64 12
  store i8 %78, ptr %79, align 1, !tbaa !5
  %80 = load i8, ptr %43, align 1, !tbaa !5
  %81 = getelementptr inbounds i8, ptr %2, i64 13
  store i8 %80, ptr %81, align 1, !tbaa !5
  %82 = load i8, ptr %46, align 1, !tbaa !5
  %83 = getelementptr inbounds i8, ptr %2, i64 14
  store i8 %82, ptr %83, align 1, !tbaa !5
  %84 = load i8, ptr %49, align 1, !tbaa !5
  %85 = getelementptr inbounds i8, ptr %2, i64 15
  store i8 %84, ptr %85, align 1, !tbaa !5
  ret void
}

; Function Attrs: nounwind uwtable
declare hidden void @inv_shift_rows(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare hidden void @inv_sub_bytes(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare hidden void @inv_mix_columns(ptr noundef) local_unnamed_addr #0

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

!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"}
!8 = !{!9, !10, i64 16}
!9 = !{!"", !6, i64 0, !10, i64 16, !10, i64 20, !6, i64 24}
!10 = !{!"int", !6, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


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