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

; 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._cpARCfour = type { i32, i32, i32, [256 x i8], [256 x i8] }

; Function Attrs: nounwind uwtable
define dso_local i32 @ippsARCFourInit(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 i32, align 4
  %9 = alloca [256 x i8], align 16
  %10 = alloca i8, align 1
  %11 = alloca i8, align 1
  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
  %12 = load ptr, ptr %7, align 8, !tbaa !5
  %13 = icmp eq ptr null, %12
  br i1 %13, label %14, label %15

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

15:                                               ; preds = %3
  %16 = load ptr, ptr %5, align 8, !tbaa !5
  %17 = icmp eq ptr null, %16
  br i1 %17, label %18, label %19

18:                                               ; preds = %15
  store i32 -8, ptr %4, align 4
  br label %108

19:                                               ; preds = %15
  %20 = load i32, ptr %6, align 4, !tbaa !9
  %21 = icmp sgt i32 1, %20
  br i1 %21, label %25, label %22

22:                                               ; preds = %19
  %23 = load i32, ptr %6, align 4, !tbaa !9
  %24 = icmp slt i32 256, %23
  br i1 %24, label %25, label %26

25:                                               ; preds = %22, %19
  store i32 -15, ptr %4, align 4
  br label %108

26:                                               ; preds = %22
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  call void @llvm.lifetime.start.p0(i64 256, ptr %9) #4
  call void @llvm.lifetime.start.p0(i64 1, ptr %10) #4
  call void @llvm.lifetime.start.p0(i64 1, ptr %11) #4
  %27 = load ptr, ptr %7, align 8, !tbaa !5
  %28 = call i64 @IPP_UINT_PTR(ptr noundef %27)
  %29 = trunc i64 %28 to i32
  %30 = xor i32 542262068, %29
  %31 = load ptr, ptr %7, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct._cpARCfour, ptr %31, i32 0, i32 0
  store i32 %30, ptr %32, align 4, !tbaa !11
  store i32 0, ptr %8, align 4, !tbaa !9
  br label %33

33:                                               ; preds = %54, %26
  %34 = load i32, ptr %8, align 4, !tbaa !9
  %35 = icmp slt i32 %34, 256
  br i1 %35, label %36, label %57

36:                                               ; preds = %33
  %37 = load i32, ptr %8, align 4, !tbaa !9
  %38 = trunc i32 %37 to i8
  %39 = load ptr, ptr %7, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct._cpARCfour, ptr %39, i32 0, i32 4
  %41 = load i32, ptr %8, align 4, !tbaa !9
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds [256 x i8], ptr %40, i64 0, i64 %42
  store i8 %38, ptr %43, align 1, !tbaa !13
  %44 = load ptr, ptr %5, align 8, !tbaa !5
  %45 = load i32, ptr %8, align 4, !tbaa !9
  %46 = load i32, ptr %6, align 4, !tbaa !9
  %47 = srem i32 %45, %46
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds i8, ptr %44, i64 %48
  %50 = load i8, ptr %49, align 1, !tbaa !13
  %51 = load i32, ptr %8, align 4, !tbaa !9
  %52 = sext i32 %51 to i64
  %53 = getelementptr inbounds [256 x i8], ptr %9, i64 0, i64 %52
  store i8 %50, ptr %53, align 1, !tbaa !13
  br label %54

54:                                               ; preds = %36
  %55 = load i32, ptr %8, align 4, !tbaa !9
  %56 = add nsw i32 %55, 1
  store i32 %56, ptr %8, align 4, !tbaa !9
  br label %33, !llvm.loop !14

57:                                               ; preds = %33
  store i8 0, ptr %10, align 1, !tbaa !13
  store i32 0, ptr %8, align 4, !tbaa !9
  br label %58

58:                                               ; preds = %102, %57
  %59 = load i32, ptr %8, align 4, !tbaa !9
  %60 = icmp slt i32 %59, 256
  br i1 %60, label %61, label %105

61:                                               ; preds = %58
  %62 = load ptr, ptr %7, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct._cpARCfour, ptr %62, i32 0, i32 4
  %64 = load i32, ptr %8, align 4, !tbaa !9
  %65 = sext i32 %64 to i64
  %66 = getelementptr inbounds [256 x i8], ptr %63, i64 0, i64 %65
  %67 = load i8, ptr %66, align 1, !tbaa !13
  %68 = zext i8 %67 to i32
  %69 = load i32, ptr %8, align 4, !tbaa !9
  %70 = sext i32 %69 to i64
  %71 = getelementptr inbounds [256 x i8], ptr %9, i64 0, i64 %70
  %72 = load i8, ptr %71, align 1, !tbaa !13
  %73 = zext i8 %72 to i32
  %74 = add nsw i32 %68, %73
  %75 = load i8, ptr %10, align 1, !tbaa !13
  %76 = zext i8 %75 to i32
  %77 = add nsw i32 %76, %74
  %78 = trunc i32 %77 to i8
  store i8 %78, ptr %10, align 1, !tbaa !13
  %79 = load ptr, ptr %7, align 8, !tbaa !5
  %80 = getelementptr inbounds %struct._cpARCfour, ptr %79, i32 0, i32 4
  %81 = load i8, ptr %10, align 1, !tbaa !13
  %82 = zext i8 %81 to i64
  %83 = getelementptr inbounds [256 x i8], ptr %80, i64 0, i64 %82
  %84 = load i8, ptr %83, align 1, !tbaa !13
  store i8 %84, ptr %11, align 1, !tbaa !13
  %85 = load ptr, ptr %7, align 8, !tbaa !5
  %86 = getelementptr inbounds %struct._cpARCfour, ptr %85, i32 0, i32 4
  %87 = load i32, ptr %8, align 4, !tbaa !9
  %88 = sext i32 %87 to i64
  %89 = getelementptr inbounds [256 x i8], ptr %86, i64 0, i64 %88
  %90 = load i8, ptr %89, align 1, !tbaa !13
  %91 = load ptr, ptr %7, align 8, !tbaa !5
  %92 = getelementptr inbounds %struct._cpARCfour, ptr %91, i32 0, i32 4
  %93 = load i8, ptr %10, align 1, !tbaa !13
  %94 = zext i8 %93 to i64
  %95 = getelementptr inbounds [256 x i8], ptr %92, i64 0, i64 %94
  store i8 %90, ptr %95, align 1, !tbaa !13
  %96 = load i8, ptr %11, align 1, !tbaa !13
  %97 = load ptr, ptr %7, align 8, !tbaa !5
  %98 = getelementptr inbounds %struct._cpARCfour, ptr %97, i32 0, i32 4
  %99 = load i32, ptr %8, align 4, !tbaa !9
  %100 = sext i32 %99 to i64
  %101 = getelementptr inbounds [256 x i8], ptr %98, i64 0, i64 %100
  store i8 %96, ptr %101, align 1, !tbaa !13
  br label %102

102:                                              ; preds = %61
  %103 = load i32, ptr %8, align 4, !tbaa !9
  %104 = add nsw i32 %103, 1
  store i32 %104, ptr %8, align 4, !tbaa !9
  br label %58, !llvm.loop !16

105:                                              ; preds = %58
  %106 = load ptr, ptr %7, align 8, !tbaa !5
  %107 = call i32 @ippsARCFourReset(ptr noundef %106)
  store i32 %107, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 1, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 1, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 256, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  br label %108

108:                                              ; preds = %105, %25, %18, %14
  %109 = load i32, ptr %4, align 4
  ret i32 %109
}

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

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

declare i32 @ippsARCFourReset(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 = { 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 #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 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 0}
!12 = !{!"_cpARCfour", !10, i64 0, !10, i64 4, !10, i64 8, !7, i64 12, !7, i64 268}
!13 = !{!7, !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = distinct !{!16, !15}


; 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 i32 @ippsARCFourInit(ptr noundef readonly %0, i32 noundef %1, ptr noundef %2) local_unnamed_addr #0 {
  %4 = alloca [256 x i8], align 16
  %5 = icmp eq ptr %2, null
  %6 = icmp eq ptr %0, null
  %or.cond37 = or i1 %6, %5
  br i1 %or.cond37, label %57, label %7

7:                                                ; preds = %3
  %8 = add i32 %1, -257
  %or.cond = icmp ult i32 %8, -256
  br i1 %or.cond, label %57, label %9

9:                                                ; preds = %7
  call void @llvm.lifetime.start.p0(i64 256, ptr nonnull %4) #4
  %10 = tail call i64 @IPP_UINT_PTR(ptr noundef nonnull %2)
  %11 = trunc i64 %10 to i32
  %12 = xor i32 %11, 542262068
  store i32 %12, ptr %2, align 4, !tbaa !5
  %13 = getelementptr inbounds i8, ptr %2, i64 268
  br label %14

14:                                               ; preds = %14, %9
  %indvars.iv = phi i64 [ 0, %9 ], [ %indvars.iv.next.1, %14 ]
  %15 = trunc nuw nsw i64 %indvars.iv to i32
  %16 = trunc i64 %indvars.iv to i8
  %17 = getelementptr inbounds [256 x i8], ptr %13, i64 0, i64 %indvars.iv
  store i8 %16, ptr %17, align 1, !tbaa !10
  %18 = urem i32 %15, %1
  %19 = zext nneg i32 %18 to i64
  %20 = getelementptr inbounds i8, ptr %0, i64 %19
  %21 = load i8, ptr %20, align 1, !tbaa !10
  %22 = getelementptr inbounds [256 x i8], ptr %4, i64 0, i64 %indvars.iv
  store i8 %21, ptr %22, align 2, !tbaa !10
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %23 = trunc nuw nsw i64 %indvars.iv.next to i32
  %24 = trunc i64 %indvars.iv.next to i8
  %25 = getelementptr inbounds [256 x i8], ptr %13, i64 0, i64 %indvars.iv.next
  store i8 %24, ptr %25, align 1, !tbaa !10
  %26 = urem i32 %23, %1
  %27 = zext nneg i32 %26 to i64
  %28 = getelementptr inbounds i8, ptr %0, i64 %27
  %29 = load i8, ptr %28, align 1, !tbaa !10
  %30 = getelementptr inbounds [256 x i8], ptr %4, i64 0, i64 %indvars.iv.next
  store i8 %29, ptr %30, align 1, !tbaa !10
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
  %exitcond.not.1 = icmp eq i64 %indvars.iv.next.1, 256
  br i1 %exitcond.not.1, label %.preheader, label %14, !llvm.loop !11

.preheader:                                       ; preds = %14, %.preheader
  %indvars.iv42 = phi i64 [ %indvars.iv.next43.1, %.preheader ], [ 0, %14 ]
  %.03240 = phi i32 [ %50, %.preheader ], [ 0, %14 ]
  %31 = getelementptr inbounds [256 x i8], ptr %13, i64 0, i64 %indvars.iv42
  %32 = load i8, ptr %31, align 1, !tbaa !10
  %33 = zext i8 %32 to i32
  %34 = getelementptr inbounds [256 x i8], ptr %4, i64 0, i64 %indvars.iv42
  %35 = load i8, ptr %34, align 2, !tbaa !10
  %36 = zext i8 %35 to i32
  %37 = add i32 %.03240, %33
  %38 = add i32 %37, %36
  %39 = and i32 %38, 255
  %40 = zext nneg i32 %39 to i64
  %41 = getelementptr inbounds [256 x i8], ptr %13, i64 0, i64 %40
  %42 = load i8, ptr %41, align 1, !tbaa !10
  store i8 %32, ptr %41, align 1, !tbaa !10
  store i8 %42, ptr %31, align 1, !tbaa !10
  %indvars.iv.next43 = or disjoint i64 %indvars.iv42, 1
  %43 = getelementptr inbounds [256 x i8], ptr %13, i64 0, i64 %indvars.iv.next43
  %44 = load i8, ptr %43, align 1, !tbaa !10
  %45 = zext i8 %44 to i32
  %46 = getelementptr inbounds [256 x i8], ptr %4, i64 0, i64 %indvars.iv.next43
  %47 = load i8, ptr %46, align 1, !tbaa !10
  %48 = zext i8 %47 to i32
  %49 = add i32 %38, %45
  %50 = add i32 %49, %48
  %51 = and i32 %50, 255
  %52 = zext nneg i32 %51 to i64
  %53 = getelementptr inbounds [256 x i8], ptr %13, i64 0, i64 %52
  %54 = load i8, ptr %53, align 1, !tbaa !10
  store i8 %44, ptr %53, align 1, !tbaa !10
  store i8 %54, ptr %43, align 1, !tbaa !10
  %indvars.iv.next43.1 = add nuw nsw i64 %indvars.iv42, 2
  %exitcond45.not.1 = icmp eq i64 %indvars.iv.next43.1, 256
  br i1 %exitcond45.not.1, label %55, label %.preheader, !llvm.loop !13

55:                                               ; preds = %.preheader
  %56 = tail call i32 @ippsARCFourReset(ptr noundef nonnull %2) #4
  call void @llvm.lifetime.end.p0(i64 256, ptr nonnull %4) #4
  br label %57

57:                                               ; preds = %7, %3, %55
  %.0 = phi i32 [ %56, %55 ], [ -8, %3 ], [ -15, %7 ]
  ret i32 %.0
}

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

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

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

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 nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #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, !7, i64 0}
!6 = !{!"_cpARCfour", !7, i64 0, !7, i64 4, !7, i64 8, !8, i64 12, !8, i64 268}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!8, !8, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}


; Effective O3 passes: BDCEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass