; LLVM IR from LoupVaillant/Monocypher-Utils :: src (monocypher)

; 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.crypto_chacha_ctx = type { [16 x i32], [16 x i32], i64 }

; Function Attrs: nounwind uwtable
declare dso_local void @crypto_wipe(ptr noundef, i64 noundef) #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 nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: nounwind uwtable
define dso_local void @crypto_chacha20_H(ptr noundef %0, ptr noundef %1, ptr noundef %2) #0 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca %struct.crypto_chacha_ctx, align 8
  %8 = alloca i64, align 8
  %9 = alloca [16 x i32], align 16
  %10 = alloca i64, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store ptr %2, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 136, ptr %7) #2
  %11 = load ptr, ptr %5, align 8, !tbaa !5
  call void @chacha20_init_key(ptr noundef %7, ptr noundef %11)
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #2
  store i64 0, ptr %8, align 8, !tbaa !9
  br label %12

12:                                               ; preds = %26, %3
  %13 = load i64, ptr %8, align 8, !tbaa !9
  %14 = icmp ult i64 %13, 4
  br i1 %14, label %16, label %15

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

16:                                               ; preds = %12
  %17 = load ptr, ptr %6, align 8, !tbaa !5
  %18 = load i64, ptr %8, align 8, !tbaa !9
  %19 = mul i64 %18, 4
  %20 = getelementptr inbounds i8, ptr %17, i64 %19
  %21 = call i32 @load32_le(ptr noundef %20)
  %22 = getelementptr inbounds %struct.crypto_chacha_ctx, ptr %7, i32 0, i32 0
  %23 = load i64, ptr %8, align 8, !tbaa !9
  %24 = add i64 %23, 12
  %25 = getelementptr inbounds [16 x i32], ptr %22, i64 0, i64 %24
  store i32 %21, ptr %25, align 4, !tbaa !11
  br label %26

26:                                               ; preds = %16
  %27 = load i64, ptr %8, align 8, !tbaa !9
  %28 = add i64 %27, 1
  store i64 %28, ptr %8, align 8, !tbaa !9
  br label %12, !llvm.loop !13

29:                                               ; preds = %15
  call void @llvm.lifetime.start.p0(i64 64, ptr %9) #2
  %30 = getelementptr inbounds [16 x i32], ptr %9, i64 0, i64 0
  %31 = getelementptr inbounds %struct.crypto_chacha_ctx, ptr %7, i32 0, i32 0
  %32 = getelementptr inbounds [16 x i32], ptr %31, i64 0, i64 0
  call void @chacha20_rounds(ptr noundef %30, ptr noundef %32)
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #2
  store i64 0, ptr %10, align 8, !tbaa !9
  br label %33

33:                                               ; preds = %54, %29
  %34 = load i64, ptr %10, align 8, !tbaa !9
  %35 = icmp ult i64 %34, 4
  br i1 %35, label %37, label %36

36:                                               ; preds = %33
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #2
  br label %57

37:                                               ; preds = %33
  %38 = load ptr, ptr %4, align 8, !tbaa !5
  %39 = load i64, ptr %10, align 8, !tbaa !9
  %40 = mul i64 %39, 4
  %41 = getelementptr inbounds i8, ptr %38, i64 %40
  %42 = load i64, ptr %10, align 8, !tbaa !9
  %43 = getelementptr inbounds [16 x i32], ptr %9, i64 0, i64 %42
  %44 = load i32, ptr %43, align 4, !tbaa !11
  call void @store32_le(ptr noundef %41, i32 noundef %44)
  %45 = load ptr, ptr %4, align 8, !tbaa !5
  %46 = getelementptr inbounds i8, ptr %45, i64 16
  %47 = load i64, ptr %10, align 8, !tbaa !9
  %48 = mul i64 %47, 4
  %49 = getelementptr inbounds i8, ptr %46, i64 %48
  %50 = load i64, ptr %10, align 8, !tbaa !9
  %51 = add i64 %50, 12
  %52 = getelementptr inbounds [16 x i32], ptr %9, i64 0, i64 %51
  %53 = load i32, ptr %52, align 4, !tbaa !11
  call void @store32_le(ptr noundef %49, i32 noundef %53)
  br label %54

54:                                               ; preds = %37
  %55 = load i64, ptr %10, align 8, !tbaa !9
  %56 = add i64 %55, 1
  store i64 %56, ptr %10, align 8, !tbaa !9
  br label %33, !llvm.loop !15

57:                                               ; preds = %36
  call void @crypto_wipe(ptr noundef %7, i64 noundef 136)
  %58 = getelementptr inbounds [16 x i32], ptr %9, i64 0, i64 0
  call void @crypto_wipe(ptr noundef %58, i64 noundef 64)
  call void @llvm.lifetime.end.p0(i64 64, ptr %9) #2
  call void @llvm.lifetime.end.p0(i64 136, ptr %7) #2
  ret void
}

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

; Function Attrs: nounwind uwtable
declare hidden i32 @load32_le(ptr noundef) #0

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

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

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 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}


; 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.crypto_chacha_ctx = type { [16 x i32], [16 x i32], i64 }

; Function Attrs: nounwind uwtable
declare dso_local void @crypto_wipe(ptr noundef, i64 noundef) local_unnamed_addr #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: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: nounwind uwtable
define dso_local void @crypto_chacha20_H(ptr noundef %0, ptr noundef %1, ptr noundef %2) local_unnamed_addr #0 {
  %4 = alloca %struct.crypto_chacha_ctx, align 8
  %5 = alloca [16 x i32], align 16
  call void @llvm.lifetime.start.p0(i64 136, ptr nonnull %4) #2
  call void @chacha20_init_key(ptr noundef nonnull %4, ptr noundef %1)
  %6 = call i32 @load32_le(ptr noundef %2)
  %7 = getelementptr inbounds i8, ptr %4, i64 48
  store i32 %6, ptr %7, align 8, !tbaa !5
  %8 = getelementptr inbounds i8, ptr %2, i64 4
  %9 = call i32 @load32_le(ptr noundef nonnull %8)
  %10 = getelementptr inbounds i8, ptr %4, i64 52
  store i32 %9, ptr %10, align 4, !tbaa !5
  %11 = getelementptr inbounds i8, ptr %2, i64 8
  %12 = call i32 @load32_le(ptr noundef nonnull %11)
  %13 = getelementptr inbounds i8, ptr %4, i64 56
  store i32 %12, ptr %13, align 8, !tbaa !5
  %14 = getelementptr inbounds i8, ptr %2, i64 12
  %15 = call i32 @load32_le(ptr noundef nonnull %14)
  %16 = getelementptr inbounds i8, ptr %4, i64 60
  store i32 %15, ptr %16, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 64, ptr nonnull %5) #2
  call void @chacha20_rounds(ptr noundef nonnull %5, ptr noundef nonnull %4)
  %17 = getelementptr inbounds i8, ptr %0, i64 16
  %18 = load i32, ptr %5, align 16, !tbaa !5
  call void @store32_le(ptr noundef %0, i32 noundef %18)
  %19 = getelementptr inbounds i8, ptr %5, i64 48
  %20 = load i32, ptr %19, align 16, !tbaa !5
  call void @store32_le(ptr noundef nonnull %17, i32 noundef %20)
  %21 = getelementptr inbounds i8, ptr %0, i64 4
  %22 = getelementptr inbounds i8, ptr %5, i64 4
  %23 = load i32, ptr %22, align 4, !tbaa !5
  call void @store32_le(ptr noundef nonnull %21, i32 noundef %23)
  %24 = getelementptr inbounds i8, ptr %0, i64 20
  %25 = getelementptr inbounds i8, ptr %5, i64 52
  %26 = load i32, ptr %25, align 4, !tbaa !5
  call void @store32_le(ptr noundef nonnull %24, i32 noundef %26)
  %27 = getelementptr inbounds i8, ptr %0, i64 8
  %28 = getelementptr inbounds i8, ptr %5, i64 8
  %29 = load i32, ptr %28, align 8, !tbaa !5
  call void @store32_le(ptr noundef nonnull %27, i32 noundef %29)
  %30 = getelementptr inbounds i8, ptr %0, i64 24
  %31 = getelementptr inbounds i8, ptr %5, i64 56
  %32 = load i32, ptr %31, align 8, !tbaa !5
  call void @store32_le(ptr noundef nonnull %30, i32 noundef %32)
  %33 = getelementptr inbounds i8, ptr %0, i64 12
  %34 = getelementptr inbounds i8, ptr %5, i64 12
  %35 = load i32, ptr %34, align 4, !tbaa !5
  call void @store32_le(ptr noundef nonnull %33, i32 noundef %35)
  %36 = getelementptr inbounds i8, ptr %0, i64 28
  %37 = getelementptr inbounds i8, ptr %5, i64 60
  %38 = load i32, ptr %37, align 4, !tbaa !5
  call void @store32_le(ptr noundef nonnull %36, i32 noundef %38)
  call void @crypto_wipe(ptr noundef nonnull %4, i64 noundef 136)
  call void @crypto_wipe(ptr noundef nonnull %5, i64 noundef 64)
  call void @llvm.lifetime.end.p0(i64 64, ptr nonnull %5) #2
  call void @llvm.lifetime.end.p0(i64 136, ptr nonnull %4) #2
  ret void
}

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

; Function Attrs: nounwind uwtable
declare hidden i32 @load32_le(ptr noundef) local_unnamed_addr #0

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

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

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 = { 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}


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