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

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

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

24:                                               ; preds = %80, %4
  %25 = load i64, ptr %9, align 8, !tbaa !9
  %26 = icmp ult i64 %25, 400
  br i1 %26, label %27, label %83

27:                                               ; preds = %24
  %28 = load ptr, ptr %5, align 8, !tbaa !5
  %29 = load i64, ptr %9, align 8, !tbaa !9
  call void @block_out(i32 noundef 3, ptr noundef %14, ptr noundef %28, i64 noundef %29)
  %30 = getelementptr inbounds [32 x i8], ptr %13, i64 0, i64 0
  %31 = load ptr, ptr %5, align 8, !tbaa !5
  %32 = load i64, ptr %8, align 8, !tbaa !9
  call void @block_out(i32 noundef 5, ptr noundef %30, ptr noundef %31, i64 noundef %32)
  %33 = getelementptr inbounds [32 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 7, ptr noundef %33, ptr noundef %34, i64 noundef %35)
  %36 = getelementptr inbounds [32 x i8], ptr %13, 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_decrypt_key(ptr noundef %36, i32 noundef %38, ptr noundef %39)
  store i64 0, ptr %10, align 8, !tbaa !9
  br label %41

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

44:                                               ; preds = %41
  %45 = getelementptr inbounds [64 x i8], ptr %12, i64 0, i64 0
  %46 = load i64, ptr %7, align 8, !tbaa !9
  %47 = getelementptr inbounds i8, ptr %45, i64 %46
  %48 = getelementptr inbounds [64 x i8], ptr %12, i64 0, i64 0
  %49 = load ptr, ptr %6, align 8, !tbaa !5
  %50 = call i32 @aes_decrypt(ptr noundef %47, ptr noundef %48, ptr noundef %49)
  %51 = getelementptr inbounds [64 x i8], ptr %12, i64 0, i64 0
  %52 = getelementptr inbounds [64 x i8], ptr %12, i64 0, i64 0
  %53 = load i64, ptr %7, align 8, !tbaa !9
  %54 = getelementptr inbounds i8, ptr %52, i64 %53
  %55 = load ptr, ptr %6, align 8, !tbaa !5
  %56 = call i32 @aes_decrypt(ptr noundef %51, ptr noundef %54, ptr noundef %55)
  br label %57

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

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

80:                                               ; preds = %60
  %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 %24, !llvm.loop !13

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

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

declare i32 @aes_decrypt(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 = 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_copy(ptr noundef, ptr noundef, i64 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 @ecb_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 %5, i64 noundef %2) #3
  call void @block_clear(ptr noundef nonnull %7, i64 noundef %3) #3
  %9 = getelementptr inbounds i8, ptr %6, i64 %2
  call void @block_copy(ptr noundef nonnull %9, ptr noundef nonnull %5, i64 noundef %2) #3
  %10 = trunc i64 %3 to i32
  %11 = shl i64 %2, 1
  %12 = getelementptr inbounds i8, ptr %6, i64 %11
  %13 = sub i64 0, %3
  %14 = getelementptr inbounds i8, ptr %12, i64 %13
  br label %15

15:                                               ; preds = %4, %21
  %.02729 = phi i64 [ 0, %4 ], [ %22, %21 ]
  call void @block_out(i32 noundef 3, ptr noundef nonnull %8, ptr noundef %0, i64 noundef %.02729) #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 7, ptr noundef nonnull %5, ptr noundef %0, i64 noundef %2) #3
  %16 = call i32 @aes_decrypt_key(ptr noundef nonnull %7, i32 noundef %10, ptr noundef %1) #3
  br label %17

17:                                               ; preds = %15, %17
  %.028 = phi i64 [ 0, %15 ], [ %20, %17 ]
  %18 = call i32 @aes_decrypt(ptr noundef nonnull %9, ptr noundef nonnull %6, ptr noundef %1) #3
  %19 = call i32 @aes_decrypt(ptr noundef nonnull %6, ptr noundef nonnull %9, ptr noundef %1) #3
  %20 = add nuw nsw i64 %.028, 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_xor(ptr noundef nonnull %7, ptr noundef nonnull %14, i64 noundef %3) #3
  call void @block_out(i32 noundef 6, ptr noundef nonnull %9, ptr noundef %0, i64 noundef %2) #3
  call void @block_copy(ptr noundef nonnull %5, ptr noundef nonnull %9, i64 noundef %2) #3
  %22 = add nuw nsw i64 %.02729, 1
  %exitcond30.not = icmp eq i64 %22, 400
  br i1 %exitcond30.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
}

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

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