; 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_vtn(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 ptr, align 8
  %14 = 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 8, ptr %13) #3
  call void @llvm.lifetime.start.p0(i64 1, ptr %14) #3
  %15 = getelementptr inbounds [32 x i8], ptr %12, i64 0, i64 0
  %16 = load i64, ptr %8, align 8, !tbaa !9
  call void @block_clear(ptr noundef %15, i64 noundef %16)
  %17 = getelementptr inbounds [32 x i8], ptr %12, i64 0, i64 0
  %18 = load ptr, ptr %5, align 8, !tbaa !5
  %19 = load i64, ptr %8, align 8, !tbaa !9
  call void @block_out(i32 noundef 5, ptr noundef %17, ptr noundef %18, i64 noundef %19)
  %20 = getelementptr inbounds [32 x i8], ptr %12, i64 0, i64 0
  %21 = load i64, ptr %8, align 8, !tbaa !9
  %22 = trunc i64 %21 to i32
  %23 = load ptr, ptr %6, align 8, !tbaa !5
  %24 = call i32 @aes_encrypt_key(ptr noundef %20, i32 noundef %22, ptr noundef %23)
  %25 = getelementptr inbounds [32 x i8], ptr %10, i64 0, i64 0
  %26 = load i64, ptr %7, align 8, !tbaa !9
  call void @block_clear(ptr noundef %25, i64 noundef %26)
  store i64 0, ptr %9, align 8, !tbaa !9
  br label %27

27:                                               ; preds = %80, %4
  %28 = load i64, ptr %9, align 8, !tbaa !9
  %29 = load i64, ptr %7, align 8, !tbaa !9
  %30 = mul i64 16, %29
  %31 = icmp ult i64 %28, %30
  br i1 %31, label %32, label %83

32:                                               ; preds = %27
  %33 = load ptr, ptr %5, align 8, !tbaa !5
  %34 = load i64, ptr %9, align 8, !tbaa !9
  call void @block_out(i32 noundef 3, ptr noundef %14, ptr noundef %33, i64 noundef %34)
  %35 = getelementptr inbounds [32 x i8], ptr %10, i64 0, i64 0
  %36 = load ptr, ptr %5, align 8, !tbaa !5
  %37 = load i64, ptr %7, align 8, !tbaa !9
  call void @block_out(i32 noundef 6, ptr noundef %35, ptr noundef %36, i64 noundef %37)
  %38 = getelementptr inbounds [32 x i8], ptr %10, i64 0, i64 0
  %39 = getelementptr inbounds [32 x i8], ptr %11, i64 0, i64 0
  %40 = load ptr, ptr %6, align 8, !tbaa !5
  %41 = call i32 @aes_encrypt(ptr noundef %38, ptr noundef %39, ptr noundef %40)
  %42 = getelementptr inbounds [32 x i8], ptr %11, i64 0, i64 0
  %43 = load ptr, ptr %5, align 8, !tbaa !5
  %44 = load i64, ptr %7, align 8, !tbaa !9
  call void @block_out(i32 noundef 7, ptr noundef %42, ptr noundef %43, i64 noundef %44)
  %45 = getelementptr inbounds [32 x i8], ptr %10, i64 0, i64 0
  %46 = load i64, ptr %7, align 8, !tbaa !9
  %47 = getelementptr inbounds i8, ptr %45, i64 %46
  %48 = getelementptr inbounds i8, ptr %47, i64 -1
  %49 = load i64, ptr %9, align 8, !tbaa !9
  %50 = udiv i64 %49, 8
  %51 = sub i64 0, %50
  %52 = getelementptr inbounds i8, ptr %48, i64 %51
  store ptr %52, ptr %13, align 8, !tbaa !5
  %53 = load i64, ptr %9, align 8, !tbaa !9
  %54 = load i64, ptr %7, align 8, !tbaa !9
  %55 = mul i64 8, %54
  %56 = icmp ult i64 %53, %55
  br i1 %56, label %57, label %68

57:                                               ; preds = %32
  %58 = load ptr, ptr %13, align 8, !tbaa !5
  %59 = load i8, ptr %58, align 1, !tbaa !11
  %60 = zext i8 %59 to i32
  %61 = shl i32 %60, 1
  %62 = or i32 %61, 1
  %63 = load ptr, ptr %13, align 8, !tbaa !5
  %64 = load i8, ptr %63, align 1, !tbaa !11
  %65 = zext i8 %64 to i32
  %66 = or i32 %65, %62
  %67 = trunc i32 %66 to i8
  store i8 %67, ptr %63, align 1, !tbaa !11
  br label %79

68:                                               ; preds = %32
  %69 = load ptr, ptr %13, align 8, !tbaa !5
  %70 = load i64, ptr %7, align 8, !tbaa !9
  %71 = getelementptr inbounds i8, ptr %69, i64 %70
  %72 = load i8, ptr %71, align 1, !tbaa !11
  %73 = zext i8 %72 to i32
  %74 = shl i32 %73, 1
  %75 = trunc i32 %74 to i8
  %76 = load ptr, ptr %13, align 8, !tbaa !5
  %77 = load i64, ptr %7, align 8, !tbaa !9
  %78 = getelementptr inbounds i8, ptr %76, i64 %77
  store i8 %75, ptr %78, align 1, !tbaa !11
  br label %79

79:                                               ; preds = %68, %57
  br label %80

80:                                               ; preds = %79
  %81 = load i64, ptr %9, align 8, !tbaa !9
  %82 = add i64 %81, 1
  store i64 %82, ptr %9, align 8, !tbaa !9
  br label %27, !llvm.loop !12

83:                                               ; preds = %27
  call void @llvm.lifetime.end.p0(i64 1, ptr %14) #3
  call void @llvm.lifetime.end.p0(i64 8, 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_vtn(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
  call void @block_clear(ptr noundef nonnull %5, i64 noundef %2) #3
  %11 = shl i64 %2, 4
  %.not = icmp eq i64 %11, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %4
  %12 = getelementptr inbounds i8, ptr %5, i64 %2
  %13 = getelementptr inbounds i8, ptr %12, i64 -1
  %14 = shl i64 %2, 3
  br label %15

15:                                               ; preds = %.lr.ph, %30
  %.025 = phi i64 [ 0, %.lr.ph ], [ %31, %30 ]
  call void @block_out(i32 noundef 3, ptr noundef nonnull %8, ptr noundef %0, i64 noundef %.025) #3
  call void @block_out(i32 noundef 6, ptr noundef nonnull %5, ptr noundef %0, i64 noundef %2) #3
  %16 = 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
  %17 = lshr i64 %.025, 3
  %18 = sub nsw i64 0, %17
  %19 = getelementptr inbounds i8, ptr %13, i64 %18
  %20 = icmp ult i64 %.025, %14
  br i1 %20, label %21, label %26

21:                                               ; preds = %15
  %22 = load i8, ptr %19, align 1, !tbaa !5
  %23 = shl i8 %22, 1
  %24 = or i8 %22, %23
  %25 = or i8 %24, 1
  store i8 %25, ptr %19, align 1, !tbaa !5
  br label %30

26:                                               ; preds = %15
  %27 = getelementptr inbounds i8, ptr %19, i64 %2
  %28 = load i8, ptr %27, align 1, !tbaa !5
  %29 = shl i8 %28, 1
  store i8 %29, ptr %27, align 1, !tbaa !5
  br label %30

30:                                               ; preds = %21, %26
  %31 = add nuw i64 %.025, 1
  %exitcond.not = icmp eq i64 %31, %11
  br i1 %exitcond.not, label %._crit_edge, label %15, !llvm.loop !8

._crit_edge:                                      ; preds = %30, %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}
!9 = !{!"llvm.loop.mustprogress"}


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