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

; 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.SM4_GCM_CTX = type { %struct.SM4_CTR_CTX, %struct.GHASH_CTX, [16 x i8], i64, [16 x i8], i64, i64 }
%struct.SM4_CTR_CTX = type { %struct.SM4_KEY, [16 x i8], [16 x i8], i64 }
%struct.SM4_KEY = type { [32 x i32] }
%struct.GHASH_CTX = type { [2 x i64], [2 x i64], i64, i64, [16 x i8], i64 }

@stderr = external global ptr, align 8
@.str = external hidden unnamed_addr constant [13 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [61 x i8], align 1
@__FUNCTION__.sm4_gcm_decrypt_update = external hidden unnamed_addr constant [23 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: nounwind
declare i32 @fprintf(ptr noundef, ptr noundef, ...) #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) #0

declare i32 @sm4_ctr32_encrypt_update(ptr noundef, ptr noundef, i64 noundef, ptr noundef, ptr noundef) #3

declare void @ghash_update(ptr noundef, ptr noundef, i64 noundef) #3

; Function Attrs: nounwind uwtable
define dso_local i32 @sm4_gcm_decrypt_update(ptr noundef %0, ptr noundef %1, i64 noundef %2, ptr noundef %3, ptr noundef %4) #4 {
  %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 i32, align 4
  %14 = alloca [16 x i8], align 16
  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
  %15 = load ptr, ptr %7, align 8, !tbaa !5
  %16 = icmp ne ptr %15, null
  br i1 %16, label %17, label %23

17:                                               ; preds = %5
  %18 = load ptr, ptr %8, align 8, !tbaa !5
  %19 = icmp ne ptr %18, null
  br i1 %19, label %20, label %23

20:                                               ; preds = %17
  %21 = load ptr, ptr %11, align 8, !tbaa !5
  %22 = icmp ne ptr %21, null
  br i1 %22, label %29, label %23

23:                                               ; preds = %20, %17, %5
  br label %24

24:                                               ; preds = %23
  %25 = load ptr, ptr @stderr, align 8, !tbaa !5
  %26 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %25, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 239, ptr noundef @__FUNCTION__.sm4_gcm_decrypt_update) #5
  br label %27

27:                                               ; preds = %24
  br label %28

28:                                               ; preds = %27
  store i32 -1, ptr %6, align 4
  store i32 1, ptr %13, align 4
  br label %255

29:                                               ; preds = %20
  %30 = load i64, ptr %9, align 8, !tbaa !9
  %31 = icmp ugt i64 %30, 2147483647
  br i1 %31, label %32, label %38

32:                                               ; preds = %29
  br label %33

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

36:                                               ; preds = %33
  br label %37

37:                                               ; preds = %36
  store i32 -1, ptr %6, align 4
  store i32 1, ptr %13, align 4
  br label %255

38:                                               ; preds = %29
  %39 = load i64, ptr %9, align 8, !tbaa !9
  %40 = load ptr, ptr %7, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.SM4_GCM_CTX, ptr %40, i32 0, i32 6
  %42 = load i64, ptr %41, align 8, !tbaa !11
  %43 = sub i64 68719476704, %42
  %44 = icmp ugt i64 %39, %43
  br i1 %44, label %45, label %51

45:                                               ; preds = %38
  br label %46

46:                                               ; preds = %45
  %47 = load ptr, ptr @stderr, align 8, !tbaa !5
  %48 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %47, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 247, ptr noundef @__FUNCTION__.sm4_gcm_decrypt_update) #5
  br label %49

49:                                               ; preds = %46
  br label %50

50:                                               ; preds = %49
  store i32 -1, ptr %6, align 4
  store i32 1, ptr %13, align 4
  br label %255

51:                                               ; preds = %38
  %52 = load ptr, ptr %10, align 8, !tbaa !5
  %53 = icmp ne ptr %52, null
  br i1 %53, label %60, label %54

54:                                               ; preds = %51
  %55 = load i64, ptr %9, align 8, !tbaa !9
  %56 = add i64 %55, 15
  %57 = udiv i64 %56, 16
  %58 = mul i64 16, %57
  %59 = load ptr, ptr %11, align 8, !tbaa !5
  store i64 %58, ptr %59, align 8, !tbaa !9
  store i32 1, ptr %6, align 4
  store i32 1, ptr %13, align 4
  br label %255

60:                                               ; preds = %51
  %61 = load ptr, ptr %7, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.SM4_GCM_CTX, ptr %61, i32 0, i32 5
  %63 = load i64, ptr %62, align 8, !tbaa !16
  %64 = load ptr, ptr %7, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.SM4_GCM_CTX, ptr %64, i32 0, i32 3
  %66 = load i64, ptr %65, align 8, !tbaa !17
  %67 = icmp ugt i64 %63, %66
  br i1 %67, label %68, label %74

68:                                               ; preds = %60
  br label %69

69:                                               ; preds = %68
  %70 = load ptr, ptr @stderr, align 8, !tbaa !5
  %71 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %70, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 256, ptr noundef @__FUNCTION__.sm4_gcm_decrypt_update) #5
  br label %72

72:                                               ; preds = %69
  br label %73

73:                                               ; preds = %72
  store i32 -1, ptr %6, align 4
  store i32 1, ptr %13, align 4
  br label %255

74:                                               ; preds = %60
  %75 = load ptr, ptr %7, align 8, !tbaa !5
  %76 = getelementptr inbounds %struct.SM4_GCM_CTX, ptr %75, i32 0, i32 5
  %77 = load i64, ptr %76, align 8, !tbaa !16
  %78 = load ptr, ptr %7, align 8, !tbaa !5
  %79 = getelementptr inbounds %struct.SM4_GCM_CTX, ptr %78, i32 0, i32 3
  %80 = load i64, ptr %79, align 8, !tbaa !17
  %81 = icmp ult i64 %77, %80
  br i1 %81, label %82, label %130

82:                                               ; preds = %74
  %83 = load ptr, ptr %7, align 8, !tbaa !5
  %84 = getelementptr inbounds %struct.SM4_GCM_CTX, ptr %83, i32 0, i32 3
  %85 = load i64, ptr %84, align 8, !tbaa !17
  %86 = load ptr, ptr %7, align 8, !tbaa !5
  %87 = getelementptr inbounds %struct.SM4_GCM_CTX, ptr %86, i32 0, i32 5
  %88 = load i64, ptr %87, align 8, !tbaa !16
  %89 = sub i64 %85, %88
  store i64 %89, ptr %12, align 8, !tbaa !9
  %90 = load i64, ptr %9, align 8, !tbaa !9
  %91 = load i64, ptr %12, align 8, !tbaa !9
  %92 = icmp ule i64 %90, %91
  br i1 %92, label %93, label %108

93:                                               ; preds = %82
  %94 = load ptr, ptr %7, align 8, !tbaa !5
  %95 = getelementptr inbounds %struct.SM4_GCM_CTX, ptr %94, i32 0, i32 4
  %96 = getelementptr inbounds [16 x i8], ptr %95, i64 0, i64 0
  %97 = load ptr, ptr %7, align 8, !tbaa !5
  %98 = getelementptr inbounds %struct.SM4_GCM_CTX, ptr %97, i32 0, i32 5
  %99 = load i64, ptr %98, align 8, !tbaa !16
  %100 = getelementptr inbounds i8, ptr %96, i64 %99
  %101 = load ptr, ptr %8, align 8, !tbaa !5
  %102 = load i64, ptr %9, align 8, !tbaa !9
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %100, ptr align 1 %101, i64 %102, i1 false)
  %103 = load i64, ptr %9, align 8, !tbaa !9
  %104 = load ptr, ptr %7, align 8, !tbaa !5
  %105 = getelementptr inbounds %struct.SM4_GCM_CTX, ptr %104, i32 0, i32 5
  %106 = load i64, ptr %105, align 8, !tbaa !16
  %107 = add i64 %106, %103
  store i64 %107, ptr %105, align 8, !tbaa !16
  store i32 1, ptr %6, align 4
  store i32 1, ptr %13, align 4
  br label %255

108:                                              ; preds = %82
  %109 = load ptr, ptr %7, align 8, !tbaa !5
  %110 = getelementptr inbounds %struct.SM4_GCM_CTX, ptr %109, i32 0, i32 4
  %111 = getelementptr inbounds [16 x i8], ptr %110, i64 0, i64 0
  %112 = load ptr, ptr %7, align 8, !tbaa !5
  %113 = getelementptr inbounds %struct.SM4_GCM_CTX, ptr %112, i32 0, i32 5
  %114 = load i64, ptr %113, align 8, !tbaa !16
  %115 = getelementptr inbounds i8, ptr %111, i64 %114
  %116 = load ptr, ptr %8, align 8, !tbaa !5
  %117 = load i64, ptr %12, align 8, !tbaa !9
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %115, ptr align 1 %116, i64 %117, i1 false)
  %118 = load i64, ptr %12, align 8, !tbaa !9
  %119 = load ptr, ptr %7, align 8, !tbaa !5
  %120 = getelementptr inbounds %struct.SM4_GCM_CTX, ptr %119, i32 0, i32 5
  %121 = load i64, ptr %120, align 8, !tbaa !16
  %122 = add i64 %121, %118
  store i64 %122, ptr %120, align 8, !tbaa !16
  %123 = load i64, ptr %12, align 8, !tbaa !9
  %124 = load ptr, ptr %8, align 8, !tbaa !5
  %125 = getelementptr inbounds i8, ptr %124, i64 %123
  store ptr %125, ptr %8, align 8, !tbaa !5
  %126 = load i64, ptr %12, align 8, !tbaa !9
  %127 = load i64, ptr %9, align 8, !tbaa !9
  %128 = sub i64 %127, %126
  store i64 %128, ptr %9, align 8, !tbaa !9
  br label %129

129:                                              ; preds = %108
  br label %130

130:                                              ; preds = %129, %74
  %131 = load i64, ptr %9, align 8, !tbaa !9
  %132 = load ptr, ptr %7, align 8, !tbaa !5
  %133 = getelementptr inbounds %struct.SM4_GCM_CTX, ptr %132, i32 0, i32 3
  %134 = load i64, ptr %133, align 8, !tbaa !17
  %135 = icmp ule i64 %131, %134
  br i1 %135, label %136, label %184

136:                                              ; preds = %130
  call void @llvm.lifetime.start.p0(i64 16, ptr %14) #5
  %137 = load ptr, ptr %7, align 8, !tbaa !5
  %138 = getelementptr inbounds %struct.SM4_GCM_CTX, ptr %137, i32 0, i32 1
  %139 = load ptr, ptr %7, align 8, !tbaa !5
  %140 = getelementptr inbounds %struct.SM4_GCM_CTX, ptr %139, i32 0, i32 4
  %141 = getelementptr inbounds [16 x i8], ptr %140, i64 0, i64 0
  %142 = load i64, ptr %9, align 8, !tbaa !9
  call void @ghash_update(ptr noundef %138, ptr noundef %141, i64 noundef %142)
  %143 = load ptr, ptr %7, align 8, !tbaa !5
  %144 = getelementptr inbounds %struct.SM4_GCM_CTX, ptr %143, i32 0, i32 0
  %145 = load ptr, ptr %7, align 8, !tbaa !5
  %146 = getelementptr inbounds %struct.SM4_GCM_CTX, ptr %145, i32 0, i32 4
  %147 = getelementptr inbounds [16 x i8], ptr %146, i64 0, i64 0
  %148 = load i64, ptr %9, align 8, !tbaa !9
  %149 = load ptr, ptr %10, align 8, !tbaa !5
  %150 = load ptr, ptr %11, align 8, !tbaa !5
  %151 = call i32 @sm4_ctr32_encrypt_update(ptr noundef %144, ptr noundef %147, i64 noundef %148, ptr noundef %149, ptr noundef %150)
  %152 = icmp ne i32 %151, 1
  br i1 %152, label %153, label %159

153:                                              ; preds = %136
  br label %154

154:                                              ; preds = %153
  %155 = load ptr, ptr @stderr, align 8, !tbaa !5
  %156 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %155, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 278, ptr noundef @__FUNCTION__.sm4_gcm_decrypt_update) #5
  br label %157

157:                                              ; preds = %154
  br label %158

158:                                              ; preds = %157
  store i32 -1, ptr %6, align 4
  store i32 1, ptr %13, align 4
  br label %181

159:                                              ; preds = %136
  %160 = load ptr, ptr %7, align 8, !tbaa !5
  %161 = getelementptr inbounds %struct.SM4_GCM_CTX, ptr %160, i32 0, i32 3
  %162 = load i64, ptr %161, align 8, !tbaa !17
  %163 = load i64, ptr %9, align 8, !tbaa !9
  %164 = sub i64 %162, %163
  store i64 %164, ptr %12, align 8, !tbaa !9
  %165 = getelementptr inbounds [16 x i8], ptr %14, i64 0, i64 0
  %166 = load ptr, ptr %7, align 8, !tbaa !5
  %167 = getelementptr inbounds %struct.SM4_GCM_CTX, ptr %166, i32 0, i32 4
  %168 = getelementptr inbounds [16 x i8], ptr %167, i64 0, i64 0
  %169 = load i64, ptr %9, align 8, !tbaa !9
  %170 = getelementptr inbounds i8, ptr %168, i64 %169
  %171 = load i64, ptr %12, align 8, !tbaa !9
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %165, ptr align 1 %170, i64 %171, i1 false)
  %172 = getelementptr inbounds [16 x i8], ptr %14, i64 0, i64 0
  %173 = load i64, ptr %12, align 8, !tbaa !9
  %174 = getelementptr inbounds i8, ptr %172, i64 %173
  %175 = load ptr, ptr %8, align 8, !tbaa !5
  %176 = load i64, ptr %9, align 8, !tbaa !9
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %174, ptr align 1 %175, i64 %176, i1 false)
  %177 = load ptr, ptr %7, align 8, !tbaa !5
  %178 = getelementptr inbounds %struct.SM4_GCM_CTX, ptr %177, i32 0, i32 4
  %179 = getelementptr inbounds [16 x i8], ptr %178, i64 0, i64 0
  %180 = getelementptr inbounds [16 x i8], ptr %14, i64 0, i64 0
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %179, ptr align 16 %180, i64 16, i1 false)
  store i32 0, ptr %13, align 4
  br label %181

181:                                              ; preds = %159, %158
  call void @llvm.lifetime.end.p0(i64 16, ptr %14) #5
  %182 = load i32, ptr %13, align 4
  switch i32 %182, label %255 [
    i32 0, label %183
  ]

183:                                              ; preds = %181
  br label %249

184:                                              ; preds = %130
  %185 = load ptr, ptr %7, align 8, !tbaa !5
  %186 = getelementptr inbounds %struct.SM4_GCM_CTX, ptr %185, i32 0, i32 1
  %187 = load ptr, ptr %7, align 8, !tbaa !5
  %188 = getelementptr inbounds %struct.SM4_GCM_CTX, ptr %187, i32 0, i32 4
  %189 = getelementptr inbounds [16 x i8], ptr %188, i64 0, i64 0
  %190 = load ptr, ptr %7, align 8, !tbaa !5
  %191 = getelementptr inbounds %struct.SM4_GCM_CTX, ptr %190, i32 0, i32 3
  %192 = load i64, ptr %191, align 8, !tbaa !17
  call void @ghash_update(ptr noundef %186, ptr noundef %189, i64 noundef %192)
  %193 = load ptr, ptr %7, align 8, !tbaa !5
  %194 = getelementptr inbounds %struct.SM4_GCM_CTX, ptr %193, i32 0, i32 0
  %195 = load ptr, ptr %7, align 8, !tbaa !5
  %196 = getelementptr inbounds %struct.SM4_GCM_CTX, ptr %195, i32 0, i32 4
  %197 = getelementptr inbounds [16 x i8], ptr %196, i64 0, i64 0
  %198 = load ptr, ptr %7, align 8, !tbaa !5
  %199 = getelementptr inbounds %struct.SM4_GCM_CTX, ptr %198, i32 0, i32 3
  %200 = load i64, ptr %199, align 8, !tbaa !17
  %201 = load ptr, ptr %10, align 8, !tbaa !5
  %202 = load ptr, ptr %11, align 8, !tbaa !5
  %203 = call i32 @sm4_ctr32_encrypt_update(ptr noundef %194, ptr noundef %197, i64 noundef %200, ptr noundef %201, ptr noundef %202)
  %204 = icmp ne i32 %203, 1
  br i1 %204, label %205, label %211

205:                                              ; preds = %184
  br label %206

206:                                              ; preds = %205
  %207 = load ptr, ptr @stderr, align 8, !tbaa !5
  %208 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %207, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 288, ptr noundef @__FUNCTION__.sm4_gcm_decrypt_update) #5
  br label %209

209:                                              ; preds = %206
  br label %210

210:                                              ; preds = %209
  store i32 -1, ptr %6, align 4
  store i32 1, ptr %13, align 4
  br label %255

211:                                              ; preds = %184
  %212 = load ptr, ptr %11, align 8, !tbaa !5
  %213 = load i64, ptr %212, align 8, !tbaa !9
  %214 = load ptr, ptr %10, align 8, !tbaa !5
  %215 = getelementptr inbounds i8, ptr %214, i64 %213
  store ptr %215, ptr %10, align 8, !tbaa !5
  %216 = load ptr, ptr %7, align 8, !tbaa !5
  %217 = getelementptr inbounds %struct.SM4_GCM_CTX, ptr %216, i32 0, i32 3
  %218 = load i64, ptr %217, align 8, !tbaa !17
  %219 = load i64, ptr %9, align 8, !tbaa !9
  %220 = sub i64 %219, %218
  store i64 %220, ptr %9, align 8, !tbaa !9
  %221 = load ptr, ptr %7, align 8, !tbaa !5
  %222 = getelementptr inbounds %struct.SM4_GCM_CTX, ptr %221, i32 0, i32 1
  %223 = load ptr, ptr %8, align 8, !tbaa !5
  %224 = load i64, ptr %9, align 8, !tbaa !9
  call void @ghash_update(ptr noundef %222, ptr noundef %223, i64 noundef %224)
  %225 = load ptr, ptr %7, align 8, !tbaa !5
  %226 = getelementptr inbounds %struct.SM4_GCM_CTX, ptr %225, i32 0, i32 0
  %227 = load ptr, ptr %8, align 8, !tbaa !5
  %228 = load i64, ptr %9, align 8, !tbaa !9
  %229 = load ptr, ptr %10, align 8, !tbaa !5
  %230 = call i32 @sm4_ctr32_encrypt_update(ptr noundef %226, ptr noundef %227, i64 noundef %228, ptr noundef %229, ptr noundef %12)
  %231 = icmp ne i32 %230, 1
  br i1 %231, label %232, label %238

232:                                              ; preds = %211
  br label %233

233:                                              ; preds = %232
  %234 = load ptr, ptr @stderr, align 8, !tbaa !5
  %235 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %234, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 296, ptr noundef @__FUNCTION__.sm4_gcm_decrypt_update) #5
  br label %236

236:                                              ; preds = %233
  br label %237

237:                                              ; preds = %236
  store i32 -1, ptr %6, align 4
  store i32 1, ptr %13, align 4
  br label %255

238:                                              ; preds = %211
  %239 = load i64, ptr %12, align 8, !tbaa !9
  %240 = load ptr, ptr %11, align 8, !tbaa !5
  %241 = load i64, ptr %240, align 8, !tbaa !9
  %242 = add i64 %241, %239
  store i64 %242, ptr %240, align 8, !tbaa !9
  %243 = load ptr, ptr %7, align 8, !tbaa !5
  %244 = getelementptr inbounds %struct.SM4_GCM_CTX, ptr %243, i32 0, i32 4
  %245 = getelementptr inbounds [16 x i8], ptr %244, i64 0, i64 0
  %246 = load ptr, ptr %8, align 8, !tbaa !5
  %247 = load i64, ptr %9, align 8, !tbaa !9
  %248 = getelementptr inbounds i8, ptr %246, i64 %247
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %245, ptr align 1 %248, i64 16, i1 false)
  br label %249

249:                                              ; preds = %238, %183
  %250 = load i64, ptr %9, align 8, !tbaa !9
  %251 = load ptr, ptr %7, align 8, !tbaa !5
  %252 = getelementptr inbounds %struct.SM4_GCM_CTX, ptr %251, i32 0, i32 6
  %253 = load i64, ptr %252, align 8, !tbaa !11
  %254 = add i64 %253, %250
  store i64 %254, ptr %252, align 8, !tbaa !11
  store i32 1, ptr %6, align 4
  store i32 1, ptr %13, align 4
  br label %255

255:                                              ; preds = %249, %237, %210, %181, %93, %73, %54, %50, %37, %28
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #5
  %256 = load i32, ptr %6, align 4
  ret i32 %256
}

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 = { 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 = { 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 #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 288}
!12 = !{!"", !13, i64 0, !15, i64 168, !7, i64 240, !10, i64 256, !7, i64 264, !10, i64 280, !10, i64 288}
!13 = !{!"", !14, i64 0, !7, i64 128, !7, i64 144, !10, i64 160}
!14 = !{!"", !7, i64 0}
!15 = !{!"", !7, i64 0, !7, i64 16, !10, i64 32, !10, i64 40, !7, i64 48, !10, i64 64}
!16 = !{!12, !10, i64 280}
!17 = !{!12, !10, i64 256}


; 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 [61 x i8], align 1
@__FUNCTION__.sm4_gcm_decrypt_update = external hidden unnamed_addr constant [23 x i8], align 1

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

; Function Attrs: nofree nounwind
declare noundef i32 @fprintf(ptr nocapture noundef, ptr nocapture noundef readonly, ...) local_unnamed_addr #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) #0

declare i32 @sm4_ctr32_encrypt_update(ptr noundef, ptr noundef, i64 noundef, ptr noundef, ptr noundef) local_unnamed_addr #3

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

; Function Attrs: nounwind uwtable
define dso_local range(i32 -1, 2) i32 @sm4_gcm_decrypt_update(ptr noundef %0, ptr noundef %1, i64 noundef %2, ptr noundef %3, ptr noundef %4) local_unnamed_addr #4 {
  %6 = alloca i64, align 8
  %7 = alloca [16 x i8], align 16
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %6) #5
  %8 = icmp ne ptr %0, null
  %9 = icmp ne ptr %1, null
  %or.cond = and i1 %8, %9
  %10 = icmp ne ptr %4, null
  %or.cond3 = and i1 %or.cond, %10
  br i1 %or.cond3, label %14, label %11

11:                                               ; preds = %5
  %12 = load ptr, ptr @stderr, align 8, !tbaa !5
  %13 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %12, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 239, ptr noundef nonnull @__FUNCTION__.sm4_gcm_decrypt_update) #6
  br label %92

14:                                               ; preds = %5
  %15 = icmp ugt i64 %2, 2147483647
  br i1 %15, label %16, label %19

16:                                               ; preds = %14
  %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 243, ptr noundef nonnull @__FUNCTION__.sm4_gcm_decrypt_update) #6
  br label %92

19:                                               ; preds = %14
  %20 = getelementptr inbounds i8, ptr %0, i64 288
  %21 = load i64, ptr %20, align 8, !tbaa !9
  %22 = sub i64 68719476704, %21
  %23 = icmp ult i64 %22, %2
  br i1 %23, label %24, label %27

24:                                               ; preds = %19
  %25 = load ptr, ptr @stderr, align 8, !tbaa !5
  %26 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %25, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 247, ptr noundef nonnull @__FUNCTION__.sm4_gcm_decrypt_update) #6
  br label %92

27:                                               ; preds = %19
  %.not = icmp eq ptr %3, null
  br i1 %.not, label %28, label %31

28:                                               ; preds = %27
  %29 = add nuw nsw i64 %2, 15
  %30 = and i64 %29, 4294967280
  store i64 %30, ptr %4, align 8, !tbaa !15
  br label %92

31:                                               ; preds = %27
  %32 = getelementptr inbounds i8, ptr %0, i64 280
  %33 = load i64, ptr %32, align 8, !tbaa !16
  %34 = getelementptr inbounds i8, ptr %0, i64 256
  %35 = load i64, ptr %34, align 8, !tbaa !17
  %36 = icmp ugt i64 %33, %35
  br i1 %36, label %37, label %40

37:                                               ; preds = %31
  %38 = load ptr, ptr @stderr, align 8, !tbaa !5
  %39 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %38, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 256, ptr noundef nonnull @__FUNCTION__.sm4_gcm_decrypt_update) #6
  br label %92

40:                                               ; preds = %31
  %41 = icmp ult i64 %33, %35
  br i1 %41, label %42, label %54

42:                                               ; preds = %40
  %43 = sub i64 %35, %33
  store i64 %43, ptr %6, align 8, !tbaa !15
  %.not87 = icmp ult i64 %43, %2
  %44 = getelementptr inbounds i8, ptr %0, i64 264
  %45 = getelementptr inbounds i8, ptr %44, i64 %33
  br i1 %.not87, label %49, label %46

46:                                               ; preds = %42
  tail call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 1 %45, ptr nonnull align 1 %1, i64 %2, i1 false)
  %47 = load i64, ptr %32, align 8, !tbaa !16
  %48 = add i64 %47, %2
  store i64 %48, ptr %32, align 8, !tbaa !16
  br label %92

49:                                               ; preds = %42
  tail call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 1 %45, ptr nonnull align 1 %1, i64 %43, i1 false)
  %50 = load i64, ptr %32, align 8, !tbaa !16
  %51 = add i64 %50, %43
  store i64 %51, ptr %32, align 8, !tbaa !16
  %52 = getelementptr inbounds i8, ptr %1, i64 %43
  %53 = sub nsw i64 %2, %43
  %.pre = load i64, ptr %34, align 8, !tbaa !17
  br label %54

54:                                               ; preds = %49, %40
  %55 = phi i64 [ %.pre, %49 ], [ %35, %40 ]
  %.077 = phi ptr [ %52, %49 ], [ %1, %40 ]
  %.075 = phi i64 [ %53, %49 ], [ %2, %40 ]
  %.not88 = icmp ugt i64 %.075, %55
  br i1 %.not88, label %67, label %56

56:                                               ; preds = %54
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %7) #5
  %57 = getelementptr inbounds i8, ptr %0, i64 168
  %58 = getelementptr inbounds i8, ptr %0, i64 264
  tail call void @ghash_update(ptr noundef nonnull %57, ptr noundef nonnull %58, i64 noundef %.075) #5
  %59 = tail call i32 @sm4_ctr32_encrypt_update(ptr noundef nonnull %0, ptr noundef nonnull %58, i64 noundef %.075, ptr noundef nonnull %3, ptr noundef nonnull %4) #5
  %.not91 = icmp eq i32 %59, 1
  br i1 %.not91, label %.thread, label %64

.thread:                                          ; preds = %56
  %60 = load i64, ptr %34, align 8, !tbaa !17
  %61 = sub i64 %60, %.075
  %62 = getelementptr inbounds i8, ptr %58, i64 %.075
  call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 16 %7, ptr nonnull align 1 %62, i64 %61, i1 false)
  %63 = getelementptr inbounds i8, ptr %7, i64 %61
  call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 1 %63, ptr align 1 %.077, i64 %.075, i1 false)
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %58, ptr noundef nonnull align 16 dereferenceable(16) %7, i64 16, i1 false)
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %7) #5
  br label %89

64:                                               ; preds = %56
  %65 = load ptr, ptr @stderr, align 8, !tbaa !5
  %66 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %65, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 278, ptr noundef nonnull @__FUNCTION__.sm4_gcm_decrypt_update) #6
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %7) #5
  br label %92

67:                                               ; preds = %54
  %68 = getelementptr inbounds i8, ptr %0, i64 168
  %69 = getelementptr inbounds i8, ptr %0, i64 264
  tail call void @ghash_update(ptr noundef nonnull %68, ptr noundef nonnull %69, i64 noundef %55) #5
  %70 = load i64, ptr %34, align 8, !tbaa !17
  %71 = tail call i32 @sm4_ctr32_encrypt_update(ptr noundef nonnull %0, ptr noundef nonnull %69, i64 noundef %70, ptr noundef nonnull %3, ptr noundef nonnull %4) #5
  %.not89 = icmp eq i32 %71, 1
  br i1 %.not89, label %75, label %72

72:                                               ; preds = %67
  %73 = load ptr, ptr @stderr, align 8, !tbaa !5
  %74 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %73, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 288, ptr noundef nonnull @__FUNCTION__.sm4_gcm_decrypt_update) #6
  br label %92

75:                                               ; preds = %67
  %76 = load i64, ptr %4, align 8, !tbaa !15
  %77 = getelementptr inbounds i8, ptr %3, i64 %76
  %78 = load i64, ptr %34, align 8, !tbaa !17
  %79 = sub i64 %.075, %78
  tail call void @ghash_update(ptr noundef nonnull %68, ptr noundef %.077, i64 noundef %79) #5
  %80 = call i32 @sm4_ctr32_encrypt_update(ptr noundef nonnull %0, ptr noundef %.077, i64 noundef %79, ptr noundef nonnull %77, ptr noundef nonnull %6) #5
  %.not90 = icmp eq i32 %80, 1
  br i1 %.not90, label %84, label %81

81:                                               ; preds = %75
  %82 = load ptr, ptr @stderr, align 8, !tbaa !5
  %83 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %82, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 296, ptr noundef nonnull @__FUNCTION__.sm4_gcm_decrypt_update) #6
  br label %92

84:                                               ; preds = %75
  %85 = load i64, ptr %6, align 8, !tbaa !15
  %86 = load i64, ptr %4, align 8, !tbaa !15
  %87 = add i64 %86, %85
  store i64 %87, ptr %4, align 8, !tbaa !15
  %88 = getelementptr inbounds i8, ptr %.077, i64 %79
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %69, ptr noundef nonnull align 1 dereferenceable(16) %88, i64 16, i1 false)
  br label %89

89:                                               ; preds = %.thread, %84
  %.176 = phi i64 [ %79, %84 ], [ %.075, %.thread ]
  %90 = load i64, ptr %20, align 8, !tbaa !9
  %91 = add i64 %90, %.176
  store i64 %91, ptr %20, align 8, !tbaa !9
  br label %92

92:                                               ; preds = %64, %89, %81, %72, %46, %37, %28, %24, %16, %11
  %.1 = phi i32 [ -1, %16 ], [ -1, %24 ], [ -1, %37 ], [ 1, %46 ], [ 1, %89 ], [ -1, %64 ], [ -1, %72 ], [ -1, %81 ], [ 1, %28 ], [ -1, %11 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %6) #5
  ret i32 %.1
}

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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 = { 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 #5 = { nounwind }
attributes #6 = { 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 = !{!10, !13, i64 288}
!10 = !{!"", !11, i64 0, !14, i64 168, !7, i64 240, !13, i64 256, !7, i64 264, !13, i64 280, !13, i64 288}
!11 = !{!"", !12, i64 0, !7, i64 128, !7, i64 144, !13, i64 160}
!12 = !{!"", !7, i64 0}
!13 = !{!"long", !7, i64 0}
!14 = !{!"", !7, i64 0, !7, i64 16, !13, i64 32, !13, i64 40, !7, i64 48, !13, i64 64}
!15 = !{!13, !13, i64 0}
!16 = !{!10, !13, i64 280}
!17 = !{!10, !13, i64 256}


; Effective O3 passes: CorrelatedValuePropagationPass,DSEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,SROAPass,SimplifyCFGPass,TailCallElimPass