; LLVM IR from kcchu/rust-tweetnacl :: tweetnacl (crypto_hash_sha512_tweet)

; 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"

@iv = external hidden constant [64 x i8], align 16

; 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 i32 @crypto_hashblocks_sha512_tweet(ptr noundef, ptr noundef, i64 noundef) #1

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

; Function Attrs: nounwind uwtable
define dso_local i32 @crypto_hash_sha512_tweet(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 [64 x i8], align 16
  %8 = alloca [256 x i8], align 16
  %9 = alloca i64, align 8
  %10 = 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 64, ptr %7) #2
  call void @llvm.lifetime.start.p0(i64 256, ptr %8) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #2
  %11 = load i64, ptr %6, align 8, !tbaa !9
  store i64 %11, ptr %10, align 8, !tbaa !9
  store i64 0, ptr %9, align 8, !tbaa !9
  br label %12

12:                                               ; preds = %21, %3
  %13 = load i64, ptr %9, align 8, !tbaa !9
  %14 = icmp ult i64 %13, 64
  br i1 %14, label %15, label %24

15:                                               ; preds = %12
  %16 = load i64, ptr %9, align 8, !tbaa !9
  %17 = getelementptr inbounds [64 x i8], ptr @iv, i64 0, i64 %16
  %18 = load i8, ptr %17, align 1, !tbaa !11
  %19 = load i64, ptr %9, align 8, !tbaa !9
  %20 = getelementptr inbounds [64 x i8], ptr %7, i64 0, i64 %19
  store i8 %18, ptr %20, align 1, !tbaa !11
  br label %21

21:                                               ; preds = %15
  %22 = load i64, ptr %9, align 8, !tbaa !9
  %23 = add i64 %22, 1
  store i64 %23, ptr %9, align 8, !tbaa !9
  br label %12, !llvm.loop !12

24:                                               ; preds = %12
  %25 = getelementptr inbounds [64 x i8], ptr %7, i64 0, i64 0
  %26 = load ptr, ptr %5, align 8, !tbaa !5
  %27 = load i64, ptr %6, align 8, !tbaa !9
  %28 = call i32 @crypto_hashblocks_sha512_tweet(ptr noundef %25, ptr noundef %26, i64 noundef %27)
  %29 = load i64, ptr %6, align 8, !tbaa !9
  %30 = load ptr, ptr %5, align 8, !tbaa !5
  %31 = getelementptr inbounds i8, ptr %30, i64 %29
  store ptr %31, ptr %5, align 8, !tbaa !5
  %32 = load i64, ptr %6, align 8, !tbaa !9
  %33 = and i64 %32, 127
  store i64 %33, ptr %6, align 8, !tbaa !9
  %34 = load i64, ptr %6, align 8, !tbaa !9
  %35 = load ptr, ptr %5, align 8, !tbaa !5
  %36 = sub i64 0, %34
  %37 = getelementptr inbounds i8, ptr %35, i64 %36
  store ptr %37, ptr %5, align 8, !tbaa !5
  store i64 0, ptr %9, align 8, !tbaa !9
  br label %38

38:                                               ; preds = %44, %24
  %39 = load i64, ptr %9, align 8, !tbaa !9
  %40 = icmp ult i64 %39, 256
  br i1 %40, label %41, label %47

41:                                               ; preds = %38
  %42 = load i64, ptr %9, align 8, !tbaa !9
  %43 = getelementptr inbounds [256 x i8], ptr %8, i64 0, i64 %42
  store i8 0, ptr %43, align 1, !tbaa !11
  br label %44

44:                                               ; preds = %41
  %45 = load i64, ptr %9, align 8, !tbaa !9
  %46 = add i64 %45, 1
  store i64 %46, ptr %9, align 8, !tbaa !9
  br label %38, !llvm.loop !14

47:                                               ; preds = %38
  store i64 0, ptr %9, align 8, !tbaa !9
  br label %48

48:                                               ; preds = %59, %47
  %49 = load i64, ptr %9, align 8, !tbaa !9
  %50 = load i64, ptr %6, align 8, !tbaa !9
  %51 = icmp ult i64 %49, %50
  br i1 %51, label %52, label %62

52:                                               ; preds = %48
  %53 = load ptr, ptr %5, align 8, !tbaa !5
  %54 = load i64, ptr %9, align 8, !tbaa !9
  %55 = getelementptr inbounds i8, ptr %53, i64 %54
  %56 = load i8, ptr %55, align 1, !tbaa !11
  %57 = load i64, ptr %9, align 8, !tbaa !9
  %58 = getelementptr inbounds [256 x i8], ptr %8, i64 0, i64 %57
  store i8 %56, ptr %58, align 1, !tbaa !11
  br label %59

59:                                               ; preds = %52
  %60 = load i64, ptr %9, align 8, !tbaa !9
  %61 = add i64 %60, 1
  store i64 %61, ptr %9, align 8, !tbaa !9
  br label %48, !llvm.loop !15

62:                                               ; preds = %48
  %63 = load i64, ptr %6, align 8, !tbaa !9
  %64 = getelementptr inbounds [256 x i8], ptr %8, i64 0, i64 %63
  store i8 -128, ptr %64, align 1, !tbaa !11
  %65 = load i64, ptr %6, align 8, !tbaa !9
  %66 = icmp ult i64 %65, 112
  %67 = zext i1 %66 to i32
  %68 = mul nsw i32 128, %67
  %69 = sub nsw i32 256, %68
  %70 = sext i32 %69 to i64
  store i64 %70, ptr %6, align 8, !tbaa !9
  %71 = load i64, ptr %10, align 8, !tbaa !9
  %72 = lshr i64 %71, 61
  %73 = trunc i64 %72 to i8
  %74 = load i64, ptr %6, align 8, !tbaa !9
  %75 = sub i64 %74, 9
  %76 = getelementptr inbounds [256 x i8], ptr %8, i64 0, i64 %75
  store i8 %73, ptr %76, align 1, !tbaa !11
  %77 = getelementptr inbounds [256 x i8], ptr %8, i64 0, i64 0
  %78 = load i64, ptr %6, align 8, !tbaa !9
  %79 = getelementptr inbounds i8, ptr %77, i64 %78
  %80 = getelementptr inbounds i8, ptr %79, i64 -8
  %81 = load i64, ptr %10, align 8, !tbaa !9
  %82 = shl i64 %81, 3
  call void @ts64(ptr noundef %80, i64 noundef %82)
  %83 = getelementptr inbounds [64 x i8], ptr %7, i64 0, i64 0
  %84 = getelementptr inbounds [256 x i8], ptr %8, i64 0, i64 0
  %85 = load i64, ptr %6, align 8, !tbaa !9
  %86 = call i32 @crypto_hashblocks_sha512_tweet(ptr noundef %83, ptr noundef %84, i64 noundef %85)
  store i64 0, ptr %9, align 8, !tbaa !9
  br label %87

87:                                               ; preds = %97, %62
  %88 = load i64, ptr %9, align 8, !tbaa !9
  %89 = icmp ult i64 %88, 64
  br i1 %89, label %90, label %100

90:                                               ; preds = %87
  %91 = load i64, ptr %9, align 8, !tbaa !9
  %92 = getelementptr inbounds [64 x i8], ptr %7, i64 0, i64 %91
  %93 = load i8, ptr %92, align 1, !tbaa !11
  %94 = load ptr, ptr %4, align 8, !tbaa !5
  %95 = load i64, ptr %9, align 8, !tbaa !9
  %96 = getelementptr inbounds i8, ptr %94, i64 %95
  store i8 %93, ptr %96, align 1, !tbaa !11
  br label %97

97:                                               ; preds = %90
  %98 = load i64, ptr %9, align 8, !tbaa !9
  %99 = add i64 %98, 1
  store i64 %99, ptr %9, align 8, !tbaa !9
  br label %87, !llvm.loop !16

100:                                              ; preds = %87
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #2
  call void @llvm.lifetime.end.p0(i64 256, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 64, ptr %7) #2
  ret i32 0
}

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 long", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = distinct !{!14, !13}
!15 = distinct !{!15, !13}
!16 = distinct !{!16, !13}


; 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"

@iv = external hidden local_unnamed_addr constant [64 x i8], align 16

; 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 i32 @crypto_hashblocks_sha512_tweet(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #1

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

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @crypto_hash_sha512_tweet(ptr nocapture noundef writeonly %0, ptr noundef %1, i64 noundef %2) local_unnamed_addr #1 {
.preheader:
  %3 = alloca [64 x i8], align 16
  %4 = alloca [256 x i8], align 16
  call void @llvm.lifetime.start.p0(i64 64, ptr nonnull %3) #4
  call void @llvm.lifetime.start.p0(i64 256, ptr nonnull %4) #4
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 16 dereferenceable(64) %3, ptr noundef nonnull align 16 dereferenceable(64) @iv, i64 64, i1 false), !tbaa !5
  %5 = call i32 @crypto_hashblocks_sha512_tweet(ptr noundef nonnull %3, ptr noundef %1, i64 noundef %2)
  %6 = and i64 %2, 127
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(256) %4, i8 0, i64 256, i1 false), !tbaa !5
  %.not = icmp eq i64 %6, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %.preheader
  %7 = getelementptr i8, ptr %1, i64 %2
  %8 = sub nsw i64 0, %6
  %9 = getelementptr i8, ptr %7, i64 %8
  call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 16 %4, ptr align 1 %9, i64 %6, i1 false), !tbaa !5
  br label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph.preheader, %.preheader
  %10 = getelementptr inbounds [256 x i8], ptr %4, i64 0, i64 %6
  store i8 -128, ptr %10, align 1, !tbaa !5
  %11 = icmp ult i64 %6, 112
  %12 = select i1 %11, i64 128, i64 256
  %13 = lshr i64 %2, 61
  %14 = trunc nuw nsw i64 %13 to i8
  %15 = add nsw i64 %12, -9
  %16 = getelementptr inbounds [256 x i8], ptr %4, i64 0, i64 %15
  store i8 %14, ptr %16, align 1, !tbaa !5
  %.sroa.sel.sroa.sel.v.sroa.sel.v.sroa.sel.v = select i1 %11, i64 120, i64 248
  %.sroa.sel.sroa.sel.v.sroa.sel.v.sroa.sel = getelementptr inbounds i8, ptr %4, i64 %.sroa.sel.sroa.sel.v.sroa.sel.v.sroa.sel.v
  %17 = shl i64 %2, 3
  call void @ts64(ptr noundef nonnull %.sroa.sel.sroa.sel.v.sroa.sel.v.sroa.sel, i64 noundef %17)
  %18 = call i32 @crypto_hashblocks_sha512_tweet(ptr noundef nonnull %3, ptr noundef nonnull %4, i64 noundef %12)
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 1 dereferenceable(64) %0, ptr noundef nonnull align 16 dereferenceable(64) %3, i64 64, i1 false), !tbaa !5
  call void @llvm.lifetime.end.p0(i64 256, ptr nonnull %4) #4
  call void @llvm.lifetime.end.p0(i64 64, ptr nonnull %3) #4
  ret i32 0
}

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

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 = { 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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}


; Effective O3 passes: BDCEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LoopIdiomRecognizePass,LoopRotatePass,LoopSimplifyPass,PostOrderFunctionAttrsPass,SCCPPass,SROAPass,SimplifyCFGPass