; LLVM IR from square/subzero :: core/external-crypto/modes (cwc)

; 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.cwc_ctx = type { [4 x i32], [4 x i32], [4 x i32], [1 x %struct.aes_crypt_ctx], [4 x i32], [8 x i32], i32, i32, i32, [4 x i8] }
%struct.aes_crypt_ctx = type { [60 x i32], %union.aes_inf, [12 x i8] }
%union.aes_inf = type { i32 }

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

; Function Attrs: nounwind uwtable
define dso_local i32 @cwc_init_message(ptr noundef %0, i64 noundef %1, ptr noundef %2) #2 {
  %4 = alloca ptr, align 8
  %5 = alloca i64, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i64 %1, ptr %5, align 8, !tbaa !9
  store ptr %2, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  %8 = load ptr, ptr %6, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct.cwc_ctx, ptr %8, i32 0, i32 0
  %10 = getelementptr inbounds [4 x i32], ptr %9, i64 0, i64 0
  %11 = getelementptr inbounds i8, ptr %10, i64 0
  store i8 -128, ptr %11, align 16, !tbaa !11
  store i32 0, ptr %7, align 4, !tbaa !12
  br label %12

12:                                               ; preds = %28, %3
  %13 = load i32, ptr %7, align 4, !tbaa !12
  %14 = icmp ult i32 %13, 11
  br i1 %14, label %15, label %31

15:                                               ; preds = %12
  %16 = load ptr, ptr %4, align 8, !tbaa !5
  %17 = load i32, ptr %7, align 4, !tbaa !12
  %18 = zext i32 %17 to i64
  %19 = getelementptr inbounds i8, ptr %16, i64 %18
  %20 = load i8, ptr %19, align 1, !tbaa !11
  %21 = load ptr, ptr %6, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.cwc_ctx, ptr %21, i32 0, i32 0
  %23 = getelementptr inbounds [4 x i32], ptr %22, i64 0, i64 0
  %24 = load i32, ptr %7, align 4, !tbaa !12
  %25 = add i32 %24, 1
  %26 = zext i32 %25 to i64
  %27 = getelementptr inbounds i8, ptr %23, i64 %26
  store i8 %20, ptr %27, align 1, !tbaa !11
  br label %28

28:                                               ; preds = %15
  %29 = load i32, ptr %7, align 4, !tbaa !12
  %30 = add i32 %29, 1
  store i32 %30, ptr %7, align 4, !tbaa !12
  br label %12, !llvm.loop !14

31:                                               ; preds = %12
  %32 = load ptr, ptr %6, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.cwc_ctx, ptr %32, i32 0, i32 0
  %34 = getelementptr inbounds [4 x i32], ptr %33, i64 0, i64 0
  %35 = getelementptr inbounds i8, ptr %34, i64 12
  store i32 0, ptr %35, align 4, !tbaa !12
  %36 = load ptr, ptr %6, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.cwc_ctx, ptr %36, i32 0, i32 2
  %38 = getelementptr inbounds [4 x i32], ptr %37, i64 0, i64 0
  call void @llvm.memset.p0.i64(ptr align 16 %38, i8 0, i64 16, i1 false)
  %39 = load ptr, ptr %6, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.cwc_ctx, ptr %39, i32 0, i32 6
  store i32 0, ptr %40, align 16, !tbaa !16
  %41 = load ptr, ptr %6, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.cwc_ctx, ptr %41, i32 0, i32 8
  store i32 0, ptr %42, align 8, !tbaa !18
  %43 = load ptr, ptr %6, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.cwc_ctx, ptr %43, i32 0, i32 7
  store i32 0, ptr %44, align 4, !tbaa !19
  %45 = load ptr, ptr %6, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.cwc_ctx, ptr %45, i32 0, i32 5
  %47 = getelementptr inbounds [8 x i32], ptr %46, i64 0, i64 0
  call void @llvm.memset.p0.i64(ptr align 16 %47, i8 0, i64 32, i1 false)
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  ret i32 0
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #2 = { 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 #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 = !{!7, !7, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"int", !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = !{!17, !13, i64 352}
!17 = !{!"", !7, i64 0, !7, i64 16, !7, i64 32, !7, i64 48, !7, i64 304, !7, i64 320, !13, i64 352, !13, i64 356, !13, i64 360}
!18 = !{!17, !13, i64 360}
!19 = !{!17, !13, i64 356}


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

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: readwrite) uwtable
define dso_local noundef i32 @cwc_init_message(ptr nocapture noundef readonly %0, i64 noundef %1, ptr nocapture noundef writeonly %2) local_unnamed_addr #1 {
  store i8 -128, ptr %2, align 16, !tbaa !5
  %4 = load i8, ptr %0, align 1, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %2, i64 1
  store i8 %4, ptr %5, align 1, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %0, i64 1
  %7 = load i8, ptr %6, align 1, !tbaa !5
  %8 = getelementptr inbounds i8, ptr %2, i64 2
  store i8 %7, ptr %8, align 1, !tbaa !5
  %9 = getelementptr inbounds i8, ptr %0, i64 2
  %10 = load i8, ptr %9, align 1, !tbaa !5
  %11 = getelementptr inbounds i8, ptr %2, i64 3
  store i8 %10, ptr %11, align 1, !tbaa !5
  %12 = getelementptr inbounds i8, ptr %0, i64 3
  %13 = load i8, ptr %12, align 1, !tbaa !5
  %14 = getelementptr inbounds i8, ptr %2, i64 4
  store i8 %13, ptr %14, align 1, !tbaa !5
  %15 = getelementptr inbounds i8, ptr %0, i64 4
  %16 = load i8, ptr %15, align 1, !tbaa !5
  %17 = getelementptr inbounds i8, ptr %2, i64 5
  store i8 %16, ptr %17, align 1, !tbaa !5
  %18 = getelementptr inbounds i8, ptr %0, i64 5
  %19 = load i8, ptr %18, align 1, !tbaa !5
  %20 = getelementptr inbounds i8, ptr %2, i64 6
  store i8 %19, ptr %20, align 1, !tbaa !5
  %21 = getelementptr inbounds i8, ptr %0, i64 6
  %22 = load i8, ptr %21, align 1, !tbaa !5
  %23 = getelementptr inbounds i8, ptr %2, i64 7
  store i8 %22, ptr %23, align 1, !tbaa !5
  %24 = getelementptr inbounds i8, ptr %0, i64 7
  %25 = load i8, ptr %24, align 1, !tbaa !5
  %26 = getelementptr inbounds i8, ptr %2, i64 8
  store i8 %25, ptr %26, align 1, !tbaa !5
  %27 = getelementptr inbounds i8, ptr %0, i64 8
  %28 = load i8, ptr %27, align 1, !tbaa !5
  %29 = getelementptr inbounds i8, ptr %2, i64 9
  store i8 %28, ptr %29, align 1, !tbaa !5
  %30 = getelementptr inbounds i8, ptr %0, i64 9
  %31 = load i8, ptr %30, align 1, !tbaa !5
  %32 = getelementptr inbounds i8, ptr %2, i64 10
  store i8 %31, ptr %32, align 1, !tbaa !5
  %33 = getelementptr inbounds i8, ptr %0, i64 10
  %34 = load i8, ptr %33, align 1, !tbaa !5
  %35 = getelementptr inbounds i8, ptr %2, i64 11
  store i8 %34, ptr %35, align 1, !tbaa !5
  %36 = getelementptr inbounds i8, ptr %2, i64 12
  store i32 0, ptr %36, align 4, !tbaa !8
  %37 = getelementptr inbounds i8, ptr %2, i64 32
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(16) %37, i8 0, i64 16, i1 false)
  %38 = getelementptr inbounds i8, ptr %2, i64 320
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(44) %38, i8 0, i64 44, i1 false)
  ret i32 0
}

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

!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"}
!8 = !{!9, !9, i64 0}
!9 = !{!"int", !6, i64 0}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LoopRotatePass,MemCpyOptPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass