; LLVM IR from intel/cryptography-primitives :: sources/ippcp/sms4 (pcpsms4setkey)

; 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._cpSMS4 = type { i32, [32 x i32], [32 x i32] }

; Function Attrs: nounwind uwtable
define dso_local i32 @ippsSMS4SetKey(ptr noundef %0, i32 noundef %1, ptr noundef %2) #0 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca [16 x i8], align 16
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !9
  store ptr %2, ptr %7, align 8, !tbaa !5
  %11 = load ptr, ptr %7, align 8, !tbaa !5
  %12 = icmp eq ptr null, %11
  br i1 %12, label %13, label %14

13:                                               ; preds = %3
  store i32 -8, ptr %4, align 4
  br label %62

14:                                               ; preds = %3
  %15 = load ptr, ptr %7, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct._cpSMS4, ptr %15, i32 0, i32 0
  %17 = load i32, ptr %16, align 4, !tbaa !11
  %18 = load ptr, ptr %7, align 8, !tbaa !5
  %19 = call i64 @IPP_UINT_PTR(ptr noundef %18)
  %20 = trunc i64 %19 to i32
  %21 = xor i32 %17, %20
  %22 = icmp eq i32 %21, 1397576500
  br i1 %22, label %24, label %23

23:                                               ; preds = %14
  store i32 -13, ptr %4, align 4
  br label %62

24:                                               ; preds = %14
  %25 = load i32, ptr %6, align 4, !tbaa !9
  %26 = icmp slt i32 %25, 16
  br i1 %26, label %27, label %28

27:                                               ; preds = %24
  store i32 -15, ptr %4, align 4
  br label %62

28:                                               ; preds = %24
  call void @llvm.lifetime.start.p0(i64 16, ptr %8) #4
  call void @llvm.memset.p0.i64(ptr align 16 %8, i8 0, i64 16, i1 false)
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  %29 = load ptr, ptr %5, align 8, !tbaa !5
  %30 = icmp ne ptr %29, null
  br i1 %30, label %31, label %33

31:                                               ; preds = %28
  %32 = load ptr, ptr %5, align 8, !tbaa !5
  br label %35

33:                                               ; preds = %28
  %34 = getelementptr inbounds [16 x i8], ptr %8, i64 0, i64 0
  br label %35

35:                                               ; preds = %33, %31
  %36 = phi ptr [ %32, %31 ], [ %34, %33 ]
  store ptr %36, ptr %9, align 8, !tbaa !5
  %37 = load ptr, ptr %7, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct._cpSMS4, ptr %37, i32 0, i32 1
  %39 = getelementptr inbounds [32 x i32], ptr %38, i64 0, i64 0
  %40 = load ptr, ptr %9, align 8, !tbaa !5
  call void @cpSMS4_SetRoundKeys(ptr noundef %39, ptr noundef %40)
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #4
  store i32 0, ptr %10, align 4, !tbaa !9
  br label %41

41:                                               ; preds = %58, %35
  %42 = load i32, ptr %10, align 4, !tbaa !9
  %43 = icmp slt i32 %42, 32
  br i1 %43, label %44, label %61

44:                                               ; preds = %41
  %45 = load ptr, ptr %7, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct._cpSMS4, ptr %45, i32 0, i32 1
  %47 = load i32, ptr %10, align 4, !tbaa !9
  %48 = sub nsw i32 32, %47
  %49 = sub nsw i32 %48, 1
  %50 = sext i32 %49 to i64
  %51 = getelementptr inbounds [32 x i32], ptr %46, i64 0, i64 %50
  %52 = load i32, ptr %51, align 4, !tbaa !9
  %53 = load ptr, ptr %7, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct._cpSMS4, ptr %53, i32 0, i32 2
  %55 = load i32, ptr %10, align 4, !tbaa !9
  %56 = sext i32 %55 to i64
  %57 = getelementptr inbounds [32 x i32], ptr %54, i64 0, i64 %56
  store i32 %52, ptr %57, align 4, !tbaa !9
  br label %58

58:                                               ; preds = %44
  %59 = load i32, ptr %10, align 4, !tbaa !9
  %60 = add nsw i32 %59, 1
  store i32 %60, ptr %10, align 4, !tbaa !9
  br label %41, !llvm.loop !13

61:                                               ; preds = %41
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  store i32 0, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 16, ptr %8) #4
  br label %62

62:                                               ; preds = %61, %27, %23, %13
  %63 = load i32, ptr %4, align 4
  ret i32 %63
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden i64 @IPP_UINT_PTR(ptr noundef) #1

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

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

; Function Attrs: nounwind uwtable
declare hidden void @cpSMS4_SetRoundKeys(ptr noundef, ptr noundef) #0

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

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 = { 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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { nocallback nofree nounwind willreturn memory(argmem: write) }
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 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 0}
!12 = !{!"_cpSMS4", !10, i64 0, !7, i64 4, !7, i64 132}
!13 = distinct !{!13, !14}
!14 = !{!"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: nounwind uwtable
define dso_local range(i32 -15, 1) i32 @ippsSMS4SetKey(ptr noundef %0, i32 noundef %1, ptr noundef %2) local_unnamed_addr #0 {
  %4 = alloca [16 x i8], align 16
  %5 = icmp eq ptr %2, null
  br i1 %5, label %48, label %6

6:                                                ; preds = %3
  %7 = load i32, ptr %2, align 4, !tbaa !5
  %8 = tail call i64 @IPP_UINT_PTR(ptr noundef nonnull %2)
  %9 = trunc i64 %8 to i32
  %10 = xor i32 %7, %9
  %11 = icmp eq i32 %10, 1397576500
  br i1 %11, label %12, label %48

12:                                               ; preds = %6
  %13 = icmp slt i32 %1, 16
  br i1 %13, label %48, label %14

14:                                               ; preds = %12
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %4) #4
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(16) %4, i8 0, i64 16, i1 false)
  %.not = icmp eq ptr %0, null
  %15 = select i1 %.not, ptr %4, ptr %0
  %16 = getelementptr inbounds i8, ptr %2, i64 4
  call void @cpSMS4_SetRoundKeys(ptr noundef nonnull %16, ptr noundef nonnull %15)
  %17 = getelementptr inbounds i8, ptr %2, i64 132
  %18 = getelementptr inbounds i8, ptr %2, i64 116
  %19 = load <4 x i32>, ptr %18, align 4, !tbaa !10
  %20 = shufflevector <4 x i32> %19, <4 x i32> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>
  store <4 x i32> %20, ptr %17, align 4, !tbaa !10
  %21 = getelementptr inbounds i8, ptr %2, i64 148
  %22 = getelementptr inbounds i8, ptr %2, i64 100
  %23 = load <4 x i32>, ptr %22, align 4, !tbaa !10
  %24 = shufflevector <4 x i32> %23, <4 x i32> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>
  store <4 x i32> %24, ptr %21, align 4, !tbaa !10
  %25 = getelementptr inbounds i8, ptr %2, i64 164
  %26 = getelementptr inbounds i8, ptr %2, i64 84
  %27 = load <4 x i32>, ptr %26, align 4, !tbaa !10
  %28 = shufflevector <4 x i32> %27, <4 x i32> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>
  store <4 x i32> %28, ptr %25, align 4, !tbaa !10
  %29 = getelementptr inbounds i8, ptr %2, i64 180
  %30 = getelementptr inbounds i8, ptr %2, i64 68
  %31 = load <4 x i32>, ptr %30, align 4, !tbaa !10
  %32 = shufflevector <4 x i32> %31, <4 x i32> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>
  store <4 x i32> %32, ptr %29, align 4, !tbaa !10
  %33 = getelementptr inbounds i8, ptr %2, i64 196
  %34 = getelementptr inbounds i8, ptr %2, i64 52
  %35 = load <4 x i32>, ptr %34, align 4, !tbaa !10
  %36 = shufflevector <4 x i32> %35, <4 x i32> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>
  store <4 x i32> %36, ptr %33, align 4, !tbaa !10
  %37 = getelementptr inbounds i8, ptr %2, i64 212
  %38 = getelementptr inbounds i8, ptr %2, i64 36
  %39 = load <4 x i32>, ptr %38, align 4, !tbaa !10
  %40 = shufflevector <4 x i32> %39, <4 x i32> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>
  store <4 x i32> %40, ptr %37, align 4, !tbaa !10
  %41 = getelementptr inbounds i8, ptr %2, i64 228
  %42 = getelementptr inbounds i8, ptr %2, i64 20
  %43 = load <4 x i32>, ptr %42, align 4, !tbaa !10
  %44 = shufflevector <4 x i32> %43, <4 x i32> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>
  store <4 x i32> %44, ptr %41, align 4, !tbaa !10
  %45 = getelementptr inbounds i8, ptr %2, i64 244
  %46 = load <4 x i32>, ptr %16, align 4, !tbaa !10
  %47 = shufflevector <4 x i32> %46, <4 x i32> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>
  store <4 x i32> %47, ptr %45, align 4, !tbaa !10
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %4) #4
  br label %48

48:                                               ; preds = %12, %6, %3, %14
  %.014 = phi i32 [ 0, %14 ], [ -8, %3 ], [ -13, %6 ], [ -15, %12 ]
  ret i32 %.014
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden i64 @IPP_UINT_PTR(ptr noundef) local_unnamed_addr #1

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

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

; Function Attrs: nounwind uwtable
declare hidden void @cpSMS4_SetRoundKeys(ptr noundef, ptr noundef) local_unnamed_addr #0

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

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


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