; LLVM IR from square/subzero :: core/external-crypto/aes (aesgav)

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

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

declare void @block_out(i32 noundef, ptr noundef, ptr noundef, i64 noundef) #1

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

declare void @block_clear(ptr noundef, i64 noundef) #1

declare i32 @aes_encrypt_key(ptr noundef, i32 noundef, ptr noundef) #1

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

; Function Attrs: nounwind uwtable
define dso_local void @ecb_vk(ptr noundef %0, ptr noundef %1, i64 noundef %2, i64 noundef %3) #2 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  %9 = alloca i64, align 8
  %10 = alloca [32 x i8], align 16
  %11 = alloca [32 x i8], align 16
  %12 = alloca [32 x i8], align 16
  %13 = alloca i8, align 1
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store i64 %2, ptr %7, align 8, !tbaa !9
  store i64 %3, ptr %8, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.start.p0(i64 32, ptr %10) #3
  call void @llvm.lifetime.start.p0(i64 32, ptr %11) #3
  call void @llvm.lifetime.start.p0(i64 32, ptr %12) #3
  call void @llvm.lifetime.start.p0(i64 1, ptr %13) #3
  %14 = getelementptr inbounds [32 x i8], ptr %10, i64 0, i64 0
  %15 = load i64, ptr %7, align 8, !tbaa !9
  call void @block_clear(ptr noundef %14, i64 noundef %15)
  %16 = getelementptr inbounds [32 x i8], ptr %10, i64 0, i64 0
  %17 = load ptr, ptr %5, align 8, !tbaa !5
  %18 = load i64, ptr %7, align 8, !tbaa !9
  call void @block_out(i32 noundef 6, ptr noundef %16, ptr noundef %17, i64 noundef %18)
  store i64 0, ptr %9, align 8, !tbaa !9
  br label %19

19:                                               ; preds = %59, %4
  %20 = load i64, ptr %9, align 8, !tbaa !9
  %21 = load i64, ptr %8, align 8, !tbaa !9
  %22 = mul i64 8, %21
  %23 = icmp ule i64 %20, %22
  br i1 %23, label %24, label %62

24:                                               ; preds = %19
  %25 = load ptr, ptr %5, align 8, !tbaa !5
  %26 = load i64, ptr %9, align 8, !tbaa !9
  call void @block_out(i32 noundef 3, ptr noundef %13, ptr noundef %25, i64 noundef %26)
  %27 = getelementptr inbounds [32 x i8], ptr %12, i64 0, i64 0
  %28 = load i64, ptr %8, align 8, !tbaa !9
  call void @block_clear(ptr noundef %27, i64 noundef %28)
  %29 = load i64, ptr %9, align 8, !tbaa !9
  %30 = icmp ne i64 %29, 0
  br i1 %30, label %31, label %43

31:                                               ; preds = %24
  %32 = load i64, ptr %9, align 8, !tbaa !9
  %33 = sub i64 %32, 1
  %34 = urem i64 %33, 8
  %35 = trunc i64 %34 to i32
  %36 = ashr i32 128, %35
  %37 = trunc i32 %36 to i8
  %38 = getelementptr inbounds [32 x i8], ptr %12, i64 0, i64 0
  %39 = load i64, ptr %9, align 8, !tbaa !9
  %40 = sub i64 %39, 1
  %41 = udiv i64 %40, 8
  %42 = getelementptr inbounds i8, ptr %38, i64 %41
  store i8 %37, ptr %42, align 1, !tbaa !11
  br label %43

43:                                               ; preds = %31, %24
  %44 = getelementptr inbounds [32 x i8], ptr %12, i64 0, i64 0
  %45 = load ptr, ptr %5, align 8, !tbaa !5
  %46 = load i64, ptr %8, align 8, !tbaa !9
  call void @block_out(i32 noundef 5, ptr noundef %44, ptr noundef %45, i64 noundef %46)
  %47 = getelementptr inbounds [32 x i8], ptr %12, i64 0, i64 0
  %48 = load i64, ptr %8, align 8, !tbaa !9
  %49 = trunc i64 %48 to i32
  %50 = load ptr, ptr %6, align 8, !tbaa !5
  %51 = call i32 @aes_encrypt_key(ptr noundef %47, i32 noundef %49, ptr noundef %50)
  %52 = getelementptr inbounds [32 x i8], ptr %10, i64 0, i64 0
  %53 = getelementptr inbounds [32 x i8], ptr %11, i64 0, i64 0
  %54 = load ptr, ptr %6, align 8, !tbaa !5
  %55 = call i32 @aes_encrypt(ptr noundef %52, ptr noundef %53, ptr noundef %54)
  %56 = getelementptr inbounds [32 x i8], ptr %11, i64 0, i64 0
  %57 = load ptr, ptr %5, align 8, !tbaa !5
  %58 = load i64, ptr %7, align 8, !tbaa !9
  call void @block_out(i32 noundef 7, ptr noundef %56, ptr noundef %57, i64 noundef %58)
  br label %59

59:                                               ; preds = %43
  %60 = load i64, ptr %9, align 8, !tbaa !9
  %61 = add i64 %60, 1
  store i64 %61, ptr %9, align 8, !tbaa !9
  br label %19, !llvm.loop !12

62:                                               ; preds = %19
  call void @llvm.lifetime.end.p0(i64 1, ptr %13) #3
  call void @llvm.lifetime.end.p0(i64 32, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 32, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 32, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 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 #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 = !{!"long", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"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

declare void @block_out(i32 noundef, 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.end.p0(i64 immarg, ptr nocapture) #0

declare void @block_clear(ptr noundef, i64 noundef) local_unnamed_addr #1

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

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

; Function Attrs: nounwind uwtable
define dso_local void @ecb_vk(ptr noundef %0, ptr noundef %1, i64 noundef %2, i64 noundef %3) local_unnamed_addr #2 {
  %5 = alloca [32 x i8], align 16
  %6 = alloca [32 x i8], align 16
  %7 = alloca [32 x i8], align 16
  %8 = alloca i8, align 1
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %5) #3
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %6) #3
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %7) #3
  call void @llvm.lifetime.start.p0(i64 1, ptr nonnull %8) #3
  call void @block_clear(ptr noundef nonnull %5, i64 noundef %2) #3
  call void @block_out(i32 noundef 6, ptr noundef nonnull %5, ptr noundef %0, i64 noundef %2) #3
  %9 = shl i64 %3, 3
  %10 = trunc i64 %3 to i32
  call void @block_out(i32 noundef 3, ptr noundef nonnull %8, ptr noundef %0, i64 noundef 0) #3
  call void @block_clear(ptr noundef nonnull %7, i64 noundef %3) #3
  call void @block_out(i32 noundef 5, ptr noundef nonnull %7, ptr noundef %0, i64 noundef %3) #3
  %11 = call i32 @aes_encrypt_key(ptr noundef nonnull %7, i32 noundef %10, ptr noundef %1) #3
  %12 = call i32 @aes_encrypt(ptr noundef nonnull %5, ptr noundef nonnull %6, ptr noundef %1) #3
  call void @block_out(i32 noundef 7, ptr noundef nonnull %6, ptr noundef %0, i64 noundef %2) #3
  %exitcond.peel.not = icmp eq i64 %9, 0
  br i1 %exitcond.peel.not, label %.loopexit, label %.peel.next

.peel.next:                                       ; preds = %4, %.peel.next
  %.019 = phi i64 [ %21, %.peel.next ], [ 1, %4 ]
  call void @block_out(i32 noundef 3, ptr noundef nonnull %8, ptr noundef %0, i64 noundef %.019) #3
  call void @block_clear(ptr noundef nonnull %7, i64 noundef %3) #3
  %13 = add i64 %.019, -1
  %14 = trunc i64 %13 to i8
  %15 = and i8 %14, 7
  %16 = lshr exact i8 -128, %15
  %17 = lshr i64 %13, 3
  %18 = getelementptr inbounds i8, ptr %7, i64 %17
  store i8 %16, ptr %18, align 1, !tbaa !5
  call void @block_out(i32 noundef 5, ptr noundef nonnull %7, ptr noundef %0, i64 noundef %3) #3
  %19 = call i32 @aes_encrypt_key(ptr noundef nonnull %7, i32 noundef %10, ptr noundef %1) #3
  %20 = call i32 @aes_encrypt(ptr noundef nonnull %5, ptr noundef nonnull %6, ptr noundef %1) #3
  call void @block_out(i32 noundef 7, ptr noundef nonnull %6, ptr noundef %0, i64 noundef %2) #3
  %21 = add nuw i64 %.019, 1
  %exitcond.not = icmp eq i64 %.019, %9
  br i1 %exitcond.not, label %.loopexit, label %.peel.next, !llvm.loop !8

.loopexit:                                        ; preds = %.peel.next, %4
  call void @llvm.lifetime.end.p0(i64 1, ptr nonnull %8) #3
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %7) #3
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %6) #3
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %5) #3
  ret void
}

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 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 #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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = distinct !{!8, !9, !10}
!9 = !{!"llvm.loop.mustprogress"}
!10 = !{!"llvm.loop.peeled.count", i32 1}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopFullUnrollPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SCCPPass,SROAPass,SimplifyCFGPass