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

; 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.SM3_LMS_KEY = type { %struct.SM3_LMS_PUBLIC_KEY, ptr, [32 x i8], i32 }
%struct.SM3_LMS_PUBLIC_KEY = type { [4 x i8], [4 x i8], [16 x i8], [32 x i8] }
%struct.SM3_LMS_SIGNATURE = type { [4 x i8], [4 x i8], %struct.anon, [25 x [32 x i8]] }
%struct.anon = type { [4 x i8], [34 x [32 x i8]], [32 x i8] }

@stderr = external global ptr, align 8
@.str.14 = external hidden unnamed_addr constant [13 x i8], align 1
@.str.15 = external hidden unnamed_addr constant [61 x i8], align 1
@__FUNCTION__.sm3_lms_do_sign = external hidden unnamed_addr constant [16 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local i32 @sm3_lms_type_to_height(i32 noundef, ptr noundef) #0

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

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

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #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: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #2

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

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

; Function Attrs: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #4

; Function Attrs: nounwind uwtable
define dso_local i32 @sm3_lms_do_sign(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3) #0 {
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  %14 = alloca ptr, align 8
  %15 = alloca i32, align 4
  %16 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store ptr %2, ptr %8, align 8, !tbaa !5
  store ptr %3, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #5
  %17 = load ptr, ptr %6, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.SM3_LMS_KEY, ptr %17, i32 0, i32 0
  %19 = getelementptr inbounds %struct.SM3_LMS_PUBLIC_KEY, ptr %18, i32 0, i32 0
  %20 = getelementptr inbounds [4 x i8], ptr %19, i64 0, i64 0
  %21 = load i8, ptr %20, align 8, !tbaa !9
  %22 = zext i8 %21 to i32
  %23 = shl i32 %22, 24
  %24 = load ptr, ptr %6, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.SM3_LMS_KEY, ptr %24, i32 0, i32 0
  %26 = getelementptr inbounds %struct.SM3_LMS_PUBLIC_KEY, ptr %25, i32 0, i32 0
  %27 = getelementptr inbounds [4 x i8], ptr %26, i64 0, i64 1
  %28 = load i8, ptr %27, align 1, !tbaa !9
  %29 = zext i8 %28 to i32
  %30 = shl i32 %29, 16
  %31 = or i32 %23, %30
  %32 = load ptr, ptr %6, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.SM3_LMS_KEY, ptr %32, i32 0, i32 0
  %34 = getelementptr inbounds %struct.SM3_LMS_PUBLIC_KEY, ptr %33, i32 0, i32 0
  %35 = getelementptr inbounds [4 x i8], ptr %34, i64 0, i64 2
  %36 = load i8, ptr %35, align 2, !tbaa !9
  %37 = zext i8 %36 to i32
  %38 = shl i32 %37, 8
  %39 = or i32 %31, %38
  %40 = load ptr, ptr %6, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.SM3_LMS_KEY, ptr %40, i32 0, i32 0
  %42 = getelementptr inbounds %struct.SM3_LMS_PUBLIC_KEY, ptr %41, i32 0, i32 0
  %43 = getelementptr inbounds [4 x i8], ptr %42, i64 0, i64 3
  %44 = load i8, ptr %43, align 1, !tbaa !9
  %45 = zext i8 %44 to i32
  %46 = or i32 %39, %45
  store i32 %46, ptr %10, align 4, !tbaa !10
  %47 = load i32, ptr %10, align 4, !tbaa !10
  %48 = call i32 @sm3_lms_type_to_height(i32 noundef %47, ptr noundef %11)
  %49 = icmp ne i32 %48, 1
  br i1 %49, label %50, label %56

50:                                               ; preds = %4
  br label %51

51:                                               ; preds = %50
  %52 = load ptr, ptr @stderr, align 8, !tbaa !5
  %53 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %52, ptr noundef @.str.14, ptr noundef @.str.15, i32 noundef 720, ptr noundef @__FUNCTION__.sm3_lms_do_sign) #5
  br label %54

54:                                               ; preds = %51
  br label %55

55:                                               ; preds = %54
  store i32 -1, ptr %5, align 4
  store i32 1, ptr %16, align 4
  br label %233

56:                                               ; preds = %4
  %57 = load i32, ptr %11, align 4, !tbaa !10
  %58 = shl i32 1, %57
  store i32 %58, ptr %12, align 4, !tbaa !10
  %59 = load i32, ptr %12, align 4, !tbaa !10
  %60 = load ptr, ptr %6, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.SM3_LMS_KEY, ptr %60, i32 0, i32 3
  %62 = load i32, ptr %61, align 8, !tbaa !12
  %63 = add nsw i32 %59, %62
  store i32 %63, ptr %13, align 4, !tbaa !10
  %64 = load ptr, ptr %6, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.SM3_LMS_KEY, ptr %64, i32 0, i32 1
  %66 = load ptr, ptr %65, align 8, !tbaa !15
  %67 = icmp ne ptr %66, null
  br i1 %67, label %96, label %68

68:                                               ; preds = %56
  %69 = load i32, ptr %12, align 4, !tbaa !10
  %70 = mul nsw i32 2, %69
  %71 = sub nsw i32 %70, 1
  %72 = sext i32 %71 to i64
  %73 = mul i64 32, %72
  %74 = call noalias ptr @malloc(i64 noundef %73) #6
  %75 = load ptr, ptr %6, align 8, !tbaa !5
  %76 = getelementptr inbounds %struct.SM3_LMS_KEY, ptr %75, i32 0, i32 1
  store ptr %74, ptr %76, align 8, !tbaa !15
  %77 = icmp ne ptr %74, null
  br i1 %77, label %84, label %78

78:                                               ; preds = %68
  br label %79

79:                                               ; preds = %78
  %80 = load ptr, ptr @stderr, align 8, !tbaa !5
  %81 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %80, ptr noundef @.str.14, ptr noundef @.str.15, i32 noundef 728, ptr noundef @__FUNCTION__.sm3_lms_do_sign) #5
  br label %82

82:                                               ; preds = %79
  br label %83

83:                                               ; preds = %82
  store i32 -1, ptr %5, align 4
  store i32 1, ptr %16, align 4
  br label %233

84:                                               ; preds = %68
  %85 = load ptr, ptr %6, align 8, !tbaa !5
  %86 = getelementptr inbounds %struct.SM3_LMS_KEY, ptr %85, i32 0, i32 2
  %87 = getelementptr inbounds [32 x i8], ptr %86, i64 0, i64 0
  %88 = load ptr, ptr %6, align 8, !tbaa !5
  %89 = getelementptr inbounds %struct.SM3_LMS_KEY, ptr %88, i32 0, i32 0
  %90 = getelementptr inbounds %struct.SM3_LMS_PUBLIC_KEY, ptr %89, i32 0, i32 2
  %91 = getelementptr inbounds [16 x i8], ptr %90, i64 0, i64 0
  %92 = load i32, ptr %11, align 4, !tbaa !10
  %93 = load ptr, ptr %6, align 8, !tbaa !5
  %94 = getelementptr inbounds %struct.SM3_LMS_KEY, ptr %93, i32 0, i32 1
  %95 = load ptr, ptr %94, align 8, !tbaa !15
  call void @sm3_lms_derive_merkle_tree(ptr noundef %87, ptr noundef %91, i32 noundef %92, ptr noundef %95)
  br label %96

96:                                               ; preds = %84, %56
  %97 = load ptr, ptr %6, align 8, !tbaa !5
  %98 = getelementptr inbounds %struct.SM3_LMS_KEY, ptr %97, i32 0, i32 1
  %99 = load ptr, ptr %98, align 8, !tbaa !15
  %100 = getelementptr inbounds [32 x i8], ptr %99, i64 -1
  store ptr %100, ptr %14, align 8, !tbaa !5
  %101 = load i32, ptr %10, align 4, !tbaa !10
  %102 = ashr i32 %101, 24
  %103 = trunc i32 %102 to i8
  %104 = load ptr, ptr %9, align 8, !tbaa !5
  %105 = getelementptr inbounds %struct.SM3_LMS_SIGNATURE, ptr %104, i32 0, i32 0
  %106 = getelementptr inbounds [4 x i8], ptr %105, i64 0, i64 0
  store i8 %103, ptr %106, align 1, !tbaa !9
  %107 = load i32, ptr %10, align 4, !tbaa !10
  %108 = ashr i32 %107, 16
  %109 = trunc i32 %108 to i8
  %110 = load ptr, ptr %9, align 8, !tbaa !5
  %111 = getelementptr inbounds %struct.SM3_LMS_SIGNATURE, ptr %110, i32 0, i32 0
  %112 = getelementptr inbounds [4 x i8], ptr %111, i64 0, i64 1
  store i8 %109, ptr %112, align 1, !tbaa !9
  %113 = load i32, ptr %10, align 4, !tbaa !10
  %114 = ashr i32 %113, 8
  %115 = trunc i32 %114 to i8
  %116 = load ptr, ptr %9, align 8, !tbaa !5
  %117 = getelementptr inbounds %struct.SM3_LMS_SIGNATURE, ptr %116, i32 0, i32 0
  %118 = getelementptr inbounds [4 x i8], ptr %117, i64 0, i64 2
  store i8 %115, ptr %118, align 1, !tbaa !9
  %119 = load i32, ptr %10, align 4, !tbaa !10
  %120 = trunc i32 %119 to i8
  %121 = load ptr, ptr %9, align 8, !tbaa !5
  %122 = getelementptr inbounds %struct.SM3_LMS_SIGNATURE, ptr %121, i32 0, i32 0
  %123 = getelementptr inbounds [4 x i8], ptr %122, i64 0, i64 3
  store i8 %120, ptr %123, align 1, !tbaa !9
  %124 = load ptr, ptr %6, align 8, !tbaa !5
  %125 = getelementptr inbounds %struct.SM3_LMS_KEY, ptr %124, i32 0, i32 3
  %126 = load i32, ptr %125, align 8, !tbaa !12
  %127 = ashr i32 %126, 24
  %128 = trunc i32 %127 to i8
  %129 = load ptr, ptr %9, align 8, !tbaa !5
  %130 = getelementptr inbounds %struct.SM3_LMS_SIGNATURE, ptr %129, i32 0, i32 1
  %131 = getelementptr inbounds [4 x i8], ptr %130, i64 0, i64 0
  store i8 %128, ptr %131, align 1, !tbaa !9
  %132 = load ptr, ptr %6, align 8, !tbaa !5
  %133 = getelementptr inbounds %struct.SM3_LMS_KEY, ptr %132, i32 0, i32 3
  %134 = load i32, ptr %133, align 8, !tbaa !12
  %135 = ashr i32 %134, 16
  %136 = trunc i32 %135 to i8
  %137 = load ptr, ptr %9, align 8, !tbaa !5
  %138 = getelementptr inbounds %struct.SM3_LMS_SIGNATURE, ptr %137, i32 0, i32 1
  %139 = getelementptr inbounds [4 x i8], ptr %138, i64 0, i64 1
  store i8 %136, ptr %139, align 1, !tbaa !9
  %140 = load ptr, ptr %6, align 8, !tbaa !5
  %141 = getelementptr inbounds %struct.SM3_LMS_KEY, ptr %140, i32 0, i32 3
  %142 = load i32, ptr %141, align 8, !tbaa !12
  %143 = ashr i32 %142, 8
  %144 = trunc i32 %143 to i8
  %145 = load ptr, ptr %9, align 8, !tbaa !5
  %146 = getelementptr inbounds %struct.SM3_LMS_SIGNATURE, ptr %145, i32 0, i32 1
  %147 = getelementptr inbounds [4 x i8], ptr %146, i64 0, i64 2
  store i8 %144, ptr %147, align 1, !tbaa !9
  %148 = load ptr, ptr %6, align 8, !tbaa !5
  %149 = getelementptr inbounds %struct.SM3_LMS_KEY, ptr %148, i32 0, i32 3
  %150 = load i32, ptr %149, align 8, !tbaa !12
  %151 = trunc i32 %150 to i8
  %152 = load ptr, ptr %9, align 8, !tbaa !5
  %153 = getelementptr inbounds %struct.SM3_LMS_SIGNATURE, ptr %152, i32 0, i32 1
  %154 = getelementptr inbounds [4 x i8], ptr %153, i64 0, i64 3
  store i8 %151, ptr %154, align 1, !tbaa !9
  %155 = load ptr, ptr %9, align 8, !tbaa !5
  %156 = getelementptr inbounds %struct.SM3_LMS_SIGNATURE, ptr %155, i32 0, i32 2
  %157 = getelementptr inbounds %struct.anon, ptr %156, i32 0, i32 0
  %158 = getelementptr inbounds [4 x i8], ptr %157, i64 0, i64 0
  store i8 0, ptr %158, align 1, !tbaa !9
  %159 = load ptr, ptr %9, align 8, !tbaa !5
  %160 = getelementptr inbounds %struct.SM3_LMS_SIGNATURE, ptr %159, i32 0, i32 2
  %161 = getelementptr inbounds %struct.anon, ptr %160, i32 0, i32 0
  %162 = getelementptr inbounds [4 x i8], ptr %161, i64 0, i64 1
  store i8 0, ptr %162, align 1, !tbaa !9
  %163 = load ptr, ptr %9, align 8, !tbaa !5
  %164 = getelementptr inbounds %struct.SM3_LMS_SIGNATURE, ptr %163, i32 0, i32 2
  %165 = getelementptr inbounds %struct.anon, ptr %164, i32 0, i32 0
  %166 = getelementptr inbounds [4 x i8], ptr %165, i64 0, i64 2
  store i8 0, ptr %166, align 1, !tbaa !9
  %167 = load ptr, ptr %9, align 8, !tbaa !5
  %168 = getelementptr inbounds %struct.SM3_LMS_SIGNATURE, ptr %167, i32 0, i32 2
  %169 = getelementptr inbounds %struct.anon, ptr %168, i32 0, i32 0
  %170 = getelementptr inbounds [4 x i8], ptr %169, i64 0, i64 3
  store i8 4, ptr %170, align 1, !tbaa !9
  %171 = load ptr, ptr %6, align 8, !tbaa !5
  %172 = getelementptr inbounds %struct.SM3_LMS_KEY, ptr %171, i32 0, i32 2
  %173 = getelementptr inbounds [32 x i8], ptr %172, i64 0, i64 0
  %174 = load ptr, ptr %6, align 8, !tbaa !5
  %175 = getelementptr inbounds %struct.SM3_LMS_KEY, ptr %174, i32 0, i32 0
  %176 = getelementptr inbounds %struct.SM3_LMS_PUBLIC_KEY, ptr %175, i32 0, i32 2
  %177 = getelementptr inbounds [16 x i8], ptr %176, i64 0, i64 0
  %178 = load ptr, ptr %6, align 8, !tbaa !5
  %179 = getelementptr inbounds %struct.SM3_LMS_KEY, ptr %178, i32 0, i32 3
  %180 = load i32, ptr %179, align 8, !tbaa !12
  %181 = load ptr, ptr %9, align 8, !tbaa !5
  %182 = getelementptr inbounds %struct.SM3_LMS_SIGNATURE, ptr %181, i32 0, i32 2
  %183 = getelementptr inbounds %struct.anon, ptr %182, i32 0, i32 1
  %184 = getelementptr inbounds [34 x [32 x i8]], ptr %183, i64 0, i64 0
  call void @sm3_lmots_derive_secrets(ptr noundef %173, ptr noundef %177, i32 noundef %180, ptr noundef %184)
  %185 = load ptr, ptr %6, align 8, !tbaa !5
  %186 = getelementptr inbounds %struct.SM3_LMS_KEY, ptr %185, i32 0, i32 0
  %187 = getelementptr inbounds %struct.SM3_LMS_PUBLIC_KEY, ptr %186, i32 0, i32 2
  %188 = getelementptr inbounds [16 x i8], ptr %187, i64 0, i64 0
  %189 = load ptr, ptr %6, align 8, !tbaa !5
  %190 = getelementptr inbounds %struct.SM3_LMS_KEY, ptr %189, i32 0, i32 3
  %191 = load i32, ptr %190, align 8, !tbaa !12
  %192 = load ptr, ptr %8, align 8, !tbaa !5
  %193 = load ptr, ptr %9, align 8, !tbaa !5
  %194 = getelementptr inbounds %struct.SM3_LMS_SIGNATURE, ptr %193, i32 0, i32 2
  %195 = getelementptr inbounds %struct.anon, ptr %194, i32 0, i32 1
  %196 = getelementptr inbounds [34 x [32 x i8]], ptr %195, i64 0, i64 0
  %197 = load ptr, ptr %9, align 8, !tbaa !5
  %198 = getelementptr inbounds %struct.SM3_LMS_SIGNATURE, ptr %197, i32 0, i32 2
  %199 = getelementptr inbounds %struct.anon, ptr %198, i32 0, i32 1
  %200 = getelementptr inbounds [34 x [32 x i8]], ptr %199, i64 0, i64 0
  call void @sm3_lmots_compute_signature(ptr noundef %188, i32 noundef %191, ptr noundef %192, ptr noundef %196, ptr noundef %200)
  %201 = load ptr, ptr %6, align 8, !tbaa !5
  %202 = getelementptr inbounds %struct.SM3_LMS_KEY, ptr %201, i32 0, i32 3
  %203 = load i32, ptr %202, align 8, !tbaa !12
  %204 = add nsw i32 %203, 1
  store i32 %204, ptr %202, align 8, !tbaa !12
  %205 = load ptr, ptr %9, align 8, !tbaa !5
  %206 = getelementptr inbounds %struct.SM3_LMS_SIGNATURE, ptr %205, i32 0, i32 2
  %207 = getelementptr inbounds %struct.anon, ptr %206, i32 0, i32 2
  %208 = getelementptr inbounds [32 x i8], ptr %207, i64 0, i64 0
  %209 = load ptr, ptr %7, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %208, ptr align 1 %209, i64 32, i1 false)
  store i32 0, ptr %15, align 4, !tbaa !10
  br label %210

210:                                              ; preds = %229, %96
  %211 = load i32, ptr %15, align 4, !tbaa !10
  %212 = load i32, ptr %11, align 4, !tbaa !10
  %213 = icmp slt i32 %211, %212
  br i1 %213, label %214, label %232

214:                                              ; preds = %210
  %215 = load ptr, ptr %9, align 8, !tbaa !5
  %216 = getelementptr inbounds %struct.SM3_LMS_SIGNATURE, ptr %215, i32 0, i32 3
  %217 = load i32, ptr %15, align 4, !tbaa !10
  %218 = sext i32 %217 to i64
  %219 = getelementptr inbounds [25 x [32 x i8]], ptr %216, i64 0, i64 %218
  %220 = getelementptr inbounds [32 x i8], ptr %219, i64 0, i64 0
  %221 = load ptr, ptr %14, align 8, !tbaa !5
  %222 = load i32, ptr %13, align 4, !tbaa !10
  %223 = xor i32 %222, 1
  %224 = sext i32 %223 to i64
  %225 = getelementptr inbounds [32 x i8], ptr %221, i64 %224
  %226 = getelementptr inbounds [32 x i8], ptr %225, i64 0, i64 0
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %220, ptr align 1 %226, i64 32, i1 false)
  %227 = load i32, ptr %13, align 4, !tbaa !10
  %228 = sdiv i32 %227, 2
  store i32 %228, ptr %13, align 4, !tbaa !10
  br label %229

229:                                              ; preds = %214
  %230 = load i32, ptr %15, align 4, !tbaa !10
  %231 = add nsw i32 %230, 1
  store i32 %231, ptr %15, align 4, !tbaa !10
  br label %210, !llvm.loop !16

232:                                              ; preds = %210
  store i32 1, ptr %5, align 4
  store i32 1, ptr %16, align 4
  br label %233

233:                                              ; preds = %232, %83, %55
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #5
  %234 = load i32, ptr %5, align 4
  ret i32 %234
}

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 = { 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 nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { nounwind allocsize(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 = { nounwind allocsize(0) }

!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 = !{!"int", !7, i64 0}
!12 = !{!13, !11, i64 96}
!13 = !{!"", !14, i64 0, !6, i64 56, !7, i64 64, !11, i64 96}
!14 = !{!"", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 24}
!15 = !{!13, !6, i64 56}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}


; 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.14 = external hidden unnamed_addr constant [13 x i8], align 1
@.str.15 = external hidden unnamed_addr constant [61 x i8], align 1
@__FUNCTION__.sm3_lms_do_sign = external hidden unnamed_addr constant [16 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local i32 @sm3_lms_type_to_height(i32 noundef, ptr noundef) local_unnamed_addr #0

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

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

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

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

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #4

; Function Attrs: nounwind uwtable
define dso_local range(i32 -1, 2) i32 @sm3_lms_do_sign(ptr noundef %0, ptr nocapture noundef readonly %1, ptr noundef %2, ptr noundef %3) local_unnamed_addr #0 {
  %5 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %5) #5
  %6 = load i8, ptr %0, align 8, !tbaa !5
  %7 = zext i8 %6 to i32
  %8 = shl nuw i32 %7, 24
  %9 = getelementptr inbounds i8, ptr %0, i64 1
  %10 = load i8, ptr %9, align 1, !tbaa !5
  %11 = zext i8 %10 to i32
  %12 = shl nuw nsw i32 %11, 16
  %13 = or disjoint i32 %12, %8
  %14 = getelementptr inbounds i8, ptr %0, i64 2
  %15 = load i8, ptr %14, align 2, !tbaa !5
  %16 = zext i8 %15 to i32
  %17 = shl nuw nsw i32 %16, 8
  %18 = getelementptr inbounds i8, ptr %0, i64 3
  %19 = load i8, ptr %18, align 1, !tbaa !5
  %20 = zext i8 %19 to i32
  %21 = or disjoint i32 %13, %17
  %22 = or disjoint i32 %21, %20
  %23 = call i32 @sm3_lms_type_to_height(i32 noundef %22, ptr noundef nonnull %5)
  %.not = icmp eq i32 %23, 1
  br i1 %.not, label %24, label %.loopexit.sink.split

24:                                               ; preds = %4
  %25 = load i32, ptr %5, align 4, !tbaa !8
  %26 = shl nuw i32 1, %25
  %27 = getelementptr inbounds i8, ptr %0, i64 96
  %28 = load i32, ptr %27, align 8, !tbaa !10
  %29 = add nsw i32 %26, %28
  %30 = getelementptr inbounds i8, ptr %0, i64 56
  %31 = load ptr, ptr %30, align 8, !tbaa !14
  %.not56 = icmp eq ptr %31, null
  br i1 %.not56, label %32, label %41

32:                                               ; preds = %24
  %33 = shl i32 2, %25
  %34 = add nsw i32 %33, -1
  %35 = sext i32 %34 to i64
  %36 = shl nsw i64 %35, 5
  %37 = call noalias ptr @malloc(i64 noundef %36) #6
  store ptr %37, ptr %30, align 8, !tbaa !14
  %.not57 = icmp eq ptr %37, null
  br i1 %.not57, label %.loopexit.sink.split, label %38

38:                                               ; preds = %32
  %39 = getelementptr inbounds i8, ptr %0, i64 64
  %40 = getelementptr inbounds i8, ptr %0, i64 8
  call void @sm3_lms_derive_merkle_tree(ptr noundef nonnull %39, ptr noundef nonnull %40, i32 noundef %25, ptr noundef nonnull %37)
  %.pre = load ptr, ptr %30, align 8, !tbaa !14
  br label %41

41:                                               ; preds = %38, %24
  %42 = phi ptr [ %.pre, %38 ], [ %31, %24 ]
  %43 = getelementptr inbounds i8, ptr %42, i64 -32
  store i8 %6, ptr %3, align 1, !tbaa !5
  %44 = getelementptr inbounds i8, ptr %3, i64 1
  store i8 %10, ptr %44, align 1, !tbaa !5
  %45 = getelementptr inbounds i8, ptr %3, i64 2
  store i8 %15, ptr %45, align 1, !tbaa !5
  %46 = getelementptr inbounds i8, ptr %3, i64 3
  store i8 %19, ptr %46, align 1, !tbaa !5
  %47 = load i32, ptr %27, align 8, !tbaa !10
  %48 = lshr i32 %47, 24
  %49 = trunc nuw i32 %48 to i8
  %50 = getelementptr inbounds i8, ptr %3, i64 4
  store i8 %49, ptr %50, align 1, !tbaa !5
  %51 = load i32, ptr %27, align 8, !tbaa !10
  %52 = lshr i32 %51, 16
  %53 = trunc i32 %52 to i8
  %54 = getelementptr inbounds i8, ptr %3, i64 5
  store i8 %53, ptr %54, align 1, !tbaa !5
  %55 = load i32, ptr %27, align 8, !tbaa !10
  %56 = lshr i32 %55, 8
  %57 = trunc i32 %56 to i8
  %58 = getelementptr inbounds i8, ptr %3, i64 6
  store i8 %57, ptr %58, align 1, !tbaa !5
  %59 = load i32, ptr %27, align 8, !tbaa !10
  %60 = trunc i32 %59 to i8
  %61 = getelementptr inbounds i8, ptr %3, i64 7
  store i8 %60, ptr %61, align 1, !tbaa !5
  %62 = getelementptr inbounds i8, ptr %3, i64 8
  store <4 x i8> <i8 0, i8 0, i8 0, i8 4>, ptr %62, align 1, !tbaa !5
  %63 = getelementptr inbounds i8, ptr %0, i64 64
  %64 = getelementptr inbounds i8, ptr %0, i64 8
  %65 = load i32, ptr %27, align 8, !tbaa !10
  %66 = getelementptr inbounds i8, ptr %3, i64 12
  call void @sm3_lmots_derive_secrets(ptr noundef nonnull %63, ptr noundef nonnull %64, i32 noundef %65, ptr noundef nonnull %66)
  %67 = load i32, ptr %27, align 8, !tbaa !10
  call void @sm3_lmots_compute_signature(ptr noundef nonnull %64, i32 noundef %67, ptr noundef %2, ptr noundef nonnull %66, ptr noundef nonnull %66)
  %68 = load i32, ptr %27, align 8, !tbaa !10
  %69 = add nsw i32 %68, 1
  store i32 %69, ptr %27, align 8, !tbaa !10
  %70 = getelementptr inbounds i8, ptr %3, i64 1100
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 1 dereferenceable(32) %70, ptr noundef nonnull align 1 dereferenceable(32) %1, i64 32, i1 false)
  %71 = load i32, ptr %5, align 4, !tbaa !8
  %72 = icmp sgt i32 %71, 0
  br i1 %72, label %.lr.ph, label %.loopexit

.lr.ph:                                           ; preds = %41
  %73 = getelementptr inbounds i8, ptr %3, i64 1132
  %wide.trip.count = zext nneg i32 %71 to i64
  %xtraiter = and i64 %wide.trip.count, 1
  %74 = icmp eq i32 %71, 1
  br i1 %74, label %.loopexit.loopexit.unr-lcssa, label %.lr.ph.new

.lr.ph.new:                                       ; preds = %.lr.ph
  %unroll_iter = and i64 %wide.trip.count, 2147483646
  br label %75

75:                                               ; preds = %75, %.lr.ph.new
  %indvars.iv = phi i64 [ 0, %.lr.ph.new ], [ %indvars.iv.next.1, %75 ]
  %.05458 = phi i32 [ %29, %.lr.ph.new ], [ %85, %75 ]
  %niter = phi i64 [ 0, %.lr.ph.new ], [ %niter.next.1, %75 ]
  %76 = getelementptr inbounds [25 x [32 x i8]], ptr %73, i64 0, i64 %indvars.iv
  %77 = xor i32 %.05458, 1
  %78 = sext i32 %77 to i64
  %79 = getelementptr inbounds [32 x i8], ptr %43, i64 %78
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 1 dereferenceable(32) %76, ptr noundef nonnull align 1 dereferenceable(32) %79, i64 32, i1 false)
  %80 = sdiv i32 %.05458, 2
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %81 = getelementptr inbounds [25 x [32 x i8]], ptr %73, i64 0, i64 %indvars.iv.next
  %82 = xor i32 %80, 1
  %83 = sext i32 %82 to i64
  %84 = getelementptr inbounds [32 x i8], ptr %43, i64 %83
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 1 dereferenceable(32) %81, ptr noundef nonnull align 1 dereferenceable(32) %84, i64 32, i1 false)
  %85 = sdiv i32 %.05458, 4
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
  %niter.next.1 = add i64 %niter, 2
  %niter.ncmp.1 = icmp eq i64 %niter.next.1, %unroll_iter
  br i1 %niter.ncmp.1, label %.loopexit.loopexit.unr-lcssa, label %75, !llvm.loop !15

.loopexit.sink.split:                             ; preds = %32, %4
  %.sink61 = phi i32 [ 720, %4 ], [ 728, %32 ]
  %86 = load ptr, ptr @stderr, align 8, !tbaa !17
  %87 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %86, ptr noundef nonnull @.str.14, ptr noundef nonnull @.str.15, i32 noundef %.sink61, ptr noundef nonnull @__FUNCTION__.sm3_lms_do_sign) #7
  br label %.loopexit

.loopexit.loopexit.unr-lcssa:                     ; preds = %75, %.lr.ph
  %indvars.iv.unr = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next.1, %75 ]
  %.05458.unr = phi i32 [ %29, %.lr.ph ], [ %85, %75 ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %.loopexit, label %.loopexit.loopexit.epilog-lcssa

.loopexit.loopexit.epilog-lcssa:                  ; preds = %.loopexit.loopexit.unr-lcssa
  %88 = getelementptr inbounds [25 x [32 x i8]], ptr %73, i64 0, i64 %indvars.iv.unr
  %89 = xor i32 %.05458.unr, 1
  %90 = sext i32 %89 to i64
  %91 = getelementptr inbounds [32 x i8], ptr %43, i64 %90
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 1 dereferenceable(32) %88, ptr noundef nonnull align 1 dereferenceable(32) %91, i64 32, i1 false)
  br label %.loopexit

.loopexit:                                        ; preds = %.loopexit.loopexit.epilog-lcssa, %.loopexit.loopexit.unr-lcssa, %.loopexit.sink.split, %41
  %.053 = phi i32 [ 1, %41 ], [ -1, %.loopexit.sink.split ], [ 1, %.loopexit.loopexit.unr-lcssa ], [ 1, %.loopexit.loopexit.epilog-lcssa ]
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %5) #5
  ret i32 %.053
}

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 = { 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 nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" "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 = { nounwind allocsize(0) }
attributes #7 = { 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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = !{!9, !9, i64 0}
!9 = !{!"int", !6, i64 0}
!10 = !{!11, !9, i64 96}
!11 = !{!"", !12, i64 0, !13, i64 56, !6, i64 64, !9, i64 96}
!12 = !{!"", !6, i64 0, !6, i64 4, !6, i64 8, !6, i64 24}
!13 = !{!"any pointer", !6, i64 0}
!14 = !{!11, !13, i64 56}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = !{!13, !13, i64 0}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SLPVectorizerPass,SROAPass,SimplifyCFGPass