; LLVM IR from square/subzero :: core/external-crypto/modes (cmac)

; 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"

%struct.cmac_ctx = type { [2 x i64], [1 x %struct.aes_crypt_ctx], i32, [12 x i8] }
%struct.aes_crypt_ctx = type { [60 x i32], %union.aes_inf, [12 x i8] }
%union.aes_inf = type { i32 }

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #0

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @xor_block_aligned(ptr noundef, ptr noundef, ptr noundef) #3

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: nounwind uwtable
declare dso_local void @gf_mulx2(ptr noundef) #4

; Function Attrs: nounwind uwtable
define dso_local void @cmac_end(ptr noundef %0, ptr noundef %1) #4 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca [2 x i64], align 16
  %6 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 16, ptr %5) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #5
  %7 = getelementptr inbounds [2 x i64], ptr %5, i64 0, i64 0
  call void @llvm.memset.p0.i64(ptr align 16 %7, i8 0, i64 16, i1 false)
  %8 = getelementptr inbounds [2 x i64], ptr %5, i64 0, i64 0
  %9 = getelementptr inbounds [2 x i64], ptr %5, i64 0, i64 0
  %10 = load ptr, ptr %4, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.cmac_ctx, ptr %10, i32 0, i32 1
  %12 = getelementptr inbounds [1 x %struct.aes_crypt_ctx], ptr %11, i64 0, i64 0
  %13 = call i32 @aes_encrypt(ptr noundef %8, ptr noundef %9, ptr noundef %12)
  %14 = load ptr, ptr %4, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.cmac_ctx, ptr %14, i32 0, i32 2
  %16 = load i32, ptr %15, align 16, !tbaa !9
  %17 = and i32 %16, 15
  store i32 %17, ptr %6, align 4, !tbaa !12
  %18 = load ptr, ptr %4, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.cmac_ctx, ptr %18, i32 0, i32 2
  %20 = load i32, ptr %19, align 16, !tbaa !9
  %21 = icmp eq i32 %20, 0
  br i1 %21, label %25, label %22

22:                                               ; preds = %2
  %23 = load i32, ptr %6, align 4, !tbaa !12
  %24 = icmp ne i32 %23, 0
  br i1 %24, label %25, label %37

25:                                               ; preds = %22, %2
  %26 = load ptr, ptr %4, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.cmac_ctx, ptr %26, i32 0, i32 0
  %28 = getelementptr inbounds [2 x i64], ptr %27, i64 0, i64 0
  %29 = load i32, ptr %6, align 4, !tbaa !12
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds i8, ptr %28, i64 %30
  %32 = load i8, ptr %31, align 1, !tbaa !13
  %33 = zext i8 %32 to i32
  %34 = xor i32 %33, 128
  %35 = trunc i32 %34 to i8
  store i8 %35, ptr %31, align 1, !tbaa !13
  %36 = getelementptr inbounds [2 x i64], ptr %5, i64 0, i64 0
  call void @gf_mulx2(ptr noundef %36)
  br label %39

37:                                               ; preds = %22
  %38 = getelementptr inbounds [2 x i64], ptr %5, i64 0, i64 0
  call void @gf_mulx(ptr noundef %38)
  br label %39

39:                                               ; preds = %37, %25
  %40 = getelementptr inbounds [2 x i64], ptr %5, i64 0, i64 0
  %41 = getelementptr inbounds [2 x i64], ptr %5, i64 0, i64 0
  %42 = load ptr, ptr %4, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.cmac_ctx, ptr %42, i32 0, i32 0
  %44 = getelementptr inbounds [2 x i64], ptr %43, i64 0, i64 0
  call void @xor_block_aligned(ptr noundef %40, ptr noundef %41, ptr noundef %44)
  %45 = getelementptr inbounds [2 x i64], ptr %5, i64 0, i64 0
  %46 = getelementptr inbounds [2 x i64], ptr %5, i64 0, i64 0
  %47 = load ptr, ptr %4, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.cmac_ctx, ptr %47, i32 0, i32 1
  %49 = getelementptr inbounds [1 x %struct.aes_crypt_ctx], ptr %48, i64 0, i64 0
  %50 = call i32 @aes_encrypt(ptr noundef %45, ptr noundef %46, ptr noundef %49)
  store i32 0, ptr %6, align 4, !tbaa !12
  br label %51

51:                                               ; preds = %64, %39
  %52 = load i32, ptr %6, align 4, !tbaa !12
  %53 = icmp slt i32 %52, 16
  br i1 %53, label %54, label %67

54:                                               ; preds = %51
  %55 = getelementptr inbounds [2 x i64], ptr %5, i64 0, i64 0
  %56 = load i32, ptr %6, align 4, !tbaa !12
  %57 = sext i32 %56 to i64
  %58 = getelementptr inbounds i8, ptr %55, i64 %57
  %59 = load i8, ptr %58, align 1, !tbaa !13
  %60 = load ptr, ptr %3, align 8, !tbaa !5
  %61 = load i32, ptr %6, align 4, !tbaa !12
  %62 = sext i32 %61 to i64
  %63 = getelementptr inbounds i8, ptr %60, i64 %62
  store i8 %59, ptr %63, align 1, !tbaa !13
  br label %64

64:                                               ; preds = %54
  %65 = load i32, ptr %6, align 4, !tbaa !12
  %66 = add nsw i32 %65, 1
  store i32 %66, ptr %6, align 4, !tbaa !12
  br label %51, !llvm.loop !14

67:                                               ; preds = %51
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #5
  call void @llvm.lifetime.end.p0(i64 16, ptr %5) #5
  ret void
}

; Function Attrs: nounwind uwtable
declare hidden void @gf_mulx(ptr noundef) #4

attributes #0 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 #4 = { 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 #5 = { 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, !11, i64 272}
!10 = !{!"", !7, i64 0, !7, i64 16, !11, i64 272}
!11 = !{!"int", !7, i64 0}
!12 = !{!11, !11, i64 0}
!13 = !{!7, !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"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 nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #0

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @xor_block_aligned(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #3

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: nounwind uwtable
declare dso_local void @gf_mulx2(ptr noundef) local_unnamed_addr #4

; Function Attrs: nounwind uwtable
define dso_local void @cmac_end(ptr nocapture noundef writeonly %0, ptr noundef %1) local_unnamed_addr #4 {
  %3 = alloca [2 x i64], align 16
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %3) #6
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(16) %3, i8 0, i64 16, i1 false)
  %4 = getelementptr inbounds i8, ptr %1, i64 16
  %5 = call i32 @aes_encrypt(ptr noundef nonnull %3, ptr noundef nonnull %3, ptr noundef nonnull %4) #6
  %6 = getelementptr inbounds i8, ptr %1, i64 272
  %7 = load i32, ptr %6, align 16, !tbaa !5
  %8 = and i32 %7, 15
  %9 = icmp eq i32 %7, 0
  %10 = icmp ne i32 %8, 0
  %or.cond = or i1 %9, %10
  br i1 %or.cond, label %11, label %16

11:                                               ; preds = %2
  %12 = zext nneg i32 %8 to i64
  %13 = getelementptr inbounds i8, ptr %1, i64 %12
  %14 = load i8, ptr %13, align 1, !tbaa !10
  %15 = xor i8 %14, -128
  store i8 %15, ptr %13, align 1, !tbaa !10
  call void @gf_mulx2(ptr noundef nonnull %3)
  br label %17

16:                                               ; preds = %2
  call void @gf_mulx(ptr noundef nonnull %3)
  br label %17

17:                                               ; preds = %16, %11
  call void @xor_block_aligned(ptr noundef nonnull %3, ptr noundef nonnull %3, ptr noundef nonnull %1)
  %18 = call i32 @aes_encrypt(ptr noundef nonnull %3, ptr noundef nonnull %3, ptr noundef nonnull %4) #6
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 1 dereferenceable(16) %0, ptr noundef nonnull align 16 dereferenceable(16) %3, i64 16, i1 false), !tbaa !10
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %3) #6
  ret void
}

; Function Attrs: nounwind uwtable
declare hidden void @gf_mulx(ptr noundef) local_unnamed_addr #4

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #5

attributes #0 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #1 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 #4 = { 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 #5 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #6 = { 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, !9, i64 272}
!6 = !{!"", !7, i64 0, !7, i64 16, !9, i64 272}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!"int", !7, i64 0}
!10 = !{!7, !7, i64 0}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LoopIdiomRecognizePass,LoopRotatePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass