; 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_poly1305_ctx = type { [4 x i32], [5 x i32], [5 x i32], [4 x i32], i64 }

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

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

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

; Function Attrs: nounwind uwtable
define dso_local void @crypto_poly1305_init(ptr noundef %0, ptr noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #2
  store i64 0, ptr %5, align 8, !tbaa !9
  br label %9

9:                                                ; preds = %18, %2
  %10 = load i64, ptr %5, align 8, !tbaa !9
  %11 = icmp ult i64 %10, 5
  br i1 %11, label %13, label %12

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

13:                                               ; preds = %9
  %14 = load ptr, ptr %3, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.crypto_poly1305_ctx, ptr %14, i32 0, i32 1
  %16 = load i64, ptr %5, align 8, !tbaa !9
  %17 = getelementptr inbounds [5 x i32], ptr %15, i64 0, i64 %16
  store i32 0, ptr %17, align 4, !tbaa !11
  br label %18

18:                                               ; preds = %13
  %19 = load i64, ptr %5, align 8, !tbaa !9
  %20 = add i64 %19, 1
  store i64 %20, ptr %5, align 8, !tbaa !9
  br label %9, !llvm.loop !13

21:                                               ; preds = %12
  %22 = load ptr, ptr %3, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.crypto_poly1305_ctx, ptr %22, i32 0, i32 2
  %24 = getelementptr inbounds [5 x i32], ptr %23, i64 0, i64 4
  store i32 1, ptr %24, align 4, !tbaa !11
  %25 = load ptr, ptr %3, align 8, !tbaa !5
  call void @poly_clear_c(ptr noundef %25)
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #2
  store i64 0, ptr %6, align 8, !tbaa !9
  br label %26

26:                                               ; preds = %37, %21
  %27 = load i64, ptr %6, align 8, !tbaa !9
  %28 = icmp ult i64 %27, 1
  br i1 %28, label %30, label %29

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

30:                                               ; preds = %26
  %31 = load ptr, ptr %4, align 8, !tbaa !5
  %32 = call i32 @load32_le(ptr noundef %31)
  %33 = and i32 %32, 268435455
  %34 = load ptr, ptr %3, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.crypto_poly1305_ctx, ptr %34, i32 0, i32 0
  %36 = getelementptr inbounds [4 x i32], ptr %35, i64 0, i64 0
  store i32 %33, ptr %36, align 8, !tbaa !11
  br label %37

37:                                               ; preds = %30
  %38 = load i64, ptr %6, align 8, !tbaa !9
  %39 = add i64 %38, 1
  store i64 %39, ptr %6, align 8, !tbaa !9
  br label %26, !llvm.loop !15

40:                                               ; preds = %29
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #2
  store i64 1, ptr %7, align 8, !tbaa !9
  br label %41

41:                                               ; preds = %56, %40
  %42 = load i64, ptr %7, align 8, !tbaa !9
  %43 = icmp ult i64 %42, 4
  br i1 %43, label %45, label %44

44:                                               ; preds = %41
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #2
  br label %59

45:                                               ; preds = %41
  %46 = load ptr, ptr %4, align 8, !tbaa !5
  %47 = load i64, ptr %7, align 8, !tbaa !9
  %48 = mul i64 %47, 4
  %49 = getelementptr inbounds i8, ptr %46, i64 %48
  %50 = call i32 @load32_le(ptr noundef %49)
  %51 = and i32 %50, 268435452
  %52 = load ptr, ptr %3, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.crypto_poly1305_ctx, ptr %52, i32 0, i32 0
  %54 = load i64, ptr %7, align 8, !tbaa !9
  %55 = getelementptr inbounds [4 x i32], ptr %53, i64 0, i64 %54
  store i32 %51, ptr %55, align 4, !tbaa !11
  br label %56

56:                                               ; preds = %45
  %57 = load i64, ptr %7, align 8, !tbaa !9
  %58 = add i64 %57, 1
  store i64 %58, ptr %7, align 8, !tbaa !9
  br label %41, !llvm.loop !16

59:                                               ; preds = %44
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #2
  store i64 0, ptr %8, align 8, !tbaa !9
  br label %60

60:                                               ; preds = %75, %59
  %61 = load i64, ptr %8, align 8, !tbaa !9
  %62 = icmp ult i64 %61, 4
  br i1 %62, label %64, label %63

63:                                               ; preds = %60
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #2
  br label %78

64:                                               ; preds = %60
  %65 = load ptr, ptr %4, align 8, !tbaa !5
  %66 = load i64, ptr %8, align 8, !tbaa !9
  %67 = mul i64 %66, 4
  %68 = getelementptr inbounds i8, ptr %65, i64 %67
  %69 = getelementptr inbounds i8, ptr %68, i64 16
  %70 = call i32 @load32_le(ptr noundef %69)
  %71 = load ptr, ptr %3, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct.crypto_poly1305_ctx, ptr %71, i32 0, i32 3
  %73 = load i64, ptr %8, align 8, !tbaa !9
  %74 = getelementptr inbounds [4 x i32], ptr %72, i64 0, i64 %73
  store i32 %70, ptr %74, align 4, !tbaa !11
  br label %75

75:                                               ; preds = %64
  %76 = load i64, ptr %8, align 8, !tbaa !9
  %77 = add i64 %76, 1
  store i64 %77, ptr %8, align 8, !tbaa !9
  br label %60, !llvm.loop !17

78:                                               ; preds = %63
  ret void
}

; Function Attrs: nounwind uwtable
declare hidden void @poly_clear_c(ptr noundef) #1

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 = { 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}
!16 = distinct !{!16, !14}
!17 = distinct !{!17, !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"

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

; Function Attrs: nounwind uwtable
define dso_local void @crypto_poly1305_init(ptr noundef %0, ptr noundef %1) local_unnamed_addr #0 {
.critedge:
  %2 = getelementptr inbounds i8, ptr %0, i64 16
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 4 dereferenceable(20) %2, i8 0, i64 20, i1 false), !tbaa !5
  %3 = getelementptr inbounds i8, ptr %0, i64 52
  store i32 1, ptr %3, align 4, !tbaa !5
  tail call void @poly_clear_c(ptr noundef %0)
  %4 = tail call i32 @load32_le(ptr noundef %1)
  %5 = and i32 %4, 268435455
  store i32 %5, ptr %0, align 8, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %1, i64 4
  %7 = tail call i32 @load32_le(ptr noundef nonnull %6)
  %8 = and i32 %7, 268435452
  %9 = getelementptr inbounds i8, ptr %0, i64 4
  store i32 %8, ptr %9, align 4, !tbaa !5
  %10 = getelementptr inbounds i8, ptr %1, i64 8
  %11 = tail call i32 @load32_le(ptr noundef nonnull %10)
  %12 = and i32 %11, 268435452
  %13 = getelementptr inbounds i8, ptr %0, i64 8
  store i32 %12, ptr %13, align 4, !tbaa !5
  %14 = getelementptr inbounds i8, ptr %1, i64 12
  %15 = tail call i32 @load32_le(ptr noundef nonnull %14)
  %16 = and i32 %15, 268435452
  %17 = getelementptr inbounds i8, ptr %0, i64 12
  store i32 %16, ptr %17, align 4, !tbaa !5
  %invariant.gep = getelementptr inbounds i8, ptr %1, i64 16
  %18 = getelementptr inbounds i8, ptr %0, i64 56
  %19 = tail call i32 @load32_le(ptr noundef nonnull %invariant.gep)
  store i32 %19, ptr %18, align 4, !tbaa !5
  %gep.1 = getelementptr inbounds i8, ptr %1, i64 20
  %20 = tail call i32 @load32_le(ptr noundef nonnull %gep.1)
  %21 = getelementptr inbounds i8, ptr %0, i64 60
  store i32 %20, ptr %21, align 4, !tbaa !5
  %gep.2 = getelementptr inbounds i8, ptr %1, i64 24
  %22 = tail call i32 @load32_le(ptr noundef nonnull %gep.2)
  %23 = getelementptr inbounds i8, ptr %0, i64 64
  store i32 %22, ptr %23, align 4, !tbaa !5
  %gep.3 = getelementptr inbounds i8, ptr %1, i64 28
  %24 = tail call i32 @load32_le(ptr noundef nonnull %gep.3)
  %25 = getelementptr inbounds i8, ptr %0, i64 68
  store i32 %24, ptr %25, align 4, !tbaa !5
  ret void
}

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #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 nounwind willreturn memory(argmem: write) }

!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,InferFunctionAttrsPass,InstCombinePass,LICMPass,LoopIdiomRecognizePass,LoopRotatePass,LoopSimplifyPass,SROAPass,SimplifyCFGPass,TailCallElimPass