; 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

; Function Attrs: nounwind uwtable
define dso_local void @ecb_vt(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 %12, i64 0, i64 0
  %15 = load i64, ptr %8, align 8, !tbaa !9
  call void @block_clear(ptr noundef %14, i64 noundef %15)
  %16 = getelementptr inbounds [32 x i8], ptr %12, i64 0, i64 0
  %17 = load ptr, ptr %5, align 8, !tbaa !5
  %18 = load i64, ptr %8, align 8, !tbaa !9
  call void @block_out(i32 noundef 5, ptr noundef %16, ptr noundef %17, i64 noundef %18)
  %19 = getelementptr inbounds [32 x i8], ptr %12, i64 0, i64 0
  %20 = load i64, ptr %8, align 8, !tbaa !9
  %21 = trunc i64 %20 to i32
  %22 = load ptr, ptr %6, align 8, !tbaa !5
  %23 = call i32 @aes_encrypt_key(ptr noundef %19, i32 noundef %21, ptr noundef %22)
  store i64 0, ptr %9, align 8, !tbaa !9
  br label %24

24:                                               ; preds = %59, %4
  %25 = load i64, ptr %9, align 8, !tbaa !9
  %26 = load i64, ptr %7, align 8, !tbaa !9
  %27 = mul i64 8, %26
  %28 = icmp ule i64 %25, %27
  br i1 %28, label %29, label %62

29:                                               ; preds = %24
  %30 = load ptr, ptr %5, align 8, !tbaa !5
  %31 = load i64, ptr %9, align 8, !tbaa !9
  call void @block_out(i32 noundef 3, ptr noundef %13, ptr noundef %30, i64 noundef %31)
  %32 = getelementptr inbounds [32 x i8], ptr %10, i64 0, i64 0
  %33 = load i64, ptr %7, align 8, !tbaa !9
  call void @block_clear(ptr noundef %32, i64 noundef %33)
  %34 = load i64, ptr %9, align 8, !tbaa !9
  %35 = icmp ne i64 %34, 0
  br i1 %35, label %36, label %48

36:                                               ; preds = %29
  %37 = load i64, ptr %9, align 8, !tbaa !9
  %38 = sub i64 %37, 1
  %39 = urem i64 %38, 8
  %40 = trunc i64 %39 to i32
  %41 = ashr i32 128, %40
  %42 = trunc i32 %41 to i8
  %43 = getelementptr inbounds [32 x i8], ptr %10, i64 0, i64 0
  %44 = load i64, ptr %9, align 8, !tbaa !9
  %45 = sub i64 %44, 1
  %46 = udiv i64 %45, 8
  %47 = getelementptr inbounds i8, ptr %43, i64 %46
  store i8 %42, ptr %47, align 1, !tbaa !11
  br label %48

48:                                               ; preds = %36, %29
  %49 = getelementptr inbounds [32 x i8], ptr %10, i64 0, i64 0
  %50 = load ptr, ptr %5, align 8, !tbaa !5
  %51 = load i64, ptr %7, align 8, !tbaa !9
  call void @block_out(i32 noundef 6, ptr noundef %49, ptr noundef %50, i64 noundef %51)
  %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 = %48
  %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 %24, !llvm.loop !12

62:                                               ; preds = %24
  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
}

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

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

; Function Attrs: nounwind uwtable
define dso_local void @ecb_vt(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 %7, i64 noundef %3) #3
  call void @block_out(i32 noundef 5, ptr noundef nonnull %7, ptr noundef %0, i64 noundef %3) #3
  %9 = trunc i64 %3 to i32
  %10 = call i32 @aes_encrypt_key(ptr noundef nonnull %7, i32 noundef %9, ptr noundef %1) #3
  %11 = shl i64 %2, 3
  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 %5, i64 noundef %2) #3
  call void @block_out(i32 noundef 6, ptr noundef nonnull %5, ptr noundef %0, i64 noundef %2) #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 %11, 0
  br i1 %exitcond.peel.not, label %.loopexit, label %.peel.next

.peel.next:                                       ; preds = %4, %.peel.next
  %.019 = phi i64 [ %20, %.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 %5, i64 noundef %2) #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 %5, i64 %17
  store i8 %16, ptr %18, align 1, !tbaa !5
  call void @block_out(i32 noundef 6, ptr noundef nonnull %5, ptr noundef %0, i64 noundef %2) #3
  %19 = 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
  %20 = add nuw i64 %.019, 1
  %exitcond.not = icmp eq i64 %.019, %11
  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
}

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

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