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

@stderr = external global ptr, align 8
@.str = external hidden unnamed_addr constant [13 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [63 x i8], align 1
@__FUNCTION__.aes_cbc_padding_decrypt = external hidden unnamed_addr constant [24 x i8], align 1

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

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

20:                                               ; preds = %6
  br label %21

21:                                               ; preds = %20
  %22 = load ptr, ptr @stderr, align 8, !tbaa !5
  %23 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %22, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 76, ptr noundef @__FUNCTION__.aes_cbc_padding_decrypt) #4
  br label %24

24:                                               ; preds = %21
  br label %25

25:                                               ; preds = %24
  store i32 0, ptr %7, align 4
  store i32 1, ptr %17, align 4
  br label %92

26:                                               ; preds = %6
  %27 = load i64, ptr %11, align 8, !tbaa !9
  %28 = urem i64 %27, 16
  %29 = icmp ne i64 %28, 0
  br i1 %29, label %33, label %30

30:                                               ; preds = %26
  %31 = load i64, ptr %11, align 8, !tbaa !9
  %32 = icmp ult i64 %31, 16
  br i1 %32, label %33, label %39

33:                                               ; preds = %30, %26
  br label %34

34:                                               ; preds = %33
  %35 = load ptr, ptr @stderr, align 8, !tbaa !5
  %36 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %35, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 80, ptr noundef @__FUNCTION__.aes_cbc_padding_decrypt) #4
  br label %37

37:                                               ; preds = %34
  br label %38

38:                                               ; preds = %37
  store i32 -1, ptr %7, align 4
  store i32 1, ptr %17, align 4
  br label %92

39:                                               ; preds = %30
  %40 = load i64, ptr %11, align 8, !tbaa !9
  %41 = icmp ugt i64 %40, 16
  br i1 %41, label %42, label %54

42:                                               ; preds = %39
  %43 = load ptr, ptr %8, align 8, !tbaa !5
  %44 = load ptr, ptr %9, align 8, !tbaa !5
  %45 = load ptr, ptr %10, align 8, !tbaa !5
  %46 = load i64, ptr %11, align 8, !tbaa !9
  %47 = udiv i64 %46, 16
  %48 = sub i64 %47, 1
  %49 = load ptr, ptr %12, align 8, !tbaa !5
  call void @aes_cbc_decrypt(ptr noundef %43, ptr noundef %44, ptr noundef %45, i64 noundef %48, ptr noundef %49)
  %50 = load ptr, ptr %10, align 8, !tbaa !5
  %51 = load i64, ptr %11, align 8, !tbaa !9
  %52 = getelementptr inbounds i8, ptr %50, i64 %51
  %53 = getelementptr inbounds i8, ptr %52, i64 -32
  store ptr %53, ptr %9, align 8, !tbaa !5
  br label %54

54:                                               ; preds = %42, %39
  %55 = load ptr, ptr %8, align 8, !tbaa !5
  %56 = load ptr, ptr %9, align 8, !tbaa !5
  %57 = load ptr, ptr %10, align 8, !tbaa !5
  %58 = load i64, ptr %11, align 8, !tbaa !9
  %59 = getelementptr inbounds i8, ptr %57, i64 %58
  %60 = getelementptr inbounds i8, ptr %59, i64 -16
  %61 = getelementptr inbounds [16 x i8], ptr %14, i64 0, i64 0
  call void @aes_cbc_decrypt(ptr noundef %55, ptr noundef %56, ptr noundef %60, i64 noundef 1, ptr noundef %61)
  %62 = getelementptr inbounds [16 x i8], ptr %14, i64 0, i64 15
  %63 = load i8, ptr %62, align 1, !tbaa !11
  %64 = zext i8 %63 to i32
  store i32 %64, ptr %16, align 4, !tbaa !12
  %65 = load i32, ptr %16, align 4, !tbaa !12
  %66 = icmp slt i32 %65, 1
  br i1 %66, label %70, label %67

67:                                               ; preds = %54
  %68 = load i32, ptr %16, align 4, !tbaa !12
  %69 = icmp sgt i32 %68, 16
  br i1 %69, label %70, label %76

70:                                               ; preds = %67, %54
  br label %71

71:                                               ; preds = %70
  %72 = load ptr, ptr @stderr, align 8, !tbaa !5
  %73 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %72, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 90, ptr noundef @__FUNCTION__.aes_cbc_padding_decrypt) #4
  br label %74

74:                                               ; preds = %71
  br label %75

75:                                               ; preds = %74
  store i32 -1, ptr %7, align 4
  store i32 1, ptr %17, align 4
  br label %92

76:                                               ; preds = %67
  %77 = load i32, ptr %16, align 4, !tbaa !12
  %78 = sext i32 %77 to i64
  %79 = load i64, ptr %15, align 8, !tbaa !9
  %80 = sub i64 %79, %78
  store i64 %80, ptr %15, align 8, !tbaa !9
  %81 = load ptr, ptr %12, align 8, !tbaa !5
  %82 = load i64, ptr %11, align 8, !tbaa !9
  %83 = getelementptr inbounds i8, ptr %81, i64 %82
  %84 = getelementptr inbounds i8, ptr %83, i64 -16
  %85 = getelementptr inbounds [16 x i8], ptr %14, i64 0, i64 0
  %86 = load i64, ptr %15, align 8, !tbaa !9
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %84, ptr align 16 %85, i64 %86, i1 false)
  %87 = load i64, ptr %11, align 8, !tbaa !9
  %88 = load i32, ptr %16, align 4, !tbaa !12
  %89 = sext i32 %88 to i64
  %90 = sub i64 %87, %89
  %91 = load ptr, ptr %13, align 8, !tbaa !5
  store i64 %90, ptr %91, align 8, !tbaa !9
  store i32 1, ptr %7, align 4
  store i32 1, ptr %17, align 4
  br label %92

92:                                               ; preds = %76, %75, %38, %25
  call void @llvm.lifetime.end.p0(i64 4, ptr %16) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #4
  call void @llvm.lifetime.end.p0(i64 16, ptr %14) #4
  %93 = load i32, ptr %7, align 4
  ret i32 %93
}

; Function Attrs: nounwind
declare i32 @fprintf(ptr noundef, ptr noundef, ...) #3

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 = { nounwind "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 #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 = !{!7, !7, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"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"

@stderr = external local_unnamed_addr global ptr, align 8
@.str = external hidden unnamed_addr constant [13 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [63 x i8], align 1
@__FUNCTION__.aes_cbc_padding_decrypt = external hidden unnamed_addr constant [24 x i8], align 1

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

; Function Attrs: nounwind uwtable
define dso_local range(i32 -1, 2) i32 @aes_cbc_padding_decrypt(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 = icmp eq i64 %3, 0
  br i1 %8, label %9, label %12

9:                                                ; preds = %6
  %10 = load ptr, ptr @stderr, align 8, !tbaa !5
  %11 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %10, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 76, ptr noundef nonnull @__FUNCTION__.aes_cbc_padding_decrypt) #5
  br label %41

12:                                               ; preds = %6
  %13 = and i64 %3, 15
  %14 = icmp ne i64 %13, 0
  %15 = icmp ult i64 %3, 16
  %or.cond = or i1 %15, %14
  br i1 %or.cond, label %16, label %19

16:                                               ; preds = %12
  %17 = load ptr, ptr @stderr, align 8, !tbaa !5
  %18 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %17, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 80, ptr noundef nonnull @__FUNCTION__.aes_cbc_padding_decrypt) #5
  br label %41

19:                                               ; preds = %12
  %20 = icmp ugt i64 %3, 16
  br i1 %20, label %21, label %26

21:                                               ; preds = %19
  %22 = lshr exact i64 %3, 4
  %23 = add nsw i64 %22, -1
  tail call void @aes_cbc_decrypt(ptr noundef %0, ptr noundef %1, ptr noundef %2, i64 noundef %23, ptr noundef %4)
  %24 = getelementptr inbounds i8, ptr %2, i64 %3
  %25 = getelementptr inbounds i8, ptr %24, i64 -32
  br label %26

26:                                               ; preds = %21, %19
  %.028 = phi ptr [ %25, %21 ], [ %1, %19 ]
  %27 = getelementptr inbounds i8, ptr %2, i64 %3
  %28 = getelementptr inbounds i8, ptr %27, i64 -16
  call void @aes_cbc_decrypt(ptr noundef %0, ptr noundef %.028, ptr noundef nonnull %28, i64 noundef 1, ptr noundef nonnull %7)
  %29 = getelementptr inbounds i8, ptr %7, i64 15
  %30 = load i8, ptr %29, align 1, !tbaa !9
  %31 = add i8 %30, -17
  %or.cond3 = icmp ult i8 %31, -16
  br i1 %or.cond3, label %32, label %35

32:                                               ; preds = %26
  %33 = load ptr, ptr @stderr, align 8, !tbaa !5
  %34 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %33, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 90, ptr noundef nonnull @__FUNCTION__.aes_cbc_padding_decrypt) #5
  br label %41

35:                                               ; preds = %26
  %36 = zext nneg i8 %30 to i64
  %37 = sub nuw nsw i64 16, %36
  %38 = getelementptr inbounds i8, ptr %4, i64 %3
  %39 = getelementptr inbounds i8, ptr %38, i64 -16
  call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 1 %39, ptr nonnull align 16 %7, i64 %37, i1 false)
  %40 = sub nuw i64 %3, %36
  store i64 %40, ptr %5, align 8, !tbaa !10
  br label %41

41:                                               ; preds = %35, %32, %16, %9
  %.0 = phi i32 [ 0, %9 ], [ -1, %16 ], [ -1, %32 ], [ 1, %35 ]
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %7) #4
  ret i32 %.0
}

; Function Attrs: nofree nounwind
declare noundef i32 @fprintf(ptr nocapture noundef, ptr nocapture noundef readonly, ...) local_unnamed_addr #3

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 = { nofree nounwind "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 #4 = { nounwind }
attributes #5 = { cold 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 = !{!7, !7, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"long", !7, i64 0}


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