; LLVM IR from guanzhi/GmSSL :: src (aes_modes)

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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @aes_cbc_padding_encrypt(ptr noundef %0, ptr noundef %1, ptr noundef %2, i64 noundef %3, ptr noundef %4, ptr noundef %5) #0 {
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i64, align 8
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca [16 x i8], align 16
  %14 = alloca i64, align 8
  %15 = alloca i32, align 4
  store ptr %0, ptr %7, align 8, !tbaa !5
  store ptr %1, ptr %8, align 8, !tbaa !5
  store ptr %2, ptr %9, align 8, !tbaa !5
  store i64 %3, ptr %10, align 8, !tbaa !9
  store ptr %4, ptr %11, align 8, !tbaa !5
  store ptr %5, ptr %12, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 16, ptr %13) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #4
  %16 = load i64, ptr %10, align 8, !tbaa !9
  %17 = urem i64 %16, 16
  store i64 %17, ptr %14, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #4
  %18 = load i64, ptr %10, align 8, !tbaa !9
  %19 = urem i64 %18, 16
  %20 = sub i64 16, %19
  %21 = trunc i64 %20 to i32
  store i32 %21, ptr %15, align 4, !tbaa !11
  %22 = load ptr, ptr %9, align 8, !tbaa !5
  %23 = icmp ne ptr %22, null
  br i1 %23, label %24, label %33

24:                                               ; preds = %6
  %25 = getelementptr inbounds [16 x i8], ptr %13, i64 0, i64 0
  %26 = load ptr, ptr %9, align 8, !tbaa !5
  %27 = load i64, ptr %10, align 8, !tbaa !9
  %28 = getelementptr inbounds i8, ptr %26, i64 %27
  %29 = load i64, ptr %14, align 8, !tbaa !9
  %30 = sub i64 0, %29
  %31 = getelementptr inbounds i8, ptr %28, i64 %30
  %32 = load i64, ptr %14, align 8, !tbaa !9
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %25, ptr align 1 %31, i64 %32, i1 false)
  br label %33

33:                                               ; preds = %24, %6
  %34 = getelementptr inbounds [16 x i8], ptr %13, i64 0, i64 0
  %35 = load i64, ptr %14, align 8, !tbaa !9
  %36 = getelementptr inbounds i8, ptr %34, i64 %35
  %37 = load i32, ptr %15, align 4, !tbaa !11
  %38 = trunc i32 %37 to i8
  %39 = load i32, ptr %15, align 4, !tbaa !11
  %40 = sext i32 %39 to i64
  call void @llvm.memset.p0.i64(ptr align 1 %36, i8 %38, i64 %40, i1 false)
  %41 = load i64, ptr %10, align 8, !tbaa !9
  %42 = udiv i64 %41, 16
  %43 = icmp ne i64 %42, 0
  br i1 %43, label %44, label %58

44:                                               ; preds = %33
  %45 = load ptr, ptr %7, align 8, !tbaa !5
  %46 = load ptr, ptr %8, align 8, !tbaa !5
  %47 = load ptr, ptr %9, align 8, !tbaa !5
  %48 = load i64, ptr %10, align 8, !tbaa !9
  %49 = udiv i64 %48, 16
  %50 = load ptr, ptr %11, align 8, !tbaa !5
  call void @aes_cbc_encrypt(ptr noundef %45, ptr noundef %46, ptr noundef %47, i64 noundef %49, ptr noundef %50)
  %51 = load i64, ptr %10, align 8, !tbaa !9
  %52 = load i64, ptr %14, align 8, !tbaa !9
  %53 = sub i64 %51, %52
  %54 = load ptr, ptr %11, align 8, !tbaa !5
  %55 = getelementptr inbounds i8, ptr %54, i64 %53
  store ptr %55, ptr %11, align 8, !tbaa !5
  %56 = load ptr, ptr %11, align 8, !tbaa !5
  %57 = getelementptr inbounds i8, ptr %56, i64 -16
  store ptr %57, ptr %8, align 8, !tbaa !5
  br label %58

58:                                               ; preds = %44, %33
  %59 = load ptr, ptr %7, align 8, !tbaa !5
  %60 = load ptr, ptr %8, align 8, !tbaa !5
  %61 = getelementptr inbounds [16 x i8], ptr %13, i64 0, i64 0
  %62 = load ptr, ptr %11, align 8, !tbaa !5
  call void @aes_cbc_encrypt(ptr noundef %59, ptr noundef %60, ptr noundef %61, i64 noundef 1, ptr noundef %62)
  %63 = load i64, ptr %10, align 8, !tbaa !9
  %64 = load i64, ptr %14, align 8, !tbaa !9
  %65 = sub i64 %63, %64
  %66 = add i64 %65, 16
  %67 = load ptr, ptr %12, align 8, !tbaa !5
  store i64 %66, ptr %67, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #4
  call void @llvm.lifetime.end.p0(i64 16, ptr %13) #4
  ret i32 1
}

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

; 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 = { 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 = !{!"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, !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"

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

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @aes_cbc_padding_encrypt(ptr noundef %0, ptr noundef %1, ptr noundef %2, i64 noundef %3, ptr noundef %4, ptr nocapture noundef writeonly %5) local_unnamed_addr #0 {
  %7 = alloca [16 x i8], align 16
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %7) #4
  %8 = and i64 %3, 15
  %9 = trunc nuw nsw i64 %8 to i32
  %10 = sub nuw nsw i32 16, %9
  %.not = icmp eq ptr %2, null
  br i1 %.not, label %15, label %11

11:                                               ; preds = %6
  %12 = getelementptr inbounds i8, ptr %2, i64 %3
  %13 = sub nsw i64 0, %8
  %14 = getelementptr inbounds i8, ptr %12, i64 %13
  call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 16 %7, ptr nonnull align 1 %14, i64 %8, i1 false)
  br label %15

15:                                               ; preds = %11, %6
  %16 = getelementptr inbounds i8, ptr %7, i64 %8
  %17 = trunc nuw nsw i32 %10 to i8
  %18 = zext nneg i32 %10 to i64
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 1 dereferenceable(1) %16, i8 %17, i64 %18, i1 false)
  %.not28 = icmp ult i64 %3, 16
  br i1 %.not28, label %._crit_edge, label %19

19:                                               ; preds = %15
  %20 = lshr i64 %3, 4
  tail call void @aes_cbc_encrypt(ptr noundef %0, ptr noundef %1, ptr noundef %2, i64 noundef %20, ptr noundef %4)
  %21 = and i64 %3, -16
  %22 = getelementptr inbounds i8, ptr %4, i64 %21
  %23 = getelementptr inbounds i8, ptr %22, i64 -16
  %24 = add i64 %21, 16
  br label %._crit_edge

._crit_edge:                                      ; preds = %15, %19
  %.pre-phi = phi i64 [ %24, %19 ], [ 16, %15 ]
  %.025 = phi ptr [ %22, %19 ], [ %4, %15 ]
  %.0 = phi ptr [ %23, %19 ], [ %1, %15 ]
  call void @aes_cbc_encrypt(ptr noundef %0, ptr noundef %.0, ptr noundef nonnull %7, i64 noundef 1, ptr noundef %.025)
  store i64 %.pre-phi, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %7) #4
  ret i32 1
}

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

; Function Attrs: mustprogress 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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { mustprogress 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 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,PostOrderFunctionAttrsPass,SROAPass,TailCallElimPass