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

; 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: nounwind uwtable
define dso_local void @AES_encrypt(ptr noundef %0, ptr noundef %1, ptr noundef %2) #0 {
  %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
  call void @add_roundkey(ptr noundef %32, i32 noundef 0)
  store i32 1, ptr %8, align 4, !tbaa !9
  br label %33

33:                                               ; preds = %45, %31
  %34 = load i32, ptr %8, align 4, !tbaa !9
  %35 = load ptr, ptr %4, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.aes_ctx_t, ptr %35, i32 0, i32 1
  %37 = load i32, ptr %36, align 4, !tbaa !14
  %38 = icmp slt i32 %34, %37
  br i1 %38, label %39, label %48

39:                                               ; preds = %33
  %40 = load ptr, ptr %4, align 8, !tbaa !5
  call void @sub_bytes(ptr noundef %40)
  %41 = load ptr, ptr %4, align 8, !tbaa !5
  call void @shift_rows(ptr noundef %41)
  %42 = load ptr, ptr %4, align 8, !tbaa !5
  call void @mix_columns(ptr noundef %42)
  %43 = load ptr, ptr %4, align 8, !tbaa !5
  %44 = load i32, ptr %8, align 4, !tbaa !9
  call void @add_roundkey(ptr noundef %43, i32 noundef %44)
  br label %45

45:                                               ; preds = %39
  %46 = load i32, ptr %8, align 4, !tbaa !9
  %47 = add nsw i32 %46, 1
  store i32 %47, ptr %8, align 4, !tbaa !9
  br label %33, !llvm.loop !16

48:                                               ; preds = %33
  %49 = load ptr, ptr %4, align 8, !tbaa !5
  call void @sub_bytes(ptr noundef %49)
  %50 = load ptr, ptr %4, align 8, !tbaa !5
  call void @shift_rows(ptr noundef %50)
  %51 = load ptr, ptr %4, align 8, !tbaa !5
  %52 = load ptr, ptr %4, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.aes_ctx_t, ptr %52, i32 0, i32 1
  %54 = load i32, ptr %53, align 4, !tbaa !14
  call void @add_roundkey(ptr noundef %51, i32 noundef %54)
  store i32 0, ptr %7, align 4, !tbaa !9
  br label %55

55:                                               ; preds = %74, %48
  %56 = load i32, ptr %7, align 4, !tbaa !9
  %57 = icmp slt i32 %56, 16
  br i1 %57, label %58, label %77

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

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

77:                                               ; preds = %55
  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: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

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

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

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

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

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

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 = { 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
define dso_local void @AES_encrypt(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
  tail call void @add_roundkey(ptr noundef nonnull %0, i32 noundef 0)
  %50 = getelementptr inbounds i8, ptr %0, i64 16
  %51 = load i32, ptr %50, align 4, !tbaa !8
  %52 = icmp sgt i32 %51, 1
  br i1 %52, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %3, %.lr.ph
  %.028 = phi i32 [ %53, %.lr.ph ], [ 1, %3 ]
  tail call void @sub_bytes(ptr noundef nonnull %0)
  tail call void @shift_rows(ptr noundef nonnull %0)
  tail call void @mix_columns(ptr noundef nonnull %0)
  tail call void @add_roundkey(ptr noundef nonnull %0, i32 noundef %.028)
  %53 = add nuw nsw i32 %.028, 1
  %54 = load i32, ptr %50, align 4, !tbaa !8
  %55 = icmp slt i32 %53, %54
  br i1 %55, label %.lr.ph, label %._crit_edge, !llvm.loop !11

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

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

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

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

; Function Attrs: nounwind uwtable
declare hidden void @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,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass