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

; 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.eax_ctx = type { [2 x i64], [2 x i64], [2 x i64], [2 x i64], [2 x i64], [4 x i64], [1 x %struct.aes_crypt_ctx], i32, i32, i32 }
%struct.aes_crypt_ctx = type { [60 x i32], %union.aes_inf, [12 x i8] }
%union.aes_inf = type { i32 }

@eax_init_and_key.x_t = external hidden global [4 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i32 @eax_init_and_key(ptr noundef %0, i64 noundef %1, ptr noundef %2) #0 {
  %4 = alloca ptr, align 8
  %5 = alloca i64, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i8, align 1
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i64 %1, ptr %5, align 8, !tbaa !9
  store ptr %2, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 1, ptr %7) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  %10 = load ptr, ptr %6, align 8, !tbaa !5
  call void @llvm.memset.p0.i64(ptr align 16 %10, i8 0, i64 384, i1 false)
  %11 = load ptr, ptr %4, align 8, !tbaa !5
  %12 = load i64, ptr %5, align 8, !tbaa !9
  %13 = trunc i64 %12 to i32
  %14 = load ptr, ptr %6, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.eax_ctx, ptr %14, i32 0, i32 6
  %16 = getelementptr inbounds [1 x %struct.aes_crypt_ctx], ptr %15, i64 0, i64 0
  %17 = call i32 @aes_encrypt_key(ptr noundef %11, i32 noundef %13, ptr noundef %16)
  %18 = load ptr, ptr %6, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.eax_ctx, ptr %18, i32 0, i32 5
  %20 = getelementptr inbounds [4 x i64], ptr %19, i64 0, i64 0
  %21 = load ptr, ptr %6, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.eax_ctx, ptr %21, i32 0, i32 5
  %23 = getelementptr inbounds [4 x i64], ptr %22, i64 0, i64 0
  %24 = load ptr, ptr %6, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.eax_ctx, ptr %24, i32 0, i32 6
  %26 = getelementptr inbounds [1 x %struct.aes_crypt_ctx], ptr %25, i64 0, i64 0
  %27 = call i32 @aes_encrypt(ptr noundef %20, ptr noundef %23, ptr noundef %26)
  store i32 0, ptr %9, align 4, !tbaa !11
  %28 = load ptr, ptr %6, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.eax_ctx, ptr %28, i32 0, i32 5
  %30 = getelementptr inbounds [4 x i64], ptr %29, i64 0, i64 0
  store ptr %30, ptr %8, align 8, !tbaa !5
  %31 = load ptr, ptr %8, align 8, !tbaa !5
  %32 = load i8, ptr %31, align 1, !tbaa !13
  %33 = zext i8 %32 to i32
  %34 = ashr i32 %33, 6
  %35 = trunc i32 %34 to i8
  store i8 %35, ptr %7, align 1, !tbaa !13
  br label %36

36:                                               ; preds = %65, %3
  %37 = load i32, ptr %9, align 4, !tbaa !11
  %38 = icmp ult i32 %37, 15
  br i1 %38, label %39, label %70

39:                                               ; preds = %36
  %40 = load ptr, ptr %8, align 8, !tbaa !5
  %41 = load i8, ptr %40, align 1, !tbaa !13
  %42 = zext i8 %41 to i32
  %43 = shl i32 %42, 2
  %44 = load ptr, ptr %8, align 8, !tbaa !5
  %45 = getelementptr inbounds i8, ptr %44, i64 1
  %46 = load i8, ptr %45, align 1, !tbaa !13
  %47 = zext i8 %46 to i32
  %48 = ashr i32 %47, 6
  %49 = or i32 %43, %48
  %50 = trunc i32 %49 to i8
  %51 = load ptr, ptr %8, align 8, !tbaa !5
  %52 = getelementptr inbounds i8, ptr %51, i64 16
  store i8 %50, ptr %52, align 1, !tbaa !13
  %53 = load ptr, ptr %8, align 8, !tbaa !5
  %54 = load i8, ptr %53, align 1, !tbaa !13
  %55 = zext i8 %54 to i32
  %56 = shl i32 %55, 1
  %57 = load ptr, ptr %8, align 8, !tbaa !5
  %58 = getelementptr inbounds i8, ptr %57, i64 1
  %59 = load i8, ptr %58, align 1, !tbaa !13
  %60 = zext i8 %59 to i32
  %61 = ashr i32 %60, 7
  %62 = or i32 %56, %61
  %63 = trunc i32 %62 to i8
  %64 = load ptr, ptr %8, align 8, !tbaa !5
  store i8 %63, ptr %64, align 1, !tbaa !13
  br label %65

65:                                               ; preds = %39
  %66 = load i32, ptr %9, align 4, !tbaa !11
  %67 = add i32 %66, 1
  store i32 %67, ptr %9, align 4, !tbaa !11
  %68 = load ptr, ptr %8, align 8, !tbaa !5
  %69 = getelementptr inbounds i8, ptr %68, i32 1
  store ptr %69, ptr %8, align 8, !tbaa !5
  br label %36, !llvm.loop !14

70:                                               ; preds = %36
  %71 = load ptr, ptr %8, align 8, !tbaa !5
  %72 = load i8, ptr %71, align 1, !tbaa !13
  %73 = zext i8 %72 to i32
  %74 = shl i32 %73, 2
  %75 = load i8, ptr %7, align 1, !tbaa !13
  %76 = zext i8 %75 to i64
  %77 = getelementptr inbounds [4 x i8], ptr @eax_init_and_key.x_t, i64 0, i64 %76
  %78 = load i8, ptr %77, align 1, !tbaa !13
  %79 = zext i8 %78 to i32
  %80 = xor i32 %74, %79
  %81 = trunc i32 %80 to i8
  %82 = load ptr, ptr %8, align 8, !tbaa !5
  %83 = getelementptr inbounds i8, ptr %82, i64 16
  store i8 %81, ptr %83, align 1, !tbaa !13
  %84 = load i8, ptr %7, align 1, !tbaa !13
  %85 = zext i8 %84 to i32
  %86 = ashr i32 %85, 1
  %87 = trunc i32 %86 to i8
  store i8 %87, ptr %7, align 1, !tbaa !13
  %88 = zext i8 %87 to i32
  %89 = load ptr, ptr %8, align 8, !tbaa !5
  %90 = getelementptr inbounds i8, ptr %89, i64 15
  %91 = load i8, ptr %90, align 1, !tbaa !13
  %92 = zext i8 %91 to i32
  %93 = xor i32 %92, %88
  %94 = trunc i32 %93 to i8
  store i8 %94, ptr %90, align 1, !tbaa !13
  %95 = load ptr, ptr %8, align 8, !tbaa !5
  %96 = load i8, ptr %95, align 1, !tbaa !13
  %97 = zext i8 %96 to i32
  %98 = shl i32 %97, 1
  %99 = load i8, ptr %7, align 1, !tbaa !13
  %100 = zext i8 %99 to i64
  %101 = getelementptr inbounds [4 x i8], ptr @eax_init_and_key.x_t, i64 0, i64 %100
  %102 = load i8, ptr %101, align 1, !tbaa !13
  %103 = zext i8 %102 to i32
  %104 = xor i32 %98, %103
  %105 = trunc i32 %104 to i8
  %106 = load ptr, ptr %8, align 8, !tbaa !5
  store i8 %105, ptr %106, align 1, !tbaa !13
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 1, ptr %7) #4
  ret i32 0
}

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

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

declare i32 @aes_encrypt_key(ptr noundef, i32 noundef, ptr noundef) #3

declare i32 @aes_encrypt(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

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #3 = { "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 = !{!"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 = !{!12, !12, i64 0}
!12 = !{!"int", !7, 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"

@eax_init_and_key.x_t = external hidden local_unnamed_addr global [4 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @eax_init_and_key(ptr noundef %0, i64 noundef %1, ptr noundef %2) local_unnamed_addr #0 {
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(384) %2, i8 0, i64 384, i1 false)
  %4 = trunc i64 %1 to i32
  %5 = getelementptr inbounds i8, ptr %2, i64 112
  %6 = tail call i32 @aes_encrypt_key(ptr noundef %0, i32 noundef %4, ptr noundef nonnull %5) #4
  %7 = getelementptr inbounds i8, ptr %2, i64 80
  %8 = tail call i32 @aes_encrypt(ptr noundef nonnull %7, ptr noundef nonnull %7, ptr noundef nonnull %5) #4
  %9 = getelementptr inbounds i8, ptr %2, i64 96
  %10 = getelementptr inbounds i8, ptr %2, i64 88
  %11 = load <8 x i8>, ptr %7, align 1, !tbaa !5
  %12 = shufflevector <8 x i8> %11, <8 x i8> poison, <8 x i32> <i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 poison>
  %13 = getelementptr inbounds i8, ptr %2, i64 104
  %14 = getelementptr inbounds i8, ptr %2, i64 92
  %15 = load i8, ptr %14, align 1, !tbaa !5
  %16 = load <4 x i8>, ptr %10, align 1, !tbaa !5
  %17 = shufflevector <4 x i8> %16, <4 x i8> poison, <8 x i32> <i32 0, i32 1, i32 2, i32 3, i32 poison, i32 poison, i32 poison, i32 poison>
  %18 = shufflevector <8 x i8> %11, <8 x i8> %17, <8 x i32> <i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8>
  %19 = tail call <8 x i8> @llvm.fshl.v8i8(<8 x i8> %11, <8 x i8> %18, <8 x i8> <i8 2, i8 2, i8 2, i8 2, i8 2, i8 2, i8 2, i8 2>)
  store <8 x i8> %19, ptr %9, align 1, !tbaa !5
  %20 = shufflevector <8 x i8> %12, <8 x i8> %17, <8 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 8>
  %21 = tail call <8 x i8> @llvm.fshl.v8i8(<8 x i8> %11, <8 x i8> %20, <8 x i8> <i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1>)
  store <8 x i8> %21, ptr %7, align 1, !tbaa !5
  %22 = shufflevector <4 x i8> %16, <4 x i8> poison, <4 x i32> <i32 1, i32 2, i32 3, i32 poison>
  %23 = insertelement <4 x i8> %22, i8 %15, i64 3
  %24 = tail call <4 x i8> @llvm.fshl.v4i8(<4 x i8> %16, <4 x i8> %23, <4 x i8> <i8 2, i8 2, i8 2, i8 2>)
  store <4 x i8> %24, ptr %13, align 1, !tbaa !5
  %25 = tail call <4 x i8> @llvm.fshl.v4i8(<4 x i8> %16, <4 x i8> %23, <4 x i8> <i8 1, i8 1, i8 1, i8 1>)
  store <4 x i8> %25, ptr %10, align 1, !tbaa !5
  %26 = getelementptr inbounds i8, ptr %2, i64 93
  %27 = load i8, ptr %26, align 1, !tbaa !5
  %28 = tail call i8 @llvm.fshl.i8(i8 %15, i8 %27, i8 2)
  %29 = getelementptr inbounds i8, ptr %2, i64 108
  store i8 %28, ptr %29, align 1, !tbaa !5
  %30 = tail call i8 @llvm.fshl.i8(i8 %15, i8 %27, i8 1)
  store i8 %30, ptr %14, align 1, !tbaa !5
  %31 = getelementptr inbounds i8, ptr %2, i64 94
  %32 = load i8, ptr %31, align 1, !tbaa !5
  %33 = tail call i8 @llvm.fshl.i8(i8 %27, i8 %32, i8 2)
  %34 = getelementptr inbounds i8, ptr %2, i64 109
  store i8 %33, ptr %34, align 1, !tbaa !5
  %35 = tail call i8 @llvm.fshl.i8(i8 %27, i8 %32, i8 1)
  store i8 %35, ptr %26, align 1, !tbaa !5
  %36 = getelementptr inbounds i8, ptr %2, i64 95
  %37 = load i8, ptr %36, align 1, !tbaa !5
  %38 = tail call i8 @llvm.fshl.i8(i8 %32, i8 %37, i8 2)
  %39 = getelementptr inbounds i8, ptr %2, i64 110
  store i8 %38, ptr %39, align 1, !tbaa !5
  %40 = tail call i8 @llvm.fshl.i8(i8 %32, i8 %37, i8 1)
  store i8 %40, ptr %31, align 1, !tbaa !5
  %41 = extractelement <8 x i8> %11, i64 0
  %42 = lshr i8 %41, 6
  %43 = shl i8 %37, 2
  %44 = zext nneg i8 %42 to i64
  %45 = getelementptr inbounds [4 x i8], ptr @eax_init_and_key.x_t, i64 0, i64 %44
  %46 = load i8, ptr %45, align 1, !tbaa !5
  %47 = xor i8 %43, %46
  %48 = getelementptr inbounds i8, ptr %2, i64 111
  store i8 %47, ptr %48, align 1, !tbaa !5
  %49 = lshr i8 %41, 7
  %50 = load i8, ptr %39, align 1, !tbaa !5
  %51 = xor i8 %50, %49
  store i8 %51, ptr %39, align 1, !tbaa !5
  %52 = shl i8 %37, 1
  %53 = zext nneg i8 %49 to i64
  %54 = getelementptr inbounds [4 x i8], ptr @eax_init_and_key.x_t, i64 0, i64 %53
  %55 = load i8, ptr %54, align 1, !tbaa !5
  %56 = xor i8 %55, %52
  store i8 %56, ptr %36, align 1, !tbaa !5
  ret i32 0
}

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

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

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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i8 @llvm.fshl.i8(i8, i8, i8) #3

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare <8 x i8> @llvm.fshl.v8i8(<8 x i8>, <8 x i8>, <8 x i8>) #3

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare <4 x i8> @llvm.fshl.v4i8(<4 x i8>, <4 x i8>, <4 x i8>) #3

attributes #0 = { 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 #1 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LCSSAPass,LoopRotatePass,PostOrderFunctionAttrsPass,ReassociatePass,SLPVectorizerPass,SROAPass,SimplifyCFGPass,TailCallElimPass