; LLVM IR from square/subzero :: core/external-crypto/aes (aestmr)

; 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

; Function Attrs: inlinehint nounwind uwtable
declare hidden i64 @read_tsc() #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_rndfill(ptr noundef, i64 noundef) #2

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

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

; Function Attrs: nounwind uwtable
define dso_local double @d_cycles(i64 noundef %0, ptr noundef %1) #3 {
  %3 = alloca i64, align 8
  %4 = alloca ptr, align 8
  %5 = alloca [16 x i8], align 16
  %6 = alloca [16 x i8], align 16
  %7 = alloca [32 x i8], align 16
  %8 = alloca double, align 8
  %9 = alloca double, align 8
  %10 = alloca double, align 8
  %11 = alloca double, align 8
  %12 = alloca i32, align 4
  store i64 %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 16, ptr %5) #4
  call void @llvm.lifetime.start.p0(i64 16, ptr %6) #4
  call void @llvm.lifetime.start.p0(i64 32, ptr %7) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  store double -1.000000e+00, ptr %10, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  store double -1.000000e+00, ptr %11, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #4
  %13 = getelementptr inbounds [32 x i8], ptr %7, i64 0, i64 0
  call void @block_rndfill(ptr noundef %13, i64 noundef 32)
  %14 = getelementptr inbounds [16 x i8], ptr %5, i64 0, i64 0
  call void @block_rndfill(ptr noundef %14, i64 noundef 16)
  %15 = getelementptr inbounds [32 x i8], ptr %7, i64 0, i64 0
  %16 = load i64, ptr %3, align 8, !tbaa !5
  %17 = trunc i64 %16 to i32
  %18 = load ptr, ptr %4, align 8, !tbaa !9
  %19 = call i32 @aes_decrypt_key(ptr noundef %15, i32 noundef %17, ptr noundef %18)
  store double 0x41EFFFFFFFE00000, ptr %11, align 8, !tbaa !11
  store double 0x41EFFFFFFFE00000, ptr %10, align 8, !tbaa !11
  %20 = getelementptr inbounds [16 x i8], ptr %5, i64 0, i64 0
  %21 = getelementptr inbounds [16 x i8], ptr %6, i64 0, i64 0
  %22 = load ptr, ptr %4, align 8, !tbaa !9
  %23 = call i32 @aes_decrypt(ptr noundef %20, ptr noundef %21, ptr noundef %22)
  store i32 0, ptr %12, align 4, !tbaa !13
  br label %24

24:                                               ; preds = %103, %2
  %25 = load i32, ptr %12, align 4, !tbaa !13
  %26 = icmp slt i32 %25, 100
  br i1 %26, label %27, label %106

27:                                               ; preds = %24
  %28 = getelementptr inbounds [16 x i8], ptr %5, i64 0, i64 0
  call void @block_rndfill(ptr noundef %28, i64 noundef 16)
  %29 = call i64 @read_tsc()
  %30 = uitofp i64 %29 to double
  store double %30, ptr %8, align 8, !tbaa !11
  %31 = getelementptr inbounds [16 x i8], ptr %6, i64 0, i64 0
  %32 = getelementptr inbounds [16 x i8], ptr %6, i64 0, i64 0
  %33 = load ptr, ptr %4, align 8, !tbaa !9
  %34 = call i32 @aes_decrypt(ptr noundef %31, ptr noundef %32, ptr noundef %33)
  %35 = call i64 @read_tsc()
  %36 = uitofp i64 %35 to double
  %37 = load double, ptr %8, align 8, !tbaa !11
  %38 = fsub double %36, %37
  store double %38, ptr %8, align 8, !tbaa !11
  %39 = call i64 @read_tsc()
  %40 = uitofp i64 %39 to double
  store double %40, ptr %9, align 8, !tbaa !11
  %41 = getelementptr inbounds [16 x i8], ptr %6, i64 0, i64 0
  %42 = getelementptr inbounds [16 x i8], ptr %6, i64 0, i64 0
  %43 = load ptr, ptr %4, align 8, !tbaa !9
  %44 = call i32 @aes_decrypt(ptr noundef %41, ptr noundef %42, ptr noundef %43)
  %45 = getelementptr inbounds [16 x i8], ptr %6, i64 0, i64 0
  %46 = getelementptr inbounds [16 x i8], ptr %6, i64 0, i64 0
  %47 = load ptr, ptr %4, align 8, !tbaa !9
  %48 = call i32 @aes_decrypt(ptr noundef %45, ptr noundef %46, ptr noundef %47)
  %49 = getelementptr inbounds [16 x i8], ptr %6, i64 0, i64 0
  %50 = getelementptr inbounds [16 x i8], ptr %6, i64 0, i64 0
  %51 = load ptr, ptr %4, align 8, !tbaa !9
  %52 = call i32 @aes_decrypt(ptr noundef %49, ptr noundef %50, ptr noundef %51)
  %53 = getelementptr inbounds [16 x i8], ptr %6, i64 0, i64 0
  %54 = getelementptr inbounds [16 x i8], ptr %6, i64 0, i64 0
  %55 = load ptr, ptr %4, align 8, !tbaa !9
  %56 = call i32 @aes_decrypt(ptr noundef %53, ptr noundef %54, ptr noundef %55)
  %57 = getelementptr inbounds [16 x i8], ptr %6, i64 0, i64 0
  %58 = getelementptr inbounds [16 x i8], ptr %6, i64 0, i64 0
  %59 = load ptr, ptr %4, align 8, !tbaa !9
  %60 = call i32 @aes_decrypt(ptr noundef %57, ptr noundef %58, ptr noundef %59)
  %61 = getelementptr inbounds [16 x i8], ptr %6, i64 0, i64 0
  %62 = getelementptr inbounds [16 x i8], ptr %6, i64 0, i64 0
  %63 = load ptr, ptr %4, align 8, !tbaa !9
  %64 = call i32 @aes_decrypt(ptr noundef %61, ptr noundef %62, ptr noundef %63)
  %65 = getelementptr inbounds [16 x i8], ptr %6, i64 0, i64 0
  %66 = getelementptr inbounds [16 x i8], ptr %6, i64 0, i64 0
  %67 = load ptr, ptr %4, align 8, !tbaa !9
  %68 = call i32 @aes_decrypt(ptr noundef %65, ptr noundef %66, ptr noundef %67)
  %69 = getelementptr inbounds [16 x i8], ptr %6, i64 0, i64 0
  %70 = getelementptr inbounds [16 x i8], ptr %6, i64 0, i64 0
  %71 = load ptr, ptr %4, align 8, !tbaa !9
  %72 = call i32 @aes_decrypt(ptr noundef %69, ptr noundef %70, ptr noundef %71)
  %73 = getelementptr inbounds [16 x i8], ptr %6, i64 0, i64 0
  %74 = getelementptr inbounds [16 x i8], ptr %6, i64 0, i64 0
  %75 = load ptr, ptr %4, align 8, !tbaa !9
  %76 = call i32 @aes_decrypt(ptr noundef %73, ptr noundef %74, ptr noundef %75)
  %77 = call i64 @read_tsc()
  %78 = uitofp i64 %77 to double
  %79 = load double, ptr %9, align 8, !tbaa !11
  %80 = fsub double %78, %79
  store double %80, ptr %9, align 8, !tbaa !11
  %81 = load i32, ptr %12, align 4, !tbaa !13
  %82 = icmp sgt i32 %81, 10
  br i1 %82, label %83, label %102

83:                                               ; preds = %27
  %84 = load double, ptr %10, align 8, !tbaa !11
  %85 = load double, ptr %8, align 8, !tbaa !11
  %86 = fcmp olt double %84, %85
  br i1 %86, label %87, label %89

87:                                               ; preds = %83
  %88 = load double, ptr %10, align 8, !tbaa !11
  br label %91

89:                                               ; preds = %83
  %90 = load double, ptr %8, align 8, !tbaa !11
  br label %91

91:                                               ; preds = %89, %87
  %92 = phi double [ %88, %87 ], [ %90, %89 ]
  store double %92, ptr %10, align 8, !tbaa !11
  %93 = load double, ptr %11, align 8, !tbaa !11
  %94 = load double, ptr %9, align 8, !tbaa !11
  %95 = fcmp olt double %93, %94
  br i1 %95, label %96, label %98

96:                                               ; preds = %91
  %97 = load double, ptr %11, align 8, !tbaa !11
  br label %100

98:                                               ; preds = %91
  %99 = load double, ptr %9, align 8, !tbaa !11
  br label %100

100:                                              ; preds = %98, %96
  %101 = phi double [ %97, %96 ], [ %99, %98 ]
  store double %101, ptr %11, align 8, !tbaa !11
  br label %102

102:                                              ; preds = %100, %27
  br label %103

103:                                              ; preds = %102
  %104 = load i32, ptr %12, align 4, !tbaa !13
  %105 = add nsw i32 %104, 1
  store i32 %105, ptr %12, align 4, !tbaa !13
  br label %24, !llvm.loop !15

106:                                              ; preds = %24
  %107 = load double, ptr %11, align 8, !tbaa !11
  %108 = load double, ptr %10, align 8, !tbaa !11
  %109 = fsub double %107, %108
  %110 = fadd double %109, 4.000000e+00
  %111 = fdiv double %110, 8.000000e+00
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 32, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 16, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 16, ptr %5) #4
  ret double %111
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { inlinehint 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 #2 = { "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 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 #4 = { 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 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"double", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"int", !7, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"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

; Function Attrs: inlinehint nounwind uwtable
declare hidden i64 @read_tsc() 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_rndfill(ptr noundef, i64 noundef) local_unnamed_addr #2

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

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

; Function Attrs: nounwind uwtable
define dso_local double @d_cycles(i64 noundef %0, ptr noundef %1) local_unnamed_addr #3 {
  %3 = alloca [16 x i8], align 16
  %4 = alloca [16 x i8], align 16
  %5 = alloca [32 x i8], align 16
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %3) #4
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %4) #4
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %5) #4
  call void @block_rndfill(ptr noundef nonnull %5, i64 noundef 32) #4
  call void @block_rndfill(ptr noundef nonnull %3, i64 noundef 16) #4
  %6 = trunc i64 %0 to i32
  %7 = call i32 @aes_decrypt_key(ptr noundef nonnull %5, i32 noundef %6, ptr noundef %1) #4
  %8 = call i32 @aes_decrypt(ptr noundef nonnull %3, ptr noundef nonnull %4, ptr noundef %1) #4
  br label %9

9:                                                ; preds = %2, %36
  %.032 = phi i32 [ 0, %2 ], [ %38, %36 ]
  %10 = phi <2 x double> [ <double 0x41EFFFFFFFE00000, double 0x41EFFFFFFFE00000>, %2 ], [ %37, %36 ]
  call void @block_rndfill(ptr noundef nonnull %3, i64 noundef 16) #4
  %11 = call i64 @read_tsc()
  %12 = call i32 @aes_decrypt(ptr noundef nonnull %4, ptr noundef nonnull %4, ptr noundef %1) #4
  %13 = call i64 @read_tsc()
  %14 = call i64 @read_tsc()
  %15 = call i32 @aes_decrypt(ptr noundef nonnull %4, ptr noundef nonnull %4, ptr noundef %1) #4
  %16 = call i32 @aes_decrypt(ptr noundef nonnull %4, ptr noundef nonnull %4, ptr noundef %1) #4
  %17 = call i32 @aes_decrypt(ptr noundef nonnull %4, ptr noundef nonnull %4, ptr noundef %1) #4
  %18 = call i32 @aes_decrypt(ptr noundef nonnull %4, ptr noundef nonnull %4, ptr noundef %1) #4
  %19 = call i32 @aes_decrypt(ptr noundef nonnull %4, ptr noundef nonnull %4, ptr noundef %1) #4
  %20 = call i32 @aes_decrypt(ptr noundef nonnull %4, ptr noundef nonnull %4, ptr noundef %1) #4
  %21 = call i32 @aes_decrypt(ptr noundef nonnull %4, ptr noundef nonnull %4, ptr noundef %1) #4
  %22 = call i32 @aes_decrypt(ptr noundef nonnull %4, ptr noundef nonnull %4, ptr noundef %1) #4
  %23 = call i32 @aes_decrypt(ptr noundef nonnull %4, ptr noundef nonnull %4, ptr noundef %1) #4
  %24 = call i64 @read_tsc()
  %25 = icmp ugt i32 %.032, 10
  br i1 %25, label %26, label %36

26:                                               ; preds = %9
  %27 = insertelement <2 x i64> poison, i64 %13, i64 0
  %28 = insertelement <2 x i64> %27, i64 %24, i64 1
  %29 = uitofp <2 x i64> %28 to <2 x double>
  %30 = insertelement <2 x i64> poison, i64 %11, i64 0
  %31 = insertelement <2 x i64> %30, i64 %14, i64 1
  %32 = uitofp <2 x i64> %31 to <2 x double>
  %33 = fsub <2 x double> %29, %32
  %34 = fcmp olt <2 x double> %10, %33
  %35 = select <2 x i1> %34, <2 x double> %10, <2 x double> %33
  br label %36

36:                                               ; preds = %9, %26
  %37 = phi <2 x double> [ %35, %26 ], [ %10, %9 ]
  %38 = add nuw nsw i32 %.032, 1
  %exitcond.not = icmp eq i32 %38, 100
  br i1 %exitcond.not, label %39, label %9, !llvm.loop !5

39:                                               ; preds = %36
  %shift = shufflevector <2 x double> %37, <2 x double> poison, <2 x i32> <i32 1, i32 poison>
  %40 = fsub <2 x double> %shift, %37
  %41 = extractelement <2 x double> %40, i64 0
  %42 = fadd double %41, 4.000000e+00
  %43 = fmul double %42, 1.250000e-01
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %5) #4
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %4) #4
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %3) #4
  ret double %43
}

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { inlinehint 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 #2 = { "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 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 #4 = { 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"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LoopRotatePass,LoopUnrollPass,SLPVectorizerPass,SROAPass,SimplifyCFGPass,VectorCombinePass