; 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

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

; Function Attrs: nounwind uwtable
define dso_local void @cbc_me(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 i64, align 8
  %11 = alloca [64 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 8, ptr %10) #3
  call void @llvm.lifetime.start.p0(i64 64, 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 [64 x i8], ptr %11, i64 0, i64 0
  %17 = load i64, ptr %7, align 8, !tbaa !9
  %18 = mul i64 2, %17
  call void @block_clear(ptr noundef %16, i64 noundef %18)
  store i64 0, ptr %9, align 8, !tbaa !9
  br label %19

19:                                               ; preds = %85, %4
  %20 = load i64, ptr %9, align 8, !tbaa !9
  %21 = icmp ult i64 %20, 400
  br i1 %21, label %22, label %88

22:                                               ; preds = %19
  %23 = load ptr, ptr %5, align 8, !tbaa !5
  %24 = load i64, ptr %9, align 8, !tbaa !9
  call void @block_out(i32 noundef 3, ptr noundef %13, ptr noundef %23, i64 noundef %24)
  %25 = getelementptr inbounds [32 x i8], ptr %12, i64 0, i64 0
  %26 = load ptr, ptr %5, align 8, !tbaa !5
  %27 = load i64, ptr %8, align 8, !tbaa !9
  call void @block_out(i32 noundef 5, ptr noundef %25, ptr noundef %26, i64 noundef %27)
  %28 = getelementptr inbounds [64 x i8], ptr %11, i64 0, i64 0
  %29 = load i64, ptr %7, align 8, !tbaa !9
  %30 = getelementptr inbounds i8, ptr %28, i64 %29
  %31 = load ptr, ptr %5, align 8, !tbaa !5
  %32 = load i64, ptr %7, align 8, !tbaa !9
  call void @block_out(i32 noundef 4, ptr noundef %30, ptr noundef %31, i64 noundef %32)
  %33 = getelementptr inbounds [64 x i8], ptr %11, i64 0, i64 0
  %34 = load ptr, ptr %5, align 8, !tbaa !5
  %35 = load i64, ptr %7, align 8, !tbaa !9
  call void @block_out(i32 noundef 6, ptr noundef %33, ptr noundef %34, i64 noundef %35)
  %36 = getelementptr inbounds [32 x i8], ptr %12, i64 0, i64 0
  %37 = load i64, ptr %8, align 8, !tbaa !9
  %38 = trunc i64 %37 to i32
  %39 = load ptr, ptr %6, align 8, !tbaa !5
  %40 = call i32 @aes_encrypt_key(ptr noundef %36, i32 noundef %38, ptr noundef %39)
  store i64 0, ptr %10, align 8, !tbaa !9
  br label %41

41:                                               ; preds = %67, %22
  %42 = load i64, ptr %10, align 8, !tbaa !9
  %43 = icmp ult i64 %42, 5000
  br i1 %43, label %44, label %70

44:                                               ; preds = %41
  %45 = getelementptr inbounds [64 x i8], ptr %11, i64 0, i64 0
  %46 = getelementptr inbounds [64 x i8], ptr %11, i64 0, i64 0
  %47 = load i64, ptr %7, align 8, !tbaa !9
  %48 = getelementptr inbounds i8, ptr %46, i64 %47
  %49 = load i64, ptr %7, align 8, !tbaa !9
  call void @block_xor(ptr noundef %45, ptr noundef %48, i64 noundef %49)
  %50 = getelementptr inbounds [64 x i8], ptr %11, i64 0, i64 0
  %51 = getelementptr inbounds [64 x i8], ptr %11, i64 0, i64 0
  %52 = load ptr, ptr %6, align 8, !tbaa !5
  %53 = call i32 @aes_encrypt(ptr noundef %50, ptr noundef %51, ptr noundef %52)
  %54 = getelementptr inbounds [64 x i8], ptr %11, i64 0, i64 0
  %55 = load i64, ptr %7, align 8, !tbaa !9
  %56 = getelementptr inbounds i8, ptr %54, i64 %55
  %57 = getelementptr inbounds [64 x i8], ptr %11, i64 0, i64 0
  %58 = load i64, ptr %7, align 8, !tbaa !9
  call void @block_xor(ptr noundef %56, ptr noundef %57, i64 noundef %58)
  %59 = getelementptr inbounds [64 x i8], ptr %11, i64 0, i64 0
  %60 = load i64, ptr %7, align 8, !tbaa !9
  %61 = getelementptr inbounds i8, ptr %59, i64 %60
  %62 = getelementptr inbounds [64 x i8], ptr %11, i64 0, i64 0
  %63 = load i64, ptr %7, align 8, !tbaa !9
  %64 = getelementptr inbounds i8, ptr %62, i64 %63
  %65 = load ptr, ptr %6, align 8, !tbaa !5
  %66 = call i32 @aes_encrypt(ptr noundef %61, ptr noundef %64, ptr noundef %65)
  br label %67

67:                                               ; preds = %44
  %68 = load i64, ptr %10, align 8, !tbaa !9
  %69 = add i64 %68, 1
  store i64 %69, ptr %10, align 8, !tbaa !9
  br label %41, !llvm.loop !11

70:                                               ; preds = %41
  %71 = getelementptr inbounds [64 x i8], ptr %11, i64 0, i64 0
  %72 = load i64, ptr %7, align 8, !tbaa !9
  %73 = getelementptr inbounds i8, ptr %71, i64 %72
  %74 = load ptr, ptr %5, align 8, !tbaa !5
  %75 = load i64, ptr %7, align 8, !tbaa !9
  call void @block_out(i32 noundef 7, ptr noundef %73, ptr noundef %74, i64 noundef %75)
  %76 = getelementptr inbounds [32 x i8], ptr %12, i64 0, i64 0
  %77 = getelementptr inbounds [64 x i8], ptr %11, i64 0, i64 0
  %78 = load i64, ptr %7, align 8, !tbaa !9
  %79 = mul i64 2, %78
  %80 = getelementptr inbounds i8, ptr %77, i64 %79
  %81 = load i64, ptr %8, align 8, !tbaa !9
  %82 = sub i64 0, %81
  %83 = getelementptr inbounds i8, ptr %80, i64 %82
  %84 = load i64, ptr %8, align 8, !tbaa !9
  call void @block_xor(ptr noundef %76, ptr noundef %83, i64 noundef %84)
  br label %85

85:                                               ; preds = %70
  %86 = load i64, ptr %9, align 8, !tbaa !9
  %87 = add i64 %86, 1
  store i64 %87, ptr %9, align 8, !tbaa !9
  br label %19, !llvm.loop !13

88:                                               ; 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 64, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 8, 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 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}


; 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

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

; Function Attrs: nounwind uwtable
define dso_local void @cbc_me(ptr noundef %0, ptr noundef %1, i64 noundef %2, i64 noundef %3) local_unnamed_addr #2 {
  %5 = alloca [64 x i8], align 16
  %6 = alloca [32 x i8], align 16
  %7 = alloca i8, align 1
  call void @llvm.lifetime.start.p0(i64 64, ptr nonnull %5) #3
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %6) #3
  call void @llvm.lifetime.start.p0(i64 1, ptr nonnull %7) #3
  call void @block_clear(ptr noundef nonnull %6, i64 noundef %3) #3
  %8 = shl i64 %2, 1
  call void @block_clear(ptr noundef nonnull %5, i64 noundef %8) #3
  %9 = getelementptr inbounds i8, ptr %5, i64 %2
  %10 = trunc i64 %3 to i32
  %11 = getelementptr inbounds i8, ptr %5, i64 %8
  %12 = sub i64 0, %3
  %13 = getelementptr inbounds i8, ptr %11, i64 %12
  br label %14

14:                                               ; preds = %4, %20
  %.03032 = phi i64 [ 0, %4 ], [ %21, %20 ]
  call void @block_out(i32 noundef 3, ptr noundef nonnull %7, ptr noundef %0, i64 noundef %.03032) #3
  call void @block_out(i32 noundef 5, ptr noundef nonnull %6, ptr noundef %0, i64 noundef %3) #3
  call void @block_out(i32 noundef 4, ptr noundef nonnull %9, ptr noundef %0, i64 noundef %2) #3
  call void @block_out(i32 noundef 6, ptr noundef nonnull %5, ptr noundef %0, i64 noundef %2) #3
  %15 = call i32 @aes_encrypt_key(ptr noundef nonnull %6, i32 noundef %10, ptr noundef %1) #3
  br label %16

16:                                               ; preds = %14, %16
  %.031 = phi i64 [ 0, %14 ], [ %19, %16 ]
  call void @block_xor(ptr noundef nonnull %5, ptr noundef nonnull %9, i64 noundef %2) #3
  %17 = call i32 @aes_encrypt(ptr noundef nonnull %5, ptr noundef nonnull %5, ptr noundef %1) #3
  call void @block_xor(ptr noundef nonnull %9, ptr noundef nonnull %5, i64 noundef %2) #3
  %18 = call i32 @aes_encrypt(ptr noundef nonnull %9, ptr noundef nonnull %9, ptr noundef %1) #3
  %19 = add nuw nsw i64 %.031, 1
  %exitcond.not = icmp eq i64 %19, 5000
  br i1 %exitcond.not, label %20, label %16, !llvm.loop !5

20:                                               ; preds = %16
  call void @block_out(i32 noundef 7, ptr noundef nonnull %9, ptr noundef %0, i64 noundef %2) #3
  call void @block_xor(ptr noundef nonnull %6, ptr noundef nonnull %13, i64 noundef %3) #3
  %21 = add nuw nsw i64 %.03032, 1
  %exitcond33.not = icmp eq i64 %21, 400
  br i1 %exitcond33.not, label %22, label %14, !llvm.loop !7

22:                                               ; preds = %20
  call void @llvm.lifetime.end.p0(i64 1, ptr nonnull %7) #3
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %6) #3
  call void @llvm.lifetime.end.p0(i64 64, 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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}
!7 = distinct !{!7, !6}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LICMPass,LoopRotatePass,SROAPass,SimplifyCFGPass