; LLVM IR from cryspen/libcrux :: sys/pqclean/c (fips202)

; 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.shake128ctx = type { ptr }

; Function Attrs: nounwind uwtable
declare dso_local void @shake128_absorb(ptr noundef, ptr noundef, i64 noundef) #0

; Function Attrs: nounwind uwtable
declare dso_local void @shake128_squeezeblocks(ptr noundef, i64 noundef, ptr noundef) #0

; Function Attrs: nounwind uwtable
declare dso_local void @shake128_ctx_release(ptr noundef) #0

; Function Attrs: nounwind uwtable
define dso_local void @shake128(ptr noundef %0, i64 noundef %1, ptr noundef %2, i64 noundef %3) #0 {
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i64, align 8
  %9 = alloca i64, align 8
  %10 = alloca [168 x i8], align 16
  %11 = alloca %struct.shake128ctx, align 8
  %12 = alloca i64, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i64 %1, ptr %6, align 8, !tbaa !9
  store ptr %2, ptr %7, align 8, !tbaa !5
  store i64 %3, ptr %8, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #2
  %13 = load i64, ptr %6, align 8, !tbaa !9
  %14 = udiv i64 %13, 168
  store i64 %14, ptr %9, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 168, ptr %10) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #2
  %15 = load ptr, ptr %7, align 8, !tbaa !5
  %16 = load i64, ptr %8, align 8, !tbaa !9
  call void @shake128_absorb(ptr noundef %11, ptr noundef %15, i64 noundef %16)
  %17 = load ptr, ptr %5, align 8, !tbaa !5
  %18 = load i64, ptr %9, align 8, !tbaa !9
  call void @shake128_squeezeblocks(ptr noundef %17, i64 noundef %18, ptr noundef %11)
  %19 = load i64, ptr %9, align 8, !tbaa !9
  %20 = mul i64 %19, 168
  %21 = load ptr, ptr %5, align 8, !tbaa !5
  %22 = getelementptr inbounds i8, ptr %21, i64 %20
  store ptr %22, ptr %5, align 8, !tbaa !5
  %23 = load i64, ptr %9, align 8, !tbaa !9
  %24 = mul i64 %23, 168
  %25 = load i64, ptr %6, align 8, !tbaa !9
  %26 = sub i64 %25, %24
  store i64 %26, ptr %6, align 8, !tbaa !9
  %27 = load i64, ptr %6, align 8, !tbaa !9
  %28 = icmp ne i64 %27, 0
  br i1 %28, label %29, label %47

29:                                               ; preds = %4
  %30 = getelementptr inbounds [168 x i8], ptr %10, i64 0, i64 0
  call void @shake128_squeezeblocks(ptr noundef %30, i64 noundef 1, ptr noundef %11)
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #2
  store i64 0, ptr %12, align 8, !tbaa !9
  br label %31

31:                                               ; preds = %43, %29
  %32 = load i64, ptr %12, align 8, !tbaa !9
  %33 = load i64, ptr %6, align 8, !tbaa !9
  %34 = icmp ult i64 %32, %33
  br i1 %34, label %36, label %35

35:                                               ; preds = %31
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #2
  br label %46

36:                                               ; preds = %31
  %37 = load i64, ptr %12, align 8, !tbaa !9
  %38 = getelementptr inbounds [168 x i8], ptr %10, i64 0, i64 %37
  %39 = load i8, ptr %38, align 1, !tbaa !11
  %40 = load ptr, ptr %5, align 8, !tbaa !5
  %41 = load i64, ptr %12, align 8, !tbaa !9
  %42 = getelementptr inbounds i8, ptr %40, i64 %41
  store i8 %39, ptr %42, align 1, !tbaa !11
  br label %43

43:                                               ; preds = %36
  %44 = load i64, ptr %12, align 8, !tbaa !9
  %45 = add i64 %44, 1
  store i64 %45, ptr %12, align 8, !tbaa !9
  br label %31, !llvm.loop !12

46:                                               ; preds = %35
  br label %47

47:                                               ; preds = %46, %4
  call void @shake128_ctx_release(ptr noundef %11)
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #2
  call void @llvm.lifetime.end.p0(i64 168, ptr %10) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #2
  ret void
}

; 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 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 = { 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 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"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"

%struct.shake128ctx = type { ptr }

; Function Attrs: nounwind uwtable
declare dso_local void @shake128_absorb(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local void @shake128_squeezeblocks(ptr noundef, i64 noundef, ptr noundef) local_unnamed_addr #0

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

; Function Attrs: nounwind uwtable
define dso_local void @shake128(ptr noundef %0, i64 noundef %1, ptr noundef %2, i64 noundef %3) local_unnamed_addr #0 {
  %5 = alloca [168 x i8], align 16
  %6 = alloca %struct.shake128ctx, align 8
  %7 = udiv i64 %1, 168
  %.recomposed = urem i64 %1, 168
  call void @llvm.lifetime.start.p0(i64 168, ptr nonnull %5) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %6) #4
  call void @shake128_absorb(ptr noundef nonnull %6, ptr noundef %2, i64 noundef %3)
  call void @shake128_squeezeblocks(ptr noundef %0, i64 noundef %7, ptr noundef nonnull %6)
  %8 = mul nuw i64 %7, 168
  %.not = icmp eq i64 %8, %1
  br i1 %.not, label %.loopexit, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %4
  %9 = getelementptr i8, ptr %0, i64 %8
  call void @shake128_squeezeblocks(ptr noundef nonnull %5, i64 noundef 1, ptr noundef nonnull %6)
  %umax = call i64 @llvm.umax.i64(i64 %.recomposed, i64 1)
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 1 dereferenceable(1) %9, ptr noundef nonnull align 16 dereferenceable(1) %5, i64 %umax, i1 false), !tbaa !5
  br label %.loopexit

.loopexit:                                        ; preds = %.lr.ph.preheader, %4
  call void @shake128_ctx_release(ptr noundef nonnull %6)
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %6) #4
  call void @llvm.lifetime.end.p0(i64 168, ptr nonnull %5) #4
  ret void
}

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

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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.umax.i64(i64, i64) #2

; 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) #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 nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #3 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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: DivRemPairsPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopIdiomRecognizePass,LoopRotatePass,LoopSimplifyPass,SCCPPass,SROAPass,SimplifyCFGPass