; 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 void @block_xor(ptr noundef, ptr noundef, i64 noundef) #1

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

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

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

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

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

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

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

64:                                               ; preds = %45
  %65 = load i64, ptr %10, align 8, !tbaa !9
  %66 = add i64 %65, 1
  store i64 %66, ptr %10, align 8, !tbaa !9
  br label %42, !llvm.loop !11

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

82:                                               ; preds = %67
  %83 = load i64, ptr %9, align 8, !tbaa !9
  %84 = add i64 %83, 1
  store i64 %84, ptr %9, align 8, !tbaa !9
  br label %20, !llvm.loop !13

85:                                               ; preds = %20
  call void @llvm.lifetime.end.p0(i64 1, ptr %14) #3
  call void @llvm.lifetime.end.p0(i64 32, ptr %13) #3
  call void @llvm.lifetime.end.p0(i64 64, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 32, 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 void @block_xor(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #1

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

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

; Function Attrs: nounwind uwtable
define dso_local void @cbc_md(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 [64 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 64, 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
  %9 = shl i64 %2, 1
  call void @block_clear(ptr noundef nonnull %6, i64 noundef %9) #3
  %10 = getelementptr inbounds i8, ptr %6, i64 %2
  %11 = trunc i64 %3 to i32
  %12 = getelementptr inbounds i8, ptr %6, i64 %9
  %13 = sub i64 0, %3
  %14 = getelementptr inbounds i8, ptr %12, i64 %13
  br label %15

15:                                               ; preds = %4, %21
  %.02830 = phi i64 [ 0, %4 ], [ %22, %21 ]
  call void @block_out(i32 noundef 3, ptr noundef nonnull %8, ptr noundef %0, i64 noundef %.02830) #3
  call void @block_out(i32 noundef 5, ptr noundef nonnull %7, ptr noundef %0, i64 noundef %3) #3
  call void @block_out(i32 noundef 4, ptr noundef nonnull %6, ptr noundef %0, i64 noundef %2) #3
  call void @block_out(i32 noundef 7, ptr noundef nonnull %10, ptr noundef %0, i64 noundef %2) #3
  %16 = call i32 @aes_decrypt_key(ptr noundef nonnull %7, i32 noundef %11, ptr noundef %1) #3
  br label %17

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

21:                                               ; preds = %17
  call void @block_out(i32 noundef 6, ptr noundef nonnull %10, ptr noundef %0, i64 noundef %2) #3
  call void @block_xor(ptr noundef nonnull %7, ptr noundef nonnull %14, i64 noundef %3) #3
  %22 = add nuw nsw i64 %.02830, 1
  %exitcond31.not = icmp eq i64 %22, 400
  br i1 %exitcond31.not, label %23, label %15, !llvm.loop !7

23:                                               ; preds = %21
  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 64, 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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}
!7 = distinct !{!7, !6}


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