; LLVM IR from machinefi/psa-crypto-esp32 :: crypto (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.tc_aes_key_sched_struct = type { [44 x i32] }

; 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 i32 @tc_aes_encrypt(ptr noundef %0, ptr noundef %1, ptr noundef %2) #1 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca [16 x i8], align 16
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 16, ptr %8) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  %11 = load ptr, ptr %5, align 8, !tbaa !5
  %12 = icmp eq ptr %11, null
  br i1 %12, label %13, label %14

13:                                               ; preds = %3
  store i32 0, ptr %4, align 4
  store i32 1, ptr %10, align 4
  br label %67

14:                                               ; preds = %3
  %15 = load ptr, ptr %6, align 8, !tbaa !5
  %16 = icmp eq ptr %15, null
  br i1 %16, label %17, label %18

17:                                               ; preds = %14
  store i32 0, ptr %4, align 4
  store i32 1, ptr %10, align 4
  br label %67

18:                                               ; preds = %14
  %19 = load ptr, ptr %7, align 8, !tbaa !5
  %20 = icmp eq ptr %19, null
  br i1 %20, label %21, label %22

21:                                               ; preds = %18
  store i32 0, ptr %4, align 4
  store i32 1, ptr %10, align 4
  br label %67

22:                                               ; preds = %18
  br label %23

23:                                               ; preds = %22
  br label %24

24:                                               ; preds = %23
  %25 = getelementptr inbounds [16 x i8], ptr %8, i64 0, i64 0
  %26 = load ptr, ptr %6, align 8, !tbaa !5
  %27 = call i32 @_copy(ptr noundef %25, i32 noundef 16, ptr noundef %26, i32 noundef 16)
  %28 = getelementptr inbounds [16 x i8], ptr %8, i64 0, i64 0
  %29 = load ptr, ptr %7, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.tc_aes_key_sched_struct, ptr %29, i32 0, i32 0
  %31 = getelementptr inbounds [44 x i32], ptr %30, i64 0, i64 0
  call void @add_round_key(ptr noundef %28, ptr noundef %31)
  store i32 0, ptr %9, align 4, !tbaa !9
  br label %32

32:                                               ; preds = %48, %24
  %33 = load i32, ptr %9, align 4, !tbaa !9
  %34 = icmp ult i32 %33, 9
  br i1 %34, label %35, label %51

35:                                               ; preds = %32
  %36 = getelementptr inbounds [16 x i8], ptr %8, i64 0, i64 0
  call void @sub_bytes(ptr noundef %36)
  %37 = getelementptr inbounds [16 x i8], ptr %8, i64 0, i64 0
  call void @shift_rows(ptr noundef %37)
  %38 = getelementptr inbounds [16 x i8], ptr %8, i64 0, i64 0
  call void @mix_columns(ptr noundef %38)
  %39 = getelementptr inbounds [16 x i8], ptr %8, i64 0, i64 0
  %40 = load ptr, ptr %7, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.tc_aes_key_sched_struct, ptr %40, i32 0, i32 0
  %42 = getelementptr inbounds [44 x i32], ptr %41, i64 0, i64 0
  %43 = load i32, ptr %9, align 4, !tbaa !9
  %44 = add i32 %43, 1
  %45 = mul i32 4, %44
  %46 = zext i32 %45 to i64
  %47 = getelementptr inbounds i32, ptr %42, i64 %46
  call void @add_round_key(ptr noundef %39, ptr noundef %47)
  br label %48

48:                                               ; preds = %35
  %49 = load i32, ptr %9, align 4, !tbaa !9
  %50 = add i32 %49, 1
  store i32 %50, ptr %9, align 4, !tbaa !9
  br label %32, !llvm.loop !11

51:                                               ; preds = %32
  %52 = getelementptr inbounds [16 x i8], ptr %8, i64 0, i64 0
  call void @sub_bytes(ptr noundef %52)
  %53 = getelementptr inbounds [16 x i8], ptr %8, i64 0, i64 0
  call void @shift_rows(ptr noundef %53)
  %54 = getelementptr inbounds [16 x i8], ptr %8, i64 0, i64 0
  %55 = load ptr, ptr %7, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.tc_aes_key_sched_struct, ptr %55, i32 0, i32 0
  %57 = getelementptr inbounds [44 x i32], ptr %56, i64 0, i64 0
  %58 = load i32, ptr %9, align 4, !tbaa !9
  %59 = add i32 %58, 1
  %60 = mul i32 4, %59
  %61 = zext i32 %60 to i64
  %62 = getelementptr inbounds i32, ptr %57, i64 %61
  call void @add_round_key(ptr noundef %54, ptr noundef %62)
  %63 = load ptr, ptr %5, align 8, !tbaa !5
  %64 = getelementptr inbounds [16 x i8], ptr %8, i64 0, i64 0
  %65 = call i32 @_copy(ptr noundef %63, i32 noundef 16, ptr noundef %64, i32 noundef 16)
  %66 = getelementptr inbounds [16 x i8], ptr %8, i64 0, i64 0
  call void @_set(ptr noundef %66, i8 noundef zeroext 0, i32 noundef 16)
  store i32 1, ptr %4, align 4
  store i32 1, ptr %10, align 4
  br label %67

67:                                               ; preds = %51, %21, %17, %13
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 16, ptr %8) #4
  %68 = load i32, ptr %4, align 4
  ret i32 %68
}

declare i32 @_copy(ptr noundef, i32 noundef, ptr noundef, i32 noundef) #2

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @add_round_key(ptr noundef, ptr noundef) #3

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

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

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

declare void @_set(ptr noundef, i8 noundef zeroext, i32 noundef) #2

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 = { "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 #3 = { inlinehint 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 #4 = { 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 = distinct !{!11, !12}
!12 = !{!"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 nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: mustprogress 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 range(i32 0, 2) i32 @tc_aes_encrypt(ptr noundef %0, ptr noundef %1, ptr noundef %2) local_unnamed_addr #1 {
  %4 = alloca [16 x i8], align 16
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %4) #4
  %5 = icmp eq ptr %0, null
  %6 = icmp eq ptr %1, null
  %or.cond = or i1 %5, %6
  %7 = icmp eq ptr %2, null
  %or.cond16 = or i1 %or.cond, %7
  br i1 %or.cond16, label %21, label %8

8:                                                ; preds = %3
  %9 = call i32 @_copy(ptr noundef nonnull %4, i32 noundef 16, ptr noundef nonnull %1, i32 noundef 16) #4
  call void @add_round_key(ptr noundef nonnull %4, ptr noundef nonnull %2)
  call void @sub_bytes(ptr noundef nonnull %4)
  call void @shift_rows(ptr noundef nonnull %4)
  call void @mix_columns(ptr noundef nonnull %4)
  %10 = getelementptr inbounds i8, ptr %2, i64 16
  call void @add_round_key(ptr noundef nonnull %4, ptr noundef nonnull %10)
  call void @sub_bytes(ptr noundef nonnull %4)
  call void @shift_rows(ptr noundef nonnull %4)
  call void @mix_columns(ptr noundef nonnull %4)
  %11 = getelementptr inbounds i8, ptr %2, i64 32
  call void @add_round_key(ptr noundef nonnull %4, ptr noundef nonnull %11)
  call void @sub_bytes(ptr noundef nonnull %4)
  call void @shift_rows(ptr noundef nonnull %4)
  call void @mix_columns(ptr noundef nonnull %4)
  %12 = getelementptr inbounds i8, ptr %2, i64 48
  call void @add_round_key(ptr noundef nonnull %4, ptr noundef nonnull %12)
  call void @sub_bytes(ptr noundef nonnull %4)
  call void @shift_rows(ptr noundef nonnull %4)
  call void @mix_columns(ptr noundef nonnull %4)
  %13 = getelementptr inbounds i8, ptr %2, i64 64
  call void @add_round_key(ptr noundef nonnull %4, ptr noundef nonnull %13)
  call void @sub_bytes(ptr noundef nonnull %4)
  call void @shift_rows(ptr noundef nonnull %4)
  call void @mix_columns(ptr noundef nonnull %4)
  %14 = getelementptr inbounds i8, ptr %2, i64 80
  call void @add_round_key(ptr noundef nonnull %4, ptr noundef nonnull %14)
  call void @sub_bytes(ptr noundef nonnull %4)
  call void @shift_rows(ptr noundef nonnull %4)
  call void @mix_columns(ptr noundef nonnull %4)
  %15 = getelementptr inbounds i8, ptr %2, i64 96
  call void @add_round_key(ptr noundef nonnull %4, ptr noundef nonnull %15)
  call void @sub_bytes(ptr noundef nonnull %4)
  call void @shift_rows(ptr noundef nonnull %4)
  call void @mix_columns(ptr noundef nonnull %4)
  %16 = getelementptr inbounds i8, ptr %2, i64 112
  call void @add_round_key(ptr noundef nonnull %4, ptr noundef nonnull %16)
  call void @sub_bytes(ptr noundef nonnull %4)
  call void @shift_rows(ptr noundef nonnull %4)
  call void @mix_columns(ptr noundef nonnull %4)
  %17 = getelementptr inbounds i8, ptr %2, i64 128
  call void @add_round_key(ptr noundef nonnull %4, ptr noundef nonnull %17)
  call void @sub_bytes(ptr noundef nonnull %4)
  call void @shift_rows(ptr noundef nonnull %4)
  call void @mix_columns(ptr noundef nonnull %4)
  %18 = getelementptr inbounds i8, ptr %2, i64 144
  call void @add_round_key(ptr noundef nonnull %4, ptr noundef nonnull %18)
  call void @sub_bytes(ptr noundef nonnull %4)
  call void @shift_rows(ptr noundef nonnull %4)
  %19 = getelementptr inbounds i8, ptr %2, i64 160
  call void @add_round_key(ptr noundef nonnull %4, ptr noundef nonnull %19)
  %20 = call i32 @_copy(ptr noundef nonnull %0, i32 noundef 16, ptr noundef nonnull %4, i32 noundef 16) #4
  call void @_set(ptr noundef nonnull %4, i8 noundef zeroext 0, i32 noundef 16) #4
  br label %21

21:                                               ; preds = %3, %8
  %.012 = phi i32 [ 1, %8 ], [ 0, %3 ]
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %4) #4
  ret i32 %.012
}

declare i32 @_copy(ptr noundef, i32 noundef, ptr noundef, i32 noundef) local_unnamed_addr #2

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @add_round_key(ptr noundef, ptr noundef) local_unnamed_addr #3

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

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

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

declare void @_set(ptr noundef, i8 noundef zeroext, i32 noundef) local_unnamed_addr #2

attributes #0 = { mustprogress 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 = { "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 #3 = { inlinehint 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 #4 = { 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)"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LCSSAPass,LoopRotatePass,ReassociatePass,SROAPass,SimplifyCFGPass