; LLVM IR from cryspen/libcrux :: sys/hacl/c/src (Hacl_MAC_Poly1305)

; 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.Hacl_MAC_Poly1305_state_t_s = type { ptr, ptr, i64, ptr }

; 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 dso_local void @Hacl_MAC_Poly1305_poly1305_finish(ptr noundef, ptr noundef, ptr noundef) #1

; 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) #2

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

; Function Attrs: nounwind uwtable
define dso_local void @Hacl_MAC_Poly1305_digest(ptr noundef %0, ptr noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca %struct.Hacl_MAC_Poly1305_state_t_s, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i64, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  %11 = alloca ptr, align 8
  %12 = alloca [25 x i64], align 16
  %13 = alloca ptr, align 8
  %14 = alloca i32, align 4
  %15 = alloca ptr, align 8
  %16 = alloca ptr, align 8
  %17 = alloca [25 x i64], align 16
  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 32, ptr %5) #4
  %18 = load ptr, ptr %3, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %5, ptr align 8 %18, i64 32, i1 false), !tbaa.struct !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  %19 = getelementptr inbounds %struct.Hacl_MAC_Poly1305_state_t_s, ptr %5, i32 0, i32 0
  %20 = load ptr, ptr %19, align 8, !tbaa !12
  store ptr %20, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  %21 = getelementptr inbounds %struct.Hacl_MAC_Poly1305_state_t_s, ptr %5, i32 0, i32 1
  %22 = load ptr, ptr %21, align 8, !tbaa !14
  store ptr %22, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  %23 = getelementptr inbounds %struct.Hacl_MAC_Poly1305_state_t_s, ptr %5, i32 0, i32 2
  %24 = load i64, ptr %23, align 8, !tbaa !15
  store i64 %24, ptr %8, align 8, !tbaa !10
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  %25 = getelementptr inbounds %struct.Hacl_MAC_Poly1305_state_t_s, ptr %5, i32 0, i32 3
  %26 = load ptr, ptr %25, align 8, !tbaa !16
  store ptr %26, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #4
  %27 = load i64, ptr %8, align 8, !tbaa !10
  %28 = urem i64 %27, 16
  %29 = icmp eq i64 %28, 0
  br i1 %29, label %30, label %34

30:                                               ; preds = %2
  %31 = load i64, ptr %8, align 8, !tbaa !10
  %32 = icmp ugt i64 %31, 0
  br i1 %32, label %33, label %34

33:                                               ; preds = %30
  store i32 16, ptr %10, align 4, !tbaa !17
  br label %38

34:                                               ; preds = %30, %2
  %35 = load i64, ptr %8, align 8, !tbaa !10
  %36 = urem i64 %35, 16
  %37 = trunc i64 %36 to i32
  store i32 %37, ptr %10, align 4, !tbaa !17
  br label %38

38:                                               ; preds = %34, %33
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  %39 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %39, ptr %11, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 200, ptr %12) #4
  call void @llvm.memset.p0.i64(ptr align 16 %12, i8 0, i64 200, i1 false)
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #4
  %40 = getelementptr inbounds [25 x i64], ptr %12, i64 0, i64 0
  store ptr %40, ptr %13, align 8, !tbaa !5
  %41 = load ptr, ptr %13, align 8, !tbaa !5
  %42 = load ptr, ptr %6, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %41, ptr align 8 %42, i64 200, i1 false)
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #4
  %43 = load i32, ptr %10, align 4, !tbaa !17
  %44 = urem i32 %43, 16
  %45 = icmp eq i32 %44, 0
  br i1 %45, label %46, label %50

46:                                               ; preds = %38
  %47 = load i32, ptr %10, align 4, !tbaa !17
  %48 = icmp ugt i32 %47, 0
  br i1 %48, label %49, label %50

49:                                               ; preds = %46
  store i32 16, ptr %14, align 4, !tbaa !17
  br label %53

50:                                               ; preds = %46, %38
  %51 = load i32, ptr %10, align 4, !tbaa !17
  %52 = urem i32 %51, 16
  store i32 %52, ptr %14, align 4, !tbaa !17
  br label %53

53:                                               ; preds = %50, %49
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #4
  %54 = load ptr, ptr %11, align 8, !tbaa !5
  %55 = load i32, ptr %10, align 4, !tbaa !17
  %56 = zext i32 %55 to i64
  %57 = getelementptr inbounds i8, ptr %54, i64 %56
  %58 = load i32, ptr %14, align 4, !tbaa !17
  %59 = zext i32 %58 to i64
  %60 = sub i64 0, %59
  %61 = getelementptr inbounds i8, ptr %57, i64 %60
  store ptr %61, ptr %15, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #4
  %62 = load ptr, ptr %11, align 8, !tbaa !5
  store ptr %62, ptr %16, align 8, !tbaa !5
  %63 = load ptr, ptr %13, align 8, !tbaa !5
  %64 = load ptr, ptr %16, align 8, !tbaa !5
  call void @poly1305_update(ptr noundef %63, i32 noundef 0, ptr noundef %64)
  %65 = load ptr, ptr %13, align 8, !tbaa !5
  %66 = load i32, ptr %10, align 4, !tbaa !17
  %67 = load ptr, ptr %15, align 8, !tbaa !5
  call void @poly1305_update(ptr noundef %65, i32 noundef %66, ptr noundef %67)
  call void @llvm.lifetime.start.p0(i64 200, ptr %17) #4
  call void @llvm.memset.p0.i64(ptr align 16 %17, i8 0, i64 200, i1 false)
  %68 = getelementptr inbounds [25 x i64], ptr %17, i64 0, i64 0
  %69 = load ptr, ptr %13, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %68, ptr align 8 %69, i64 200, i1 false)
  %70 = load ptr, ptr %4, align 8, !tbaa !5
  %71 = load ptr, ptr %9, align 8, !tbaa !5
  %72 = getelementptr inbounds [25 x i64], ptr %17, i64 0, i64 0
  call void @Hacl_MAC_Poly1305_poly1305_finish(ptr noundef %70, ptr noundef %71, ptr noundef %72)
  call void @llvm.lifetime.end.p0(i64 200, ptr %17) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #4
  call void @llvm.lifetime.end.p0(i64 200, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 32, ptr %5) #4
  ret void
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #3

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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { nocallback nofree nounwind willreturn memory(argmem: write) }
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 = !{i64 0, i64 8, !5, i64 8, i64 8, !5, i64 16, i64 8, !10, i64 24, i64 8, !5}
!10 = !{!11, !11, i64 0}
!11 = !{!"long", !7, i64 0}
!12 = !{!13, !6, i64 0}
!13 = !{!"Hacl_MAC_Poly1305_state_t_s", !6, i64 0, !6, i64 8, !11, i64 16, !6, i64 24}
!14 = !{!13, !6, i64 8}
!15 = !{!13, !11, i64 16}
!16 = !{!13, !6, i64 24}
!17 = !{!18, !18, i64 0}
!18 = !{!"int", !7, i64 0}


; 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: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

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

; Function Attrs: nounwind uwtable
declare dso_local void @Hacl_MAC_Poly1305_poly1305_finish(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: mustprogress 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) #2

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

; Function Attrs: nounwind uwtable
define dso_local void @Hacl_MAC_Poly1305_digest(ptr nocapture noundef readonly %0, ptr noundef %1) local_unnamed_addr #1 {
  %3 = alloca [25 x i64], align 16
  %4 = alloca [25 x i64], align 16
  %.sroa.0.0.copyload = load ptr, ptr %0, align 8, !tbaa !5
  %.sroa.4.0..sroa_idx = getelementptr inbounds i8, ptr %0, i64 8
  %.sroa.4.0.copyload = load ptr, ptr %.sroa.4.0..sroa_idx, align 8, !tbaa !5
  %.sroa.5.0..sroa_idx = getelementptr inbounds i8, ptr %0, i64 16
  %.sroa.5.0.copyload = load i64, ptr %.sroa.5.0..sroa_idx, align 8, !tbaa !9
  %.sroa.6.0..sroa_idx = getelementptr inbounds i8, ptr %0, i64 24
  %.sroa.6.0.copyload = load ptr, ptr %.sroa.6.0..sroa_idx, align 8, !tbaa !5
  %5 = and i64 %.sroa.5.0.copyload, 15
  %6 = icmp eq i64 %5, 0
  %7 = icmp ne i64 %.sroa.5.0.copyload, 0
  %or.cond = and i1 %7, %6
  %8 = trunc nuw nsw i64 %5 to i32
  %.0 = select i1 %or.cond, i32 16, i32 %8
  call void @llvm.lifetime.start.p0(i64 200, ptr nonnull %3) #3
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 16 dereferenceable(200) %3, ptr noundef nonnull align 8 dereferenceable(200) %.sroa.0.0.copyload, i64 200, i1 false)
  %9 = and i32 %.0, 15
  %10 = icmp eq i32 %9, 0
  %11 = icmp ne i32 %.0, 0
  %or.cond3 = and i1 %11, %10
  %12 = zext nneg i32 %9 to i64
  %.024 = select i1 %or.cond3, i64 16, i64 %12
  %13 = zext nneg i32 %.0 to i64
  %14 = getelementptr inbounds i8, ptr %.sroa.4.0.copyload, i64 %13
  %15 = sub nsw i64 0, %.024
  %16 = getelementptr inbounds i8, ptr %14, i64 %15
  call void @poly1305_update(ptr noundef nonnull %3, i32 noundef 0, ptr noundef %.sroa.4.0.copyload)
  call void @poly1305_update(ptr noundef nonnull %3, i32 noundef %.0, ptr noundef %16)
  call void @llvm.lifetime.start.p0(i64 200, ptr nonnull %4) #3
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 16 dereferenceable(200) %4, ptr noundef nonnull align 16 dereferenceable(200) %3, i64 200, i1 false)
  call void @Hacl_MAC_Poly1305_poly1305_finish(ptr noundef %1, ptr noundef %.sroa.6.0.copyload, ptr noundef nonnull %4)
  call void @llvm.lifetime.end.p0(i64 200, ptr nonnull %4) #3
  call void @llvm.lifetime.end.p0(i64 200, ptr nonnull %3) #3
  ret void
}

attributes #0 = { mustprogress 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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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}


; Effective O3 passes: DSEPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,MemCpyOptPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass