; 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: nounwind uwtable
define dso_local void @Poly1305_Update(ptr noundef %0, ptr noundef %1, i64 noundef %2) #0 {
  %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 i32, align 4
  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) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  %10 = load ptr, ptr %4, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.poly1305_context, ptr %10, i32 0, i32 3
  %12 = load i64, ptr %11, align 8, !tbaa !11
  store i64 %12, ptr %8, align 8, !tbaa !9
  %13 = icmp ne i64 %12, 0
  br i1 %13, label %14, label %54

14:                                               ; preds = %3
  %15 = load i64, ptr %8, align 8, !tbaa !9
  %16 = sub i64 16, %15
  store i64 %16, ptr %7, align 8, !tbaa !9
  %17 = load i64, ptr %6, align 8, !tbaa !9
  %18 = load i64, ptr %7, align 8, !tbaa !9
  %19 = icmp uge i64 %17, %18
  br i1 %19, label %20, label %40

20:                                               ; preds = %14
  %21 = load ptr, ptr %4, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.poly1305_context, ptr %21, i32 0, i32 2
  %23 = getelementptr inbounds [16 x i8], ptr %22, i64 0, i64 0
  %24 = load i64, ptr %8, align 8, !tbaa !9
  %25 = getelementptr inbounds i8, ptr %23, i64 %24
  %26 = load ptr, ptr %5, align 8, !tbaa !5
  %27 = load i64, ptr %7, align 8, !tbaa !9
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %25, ptr align 1 %26, i64 %27, i1 false)
  %28 = load ptr, ptr %4, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.poly1305_context, ptr %28, i32 0, i32 0
  %30 = getelementptr inbounds [24 x double], ptr %29, i64 0, i64 0
  %31 = load ptr, ptr %4, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.poly1305_context, ptr %31, i32 0, i32 2
  %33 = getelementptr inbounds [16 x i8], ptr %32, i64 0, i64 0
  call void @poly1305_blocks(ptr noundef %30, ptr noundef %33, i64 noundef 16, i32 noundef 1)
  %34 = load i64, ptr %7, align 8, !tbaa !9
  %35 = load ptr, ptr %5, align 8, !tbaa !5
  %36 = getelementptr inbounds i8, ptr %35, i64 %34
  store ptr %36, ptr %5, align 8, !tbaa !5
  %37 = load i64, ptr %7, align 8, !tbaa !9
  %38 = load i64, ptr %6, align 8, !tbaa !9
  %39 = sub i64 %38, %37
  store i64 %39, ptr %6, align 8, !tbaa !9
  br label %53

40:                                               ; preds = %14
  %41 = load ptr, ptr %4, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.poly1305_context, ptr %41, i32 0, i32 2
  %43 = getelementptr inbounds [16 x i8], ptr %42, i64 0, i64 0
  %44 = load i64, ptr %8, align 8, !tbaa !9
  %45 = getelementptr inbounds i8, ptr %43, i64 %44
  %46 = load ptr, ptr %5, align 8, !tbaa !5
  %47 = load i64, ptr %6, align 8, !tbaa !9
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %45, ptr align 1 %46, i64 %47, i1 false)
  %48 = load i64, ptr %8, align 8, !tbaa !9
  %49 = load i64, ptr %6, align 8, !tbaa !9
  %50 = add i64 %48, %49
  %51 = load ptr, ptr %4, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.poly1305_context, ptr %51, i32 0, i32 3
  store i64 %50, ptr %52, align 8, !tbaa !11
  store i32 1, ptr %9, align 4
  br label %84

53:                                               ; preds = %20
  br label %54

54:                                               ; preds = %53, %3
  %55 = load i64, ptr %6, align 8, !tbaa !9
  %56 = urem i64 %55, 16
  store i64 %56, ptr %7, align 8, !tbaa !9
  %57 = load i64, ptr %7, align 8, !tbaa !9
  %58 = load i64, ptr %6, align 8, !tbaa !9
  %59 = sub i64 %58, %57
  store i64 %59, ptr %6, align 8, !tbaa !9
  %60 = load i64, ptr %6, align 8, !tbaa !9
  %61 = icmp uge i64 %60, 16
  br i1 %61, label %62, label %71

62:                                               ; preds = %54
  %63 = load ptr, ptr %4, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.poly1305_context, ptr %63, i32 0, i32 0
  %65 = getelementptr inbounds [24 x double], ptr %64, i64 0, i64 0
  %66 = load ptr, ptr %5, align 8, !tbaa !5
  %67 = load i64, ptr %6, align 8, !tbaa !9
  call void @poly1305_blocks(ptr noundef %65, ptr noundef %66, i64 noundef %67, i32 noundef 1)
  %68 = load i64, ptr %6, align 8, !tbaa !9
  %69 = load ptr, ptr %5, align 8, !tbaa !5
  %70 = getelementptr inbounds i8, ptr %69, i64 %68
  store ptr %70, ptr %5, align 8, !tbaa !5
  br label %71

71:                                               ; preds = %62, %54
  %72 = load i64, ptr %7, align 8, !tbaa !9
  %73 = icmp ne i64 %72, 0
  br i1 %73, label %74, label %80

74:                                               ; preds = %71
  %75 = load ptr, ptr %4, align 8, !tbaa !5
  %76 = getelementptr inbounds %struct.poly1305_context, ptr %75, i32 0, i32 2
  %77 = getelementptr inbounds [16 x i8], ptr %76, i64 0, i64 0
  %78 = load ptr, ptr %5, align 8, !tbaa !5
  %79 = load i64, ptr %7, align 8, !tbaa !9
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %77, ptr align 1 %78, i64 %79, i1 false)
  br label %80

80:                                               ; preds = %74, %71
  %81 = load i64, ptr %7, align 8, !tbaa !9
  %82 = load ptr, ptr %4, align 8, !tbaa !5
  %83 = getelementptr inbounds %struct.poly1305_context, ptr %82, i32 0, i32 3
  store i64 %81, ptr %83, align 8, !tbaa !11
  store i32 0, ptr %9, align 4
  br label %84

84:                                               ; preds = %80, %40
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  %85 = load i32, ptr %9, align 4
  switch i32 %85, label %87 [
    i32 0, label %86
    i32 1, label %86
  ]

86:                                               ; preds = %84, %84
  ret void

87:                                               ; preds = %84
  unreachable
}

; 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 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_blocks(ptr noundef, ptr noundef, i64 noundef, i32 noundef) #0

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 willreturn memory(argmem: readwrite) }
attributes #2 = { 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}
!11 = !{!12, !10, i64 224}
!12 = !{!"poly1305_context", !7, i64 0, !7, i64 192, !7, i64 208, !10, i64 224, !13, i64 232}
!13 = !{!"", !6, i64 0, !6, i64 8}


; 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
define dso_local void @Poly1305_Update(ptr noundef %0, ptr noundef %1, i64 noundef %2) local_unnamed_addr #0 {
  %4 = getelementptr inbounds i8, ptr %0, i64 224
  %5 = load i64, ptr %4, align 8, !tbaa !5
  %.not = icmp eq i64 %5, 0
  br i1 %.not, label %15, label %6

6:                                                ; preds = %3
  %7 = sub i64 16, %5
  %.not42 = icmp ugt i64 %7, %2
  %8 = getelementptr inbounds i8, ptr %0, i64 208
  %9 = getelementptr inbounds i8, ptr %8, i64 %5
  br i1 %.not42, label %13, label %10

10:                                               ; preds = %6
  tail call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 1 %9, ptr align 1 %1, i64 %7, i1 false)
  tail call void @poly1305_blocks(ptr noundef nonnull %0, ptr noundef nonnull %8, i64 noundef 16, i32 noundef 1)
  %11 = getelementptr inbounds i8, ptr %1, i64 %7
  %12 = sub i64 %2, %7
  br label %15

13:                                               ; preds = %6
  tail call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 1 %9, ptr align 1 %1, i64 %2, i1 false)
  %14 = add i64 %5, %2
  br label %24

15:                                               ; preds = %10, %3
  %.035 = phi i64 [ %12, %10 ], [ %2, %3 ]
  %.0 = phi ptr [ %11, %10 ], [ %1, %3 ]
  %16 = and i64 %.035, 15
  %17 = icmp ugt i64 %.035, 15
  br i1 %17, label %18, label %21

18:                                               ; preds = %15
  %19 = and i64 %.035, -16
  tail call void @poly1305_blocks(ptr noundef nonnull %0, ptr noundef %.0, i64 noundef %19, i32 noundef 1)
  %20 = getelementptr inbounds i8, ptr %.0, i64 %19
  br label %21

21:                                               ; preds = %18, %15
  %.1 = phi ptr [ %20, %18 ], [ %.0, %15 ]
  %.not43 = icmp eq i64 %16, 0
  br i1 %.not43, label %24, label %22

22:                                               ; preds = %21
  %23 = getelementptr inbounds i8, ptr %0, i64 208
  tail call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 8 %23, ptr align 1 %.1, i64 %16, i1 false)
  br label %24

24:                                               ; preds = %21, %22, %13
  %storemerge = phi i64 [ %14, %13 ], [ %16, %22 ], [ 0, %21 ]
  store i64 %storemerge, ptr %4, align 8, !tbaa !5
  ret void
}

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

; Function Attrs: nounwind uwtable
declare hidden void @poly1305_blocks(ptr noundef, ptr noundef, i64 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 nounwind willreturn memory(argmem: readwrite) }

!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}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,SROAPass,SimplifyCFGPass,TailCallElimPass