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

; 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_CBC_MAC_CTX = type { %struct.SM4_KEY, [16 x i8], i64 }
%struct.SM4_KEY = type { [32 x 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 [61 x i8], align 1
@__FUNCTION__.sm4_ccm_decrypt = external hidden unnamed_addr constant [16 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 nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #1

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

; 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

; Function Attrs: nounwind uwtable
declare hidden void @length_to_bytes(i64 noundef, i64 noundef, ptr noundef) #4

declare void @sm4_cbc_mac_update(ptr noundef, ptr noundef, i64 noundef) #5

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

declare void @sm4_encrypt(ptr noundef, ptr noundef, ptr noundef) #5

; Function Attrs: nounwind uwtable
declare hidden void @sm4_ctr_n_encrypt(ptr noundef, ptr noundef, i64 noundef, ptr noundef, i64 noundef, ptr noundef) #4

declare void @sm4_cbc_mac_finish(ptr noundef, ptr noundef) #5

declare void @gmssl_memxor(ptr noundef, ptr noundef, ptr noundef, i64 noundef) #5

declare void @gmssl_secure_clear(ptr noundef, i64 noundef) #5

; Function Attrs: nounwind uwtable
define dso_local i32 @sm4_ccm_decrypt(ptr noundef %0, ptr noundef %1, i64 noundef %2, ptr noundef %3, i64 noundef %4, ptr noundef %5, i64 noundef %6, ptr noundef %7, i64 noundef %8, ptr noundef %9) #4 {
  %11 = alloca i32, align 4
  %12 = alloca ptr, align 8
  %13 = alloca ptr, align 8
  %14 = alloca i64, align 8
  %15 = alloca ptr, align 8
  %16 = alloca i64, align 8
  %17 = alloca ptr, align 8
  %18 = alloca i64, align 8
  %19 = alloca ptr, align 8
  %20 = alloca i64, align 8
  %21 = alloca ptr, align 8
  %22 = alloca %struct.SM4_CBC_MAC_CTX, align 8
  %23 = alloca [16 x i8], align 16
  %24 = alloca [16 x i8], align 16
  %25 = alloca [16 x i8], align 16
  %26 = alloca [16 x i8], align 16
  %27 = alloca i64, align 8
  %28 = alloca i32, align 4
  %29 = alloca i64, align 8
  store ptr %0, ptr %12, align 8, !tbaa !5
  store ptr %1, ptr %13, align 8, !tbaa !5
  store i64 %2, ptr %14, align 8, !tbaa !9
  store ptr %3, ptr %15, align 8, !tbaa !5
  store i64 %4, ptr %16, align 8, !tbaa !9
  store ptr %5, ptr %17, align 8, !tbaa !5
  store i64 %6, ptr %18, align 8, !tbaa !9
  store ptr %7, ptr %19, align 8, !tbaa !5
  store i64 %8, ptr %20, align 8, !tbaa !9
  store ptr %9, ptr %21, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 152, ptr %22) #7
  call void @llvm.lifetime.start.p0(i64 16, ptr %23) #7
  call void @llvm.memset.p0.i64(ptr align 16 %23, i8 0, i64 16, i1 false)
  call void @llvm.lifetime.start.p0(i64 16, ptr %24) #7
  call void @llvm.memset.p0.i64(ptr align 16 %24, i8 0, i64 16, i1 false)
  call void @llvm.lifetime.start.p0(i64 16, ptr %25) #7
  call void @llvm.memset.p0.i64(ptr align 16 %25, i8 0, i64 16, i1 false)
  call void @llvm.lifetime.start.p0(i64 16, ptr %26) #7
  call void @llvm.lifetime.start.p0(i64 8, ptr %27) #7
  %30 = load i64, ptr %14, align 8, !tbaa !9
  %31 = icmp ult i64 %30, 7
  br i1 %31, label %35, label %32

32:                                               ; preds = %10
  %33 = load i64, ptr %14, align 8, !tbaa !9
  %34 = icmp ugt i64 %33, 13
  br i1 %34, label %35, label %41

35:                                               ; preds = %32, %10
  br label %36

36:                                               ; preds = %35
  %37 = load ptr, ptr @stderr, align 8, !tbaa !5
  %38 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %37, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 149, ptr noundef @__FUNCTION__.sm4_ccm_decrypt) #7
  br label %39

39:                                               ; preds = %36
  br label %40

40:                                               ; preds = %39
  store i32 -1, ptr %11, align 4
  store i32 1, ptr %28, align 4
  br label %234

41:                                               ; preds = %32
  %42 = load ptr, ptr %15, align 8, !tbaa !5
  %43 = icmp ne ptr %42, null
  br i1 %43, label %53, label %44

44:                                               ; preds = %41
  %45 = load i64, ptr %16, align 8, !tbaa !9
  %46 = icmp ne i64 %45, 0
  br i1 %46, label %47, label %53

47:                                               ; preds = %44
  br label %48

48:                                               ; preds = %47
  %49 = load ptr, ptr @stderr, align 8, !tbaa !5
  %50 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %49, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 153, ptr noundef @__FUNCTION__.sm4_ccm_decrypt) #7
  br label %51

51:                                               ; preds = %48
  br label %52

52:                                               ; preds = %51
  store i32 -1, ptr %11, align 4
  store i32 1, ptr %28, align 4
  br label %234

53:                                               ; preds = %44, %41
  %54 = load i64, ptr %20, align 8, !tbaa !9
  %55 = icmp ult i64 %54, 4
  br i1 %55, label %63, label %56

56:                                               ; preds = %53
  %57 = load i64, ptr %20, align 8, !tbaa !9
  %58 = icmp ugt i64 %57, 16
  br i1 %58, label %63, label %59

59:                                               ; preds = %56
  %60 = load i64, ptr %20, align 8, !tbaa !9
  %61 = and i64 %60, 1
  %62 = icmp ne i64 %61, 0
  br i1 %62, label %63, label %69

63:                                               ; preds = %59, %56, %53
  br label %64

64:                                               ; preds = %63
  %65 = load ptr, ptr @stderr, align 8, !tbaa !5
  %66 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %65, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 157, ptr noundef @__FUNCTION__.sm4_ccm_decrypt) #7
  br label %67

67:                                               ; preds = %64
  br label %68

68:                                               ; preds = %67
  store i32 -1, ptr %11, align 4
  store i32 1, ptr %28, align 4
  br label %234

69:                                               ; preds = %59
  %70 = load i64, ptr %14, align 8, !tbaa !9
  %71 = sub i64 15, %70
  store i64 %71, ptr %27, align 8, !tbaa !9
  %72 = load i64, ptr %27, align 8, !tbaa !9
  %73 = icmp ult i64 %72, 8
  br i1 %73, label %74, label %88

74:                                               ; preds = %69
  %75 = load i64, ptr %18, align 8, !tbaa !9
  %76 = load i64, ptr %27, align 8, !tbaa !9
  %77 = mul i64 %76, 8
  %78 = trunc i64 %77 to i32
  %79 = shl i32 1, %78
  %80 = sext i32 %79 to i64
  %81 = icmp uge i64 %75, %80
  br i1 %81, label %82, label %88

82:                                               ; preds = %74
  br label %83

83:                                               ; preds = %82
  %84 = load ptr, ptr @stderr, align 8, !tbaa !5
  %85 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %84, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 163, ptr noundef @__FUNCTION__.sm4_ccm_decrypt) #7
  br label %86

86:                                               ; preds = %83
  br label %87

87:                                               ; preds = %86
  store i32 -1, ptr %11, align 4
  store i32 1, ptr %28, align 4
  br label %234

88:                                               ; preds = %74, %69
  call void @llvm.memset.p0.i64(ptr align 8 %22, i8 0, i64 152, i1 false)
  %89 = getelementptr inbounds %struct.SM4_CBC_MAC_CTX, ptr %22, i32 0, i32 0
  %90 = load ptr, ptr %12, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %89, ptr align 4 %90, i64 128, i1 false), !tbaa.struct !11
  %91 = load i64, ptr %16, align 8, !tbaa !9
  %92 = icmp ugt i64 %91, 0
  %93 = zext i1 %92 to i32
  %94 = and i32 %93, 1
  %95 = shl i32 %94, 6
  %96 = getelementptr inbounds [16 x i8], ptr %24, i64 0, i64 0
  %97 = load i8, ptr %96, align 16, !tbaa !12
  %98 = zext i8 %97 to i32
  %99 = or i32 %98, %95
  %100 = trunc i32 %99 to i8
  store i8 %100, ptr %96, align 16, !tbaa !12
  %101 = load i64, ptr %20, align 8, !tbaa !9
  %102 = sub i64 %101, 2
  %103 = udiv i64 %102, 2
  %104 = and i64 %103, 7
  %105 = shl i64 %104, 3
  %106 = getelementptr inbounds [16 x i8], ptr %24, i64 0, i64 0
  %107 = load i8, ptr %106, align 16, !tbaa !12
  %108 = zext i8 %107 to i64
  %109 = or i64 %108, %105
  %110 = trunc i64 %109 to i8
  store i8 %110, ptr %106, align 16, !tbaa !12
  %111 = load i64, ptr %27, align 8, !tbaa !9
  %112 = sub i64 %111, 1
  %113 = and i64 %112, 7
  %114 = getelementptr inbounds [16 x i8], ptr %24, i64 0, i64 0
  %115 = load i8, ptr %114, align 16, !tbaa !12
  %116 = zext i8 %115 to i64
  %117 = or i64 %116, %113
  %118 = trunc i64 %117 to i8
  store i8 %118, ptr %114, align 16, !tbaa !12
  %119 = getelementptr inbounds [16 x i8], ptr %24, i64 0, i64 0
  %120 = getelementptr inbounds i8, ptr %119, i64 1
  %121 = load ptr, ptr %13, align 8, !tbaa !5
  %122 = load i64, ptr %14, align 8, !tbaa !9
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %120, ptr align 1 %121, i64 %122, i1 false)
  %123 = load i64, ptr %18, align 8, !tbaa !9
  %124 = load i64, ptr %27, align 8, !tbaa !9
  %125 = getelementptr inbounds [16 x i8], ptr %24, i64 0, i64 0
  %126 = getelementptr inbounds i8, ptr %125, i64 1
  %127 = load i64, ptr %14, align 8, !tbaa !9
  %128 = getelementptr inbounds i8, ptr %126, i64 %127
  call void @length_to_bytes(i64 noundef %123, i64 noundef %124, ptr noundef %128)
  %129 = getelementptr inbounds [16 x i8], ptr %24, i64 0, i64 0
  call void @sm4_cbc_mac_update(ptr noundef %22, ptr noundef %129, i64 noundef 16)
  %130 = load ptr, ptr %15, align 8, !tbaa !5
  %131 = icmp ne ptr %130, null
  br i1 %131, label %132, label %175

132:                                              ; preds = %88
  %133 = load i64, ptr %16, align 8, !tbaa !9
  %134 = icmp ne i64 %133, 0
  br i1 %134, label %135, label %175

135:                                              ; preds = %132
  call void @llvm.lifetime.start.p0(i64 8, ptr %29) #7
  %136 = load i64, ptr %16, align 8, !tbaa !9
  %137 = icmp ult i64 %136, 65280
  br i1 %137, label %138, label %141

138:                                              ; preds = %135
  %139 = load i64, ptr %16, align 8, !tbaa !9
  %140 = getelementptr inbounds [16 x i8], ptr %24, i64 0, i64 0
  call void @length_to_bytes(i64 noundef %139, i64 noundef 2, ptr noundef %140)
  store i64 2, ptr %29, align 8, !tbaa !9
  br label %157

141:                                              ; preds = %135
  %142 = load i64, ptr %16, align 8, !tbaa !9
  %143 = icmp ult i64 %142, 4294967296
  br i1 %143, label %144, label %150

144:                                              ; preds = %141
  %145 = getelementptr inbounds [16 x i8], ptr %24, i64 0, i64 0
  store i8 -1, ptr %145, align 16, !tbaa !12
  %146 = getelementptr inbounds [16 x i8], ptr %24, i64 0, i64 1
  store i8 -2, ptr %146, align 1, !tbaa !12
  %147 = load i64, ptr %16, align 8, !tbaa !9
  %148 = getelementptr inbounds [16 x i8], ptr %24, i64 0, i64 0
  %149 = getelementptr inbounds i8, ptr %148, i64 2
  call void @length_to_bytes(i64 noundef %147, i64 noundef 4, ptr noundef %149)
  store i64 6, ptr %29, align 8, !tbaa !9
  br label %156

150:                                              ; preds = %141
  %151 = getelementptr inbounds [16 x i8], ptr %24, i64 0, i64 0
  store i8 -1, ptr %151, align 16, !tbaa !12
  %152 = getelementptr inbounds [16 x i8], ptr %24, i64 0, i64 1
  store i8 -1, ptr %152, align 1, !tbaa !12
  %153 = load i64, ptr %16, align 8, !tbaa !9
  %154 = getelementptr inbounds [16 x i8], ptr %24, i64 0, i64 0
  %155 = getelementptr inbounds i8, ptr %154, i64 2
  call void @length_to_bytes(i64 noundef %153, i64 noundef 8, ptr noundef %155)
  store i64 10, ptr %29, align 8, !tbaa !9
  br label %156

156:                                              ; preds = %150, %144
  br label %157

157:                                              ; preds = %156, %138
  %158 = getelementptr inbounds [16 x i8], ptr %24, i64 0, i64 0
  %159 = load i64, ptr %29, align 8, !tbaa !9
  call void @sm4_cbc_mac_update(ptr noundef %22, ptr noundef %158, i64 noundef %159)
  %160 = load ptr, ptr %15, align 8, !tbaa !5
  %161 = load i64, ptr %16, align 8, !tbaa !9
  call void @sm4_cbc_mac_update(ptr noundef %22, ptr noundef %160, i64 noundef %161)
  %162 = load i64, ptr %29, align 8, !tbaa !9
  %163 = load i64, ptr %16, align 8, !tbaa !9
  %164 = urem i64 %163, 16
  %165 = add i64 %162, %164
  %166 = icmp ne i64 %165, 0
  br i1 %166, label %167, label %174

167:                                              ; preds = %157
  %168 = getelementptr inbounds [16 x i8], ptr %23, i64 0, i64 0
  %169 = load i64, ptr %29, align 8, !tbaa !9
  %170 = load i64, ptr %16, align 8, !tbaa !9
  %171 = add i64 %169, %170
  %172 = urem i64 %171, 16
  %173 = sub i64 16, %172
  call void @sm4_cbc_mac_update(ptr noundef %22, ptr noundef %168, i64 noundef %173)
  br label %174

174:                                              ; preds = %167, %157
  call void @llvm.lifetime.end.p0(i64 8, ptr %29) #7
  br label %175

175:                                              ; preds = %174, %132, %88
  %176 = getelementptr inbounds [16 x i8], ptr %25, i64 0, i64 0
  store i8 0, ptr %176, align 16, !tbaa !12
  %177 = load i64, ptr %27, align 8, !tbaa !9
  %178 = sub i64 %177, 1
  %179 = and i64 %178, 7
  %180 = getelementptr inbounds [16 x i8], ptr %25, i64 0, i64 0
  %181 = load i8, ptr %180, align 16, !tbaa !12
  %182 = zext i8 %181 to i64
  %183 = or i64 %182, %179
  %184 = trunc i64 %183 to i8
  store i8 %184, ptr %180, align 16, !tbaa !12
  %185 = getelementptr inbounds [16 x i8], ptr %25, i64 0, i64 0
  %186 = getelementptr inbounds i8, ptr %185, i64 1
  %187 = load ptr, ptr %13, align 8, !tbaa !5
  %188 = load i64, ptr %14, align 8, !tbaa !9
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %186, ptr align 1 %187, i64 %188, i1 false)
  %189 = getelementptr inbounds [16 x i8], ptr %25, i64 0, i64 0
  %190 = getelementptr inbounds i8, ptr %189, i64 1
  %191 = load i64, ptr %14, align 8, !tbaa !9
  %192 = getelementptr inbounds i8, ptr %190, i64 %191
  %193 = load i64, ptr %14, align 8, !tbaa !9
  %194 = sub i64 15, %193
  call void @llvm.memset.p0.i64(ptr align 1 %192, i8 0, i64 %194, i1 false)
  %195 = load ptr, ptr %12, align 8, !tbaa !5
  %196 = getelementptr inbounds [16 x i8], ptr %25, i64 0, i64 0
  %197 = getelementptr inbounds [16 x i8], ptr %24, i64 0, i64 0
  call void @sm4_encrypt(ptr noundef %195, ptr noundef %196, ptr noundef %197)
  %198 = getelementptr inbounds [16 x i8], ptr %25, i64 0, i64 15
  store i8 1, ptr %198, align 1, !tbaa !12
  %199 = load ptr, ptr %12, align 8, !tbaa !5
  %200 = getelementptr inbounds [16 x i8], ptr %25, i64 0, i64 0
  %201 = load i64, ptr %14, align 8, !tbaa !9
  %202 = sub i64 15, %201
  %203 = load ptr, ptr %17, align 8, !tbaa !5
  %204 = load i64, ptr %18, align 8, !tbaa !9
  %205 = load ptr, ptr %21, align 8, !tbaa !5
  call void @sm4_ctr_n_encrypt(ptr noundef %199, ptr noundef %200, i64 noundef %202, ptr noundef %203, i64 noundef %204, ptr noundef %205)
  %206 = load ptr, ptr %21, align 8, !tbaa !5
  %207 = load i64, ptr %18, align 8, !tbaa !9
  call void @sm4_cbc_mac_update(ptr noundef %22, ptr noundef %206, i64 noundef %207)
  %208 = load i64, ptr %18, align 8, !tbaa !9
  %209 = urem i64 %208, 16
  %210 = icmp ne i64 %209, 0
  br i1 %210, label %211, label %216

211:                                              ; preds = %175
  %212 = getelementptr inbounds [16 x i8], ptr %23, i64 0, i64 0
  %213 = load i64, ptr %18, align 8, !tbaa !9
  %214 = urem i64 %213, 16
  %215 = sub i64 16, %214
  call void @sm4_cbc_mac_update(ptr noundef %22, ptr noundef %212, i64 noundef %215)
  br label %216

216:                                              ; preds = %211, %175
  %217 = getelementptr inbounds [16 x i8], ptr %26, i64 0, i64 0
  call void @sm4_cbc_mac_finish(ptr noundef %22, ptr noundef %217)
  %218 = getelementptr inbounds [16 x i8], ptr %26, i64 0, i64 0
  %219 = getelementptr inbounds [16 x i8], ptr %26, i64 0, i64 0
  %220 = getelementptr inbounds [16 x i8], ptr %24, i64 0, i64 0
  %221 = load i64, ptr %20, align 8, !tbaa !9
  call void @gmssl_memxor(ptr noundef %218, ptr noundef %219, ptr noundef %220, i64 noundef %221)
  %222 = getelementptr inbounds [16 x i8], ptr %26, i64 0, i64 0
  %223 = load ptr, ptr %19, align 8, !tbaa !5
  %224 = load i64, ptr %20, align 8, !tbaa !9
  %225 = call i32 @memcmp(ptr noundef %222, ptr noundef %223, i64 noundef %224) #8
  %226 = icmp ne i32 %225, 0
  br i1 %226, label %227, label %233

227:                                              ; preds = %216
  br label %228

228:                                              ; preds = %227
  %229 = load ptr, ptr @stderr, align 8, !tbaa !5
  %230 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %229, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 220, ptr noundef @__FUNCTION__.sm4_ccm_decrypt) #7
  br label %231

231:                                              ; preds = %228
  br label %232

232:                                              ; preds = %231
  call void @gmssl_secure_clear(ptr noundef %22, i64 noundef 152)
  store i32 -1, ptr %11, align 4
  store i32 1, ptr %28, align 4
  br label %234

233:                                              ; preds = %216
  call void @gmssl_secure_clear(ptr noundef %22, i64 noundef 152)
  store i32 1, ptr %11, align 4
  store i32 1, ptr %28, align 4
  br label %234

234:                                              ; preds = %233, %232, %87, %68, %52, %40
  call void @llvm.lifetime.end.p0(i64 8, ptr %27) #7
  call void @llvm.lifetime.end.p0(i64 16, ptr %26) #7
  call void @llvm.lifetime.end.p0(i64 16, ptr %25) #7
  call void @llvm.lifetime.end.p0(i64 16, ptr %24) #7
  call void @llvm.lifetime.end.p0(i64 16, ptr %23) #7
  call void @llvm.lifetime.end.p0(i64 152, ptr %22) #7
  %235 = load i32, ptr %11, align 4
  ret i32 %235
}

; Function Attrs: nounwind willreturn memory(read)
declare i32 @memcmp(ptr noundef, ptr noundef, i64 noundef) #6

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #2 = { 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 #3 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 = { "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 #6 = { nounwind willreturn memory(read) "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 #7 = { nounwind }
attributes #8 = { nounwind willreturn memory(read) }

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

%struct.SM4_CBC_MAC_CTX = type { %struct.SM4_KEY, [16 x i8], i64 }
%struct.SM4_KEY = type { [32 x i32] }

@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_ccm_decrypt = external hidden unnamed_addr constant [16 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: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #1

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

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

; Function Attrs: nounwind uwtable
declare hidden void @length_to_bytes(i64 noundef, i64 noundef, ptr noundef) local_unnamed_addr #4

declare void @sm4_cbc_mac_update(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #5

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

declare void @sm4_encrypt(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #5

; Function Attrs: nounwind uwtable
declare hidden void @sm4_ctr_n_encrypt(ptr noundef, ptr noundef, i64 noundef, ptr noundef, i64 noundef, ptr noundef) local_unnamed_addr #4

declare void @sm4_cbc_mac_finish(ptr noundef, ptr noundef) local_unnamed_addr #5

declare void @gmssl_memxor(ptr noundef, ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #5

declare void @gmssl_secure_clear(ptr noundef, i64 noundef) local_unnamed_addr #5

; Function Attrs: nounwind uwtable
define dso_local range(i32 -1, 2) i32 @sm4_ccm_decrypt(ptr noundef %0, ptr nocapture noundef readonly %1, i64 noundef %2, ptr noundef %3, i64 noundef %4, ptr noundef %5, i64 noundef %6, ptr nocapture noundef readonly %7, i64 noundef %8, ptr noundef %9) local_unnamed_addr #4 {
  %11 = alloca %struct.SM4_CBC_MAC_CTX, align 8
  %12 = alloca [16 x i8], align 16
  %13 = alloca [16 x i8], align 16
  %14 = alloca [16 x i8], align 16
  %15 = alloca [16 x i8], align 16
  call void @llvm.lifetime.start.p0(i64 152, ptr nonnull %11) #7
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %12) #7
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(16) %12, i8 0, i64 16, i1 false)
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %13) #7
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(16) %13, i8 0, i64 16, i1 false)
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %14) #7
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(16) %14, i8 0, i64 16, i1 false)
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %15) #7
  %16 = add i64 %2, -14
  %or.cond = icmp ult i64 %16, -7
  br i1 %or.cond, label %17, label %20

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

20:                                               ; preds = %10
  %21 = icmp eq ptr %3, null
  %22 = icmp ne i64 %4, 0
  %or.cond3 = and i1 %21, %22
  br i1 %or.cond3, label %23, label %26

23:                                               ; preds = %20
  %24 = load ptr, ptr @stderr, align 8, !tbaa !5
  %25 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %24, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 153, ptr noundef nonnull @__FUNCTION__.sm4_ccm_decrypt) #8
  br label %80

26:                                               ; preds = %20
  %27 = add i64 %8, -4
  %or.cond5 = icmp ult i64 %27, 13
  %28 = and i64 %8, 1
  %.not = icmp eq i64 %28, 0
  %or.cond71 = and i1 %or.cond5, %.not
  br i1 %or.cond71, label %32, label %29

29:                                               ; preds = %26
  %30 = load ptr, ptr @stderr, align 8, !tbaa !5
  %31 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %30, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 157, ptr noundef nonnull @__FUNCTION__.sm4_ccm_decrypt) #8
  br label %80

32:                                               ; preds = %26
  %33 = sub nuw nsw i64 15, %2
  %34 = icmp ugt i64 %2, 7
  br i1 %34, label %35, label %42

35:                                               ; preds = %32
  %.tr = trunc nuw nsw i64 %33 to i32
  %36 = shl nuw nsw i32 %.tr, 3
  %37 = shl nuw i32 1, %36
  %38 = zext nneg i32 %37 to i64
  %.not66 = icmp ugt i64 %38, %6
  br i1 %.not66, label %42, label %39

39:                                               ; preds = %35
  %40 = load ptr, ptr @stderr, align 8, !tbaa !5
  %41 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %40, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 163, ptr noundef nonnull @__FUNCTION__.sm4_ccm_decrypt) #8
  br label %80

42:                                               ; preds = %35, %32
  %43 = getelementptr inbounds i8, ptr %11, i64 128
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(24) %43, i8 0, i64 24, i1 false)
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(128) %11, ptr noundef nonnull align 4 dereferenceable(128) %0, i64 128, i1 false), !tbaa.struct !9
  %.not67 = icmp eq i64 %4, 0
  %44 = select i1 %.not67, i8 0, i8 64
  %.tr68 = trunc nuw i64 %8 to i8
  %45 = shl nuw nsw i8 %.tr68, 2
  %46 = add nuw nsw i8 %45, 56
  %47 = and i8 %46, 56
  %48 = trunc nuw i64 %2 to i8
  %49 = sub nsw i8 6, %48
  %50 = and i8 %49, 7
  %51 = or disjoint i8 %44, %47
  %52 = or disjoint i8 %51, %50
  store i8 %52, ptr %13, align 16, !tbaa !10
  %53 = getelementptr inbounds i8, ptr %13, i64 1
  call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 1 %53, ptr align 1 %1, i64 %2, i1 false)
  %54 = getelementptr inbounds i8, ptr %53, i64 %2
  call void @length_to_bytes(i64 noundef %6, i64 noundef %33, ptr noundef nonnull %54)
  call void @sm4_cbc_mac_update(ptr noundef nonnull %11, ptr noundef nonnull %13, i64 noundef 16) #7
  %55 = icmp ne ptr %3, null
  %or.cond7 = and i1 %55, %22
  br i1 %or.cond7, label %56, label %68

56:                                               ; preds = %42
  %57 = icmp ult i64 %4, 65280
  br i1 %57, label %58, label %59

58:                                               ; preds = %56
  call void @length_to_bytes(i64 noundef %4, i64 noundef 2, ptr noundef nonnull %13)
  br label %64

59:                                               ; preds = %56
  %60 = icmp ult i64 %4, 4294967296
  store i8 -1, ptr %13, align 16, !tbaa !10
  %61 = getelementptr inbounds i8, ptr %13, i64 2
  br i1 %60, label %62, label %63

62:                                               ; preds = %59
  store i8 -2, ptr %53, align 1, !tbaa !10
  call void @length_to_bytes(i64 noundef %4, i64 noundef 4, ptr noundef nonnull %61)
  br label %64

63:                                               ; preds = %59
  store i8 -1, ptr %53, align 1, !tbaa !10
  call void @length_to_bytes(i64 noundef %4, i64 noundef 8, ptr noundef nonnull %61)
  br label %64

64:                                               ; preds = %62, %63, %58
  %.0 = phi i64 [ 2, %58 ], [ 6, %62 ], [ 10, %63 ]
  call void @sm4_cbc_mac_update(ptr noundef nonnull %11, ptr noundef nonnull %13, i64 noundef %.0) #7
  call void @sm4_cbc_mac_update(ptr noundef nonnull %11, ptr noundef nonnull %3, i64 noundef %4) #7
  %65 = add i64 %.0, %4
  %66 = and i64 %65, 15
  %67 = sub nuw nsw i64 16, %66
  call void @sm4_cbc_mac_update(ptr noundef nonnull %11, ptr noundef nonnull %12, i64 noundef %67) #7
  br label %68

68:                                               ; preds = %64, %42
  store i8 %50, ptr %14, align 16, !tbaa !10
  %69 = getelementptr inbounds i8, ptr %14, i64 1
  call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 1 %69, ptr align 1 %1, i64 %2, i1 false)
  %70 = getelementptr inbounds i8, ptr %69, i64 %2
  call void @llvm.memset.p0.i64(ptr nonnull align 1 %70, i8 0, i64 %33, i1 false)
  call void @sm4_encrypt(ptr noundef nonnull %0, ptr noundef nonnull %14, ptr noundef nonnull %13) #7
  %71 = getelementptr inbounds i8, ptr %14, i64 15
  store i8 1, ptr %71, align 1, !tbaa !10
  call void @sm4_ctr_n_encrypt(ptr noundef nonnull %0, ptr noundef nonnull %14, i64 noundef %33, ptr noundef %5, i64 noundef %6, ptr noundef %9)
  call void @sm4_cbc_mac_update(ptr noundef nonnull %11, ptr noundef %9, i64 noundef %6) #7
  %72 = and i64 %6, 15
  %.not69 = icmp eq i64 %72, 0
  br i1 %.not69, label %75, label %73

73:                                               ; preds = %68
  %74 = sub nuw nsw i64 16, %72
  call void @sm4_cbc_mac_update(ptr noundef nonnull %11, ptr noundef nonnull %12, i64 noundef %74) #7
  br label %75

75:                                               ; preds = %73, %68
  call void @sm4_cbc_mac_finish(ptr noundef nonnull %11, ptr noundef nonnull %15) #7
  call void @gmssl_memxor(ptr noundef nonnull %15, ptr noundef nonnull %15, ptr noundef nonnull %13, i64 noundef %8) #7
  %bcmp = call i32 @bcmp(ptr nonnull %15, ptr %7, i64 %8)
  %.not70 = icmp eq i32 %bcmp, 0
  br i1 %.not70, label %79, label %76

76:                                               ; preds = %75
  %77 = load ptr, ptr @stderr, align 8, !tbaa !5
  %78 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %77, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 220, ptr noundef nonnull @__FUNCTION__.sm4_ccm_decrypt) #8
  call void @gmssl_secure_clear(ptr noundef nonnull %11, i64 noundef 152) #7
  br label %80

79:                                               ; preds = %75
  call void @gmssl_secure_clear(ptr noundef nonnull %11, i64 noundef 152) #7
  br label %80

80:                                               ; preds = %79, %76, %39, %29, %23, %17
  %.059 = phi i32 [ -1, %17 ], [ -1, %23 ], [ -1, %29 ], [ -1, %39 ], [ -1, %76 ], [ 1, %79 ]
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %15) #7
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %14) #7
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %13) #7
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %12) #7
  call void @llvm.lifetime.end.p0(i64 152, ptr nonnull %11) #7
  ret i32 %.059
}

; Function Attrs: nofree nounwind willreturn memory(argmem: read)
declare i32 @bcmp(ptr nocapture, ptr nocapture, i64) local_unnamed_addr #6

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #2 = { 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 #3 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 = { "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 #6 = { nofree nounwind willreturn memory(argmem: read) }
attributes #7 = { nounwind }
attributes #8 = { 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 = !{i64 0, i64 128, !10}
!10 = !{!7, !7, i64 0}


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