; 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: nounwind uwtable
declare dso_local void @add_4(ptr noundef, ptr noundef) #0

; 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 nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: nounwind uwtable
declare dso_local void @mlt_4(ptr noundef, ptr noundef, ptr noundef) #0

; Function Attrs: nounwind uwtable
define dso_local void @do_cwc(ptr noundef %0, ptr noundef %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca [4 x i32], align 16
  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
  %7 = load ptr, ptr %4, align 8, !tbaa !5
  %8 = getelementptr inbounds %struct.cwc_ctx, ptr %7, i32 0, i32 5
  %9 = getelementptr inbounds [8 x i32], ptr %8, i64 0, i64 0
  %10 = getelementptr inbounds i32, ptr %9, i64 4
  store ptr %10, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 16, ptr %6) #3
  %11 = load ptr, ptr %3, align 8, !tbaa !5
  %12 = getelementptr inbounds i32, ptr %11, i64 2
  %13 = load i32, ptr %12, align 4, !tbaa !9
  %14 = call i32 @__bswap_32(i32 noundef %13)
  %15 = getelementptr inbounds [4 x i32], ptr %6, i64 0, i64 3
  store i32 %14, ptr %15, align 4, !tbaa !9
  %16 = load ptr, ptr %3, align 8, !tbaa !5
  %17 = getelementptr inbounds i32, ptr %16, i64 1
  %18 = load i32, ptr %17, align 4, !tbaa !9
  %19 = call i32 @__bswap_32(i32 noundef %18)
  %20 = getelementptr inbounds [4 x i32], ptr %6, i64 0, i64 2
  store i32 %19, ptr %20, align 8, !tbaa !9
  %21 = load ptr, ptr %3, align 8, !tbaa !5
  %22 = getelementptr inbounds i32, ptr %21, i64 0
  %23 = load i32, ptr %22, align 4, !tbaa !9
  %24 = call i32 @__bswap_32(i32 noundef %23)
  %25 = getelementptr inbounds [4 x i32], ptr %6, i64 0, i64 1
  store i32 %24, ptr %25, align 4, !tbaa !9
  %26 = getelementptr inbounds [4 x i32], ptr %6, i64 0, i64 0
  store i32 0, ptr %26, align 16, !tbaa !9
  %27 = getelementptr inbounds [4 x i32], ptr %6, i64 0, i64 0
  %28 = load ptr, ptr %4, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.cwc_ctx, ptr %28, i32 0, i32 5
  %30 = getelementptr inbounds [8 x i32], ptr %29, i64 0, i64 0
  call void @add_4(ptr noundef %27, ptr noundef %30)
  %31 = load ptr, ptr %4, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.cwc_ctx, ptr %31, i32 0, i32 5
  %33 = getelementptr inbounds [8 x i32], ptr %32, i64 0, i64 0
  %34 = getelementptr inbounds [4 x i32], ptr %6, i64 0, i64 0
  %35 = load ptr, ptr %4, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.cwc_ctx, ptr %35, i32 0, i32 4
  %37 = getelementptr inbounds [4 x i32], ptr %36, i64 0, i64 0
  call void @mlt_4(ptr noundef %33, ptr noundef %34, ptr noundef %37)
  %38 = load ptr, ptr %4, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.cwc_ctx, ptr %38, i32 0, i32 5
  %40 = getelementptr inbounds [8 x i32], ptr %39, i64 0, i64 0
  %41 = load ptr, ptr %4, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.cwc_ctx, ptr %41, i32 0, i32 5
  %43 = getelementptr inbounds [8 x i32], ptr %42, i64 0, i64 0
  call void @add_4(ptr noundef %40, ptr noundef %43)
  %44 = load ptr, ptr %5, align 8, !tbaa !5
  %45 = load i32, ptr %44, align 4, !tbaa !9
  %46 = and i32 %45, -2147483648
  %47 = icmp ne i32 %46, 0
  br i1 %47, label %48, label %56

48:                                               ; preds = %2
  %49 = load ptr, ptr %5, align 8, !tbaa !5
  %50 = load i32, ptr %49, align 4, !tbaa !9
  %51 = and i32 %50, 2147483647
  store i32 %51, ptr %49, align 4, !tbaa !9
  %52 = load ptr, ptr %5, align 8, !tbaa !5
  %53 = getelementptr inbounds i32, ptr %52, i64 -1
  %54 = load i32, ptr %53, align 4, !tbaa !9
  %55 = add i32 %54, 1
  store i32 %55, ptr %53, align 4, !tbaa !9
  br label %56

56:                                               ; preds = %48, %2
  %57 = load ptr, ptr %4, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.cwc_ctx, ptr %57, i32 0, i32 5
  %59 = getelementptr inbounds [8 x i32], ptr %58, i64 0, i64 0
  %60 = load ptr, ptr %5, align 8, !tbaa !5
  call void @add_4(ptr noundef %59, ptr noundef %60)
  %61 = load ptr, ptr %4, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.cwc_ctx, ptr %61, i32 0, i32 5
  %63 = getelementptr inbounds [8 x i32], ptr %62, i64 0, i64 0
  %64 = load i32, ptr %63, align 16, !tbaa !9
  %65 = and i32 %64, -2147483648
  %66 = icmp ne i32 %65, 0
  br i1 %66, label %67, label %107

67:                                               ; preds = %56
  %68 = load ptr, ptr %4, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.cwc_ctx, ptr %68, i32 0, i32 5
  %70 = getelementptr inbounds [8 x i32], ptr %69, i64 0, i64 0
  %71 = load i32, ptr %70, align 16, !tbaa !9
  %72 = and i32 %71, 2147483647
  store i32 %72, ptr %70, align 16, !tbaa !9
  %73 = load ptr, ptr %4, align 8, !tbaa !5
  %74 = getelementptr inbounds %struct.cwc_ctx, ptr %73, i32 0, i32 5
  %75 = getelementptr inbounds [8 x i32], ptr %74, i64 0, i64 0
  %76 = getelementptr inbounds i32, ptr %75, i64 3
  %77 = load i32, ptr %76, align 4, !tbaa !9
  %78 = add i32 %77, 1
  store i32 %78, ptr %76, align 4, !tbaa !9
  %79 = icmp ne i32 %78, 0
  br i1 %79, label %104, label %80

80:                                               ; preds = %67
  %81 = load ptr, ptr %4, align 8, !tbaa !5
  %82 = getelementptr inbounds %struct.cwc_ctx, ptr %81, i32 0, i32 5
  %83 = getelementptr inbounds [8 x i32], ptr %82, i64 0, i64 0
  %84 = getelementptr inbounds i32, ptr %83, i64 2
  %85 = load i32, ptr %84, align 8, !tbaa !9
  %86 = add i32 %85, 1
  store i32 %86, ptr %84, align 8, !tbaa !9
  %87 = icmp ne i32 %86, 0
  br i1 %87, label %104, label %88

88:                                               ; preds = %80
  %89 = load ptr, ptr %4, align 8, !tbaa !5
  %90 = getelementptr inbounds %struct.cwc_ctx, ptr %89, i32 0, i32 5
  %91 = getelementptr inbounds [8 x i32], ptr %90, i64 0, i64 0
  %92 = getelementptr inbounds i32, ptr %91, i64 1
  %93 = load i32, ptr %92, align 4, !tbaa !9
  %94 = add i32 %93, 1
  store i32 %94, ptr %92, align 4, !tbaa !9
  %95 = icmp ne i32 %94, 0
  br i1 %95, label %104, label %96

96:                                               ; preds = %88
  %97 = load ptr, ptr %4, align 8, !tbaa !5
  %98 = getelementptr inbounds %struct.cwc_ctx, ptr %97, i32 0, i32 5
  %99 = getelementptr inbounds [8 x i32], ptr %98, i64 0, i64 0
  %100 = getelementptr inbounds i32, ptr %99, i64 0
  %101 = load i32, ptr %100, align 16, !tbaa !9
  %102 = add i32 %101, 1
  store i32 %102, ptr %100, align 16, !tbaa !9
  %103 = icmp ne i32 %102, 0
  br label %104

104:                                              ; preds = %96, %88, %80, %67
  %105 = phi i1 [ false, %88 ], [ false, %80 ], [ false, %67 ], [ %103, %96 ]
  %106 = zext i1 %105 to i32
  br label %107

107:                                              ; preds = %104, %56
  call void @llvm.lifetime.end.p0(i64 16, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  ret void
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @__bswap_32(i32 noundef) #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { inlinehint 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 = !{!"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"

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

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

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

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

; Function Attrs: nounwind uwtable
define dso_local void @do_cwc(ptr nocapture noundef readonly %0, ptr noundef %1) local_unnamed_addr #0 {
  %3 = alloca [4 x i32], align 16
  %4 = getelementptr inbounds i8, ptr %1, i64 320
  %5 = getelementptr inbounds i8, ptr %1, i64 336
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %3) #3
  %6 = getelementptr inbounds i8, ptr %0, i64 8
  %7 = load i32, ptr %6, align 4, !tbaa !5
  %8 = tail call i32 @__bswap_32(i32 noundef %7)
  %9 = getelementptr inbounds i8, ptr %3, i64 12
  store i32 %8, ptr %9, align 4, !tbaa !5
  %10 = getelementptr inbounds i8, ptr %0, i64 4
  %11 = load i32, ptr %10, align 4, !tbaa !5
  %12 = tail call i32 @__bswap_32(i32 noundef %11)
  %13 = getelementptr inbounds i8, ptr %3, i64 8
  store i32 %12, ptr %13, align 8, !tbaa !5
  %14 = load i32, ptr %0, align 4, !tbaa !5
  %15 = tail call i32 @__bswap_32(i32 noundef %14)
  %16 = getelementptr inbounds i8, ptr %3, i64 4
  store i32 %15, ptr %16, align 4, !tbaa !5
  store i32 0, ptr %3, align 16, !tbaa !5
  call void @add_4(ptr noundef nonnull %3, ptr noundef nonnull %4)
  %17 = getelementptr inbounds i8, ptr %1, i64 304
  call void @mlt_4(ptr noundef nonnull %4, ptr noundef nonnull %3, ptr noundef nonnull %17)
  call void @add_4(ptr noundef nonnull %4, ptr noundef nonnull %4)
  %18 = load i32, ptr %5, align 4, !tbaa !5
  %.not = icmp sgt i32 %18, -1
  br i1 %.not, label %24, label %19

19:                                               ; preds = %2
  %20 = and i32 %18, 2147483647
  store i32 %20, ptr %5, align 4, !tbaa !5
  %21 = getelementptr inbounds i8, ptr %1, i64 332
  %22 = load i32, ptr %21, align 4, !tbaa !5
  %23 = add i32 %22, 1
  store i32 %23, ptr %21, align 4, !tbaa !5
  br label %24

24:                                               ; preds = %19, %2
  call void @add_4(ptr noundef nonnull %4, ptr noundef nonnull %5)
  %25 = load i32, ptr %4, align 16, !tbaa !5
  %.not20 = icmp sgt i32 %25, -1
  br i1 %.not20, label %41, label %26

26:                                               ; preds = %24
  %27 = and i32 %25, 2147483647
  store i32 %27, ptr %4, align 16, !tbaa !5
  %28 = getelementptr inbounds i8, ptr %1, i64 332
  %29 = load i32, ptr %28, align 4, !tbaa !5
  %30 = add i32 %29, 1
  store i32 %30, ptr %28, align 4, !tbaa !5
  %.not21 = icmp eq i32 %30, 0
  br i1 %.not21, label %31, label %41

31:                                               ; preds = %26
  %32 = getelementptr inbounds i8, ptr %1, i64 328
  %33 = load i32, ptr %32, align 8, !tbaa !5
  %34 = add i32 %33, 1
  store i32 %34, ptr %32, align 8, !tbaa !5
  %.not22 = icmp eq i32 %34, 0
  br i1 %.not22, label %35, label %41

35:                                               ; preds = %31
  %36 = getelementptr inbounds i8, ptr %1, i64 324
  %37 = load i32, ptr %36, align 4, !tbaa !5
  %38 = add i32 %37, 1
  store i32 %38, ptr %36, align 4, !tbaa !5
  %.not23 = icmp eq i32 %38, 0
  br i1 %.not23, label %39, label %41

39:                                               ; preds = %35
  %40 = add nuw i32 %27, 1
  store i32 %40, ptr %4, align 16, !tbaa !5
  br label %41

41:                                               ; preds = %26, %31, %35, %39, %24
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %3) #3
  ret void
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @__bswap_32(i32 noundef) local_unnamed_addr #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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { inlinehint 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}


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