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

; Function Attrs: nounwind uwtable
define dso_local i32 @tc_aes_decrypt(ptr noundef %0, ptr noundef %1, ptr noundef %2) #0 {
  %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 %62

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 %62

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 %62

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
  %32 = getelementptr inbounds i32, ptr %31, i64 40
  call void @add_round_key(ptr noundef %28, ptr noundef %32)
  store i32 9, ptr %9, align 4, !tbaa !9
  br label %33

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

36:                                               ; preds = %33
  %37 = getelementptr inbounds [16 x i8], ptr %8, i64 0, i64 0
  call void @inv_shift_rows(ptr noundef %37)
  %38 = getelementptr inbounds [16 x i8], ptr %8, i64 0, i64 0
  call void @inv_sub_bytes(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 = mul i32 4, %43
  %45 = zext i32 %44 to i64
  %46 = getelementptr inbounds i32, ptr %42, i64 %45
  call void @add_round_key(ptr noundef %39, ptr noundef %46)
  %47 = getelementptr inbounds [16 x i8], ptr %8, i64 0, i64 0
  call void @inv_mix_columns(ptr noundef %47)
  br label %48

48:                                               ; preds = %36
  %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 %33, !llvm.loop !11

51:                                               ; preds = %33
  %52 = getelementptr inbounds [16 x i8], ptr %8, i64 0, i64 0
  call void @inv_shift_rows(ptr noundef %52)
  %53 = getelementptr inbounds [16 x i8], ptr %8, i64 0, i64 0
  call void @inv_sub_bytes(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
  call void @add_round_key(ptr noundef %54, ptr noundef %57)
  %58 = load ptr, ptr %5, align 8, !tbaa !5
  %59 = getelementptr inbounds [16 x i8], ptr %8, i64 0, i64 0
  %60 = call i32 @_copy(ptr noundef %58, i32 noundef 16, ptr noundef %59, i32 noundef 16)
  %61 = getelementptr inbounds [16 x i8], ptr %8, i64 0, i64 0
  call void @_set(ptr noundef %61, i8 noundef zeroext 0, i32 noundef 16)
  store i32 1, ptr %4, align 4
  store i32 1, ptr %10, align 4
  br label %62

62:                                               ; 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
  %63 = load i32, ptr %4, align 4
  ret i32 %63
}

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

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 @inv_shift_rows(ptr noundef) #3

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

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

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

; 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 = { "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: nounwind uwtable
define dso_local range(i32 0, 2) i32 @tc_aes_decrypt(ptr noundef %0, ptr noundef %1, ptr noundef %2) local_unnamed_addr #0 {
  %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.cond15 = or i1 %or.cond, %7
  br i1 %or.cond15, 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
  %10 = getelementptr inbounds i8, ptr %2, i64 160
  call void @add_round_key(ptr noundef nonnull %4, ptr noundef nonnull %10)
  call void @inv_shift_rows(ptr noundef nonnull %4)
  call void @inv_sub_bytes(ptr noundef nonnull %4)
  %11 = getelementptr inbounds i8, ptr %2, i64 144
  call void @add_round_key(ptr noundef nonnull %4, ptr noundef nonnull %11)
  call void @inv_mix_columns(ptr noundef nonnull %4)
  call void @inv_shift_rows(ptr noundef nonnull %4)
  call void @inv_sub_bytes(ptr noundef nonnull %4)
  %12 = getelementptr inbounds i8, ptr %2, i64 128
  call void @add_round_key(ptr noundef nonnull %4, ptr noundef nonnull %12)
  call void @inv_mix_columns(ptr noundef nonnull %4)
  call void @inv_shift_rows(ptr noundef nonnull %4)
  call void @inv_sub_bytes(ptr noundef nonnull %4)
  %13 = getelementptr inbounds i8, ptr %2, i64 112
  call void @add_round_key(ptr noundef nonnull %4, ptr noundef nonnull %13)
  call void @inv_mix_columns(ptr noundef nonnull %4)
  call void @inv_shift_rows(ptr noundef nonnull %4)
  call void @inv_sub_bytes(ptr noundef nonnull %4)
  %14 = getelementptr inbounds i8, ptr %2, i64 96
  call void @add_round_key(ptr noundef nonnull %4, ptr noundef nonnull %14)
  call void @inv_mix_columns(ptr noundef nonnull %4)
  call void @inv_shift_rows(ptr noundef nonnull %4)
  call void @inv_sub_bytes(ptr noundef nonnull %4)
  %15 = getelementptr inbounds i8, ptr %2, i64 80
  call void @add_round_key(ptr noundef nonnull %4, ptr noundef nonnull %15)
  call void @inv_mix_columns(ptr noundef nonnull %4)
  call void @inv_shift_rows(ptr noundef nonnull %4)
  call void @inv_sub_bytes(ptr noundef nonnull %4)
  %16 = getelementptr inbounds i8, ptr %2, i64 64
  call void @add_round_key(ptr noundef nonnull %4, ptr noundef nonnull %16)
  call void @inv_mix_columns(ptr noundef nonnull %4)
  call void @inv_shift_rows(ptr noundef nonnull %4)
  call void @inv_sub_bytes(ptr noundef nonnull %4)
  %17 = getelementptr inbounds i8, ptr %2, i64 48
  call void @add_round_key(ptr noundef nonnull %4, ptr noundef nonnull %17)
  call void @inv_mix_columns(ptr noundef nonnull %4)
  call void @inv_shift_rows(ptr noundef nonnull %4)
  call void @inv_sub_bytes(ptr noundef nonnull %4)
  %18 = getelementptr inbounds i8, ptr %2, i64 32
  call void @add_round_key(ptr noundef nonnull %4, ptr noundef nonnull %18)
  call void @inv_mix_columns(ptr noundef nonnull %4)
  call void @inv_shift_rows(ptr noundef nonnull %4)
  call void @inv_sub_bytes(ptr noundef nonnull %4)
  %19 = getelementptr inbounds i8, ptr %2, i64 16
  call void @add_round_key(ptr noundef nonnull %4, ptr noundef nonnull %19)
  call void @inv_mix_columns(ptr noundef nonnull %4)
  call void @inv_shift_rows(ptr noundef nonnull %4)
  call void @inv_sub_bytes(ptr noundef nonnull %4)
  call void @add_round_key(ptr noundef nonnull %4, ptr noundef nonnull %2)
  %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
  %.011 = phi i32 [ 1, %8 ], [ 0, %3 ]
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %4) #4
  ret i32 %.011
}

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

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 @inv_shift_rows(ptr noundef) local_unnamed_addr #3

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

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

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

; Function Attrs: mustprogress 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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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,LoopRotatePass,SROAPass,SimplifyCFGPass