; LLVM IR from openssl/openssl :: crypto/poly1305 (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.poly1305_context = type { [24 x double], [4 x i32], [16 x i8], i64, %struct.anon }
%struct.anon = type { ptr, ptr }

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

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

; 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
define dso_local void @Poly1305_Final(ptr noundef %0, ptr noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = 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) #3
  %6 = load ptr, ptr %3, align 8, !tbaa !5
  %7 = getelementptr inbounds %struct.poly1305_context, ptr %6, i32 0, i32 3
  %8 = load i64, ptr %7, align 8, !tbaa !9
  store i64 %8, ptr %5, align 8, !tbaa !13
  %9 = icmp ne i64 %8, 0
  br i1 %9, label %10, label %32

10:                                               ; preds = %2
  %11 = load ptr, ptr %3, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.poly1305_context, ptr %11, i32 0, i32 2
  %13 = load i64, ptr %5, align 8, !tbaa !13
  %14 = add i64 %13, 1
  store i64 %14, ptr %5, align 8, !tbaa !13
  %15 = getelementptr inbounds [16 x i8], ptr %12, i64 0, i64 %13
  store i8 1, ptr %15, align 1, !tbaa !14
  br label %16

16:                                               ; preds = %19, %10
  %17 = load i64, ptr %5, align 8, !tbaa !13
  %18 = icmp ult i64 %17, 16
  br i1 %18, label %19, label %25

19:                                               ; preds = %16
  %20 = load ptr, ptr %3, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.poly1305_context, ptr %20, i32 0, i32 2
  %22 = load i64, ptr %5, align 8, !tbaa !13
  %23 = add i64 %22, 1
  store i64 %23, ptr %5, align 8, !tbaa !13
  %24 = getelementptr inbounds [16 x i8], ptr %21, i64 0, i64 %22
  store i8 0, ptr %24, align 1, !tbaa !14
  br label %16, !llvm.loop !15

25:                                               ; preds = %16
  %26 = load ptr, ptr %3, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.poly1305_context, ptr %26, i32 0, i32 0
  %28 = getelementptr inbounds [24 x double], ptr %27, i64 0, i64 0
  %29 = load ptr, ptr %3, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.poly1305_context, ptr %29, i32 0, i32 2
  %31 = getelementptr inbounds [16 x i8], ptr %30, i64 0, i64 0
  call void @poly1305_blocks(ptr noundef %28, ptr noundef %31, i64 noundef 16, i32 noundef 0)
  br label %32

32:                                               ; preds = %25, %2
  %33 = load ptr, ptr %3, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.poly1305_context, ptr %33, i32 0, i32 0
  %35 = getelementptr inbounds [24 x double], ptr %34, i64 0, i64 0
  %36 = load ptr, ptr %4, align 8, !tbaa !5
  %37 = load ptr, ptr %3, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.poly1305_context, ptr %37, i32 0, i32 1
  %39 = getelementptr inbounds [4 x i32], ptr %38, i64 0, i64 0
  call void @poly1305_emit(ptr noundef %35, ptr noundef %36, ptr noundef %39)
  %40 = load ptr, ptr %3, align 8, !tbaa !5
  call void @OPENSSL_cleanse(ptr noundef %40, i64 noundef 248)
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  ret void
}

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

declare void @OPENSSL_cleanse(ptr noundef, i64 noundef) #2

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 = { "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 #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, !11, i64 224}
!10 = !{!"poly1305_context", !7, i64 0, !7, i64 192, !7, i64 208, !11, i64 224, !12, i64 232}
!11 = !{!"long", !7, i64 0}
!12 = !{!"", !6, i64 0, !6, i64 8}
!13 = !{!11, !11, i64 0}
!14 = !{!7, !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 void @poly1305_blocks(ptr noundef, ptr noundef, i64 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @Poly1305_Final(ptr noundef %0, ptr noundef %1) local_unnamed_addr #0 {
  %3 = getelementptr inbounds i8, ptr %0, i64 224
  %4 = load i64, ptr %3, align 8, !tbaa !5
  %.not = icmp eq i64 %4, 0
  br i1 %.not, label %11, label %5

5:                                                ; preds = %2
  %6 = getelementptr inbounds i8, ptr %0, i64 208
  %7 = getelementptr inbounds [16 x i8], ptr %6, i64 0, i64 %4
  store i8 1, ptr %7, align 1, !tbaa !12
  %.012 = add i64 %4, 1
  %8 = icmp ult i64 %.012, 16
  br i1 %8, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %5
  %9 = getelementptr i8, ptr %0, i64 %4
  %scevgep = getelementptr i8, ptr %9, i64 209
  %10 = sub nsw i64 15, %4
  tail call void @llvm.memset.p0.i64(ptr align 1 %scevgep, i8 0, i64 %10, i1 false), !tbaa !12
  br label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph.preheader, %5
  tail call void @poly1305_blocks(ptr noundef nonnull %0, ptr noundef nonnull %6, i64 noundef 16, i32 noundef 0)
  br label %11

11:                                               ; preds = %._crit_edge, %2
  %12 = getelementptr inbounds i8, ptr %0, i64 192
  tail call void @poly1305_emit(ptr noundef nonnull %0, ptr noundef %1, ptr noundef nonnull %12)
  tail call void @OPENSSL_cleanse(ptr noundef nonnull %0, i64 noundef 248) #3
  ret void
}

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

declare void @OPENSSL_cleanse(ptr noundef, i64 noundef) local_unnamed_addr #1

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

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 = { "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: write) }
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, !9, i64 224}
!6 = !{!"poly1305_context", !7, i64 0, !7, i64 192, !7, i64 208, !9, i64 224, !10, i64 232}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!"long", !7, i64 0}
!10 = !{!"", !11, i64 0, !11, i64 8}
!11 = !{!"any pointer", !7, i64 0}
!12 = !{!7, !7, i64 0}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LoopIdiomRecognizePass,LoopRotatePass,LoopSimplifyPass,SROAPass,SimplifyCFGPass,TailCallElimPass