; LLVM IR from guanzhi/GmSSL :: src (zuc_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"

%struct.ZUC_CTX = type { %struct.ZUC_STATE, [4 x i8], i64 }
%struct.ZUC_STATE = type { [16 x i32], i32, i32 }

@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__.zuc_encrypt_update = external hidden unnamed_addr constant [19 x i8], align 1

; 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: nounwind
declare i32 @fprintf(ptr noundef, ptr noundef, ...) #1

; Function Attrs: nounwind uwtable
define dso_local i32 @zuc_encrypt_update(ptr noundef %0, ptr noundef %1, i64 noundef %2, ptr noundef %3, ptr noundef %4) #2 {
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i64, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca i64, align 8
  %13 = alloca i64, align 8
  %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 i64 %2, ptr %9, align 8, !tbaa !9
  store ptr %3, ptr %10, align 8, !tbaa !5
  store ptr %4, ptr %11, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #5
  %16 = load ptr, ptr %7, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.ZUC_CTX, ptr %16, i32 0, i32 2
  %18 = load i64, ptr %17, align 8, !tbaa !11
  %19 = icmp uge i64 %18, 4
  br i1 %19, label %20, label %26

20:                                               ; preds = %5
  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 98, ptr noundef @__FUNCTION__.zuc_encrypt_update) #5
  br label %24

24:                                               ; preds = %21
  br label %25

25:                                               ; preds = %24
  store i32 -1, ptr %6, align 4
  store i32 1, ptr %15, align 4
  br label %118

26:                                               ; preds = %5
  %27 = load ptr, ptr %11, align 8, !tbaa !5
  store i64 0, ptr %27, align 8, !tbaa !9
  %28 = load ptr, ptr %7, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.ZUC_CTX, ptr %28, i32 0, i32 2
  %30 = load i64, ptr %29, align 8, !tbaa !11
  %31 = icmp ne i64 %30, 0
  br i1 %31, label %32, label %82

32:                                               ; preds = %26
  %33 = load ptr, ptr %7, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.ZUC_CTX, ptr %33, i32 0, i32 2
  %35 = load i64, ptr %34, align 8, !tbaa !11
  %36 = sub i64 4, %35
  store i64 %36, ptr %12, align 8, !tbaa !9
  %37 = load i64, ptr %9, align 8, !tbaa !9
  %38 = load i64, ptr %12, align 8, !tbaa !9
  %39 = icmp ult i64 %37, %38
  br i1 %39, label %40, label %55

40:                                               ; preds = %32
  %41 = load ptr, ptr %7, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.ZUC_CTX, ptr %41, i32 0, i32 1
  %43 = getelementptr inbounds [4 x i8], ptr %42, i64 0, i64 0
  %44 = load ptr, ptr %7, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.ZUC_CTX, ptr %44, i32 0, i32 2
  %46 = load i64, ptr %45, align 8, !tbaa !11
  %47 = getelementptr inbounds i8, ptr %43, i64 %46
  %48 = load ptr, ptr %8, align 8, !tbaa !5
  %49 = load i64, ptr %9, align 8, !tbaa !9
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %47, ptr align 1 %48, i64 %49, i1 false)
  %50 = load i64, ptr %9, align 8, !tbaa !9
  %51 = load ptr, ptr %7, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.ZUC_CTX, ptr %51, i32 0, i32 2
  %53 = load i64, ptr %52, align 8, !tbaa !11
  %54 = add i64 %53, %50
  store i64 %54, ptr %52, align 8, !tbaa !11
  store i32 1, ptr %6, align 4
  store i32 1, ptr %15, align 4
  br label %118

55:                                               ; preds = %32
  %56 = load ptr, ptr %7, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.ZUC_CTX, ptr %56, i32 0, i32 1
  %58 = getelementptr inbounds [4 x i8], ptr %57, i64 0, i64 0
  %59 = load ptr, ptr %7, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.ZUC_CTX, ptr %59, i32 0, i32 2
  %61 = load i64, ptr %60, align 8, !tbaa !11
  %62 = getelementptr inbounds i8, ptr %58, i64 %61
  %63 = load ptr, ptr %8, align 8, !tbaa !5
  %64 = load i64, ptr %12, align 8, !tbaa !9
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %62, ptr align 1 %63, i64 %64, i1 false)
  %65 = load ptr, ptr %7, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.ZUC_CTX, ptr %65, i32 0, i32 0
  %67 = load ptr, ptr %7, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct.ZUC_CTX, ptr %67, i32 0, i32 1
  %69 = getelementptr inbounds [4 x i8], ptr %68, i64 0, i64 0
  %70 = load ptr, ptr %10, align 8, !tbaa !5
  call void @zuc_encrypt(ptr noundef %66, ptr noundef %69, i64 noundef 4, ptr noundef %70)
  %71 = load i64, ptr %12, align 8, !tbaa !9
  %72 = load ptr, ptr %8, align 8, !tbaa !5
  %73 = getelementptr inbounds i8, ptr %72, i64 %71
  store ptr %73, ptr %8, align 8, !tbaa !5
  %74 = load i64, ptr %12, align 8, !tbaa !9
  %75 = load i64, ptr %9, align 8, !tbaa !9
  %76 = sub i64 %75, %74
  store i64 %76, ptr %9, align 8, !tbaa !9
  %77 = load ptr, ptr %10, align 8, !tbaa !5
  %78 = getelementptr inbounds i8, ptr %77, i64 4
  store ptr %78, ptr %10, align 8, !tbaa !5
  %79 = load ptr, ptr %11, align 8, !tbaa !5
  %80 = load i64, ptr %79, align 8, !tbaa !9
  %81 = add i64 %80, 4
  store i64 %81, ptr %79, align 8, !tbaa !9
  br label %82

82:                                               ; preds = %55, %26
  %83 = load i64, ptr %9, align 8, !tbaa !9
  %84 = icmp uge i64 %83, 4
  br i1 %84, label %85, label %105

85:                                               ; preds = %82
  %86 = load i64, ptr %9, align 8, !tbaa !9
  %87 = udiv i64 %86, 4
  store i64 %87, ptr %13, align 8, !tbaa !9
  %88 = load i64, ptr %13, align 8, !tbaa !9
  %89 = mul i64 %88, 4
  store i64 %89, ptr %14, align 8, !tbaa !9
  %90 = load ptr, ptr %7, align 8, !tbaa !5
  %91 = getelementptr inbounds %struct.ZUC_CTX, ptr %90, i32 0, i32 0
  %92 = load ptr, ptr %8, align 8, !tbaa !5
  %93 = load i64, ptr %14, align 8, !tbaa !9
  %94 = load ptr, ptr %10, align 8, !tbaa !5
  call void @zuc_encrypt(ptr noundef %91, ptr noundef %92, i64 noundef %93, ptr noundef %94)
  %95 = load i64, ptr %14, align 8, !tbaa !9
  %96 = load ptr, ptr %8, align 8, !tbaa !5
  %97 = getelementptr inbounds i8, ptr %96, i64 %95
  store ptr %97, ptr %8, align 8, !tbaa !5
  %98 = load i64, ptr %14, align 8, !tbaa !9
  %99 = load i64, ptr %9, align 8, !tbaa !9
  %100 = sub i64 %99, %98
  store i64 %100, ptr %9, align 8, !tbaa !9
  %101 = load i64, ptr %14, align 8, !tbaa !9
  %102 = load ptr, ptr %11, align 8, !tbaa !5
  %103 = load i64, ptr %102, align 8, !tbaa !9
  %104 = add i64 %103, %101
  store i64 %104, ptr %102, align 8, !tbaa !9
  br label %105

105:                                              ; preds = %85, %82
  %106 = load i64, ptr %9, align 8, !tbaa !9
  %107 = icmp ne i64 %106, 0
  br i1 %107, label %108, label %114

108:                                              ; preds = %105
  %109 = load ptr, ptr %7, align 8, !tbaa !5
  %110 = getelementptr inbounds %struct.ZUC_CTX, ptr %109, i32 0, i32 1
  %111 = getelementptr inbounds [4 x i8], ptr %110, i64 0, i64 0
  %112 = load ptr, ptr %8, align 8, !tbaa !5
  %113 = load i64, ptr %9, align 8, !tbaa !9
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %111, ptr align 1 %112, i64 %113, i1 false)
  br label %114

114:                                              ; preds = %108, %105
  %115 = load i64, ptr %9, align 8, !tbaa !9
  %116 = load ptr, ptr %7, align 8, !tbaa !5
  %117 = getelementptr inbounds %struct.ZUC_CTX, ptr %116, i32 0, i32 2
  store i64 %115, ptr %117, align 8, !tbaa !11
  store i32 1, ptr %6, align 4
  store i32 1, ptr %15, align 4
  br label %118

118:                                              ; preds = %114, %40, %25
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #5
  %119 = load i32, ptr %6, align 4
  ret i32 %119
}

; 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) #3

declare void @zuc_encrypt(ptr noundef, ptr noundef, i64 noundef, ptr noundef) #4

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { "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 #5 = { 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, !10, i64 80}
!12 = !{!"", !13, i64 0, !7, i64 72, !10, i64 80}
!13 = !{!"", !7, i64 0, !14, i64 64, !14, i64 68}
!14 = !{!"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__.zuc_encrypt_update = external hidden unnamed_addr constant [19 x i8], align 1

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

; Function Attrs: nounwind uwtable
define dso_local range(i32 -1, 2) i32 @zuc_encrypt_update(ptr noundef %0, ptr noundef %1, i64 noundef %2, ptr noundef %3, ptr nocapture noundef %4) local_unnamed_addr #1 {
  %6 = getelementptr inbounds i8, ptr %0, i64 80
  %7 = load i64, ptr %6, align 8, !tbaa !5
  %8 = icmp ugt i64 %7, 3
  br i1 %8, label %9, label %12

9:                                                ; preds = %5
  %10 = load ptr, ptr @stderr, align 8, !tbaa !12
  %11 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %10, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 98, ptr noundef nonnull @__FUNCTION__.zuc_encrypt_update) #4
  br label %40

12:                                               ; preds = %5
  store i64 0, ptr %4, align 8, !tbaa !14
  %13 = load i64, ptr %6, align 8, !tbaa !5
  %.not = icmp eq i64 %13, 0
  br i1 %.not, label %28, label %14

14:                                               ; preds = %12
  %15 = sub i64 4, %13
  %16 = icmp ugt i64 %15, %2
  %17 = getelementptr inbounds i8, ptr %0, i64 72
  %18 = getelementptr inbounds i8, ptr %17, i64 %13
  br i1 %16, label %19, label %22

19:                                               ; preds = %14
  tail call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 1 %18, ptr align 1 %1, i64 %2, i1 false)
  %20 = load i64, ptr %6, align 8, !tbaa !5
  %21 = add i64 %20, %2
  store i64 %21, ptr %6, align 8, !tbaa !5
  br label %40

22:                                               ; preds = %14
  tail call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 1 %18, ptr align 1 %1, i64 %15, i1 false)
  tail call void @zuc_encrypt(ptr noundef nonnull %0, ptr noundef nonnull %17, i64 noundef 4, ptr noundef %3) #5
  %23 = getelementptr inbounds i8, ptr %1, i64 %15
  %24 = sub i64 %2, %15
  %25 = getelementptr inbounds i8, ptr %3, i64 4
  %26 = load i64, ptr %4, align 8, !tbaa !14
  %27 = add i64 %26, 4
  store i64 %27, ptr %4, align 8, !tbaa !14
  br label %28

28:                                               ; preds = %22, %12
  %.047 = phi ptr [ %25, %22 ], [ %3, %12 ]
  %.045 = phi i64 [ %24, %22 ], [ %2, %12 ]
  %.044 = phi ptr [ %23, %22 ], [ %1, %12 ]
  %29 = icmp ugt i64 %.045, 3
  br i1 %29, label %30, label %36

30:                                               ; preds = %28
  %31 = and i64 %.045, -4
  tail call void @zuc_encrypt(ptr noundef nonnull %0, ptr noundef %.044, i64 noundef %31, ptr noundef %.047) #5
  %32 = getelementptr inbounds i8, ptr %.044, i64 %31
  %33 = and i64 %.045, 3
  %34 = load i64, ptr %4, align 8, !tbaa !14
  %35 = add i64 %34, %31
  store i64 %35, ptr %4, align 8, !tbaa !14
  br label %36

36:                                               ; preds = %30, %28
  %.146 = phi i64 [ %33, %30 ], [ %.045, %28 ]
  %.1 = phi ptr [ %32, %30 ], [ %.044, %28 ]
  %.not52 = icmp eq i64 %.146, 0
  br i1 %.not52, label %39, label %37

37:                                               ; preds = %36
  %38 = getelementptr inbounds i8, ptr %0, i64 72
  tail call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 8 %38, ptr align 1 %.1, i64 %.146, i1 false)
  br label %39

39:                                               ; preds = %37, %36
  store i64 %.146, ptr %6, align 8, !tbaa !5
  br label %40

40:                                               ; preds = %39, %19, %9
  %.0 = phi i32 [ -1, %9 ], [ 1, %19 ], [ 1, %39 ]
  ret i32 %.0
}

; 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

declare void @zuc_encrypt(ptr noundef, ptr noundef, i64 noundef, ptr noundef) local_unnamed_addr #3

attributes #0 = { 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 #1 = { 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 #2 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { "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 = { cold nounwind }
attributes #5 = { 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, !11, i64 80}
!6 = !{!"", !7, i64 0, !8, i64 72, !11, i64 80}
!7 = !{!"", !8, i64 0, !10, i64 64, !10, i64 68}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"long", !8, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"any pointer", !8, i64 0}
!14 = !{!11, !11, i64 0}


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