; LLVM IR from square/subzero :: core/trezor-crypto/aes (aestst)

; 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_encrypt_ctx = type { [60 x i32], %union.aes_inf, [12 x i8] }
%union.aes_inf = type { i32 }
%struct.aes_decrypt_ctx = type { [60 x i32], %union.aes_inf, [12 x i8] }

@pih = external dso_local global [32 x i8], align 16
@exh = external dso_local global [32 x i8], align 16
@res = external dso_local global <{ <{ [16 x i8], [16 x i8] }>, <{ [15 x i8], [17 x i8] }>, <{ [16 x i8], [16 x i8] }> }>, align 16
@.str.4 = external hidden unnamed_addr constant [33 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [49 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [14 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [14 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [14 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [14 x i8], align 1
@.str.11 = external hidden unnamed_addr constant [33 x i8], align 1
@.str.12 = external hidden unnamed_addr constant [29 x i8], align 1

declare i32 @printf(ptr noundef, ...) #0

; Function Attrs: nounwind uwtable
declare dso_local void @oblk(ptr noundef, ptr noundef, i64 noundef) #1

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

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

; Function Attrs: nounwind uwtable
declare dso_local void @message(ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local i32 @main() #1 {
  %1 = alloca i32, align 4
  %2 = alloca [32 x i8], align 16
  %3 = alloca [32 x i8], align 16
  %4 = alloca i8, align 1
  %5 = alloca [1 x %struct.aes_encrypt_ctx], align 16
  %6 = alloca [1 x %struct.aes_decrypt_ctx], align 16
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 32, ptr %2) #5
  call void @llvm.lifetime.start.p0(i64 32, ptr %3) #5
  call void @llvm.lifetime.start.p0(i64 1, ptr %4) #5
  store i8 0, ptr %4, align 1, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 256, ptr %5) #5
  call void @llvm.lifetime.start.p0(i64 256, ptr %6) #5
  %7 = call i32 @aes_init()
  call void @message(ptr noundef @.str.4)
  call void @llvm.memset.p0.i64(ptr align 16 %5, i8 0, i64 256, i1 false)
  call void @llvm.memset.p0.i64(ptr align 16 %6, i8 0, i64 256, i1 false)
  %8 = getelementptr inbounds [32 x i8], ptr %2, i64 0, i64 0
  call void @llvm.memset.p0.i64(ptr align 16 %8, i8 -52, i64 16, i1 false)
  %9 = getelementptr inbounds [32 x i8], ptr %3, i64 0, i64 0
  call void @llvm.memset.p0.i64(ptr align 16 %9, i8 -52, i64 16, i1 false)
  %10 = call i32 (ptr, ...) @printf(ptr noundef @.str.5)
  %11 = getelementptr inbounds [1 x %struct.aes_encrypt_ctx], ptr %5, i64 0, i64 0
  %12 = call i32 @aes_encrypt_key256(ptr noundef @exh, ptr noundef %11)
  call void @oblk(ptr noundef @.str.6, ptr noundef @exh, i64 noundef 32)
  call void @oblk(ptr noundef @.str.7, ptr noundef @pih, i64 noundef 16)
  %13 = getelementptr inbounds [32 x i8], ptr %2, i64 0, i64 0
  %14 = getelementptr inbounds [1 x %struct.aes_encrypt_ctx], ptr %5, i64 0, i64 0
  %15 = call i32 @aes_encrypt(ptr noundef @pih, ptr noundef %13, ptr noundef %14)
  %16 = getelementptr inbounds [32 x i8], ptr %2, i64 0, i64 0
  call void @oblk(ptr noundef @.str.8, ptr noundef %16, i64 noundef 16)
  %17 = getelementptr inbounds [32 x i8], ptr %2, i64 0, i64 0
  %18 = call i32 @memcmp(ptr noundef %17, ptr noundef getelementptr inbounds ([3 x [32 x i8]], ptr @res, i64 0, i64 2), i64 noundef 16) #6
  %19 = icmp ne i32 %18, 0
  br i1 %19, label %20, label %25

20:                                               ; preds = %0
  call void @message(ptr noundef @.str.9)
  %21 = load i8, ptr %4, align 1, !tbaa !5
  %22 = zext i8 %21 to i32
  %23 = add nsw i32 %22, 16
  %24 = trunc i32 %23 to i8
  store i8 %24, ptr %4, align 1, !tbaa !5
  br label %25

25:                                               ; preds = %20, %0
  %26 = getelementptr inbounds [1 x %struct.aes_decrypt_ctx], ptr %6, i64 0, i64 0
  %27 = call i32 @aes_decrypt_key256(ptr noundef @exh, ptr noundef %26)
  %28 = getelementptr inbounds [32 x i8], ptr %2, i64 0, i64 0
  %29 = getelementptr inbounds [32 x i8], ptr %3, i64 0, i64 0
  %30 = getelementptr inbounds [1 x %struct.aes_decrypt_ctx], ptr %6, i64 0, i64 0
  %31 = call i32 @aes_decrypt(ptr noundef %28, ptr noundef %29, ptr noundef %30)
  %32 = getelementptr inbounds [32 x i8], ptr %3, i64 0, i64 0
  call void @oblk(ptr noundef @.str.10, ptr noundef %32, i64 noundef 16)
  %33 = getelementptr inbounds [32 x i8], ptr %3, i64 0, i64 0
  %34 = call i32 @memcmp(ptr noundef %33, ptr noundef @pih, i64 noundef 16) #6
  %35 = icmp ne i32 %34, 0
  br i1 %35, label %36, label %41

36:                                               ; preds = %25
  call void @message(ptr noundef @.str.9)
  %37 = load i8, ptr %4, align 1, !tbaa !5
  %38 = zext i8 %37 to i32
  %39 = add nsw i32 %38, 32
  %40 = trunc i32 %39 to i8
  store i8 %40, ptr %4, align 1, !tbaa !5
  br label %41

41:                                               ; preds = %36, %25
  %42 = load i8, ptr %4, align 1, !tbaa !5
  %43 = icmp ne i8 %42, 0
  br i1 %43, label %45, label %44

44:                                               ; preds = %41
  call void @message(ptr noundef @.str.11)
  br label %46

45:                                               ; preds = %41
  call void @message(ptr noundef @.str.12)
  br label %46

46:                                               ; preds = %45, %44
  call void @llvm.lifetime.end.p0(i64 256, ptr %6) #5
  call void @llvm.lifetime.end.p0(i64 256, ptr %5) #5
  call void @llvm.lifetime.end.p0(i64 1, ptr %4) #5
  call void @llvm.lifetime.end.p0(i64 32, ptr %3) #5
  call void @llvm.lifetime.end.p0(i64 32, ptr %2) #5
  ret i32 0
}

declare i32 @aes_init() #0

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #3

declare i32 @aes_encrypt_key256(ptr noundef, ptr noundef) #0

declare i32 @aes_encrypt(ptr noundef, ptr noundef, ptr noundef) #0

; Function Attrs: nounwind willreturn memory(read)
declare i32 @memcmp(ptr noundef, ptr noundef, i64 noundef) #4

declare i32 @aes_decrypt_key256(ptr noundef, ptr noundef) #0

declare i32 @aes_decrypt(ptr noundef, ptr noundef, ptr noundef) #0

attributes #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 = { 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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #4 = { nounwind willreturn memory(read) "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 #5 = { nounwind }
attributes #6 = { nounwind willreturn memory(read) }

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


; 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.aes_encrypt_ctx = type { [60 x i32], %union.aes_inf, [12 x i8] }
%union.aes_inf = type { i32 }
%struct.aes_decrypt_ctx = type { [60 x i32], %union.aes_inf, [12 x i8] }

@pih = external dso_local global [32 x i8], align 16
@exh = external dso_local global [32 x i8], align 16
@res = external dso_local global <{ <{ [16 x i8], [16 x i8] }>, <{ [15 x i8], [17 x i8] }>, <{ [16 x i8], [16 x i8] }> }>, align 16
@.str.4 = external hidden unnamed_addr constant [33 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [49 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [14 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [14 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [14 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [14 x i8], align 1
@.str.11 = external hidden unnamed_addr constant [33 x i8], align 1
@.str.12 = external hidden unnamed_addr constant [29 x i8], align 1

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local void @oblk(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #1

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

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

; Function Attrs: nounwind uwtable
declare dso_local void @message(ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #1 {
  %1 = alloca [32 x i8], align 16
  %2 = alloca [32 x i8], align 16
  %3 = alloca [1 x %struct.aes_encrypt_ctx], align 16
  %4 = alloca [1 x %struct.aes_decrypt_ctx], align 16
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %1) #6
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %2) #6
  call void @llvm.lifetime.start.p0(i64 256, ptr nonnull %3) #6
  call void @llvm.lifetime.start.p0(i64 256, ptr nonnull %4) #6
  %5 = tail call i32 @aes_init() #6
  tail call void @message(ptr noundef nonnull @.str.4)
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(256) %3, i8 0, i64 256, i1 false)
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(256) %4, i8 0, i64 256, i1 false)
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(16) %1, i8 -52, i64 16, i1 false)
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(16) %2, i8 -52, i64 16, i1 false)
  %6 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.5)
  %7 = call i32 @aes_encrypt_key256(ptr noundef nonnull @exh, ptr noundef nonnull %3) #6
  call void @oblk(ptr noundef nonnull @.str.6, ptr noundef nonnull @exh, i64 noundef 32)
  call void @oblk(ptr noundef nonnull @.str.7, ptr noundef nonnull @pih, i64 noundef 16)
  %8 = call i32 @aes_encrypt(ptr noundef nonnull @pih, ptr noundef nonnull %1, ptr noundef nonnull %3) #6
  call void @oblk(ptr noundef nonnull @.str.8, ptr noundef nonnull %1, i64 noundef 16)
  %bcmp = call i32 @bcmp(ptr noundef nonnull dereferenceable(16) %1, ptr noundef nonnull dereferenceable(16) getelementptr inbounds (i8, ptr @res, i64 64), i64 16)
  %.not = icmp eq i32 %bcmp, 0
  br i1 %.not, label %10, label %9

9:                                                ; preds = %0
  call void @message(ptr noundef nonnull @.str.9)
  br label %10

10:                                               ; preds = %9, %0
  %11 = call i32 @aes_decrypt_key256(ptr noundef nonnull @exh, ptr noundef nonnull %4) #6
  %12 = call i32 @aes_decrypt(ptr noundef nonnull %1, ptr noundef nonnull %2, ptr noundef nonnull %4) #6
  call void @oblk(ptr noundef nonnull @.str.10, ptr noundef nonnull %2, i64 noundef 16)
  %bcmp3 = call i32 @bcmp(ptr noundef nonnull dereferenceable(16) %2, ptr noundef nonnull dereferenceable(16) @pih, i64 16)
  %.not4 = icmp eq i32 %bcmp3, 0
  br i1 %.not4, label %13, label %.thread

.thread:                                          ; preds = %10
  call void @message(ptr noundef nonnull @.str.9)
  br label %14

13:                                               ; preds = %10
  br i1 %.not, label %15, label %14

14:                                               ; preds = %.thread, %13
  br label %15

15:                                               ; preds = %13, %14
  %.str.12.sink = phi ptr [ @.str.12, %14 ], [ @.str.11, %13 ]
  call void @message(ptr noundef nonnull %.str.12.sink)
  call void @llvm.lifetime.end.p0(i64 256, ptr nonnull %4) #6
  call void @llvm.lifetime.end.p0(i64 256, ptr nonnull %3) #6
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %2) #6
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %1) #6
  ret i32 0
}

declare i32 @aes_init() local_unnamed_addr #3

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #4

declare i32 @aes_encrypt_key256(ptr noundef, ptr noundef) local_unnamed_addr #3

declare i32 @aes_encrypt(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #3

declare i32 @aes_decrypt_key256(ptr noundef, ptr noundef) local_unnamed_addr #3

declare i32 @aes_decrypt(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #3

; Function Attrs: nofree nounwind willreturn memory(argmem: read)
declare i32 @bcmp(ptr nocapture, ptr nocapture, i64) local_unnamed_addr #5

attributes #0 = { nofree nounwind "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 = { 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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { "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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #5 = { nofree nounwind willreturn memory(argmem: read) }
attributes #6 = { 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,EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass