; LLVM IR from vergecurrency/verge :: src/crypto/chacha20.ll (ZN8ChaCha206SetKeyEPKhm)

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

%class.ChaCha20 = type { [16 x i32] }

@_ZL5sigma = external hidden constant [17 x i8], align 16
@_ZL3tau = external hidden constant [17 x i8], align 16

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

31:                                               ; preds = %3
  %32 = load ptr, ptr %5, align 8, !tbaa !5
  %33 = getelementptr inbounds i8, ptr %32, i64 16
  store ptr %33, ptr %5, align 8, !tbaa !5
  store ptr @_ZL5sigma, ptr %7, align 8, !tbaa !5
  br label %35

34:                                               ; preds = %3
  store ptr @_ZL3tau, ptr %7, align 8, !tbaa !5
  br label %35

35:                                               ; preds = %34, %31
  %36 = load ptr, ptr %5, align 8, !tbaa !5
  %37 = getelementptr inbounds i8, ptr %36, i64 0
  %38 = call noundef i32 @_ZL8ReadLE32PKh(ptr noundef %37)
  %39 = getelementptr inbounds %class.ChaCha20, ptr %8, i32 0, i32 0
  %40 = getelementptr inbounds [16 x i32], ptr %39, i64 0, i64 8
  store i32 %38, ptr %40, align 4, !tbaa !11
  %41 = load ptr, ptr %5, align 8, !tbaa !5
  %42 = getelementptr inbounds i8, ptr %41, i64 4
  %43 = call noundef i32 @_ZL8ReadLE32PKh(ptr noundef %42)
  %44 = getelementptr inbounds %class.ChaCha20, ptr %8, i32 0, i32 0
  %45 = getelementptr inbounds [16 x i32], ptr %44, i64 0, i64 9
  store i32 %43, ptr %45, align 4, !tbaa !11
  %46 = load ptr, ptr %5, align 8, !tbaa !5
  %47 = getelementptr inbounds i8, ptr %46, i64 8
  %48 = call noundef i32 @_ZL8ReadLE32PKh(ptr noundef %47)
  %49 = getelementptr inbounds %class.ChaCha20, ptr %8, i32 0, i32 0
  %50 = getelementptr inbounds [16 x i32], ptr %49, i64 0, i64 10
  store i32 %48, ptr %50, align 4, !tbaa !11
  %51 = load ptr, ptr %5, align 8, !tbaa !5
  %52 = getelementptr inbounds i8, ptr %51, i64 12
  %53 = call noundef i32 @_ZL8ReadLE32PKh(ptr noundef %52)
  %54 = getelementptr inbounds %class.ChaCha20, ptr %8, i32 0, i32 0
  %55 = getelementptr inbounds [16 x i32], ptr %54, i64 0, i64 11
  store i32 %53, ptr %55, align 4, !tbaa !11
  %56 = load ptr, ptr %7, align 8, !tbaa !5
  %57 = getelementptr inbounds i8, ptr %56, i64 0
  %58 = call noundef i32 @_ZL8ReadLE32PKh(ptr noundef %57)
  %59 = getelementptr inbounds %class.ChaCha20, ptr %8, i32 0, i32 0
  %60 = getelementptr inbounds [16 x i32], ptr %59, i64 0, i64 0
  store i32 %58, ptr %60, align 4, !tbaa !11
  %61 = load ptr, ptr %7, align 8, !tbaa !5
  %62 = getelementptr inbounds i8, ptr %61, i64 4
  %63 = call noundef i32 @_ZL8ReadLE32PKh(ptr noundef %62)
  %64 = getelementptr inbounds %class.ChaCha20, ptr %8, i32 0, i32 0
  %65 = getelementptr inbounds [16 x i32], ptr %64, i64 0, i64 1
  store i32 %63, ptr %65, align 4, !tbaa !11
  %66 = load ptr, ptr %7, align 8, !tbaa !5
  %67 = getelementptr inbounds i8, ptr %66, i64 8
  %68 = call noundef i32 @_ZL8ReadLE32PKh(ptr noundef %67)
  %69 = getelementptr inbounds %class.ChaCha20, ptr %8, i32 0, i32 0
  %70 = getelementptr inbounds [16 x i32], ptr %69, i64 0, i64 2
  store i32 %68, ptr %70, align 4, !tbaa !11
  %71 = load ptr, ptr %7, align 8, !tbaa !5
  %72 = getelementptr inbounds i8, ptr %71, i64 12
  %73 = call noundef i32 @_ZL8ReadLE32PKh(ptr noundef %72)
  %74 = getelementptr inbounds %class.ChaCha20, ptr %8, i32 0, i32 0
  %75 = getelementptr inbounds [16 x i32], ptr %74, i64 0, i64 3
  store i32 %73, ptr %75, align 4, !tbaa !11
  %76 = getelementptr inbounds %class.ChaCha20, ptr %8, i32 0, i32 0
  %77 = getelementptr inbounds [16 x i32], ptr %76, i64 0, i64 12
  store i32 0, ptr %77, align 4, !tbaa !11
  %78 = getelementptr inbounds %class.ChaCha20, ptr %8, i32 0, i32 0
  %79 = getelementptr inbounds [16 x i32], ptr %78, i64 0, i64 13
  store i32 0, ptr %79, align 4, !tbaa !11
  %80 = getelementptr inbounds %class.ChaCha20, ptr %8, i32 0, i32 0
  %81 = getelementptr inbounds [16 x i32], ptr %80, i64 0, i64 14
  store i32 0, ptr %81, align 4, !tbaa !11
  %82 = getelementptr inbounds %class.ChaCha20, ptr %8, i32 0, i32 0
  %83 = getelementptr inbounds [16 x i32], ptr %82, i64 0, i64 15
  store i32 0, ptr %83, align 4, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  ret void
}

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

; Function Attrs: inlinehint mustprogress uwtable
declare hidden noundef i32 @_ZL8ReadLE32PKh(ptr noundef) #2

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

attributes #0 = { mustprogress 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 = { inlinehint mustprogress 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 #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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"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"

@_ZL5sigma = external hidden constant [17 x i8], align 16
@_ZL3tau = external hidden constant [17 x i8], align 16

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN8ChaCha206SetKeyEPKhm(ptr nocapture noundef nonnull writeonly align 4 dereferenceable(64) %0, ptr noundef %1, i64 noundef %2) local_unnamed_addr #0 align 2 {
  %4 = tail call noundef i32 @_ZL8ReadLE32PKh(ptr noundef %1)
  %5 = getelementptr inbounds i8, ptr %0, i64 16
  store i32 %4, ptr %5, align 4, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %1, i64 4
  %7 = tail call noundef i32 @_ZL8ReadLE32PKh(ptr noundef nonnull %6)
  %8 = getelementptr inbounds i8, ptr %0, i64 20
  store i32 %7, ptr %8, align 4, !tbaa !5
  %9 = getelementptr inbounds i8, ptr %1, i64 8
  %10 = tail call noundef i32 @_ZL8ReadLE32PKh(ptr noundef nonnull %9)
  %11 = getelementptr inbounds i8, ptr %0, i64 24
  store i32 %10, ptr %11, align 4, !tbaa !5
  %12 = getelementptr inbounds i8, ptr %1, i64 12
  %13 = tail call noundef i32 @_ZL8ReadLE32PKh(ptr noundef nonnull %12)
  %14 = getelementptr inbounds i8, ptr %0, i64 28
  store i32 %13, ptr %14, align 4, !tbaa !5
  %15 = icmp eq i64 %2, 32
  %.014.idx = select i1 %15, i64 16, i64 0
  %.014 = getelementptr inbounds i8, ptr %1, i64 %.014.idx
  %.0 = select i1 %15, ptr @_ZL5sigma, ptr @_ZL3tau
  %16 = tail call noundef i32 @_ZL8ReadLE32PKh(ptr noundef %.014)
  %17 = getelementptr inbounds i8, ptr %0, i64 32
  store i32 %16, ptr %17, align 4, !tbaa !5
  %18 = getelementptr inbounds i8, ptr %.014, i64 4
  %19 = tail call noundef i32 @_ZL8ReadLE32PKh(ptr noundef nonnull %18)
  %20 = getelementptr inbounds i8, ptr %0, i64 36
  store i32 %19, ptr %20, align 4, !tbaa !5
  %21 = getelementptr inbounds i8, ptr %.014, i64 8
  %22 = tail call noundef i32 @_ZL8ReadLE32PKh(ptr noundef nonnull %21)
  %23 = getelementptr inbounds i8, ptr %0, i64 40
  store i32 %22, ptr %23, align 4, !tbaa !5
  %24 = getelementptr inbounds i8, ptr %.014, i64 12
  %25 = tail call noundef i32 @_ZL8ReadLE32PKh(ptr noundef nonnull %24)
  %26 = getelementptr inbounds i8, ptr %0, i64 44
  store i32 %25, ptr %26, align 4, !tbaa !5
  %27 = tail call noundef i32 @_ZL8ReadLE32PKh(ptr noundef nonnull %.0)
  store i32 %27, ptr %0, align 4, !tbaa !5
  %28 = select i1 %15, ptr getelementptr inbounds (i8, ptr @_ZL5sigma, i64 4), ptr getelementptr inbounds (i8, ptr @_ZL3tau, i64 4)
  %29 = tail call noundef i32 @_ZL8ReadLE32PKh(ptr noundef nonnull %28)
  %30 = getelementptr inbounds i8, ptr %0, i64 4
  store i32 %29, ptr %30, align 4, !tbaa !5
  %31 = select i1 %15, ptr getelementptr inbounds (i8, ptr @_ZL5sigma, i64 8), ptr getelementptr inbounds (i8, ptr @_ZL3tau, i64 8)
  %32 = tail call noundef i32 @_ZL8ReadLE32PKh(ptr noundef nonnull %31)
  %33 = getelementptr inbounds i8, ptr %0, i64 8
  store i32 %32, ptr %33, align 4, !tbaa !5
  %34 = select i1 %15, ptr getelementptr inbounds (i8, ptr @_ZL5sigma, i64 12), ptr getelementptr inbounds (i8, ptr @_ZL3tau, i64 12)
  %35 = tail call noundef i32 @_ZL8ReadLE32PKh(ptr noundef nonnull %34)
  %36 = getelementptr inbounds i8, ptr %0, i64 12
  store i32 %35, ptr %36, align 4, !tbaa !5
  %37 = getelementptr inbounds i8, ptr %0, i64 48
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 4 dereferenceable(16) %37, i8 0, i64 16, i1 false)
  ret void
}

; Function Attrs: inlinehint mustprogress uwtable
declare hidden noundef i32 @_ZL8ReadLE32PKh(ptr 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 = { mustprogress 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 = { inlinehint mustprogress 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: write) }

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


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