; LLVM IR from machinefi/psa-crypto-esp32 :: psa_layer (psa_crypto_porting)

; 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] }

@s = external dso_local global %struct.tc_aes_key_sched_struct, align 4

; 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: inlinehint nounwind uwtable
define dso_local i32 @iotex_aes_crypt_ecb(ptr noundef %0, i32 noundef %1, ptr noundef %2, ptr noundef %3) #1 {
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store i32 %1, ptr %7, align 4, !tbaa !9
  store ptr %2, ptr %8, align 8, !tbaa !5
  store ptr %3, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  store i32 0, ptr %10, align 4, !tbaa !9
  %12 = load ptr, ptr %6, align 8, !tbaa !5
  %13 = icmp eq ptr %12, null
  br i1 %13, label %14, label %15

14:                                               ; preds = %4
  store i32 -33, ptr %5, align 4
  store i32 1, ptr %11, align 4
  br label %49

15:                                               ; preds = %4
  %16 = load i32, ptr %7, align 4, !tbaa !9
  %17 = icmp ne i32 %16, 1
  br i1 %17, label %18, label %22

18:                                               ; preds = %15
  %19 = load i32, ptr %7, align 4, !tbaa !9
  %20 = icmp ne i32 %19, 0
  br i1 %20, label %21, label %22

21:                                               ; preds = %18
  store i32 -33, ptr %5, align 4
  store i32 1, ptr %11, align 4
  br label %49

22:                                               ; preds = %18, %15
  %23 = load ptr, ptr %8, align 8, !tbaa !5
  %24 = icmp eq ptr %23, null
  br i1 %24, label %28, label %25

25:                                               ; preds = %22
  %26 = load ptr, ptr %9, align 8, !tbaa !5
  %27 = icmp eq ptr %26, null
  br i1 %27, label %28, label %29

28:                                               ; preds = %25, %22
  store i32 -33, ptr %5, align 4
  store i32 1, ptr %11, align 4
  br label %49

29:                                               ; preds = %25
  %30 = load i32, ptr %7, align 4, !tbaa !9
  %31 = icmp eq i32 %30, 0
  br i1 %31, label %32, label %40

32:                                               ; preds = %29
  %33 = load ptr, ptr %9, align 8, !tbaa !5
  %34 = load ptr, ptr %8, align 8, !tbaa !5
  %35 = call i32 @tc_aes_decrypt(ptr noundef %33, ptr noundef %34, ptr noundef @s)
  store i32 %35, ptr %10, align 4, !tbaa !9
  %36 = load i32, ptr %10, align 4, !tbaa !9
  %37 = icmp ne i32 %36, 1
  br i1 %37, label %38, label %39

38:                                               ; preds = %32
  store i32 -110, ptr %5, align 4
  store i32 1, ptr %11, align 4
  br label %49

39:                                               ; preds = %32
  br label %48

40:                                               ; preds = %29
  %41 = load ptr, ptr %9, align 8, !tbaa !5
  %42 = load ptr, ptr %9, align 8, !tbaa !5
  %43 = call i32 @tc_aes_encrypt(ptr noundef %41, ptr noundef %42, ptr noundef @s)
  store i32 %43, ptr %10, align 4, !tbaa !9
  %44 = load i32, ptr %10, align 4, !tbaa !9
  %45 = icmp ne i32 %44, 1
  br i1 %45, label %46, label %47

46:                                               ; preds = %40
  store i32 -110, ptr %5, align 4
  store i32 1, ptr %11, align 4
  br label %49

47:                                               ; preds = %40
  br label %48

48:                                               ; preds = %47, %39
  store i32 0, ptr %5, align 4
  store i32 1, ptr %11, align 4
  br label %49

49:                                               ; preds = %48, %46, %38, %28, %21, %14
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  %50 = load i32, ptr %5, align 4
  ret i32 %50
}

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

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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 = { 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}


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

%struct.tc_aes_key_sched_struct = type { [44 x i32] }

@s = external dso_local global %struct.tc_aes_key_sched_struct, align 4

; Function Attrs: inlinehint nounwind uwtable
define dso_local range(i32 -110, 1) i32 @iotex_aes_crypt_ecb(ptr noundef readnone %0, i32 noundef %1, ptr noundef %2, ptr noundef %3) local_unnamed_addr #0 {
  %5 = icmp eq ptr %0, null
  %or.cond = icmp ugt i32 %1, 1
  %or.cond18 = or i1 %5, %or.cond
  br i1 %or.cond18, label %16, label %6

6:                                                ; preds = %4
  %7 = icmp eq ptr %2, null
  %8 = icmp eq ptr %3, null
  %or.cond3 = or i1 %7, %8
  br i1 %or.cond3, label %16, label %9

9:                                                ; preds = %6
  %10 = icmp eq i32 %1, 0
  br i1 %10, label %11, label %13

11:                                               ; preds = %9
  %12 = tail call i32 @tc_aes_decrypt(ptr noundef nonnull %3, ptr noundef nonnull %2, ptr noundef nonnull @s) #2
  %.not17 = icmp eq i32 %12, 1
  br i1 %.not17, label %15, label %16

13:                                               ; preds = %9
  %14 = tail call i32 @tc_aes_encrypt(ptr noundef nonnull %3, ptr noundef nonnull %3, ptr noundef nonnull @s) #2
  %.not = icmp eq i32 %14, 1
  br i1 %.not, label %15, label %16

15:                                               ; preds = %13, %11
  br label %16

16:                                               ; preds = %13, %11, %6, %4, %15
  %.0 = phi i32 [ 0, %15 ], [ -33, %4 ], [ -33, %6 ], [ -110, %11 ], [ -110, %13 ]
  ret i32 %.0
}

declare i32 @tc_aes_decrypt(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

declare i32 @tc_aes_encrypt(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

attributes #0 = { 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 #1 = { "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)"}


; Effective O3 passes: CorrelatedValuePropagationPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass