; 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
declare hidden void @poly_clear_c(ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local void @crypto_poly1305_update(ptr noundef %0, ptr noundef %1, i64 noundef %2) #1 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  %9 = alloca i64, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store i64 %2, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #2
  %10 = load ptr, ptr %4, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.crypto_poly1305_ctx, ptr %10, i32 0, i32 4
  %12 = load i64, ptr %11, align 8, !tbaa !11
  %13 = xor i64 %12, -1
  %14 = add i64 %13, 1
  %15 = and i64 %14, 15
  %16 = load i64, ptr %6, align 8, !tbaa !9
  %17 = icmp ule i64 %15, %16
  br i1 %17, label %18, label %25

18:                                               ; preds = %3
  %19 = load ptr, ptr %4, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.crypto_poly1305_ctx, ptr %19, i32 0, i32 4
  %21 = load i64, ptr %20, align 8, !tbaa !11
  %22 = xor i64 %21, -1
  %23 = add i64 %22, 1
  %24 = and i64 %23, 15
  br label %27

25:                                               ; preds = %3
  %26 = load i64, ptr %6, align 8, !tbaa !9
  br label %27

27:                                               ; preds = %25, %18
  %28 = phi i64 [ %24, %18 ], [ %26, %25 ]
  store i64 %28, ptr %7, align 8, !tbaa !9
  %29 = load ptr, ptr %4, align 8, !tbaa !5
  %30 = load ptr, ptr %5, align 8, !tbaa !5
  %31 = load i64, ptr %7, align 8, !tbaa !9
  call void @poly_update(ptr noundef %29, ptr noundef %30, i64 noundef %31)
  %32 = load i64, ptr %7, align 8, !tbaa !9
  %33 = load ptr, ptr %5, align 8, !tbaa !5
  %34 = getelementptr inbounds i8, ptr %33, i64 %32
  store ptr %34, ptr %5, align 8, !tbaa !5
  %35 = load i64, ptr %7, align 8, !tbaa !9
  %36 = load i64, ptr %6, align 8, !tbaa !9
  %37 = sub i64 %36, %35
  store i64 %37, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #2
  %38 = load i64, ptr %6, align 8, !tbaa !9
  %39 = lshr i64 %38, 4
  store i64 %39, ptr %8, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #2
  store i64 0, ptr %9, align 8, !tbaa !9
  br label %40

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

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

45:                                               ; preds = %40
  %46 = load ptr, ptr %5, align 8, !tbaa !5
  %47 = getelementptr inbounds i8, ptr %46, i64 0
  %48 = call i32 @load32_le(ptr noundef %47)
  %49 = load ptr, ptr %4, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.crypto_poly1305_ctx, ptr %49, i32 0, i32 2
  %51 = getelementptr inbounds [5 x i32], ptr %50, i64 0, i64 0
  store i32 %48, ptr %51, align 4, !tbaa !13
  %52 = load ptr, ptr %5, align 8, !tbaa !5
  %53 = getelementptr inbounds i8, ptr %52, i64 4
  %54 = call i32 @load32_le(ptr noundef %53)
  %55 = load ptr, ptr %4, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.crypto_poly1305_ctx, ptr %55, i32 0, i32 2
  %57 = getelementptr inbounds [5 x i32], ptr %56, i64 0, i64 1
  store i32 %54, ptr %57, align 4, !tbaa !13
  %58 = load ptr, ptr %5, align 8, !tbaa !5
  %59 = getelementptr inbounds i8, ptr %58, i64 8
  %60 = call i32 @load32_le(ptr noundef %59)
  %61 = load ptr, ptr %4, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.crypto_poly1305_ctx, ptr %61, i32 0, i32 2
  %63 = getelementptr inbounds [5 x i32], ptr %62, i64 0, i64 2
  store i32 %60, ptr %63, align 4, !tbaa !13
  %64 = load ptr, ptr %5, align 8, !tbaa !5
  %65 = getelementptr inbounds i8, ptr %64, i64 12
  %66 = call i32 @load32_le(ptr noundef %65)
  %67 = load ptr, ptr %4, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct.crypto_poly1305_ctx, ptr %67, i32 0, i32 2
  %69 = getelementptr inbounds [5 x i32], ptr %68, i64 0, i64 3
  store i32 %66, ptr %69, align 4, !tbaa !13
  %70 = load ptr, ptr %4, align 8, !tbaa !5
  call void @poly_block(ptr noundef %70)
  %71 = load ptr, ptr %5, align 8, !tbaa !5
  %72 = getelementptr inbounds i8, ptr %71, i64 16
  store ptr %72, ptr %5, align 8, !tbaa !5
  br label %73

73:                                               ; preds = %45
  %74 = load i64, ptr %9, align 8, !tbaa !9
  %75 = add i64 %74, 1
  store i64 %75, ptr %9, align 8, !tbaa !9
  br label %40, !llvm.loop !15

76:                                               ; preds = %44
  %77 = load i64, ptr %8, align 8, !tbaa !9
  %78 = icmp ugt i64 %77, 0
  br i1 %78, label %79, label %81

79:                                               ; preds = %76
  %80 = load ptr, ptr %4, align 8, !tbaa !5
  call void @poly_clear_c(ptr noundef %80)
  br label %81

81:                                               ; preds = %79, %76
  %82 = load i64, ptr %6, align 8, !tbaa !9
  %83 = and i64 %82, 15
  store i64 %83, ptr %6, align 8, !tbaa !9
  %84 = load ptr, ptr %4, align 8, !tbaa !5
  %85 = load ptr, ptr %5, align 8, !tbaa !5
  %86 = load i64, ptr %6, align 8, !tbaa !9
  call void @poly_update(ptr noundef %84, ptr noundef %85, i64 noundef %86)
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #2
  ret void
}

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

; Function Attrs: nounwind uwtable
declare hidden void @poly_block(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, !10, i64 72}
!12 = !{!"", !7, i64 0, !7, i64 16, !7, i64 36, !7, i64 56, !10, i64 72}
!13 = !{!14, !14, i64 0}
!14 = !{!"int", !7, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"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
declare hidden i32 @load32_le(ptr noundef) local_unnamed_addr #0

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

; Function Attrs: nounwind uwtable
define dso_local void @crypto_poly1305_update(ptr noundef %0, ptr noundef %1, i64 noundef %2) local_unnamed_addr #0 {
  %4 = getelementptr inbounds i8, ptr %0, i64 72
  %5 = load i64, ptr %4, align 8, !tbaa !5
  %6 = sub i64 0, %5
  %7 = and i64 %6, 15
  %. = tail call i64 @llvm.umin.i64(i64 %7, i64 %2)
  tail call void @poly_update(ptr noundef %0, ptr noundef %1, i64 noundef %.)
  %8 = getelementptr inbounds i8, ptr %1, i64 %.
  %9 = sub i64 %2, %.
  %.not = icmp ult i64 %9, 16
  br i1 %.not, label %._crit_edge.thread, label %.lr.ph

.lr.ph:                                           ; preds = %3
  %10 = lshr i64 %9, 4
  %11 = getelementptr inbounds i8, ptr %0, i64 36
  %12 = getelementptr inbounds i8, ptr %0, i64 40
  %13 = getelementptr inbounds i8, ptr %0, i64 44
  %14 = getelementptr inbounds i8, ptr %0, i64 48
  br label %15

._crit_edge:                                      ; preds = %15
  br i1 %.not, label %._crit_edge.thread, label %25

15:                                               ; preds = %.lr.ph, %15
  %.036 = phi i64 [ 0, %.lr.ph ], [ %24, %15 ]
  %.03035 = phi ptr [ %8, %.lr.ph ], [ %23, %15 ]
  %16 = tail call i32 @load32_le(ptr noundef %.03035)
  store i32 %16, ptr %11, align 4, !tbaa !10
  %17 = getelementptr inbounds i8, ptr %.03035, i64 4
  %18 = tail call i32 @load32_le(ptr noundef nonnull %17)
  store i32 %18, ptr %12, align 4, !tbaa !10
  %19 = getelementptr inbounds i8, ptr %.03035, i64 8
  %20 = tail call i32 @load32_le(ptr noundef nonnull %19)
  store i32 %20, ptr %13, align 4, !tbaa !10
  %21 = getelementptr inbounds i8, ptr %.03035, i64 12
  %22 = tail call i32 @load32_le(ptr noundef nonnull %21)
  store i32 %22, ptr %14, align 4, !tbaa !10
  tail call void @poly_block(ptr noundef nonnull %0)
  %23 = getelementptr inbounds i8, ptr %.03035, i64 16
  %24 = add nuw nsw i64 %.036, 1
  %exitcond.not = icmp eq i64 %24, %10
  br i1 %exitcond.not, label %._crit_edge, label %15, !llvm.loop !12

25:                                               ; preds = %._crit_edge
  tail call void @poly_clear_c(ptr noundef nonnull %0)
  br label %._crit_edge.thread

._crit_edge.thread:                               ; preds = %3, %25, %._crit_edge
  %.030.lcssa38 = phi ptr [ %23, %25 ], [ %23, %._crit_edge ], [ %8, %3 ]
  %26 = and i64 %9, 15
  tail call void @poly_update(ptr noundef nonnull %0, ptr noundef %.030.lcssa38, i64 noundef %26)
  ret void
}

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

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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.umin.i64(i64, i64) #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 speculatable willreturn memory(none) }

!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, !9, i64 72}
!6 = !{!"", !7, i64 0, !7, i64 16, !7, i64 36, !7, i64 56, !9, i64 72}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!"long", !7, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"int", !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass