; LLVM IR from paintdream/DontStarveLuaJIT :: src/luajit/src (lj_str)

; 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.lua_State = type { %union.anon }
%union.anon = type { %struct.anon, [320 x i8] }
%struct.anon = type { %struct.GCRef, i8, i8, i8, i8, %struct.MRef, %struct.GCRef, ptr, ptr, %struct.MRef, %struct.MRef, %struct.GCRef, %struct.GCRef, ptr, i32 }
%struct.MRef = type { i32 }
%struct.GCRef = type { i32 }
%struct.global_State = type { ptr, i32, i32, ptr, ptr, %struct.GCState, i32, %struct.SBuf, %struct.GCstr, i8, i8, i8, i8, %struct.GCRef, %union.TValue, %union.TValue, %union.TValue, %struct.Node, %struct.GCupval, i32, i32, ptr, ptr, ptr, i32, i32, %struct.GCRef, %struct.MRef, %struct.MRef, [38 x %struct.GCRef] }
%struct.GCState = type { i32, i32, i8, i8, i8, i8, i32, %struct.GCRef, %struct.MRef, %struct.GCRef, %struct.GCRef, %struct.GCRef, %struct.GCRef, i32, i32, i32, i32 }
%struct.SBuf = type { %struct.MRef, %struct.MRef, %struct.MRef, %struct.MRef }
%struct.GCstr = type { %struct.GCRef, i8, i8, i8, i8, i32, i32 }
%union.TValue = type { i64 }
%struct.Node = type { %union.TValue, %union.TValue, %struct.MRef, %struct.MRef }
%struct.GCupval = type { %struct.GCRef, i8, i8, i8, i8, %union.anon.4, %struct.MRef, i32 }
%union.anon.4 = type { %union.TValue }
%struct.GChead = type { %struct.GCRef, i8, i8, i8, i8, %struct.GCRef, %struct.GCRef, %struct.GCRef }

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

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

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

; Function Attrs: nounwind uwtable
declare hidden void @lj_str_resize(ptr noundef, i32 noundef) #2

declare hidden ptr @lj_mem_realloc(ptr noundef, ptr noundef, i32 noundef, i32 noundef) #3

; Function Attrs: nounwind uwtable
define hidden ptr @lj_str_new(ptr noundef %0, ptr noundef %1, i64 noundef %2) #2 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i64, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  %15 = alloca i32, align 4
  %16 = alloca i64, align 8
  %17 = alloca i64, align 8
  %18 = alloca i32, align 4
  %19 = alloca ptr, align 8
  %20 = alloca ptr, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store i64 %2, ptr %7, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #8
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #8
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #8
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #8
  %21 = load i64, ptr %7, align 8, !tbaa !9
  %22 = trunc i64 %21 to i32
  store i32 %22, ptr %11, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #8
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #8
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #8
  %23 = load i32, ptr %11, align 4, !tbaa !11
  store i32 %23, ptr %14, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #8
  %24 = load i32, ptr %11, align 4, !tbaa !11
  store i32 %24, ptr %15, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #8
  call void @llvm.lifetime.start.p0(i64 8, ptr %17) #8
  %25 = load i64, ptr %7, align 8, !tbaa !9
  %26 = icmp uge i64 %25, 2147483392
  br i1 %26, label %27, label %29

27:                                               ; preds = %3
  %28 = load ptr, ptr %5, align 8, !tbaa !5
  call void @lj_err_msg(ptr noundef %28, i32 noundef 56) #9
  unreachable

29:                                               ; preds = %3
  %30 = load ptr, ptr %5, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.lua_State, ptr %30, i32 0, i32 0
  %32 = getelementptr inbounds %struct.anon, ptr %31, i32 0, i32 5
  %33 = getelementptr inbounds %struct.MRef, ptr %32, i32 0, i32 0
  %34 = load i32, ptr %33, align 8, !tbaa !13
  %35 = zext i32 %34 to i64
  %36 = inttoptr i64 %35 to ptr
  store ptr %36, ptr %8, align 8, !tbaa !5
  %37 = load i32, ptr %11, align 4, !tbaa !11
  %38 = icmp eq i32 %37, 0
  br i1 %38, label %39, label %42

39:                                               ; preds = %29
  %40 = load ptr, ptr %8, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.global_State, ptr %40, i32 0, i32 8
  store ptr %41, ptr %4, align 8
  store i32 1, ptr %18, align 4
  br label %284

42:                                               ; preds = %29
  %43 = load i32, ptr %15, align 4, !tbaa !11
  store i32 %43, ptr %14, align 4, !tbaa !11
  %44 = load i32, ptr %15, align 4, !tbaa !11
  %45 = lshr i32 %44, 5
  %46 = add i32 %45, 1
  %47 = zext i32 %46 to i64
  store i64 %47, ptr %16, align 8, !tbaa !9
  %48 = load i32, ptr %15, align 4, !tbaa !11
  %49 = zext i32 %48 to i64
  store i64 %49, ptr %17, align 8, !tbaa !9
  br label %50

50:                                               ; preds = %69, %42
  %51 = load i64, ptr %17, align 8, !tbaa !9
  %52 = load i64, ptr %16, align 8, !tbaa !9
  %53 = icmp uge i64 %51, %52
  br i1 %53, label %54, label %73

54:                                               ; preds = %50
  %55 = load i32, ptr %14, align 4, !tbaa !11
  %56 = load i32, ptr %14, align 4, !tbaa !11
  %57 = shl i32 %56, 5
  %58 = load i32, ptr %14, align 4, !tbaa !11
  %59 = lshr i32 %58, 2
  %60 = add i32 %57, %59
  %61 = load ptr, ptr %6, align 8, !tbaa !5
  %62 = load i64, ptr %17, align 8, !tbaa !9
  %63 = sub i64 %62, 1
  %64 = getelementptr inbounds i8, ptr %61, i64 %63
  %65 = load i8, ptr %64, align 1, !tbaa !13
  %66 = zext i8 %65 to i32
  %67 = add i32 %60, %66
  %68 = xor i32 %55, %67
  store i32 %68, ptr %14, align 4, !tbaa !11
  br label %69

69:                                               ; preds = %54
  %70 = load i64, ptr %16, align 8, !tbaa !9
  %71 = load i64, ptr %17, align 8, !tbaa !9
  %72 = sub i64 %71, %70
  store i64 %72, ptr %17, align 8, !tbaa !9
  br label %50, !llvm.loop !14

73:                                               ; preds = %50
  %74 = load ptr, ptr %8, align 8, !tbaa !5
  %75 = getelementptr inbounds %struct.global_State, ptr %74, i32 0, i32 0
  %76 = load ptr, ptr %75, align 8, !tbaa !16
  %77 = load i32, ptr %14, align 4, !tbaa !11
  %78 = load ptr, ptr %8, align 8, !tbaa !5
  %79 = getelementptr inbounds %struct.global_State, ptr %78, i32 0, i32 1
  %80 = load i32, ptr %79, align 8, !tbaa !25
  %81 = and i32 %77, %80
  %82 = zext i32 %81 to i64
  %83 = getelementptr inbounds %struct.GCRef, ptr %76, i64 %82
  %84 = getelementptr inbounds %struct.GCRef, ptr %83, i32 0, i32 0
  %85 = load i32, ptr %84, align 4, !tbaa !26
  %86 = zext i32 %85 to i64
  %87 = inttoptr i64 %86 to ptr
  store ptr %87, ptr %10, align 8, !tbaa !5
  %88 = load ptr, ptr %6, align 8, !tbaa !5
  %89 = ptrtoint ptr %88 to i64
  %90 = load i32, ptr %11, align 4, !tbaa !11
  %91 = zext i32 %90 to i64
  %92 = add i64 %89, %91
  %93 = sub i64 %92, 1
  %94 = and i64 %93, 4095
  %95 = icmp ule i64 %94, 4092
  %96 = xor i1 %95, true
  %97 = xor i1 %96, true
  %98 = zext i1 %97 to i32
  %99 = sext i32 %98 to i64
  %100 = call i64 @llvm.expect.i64(i64 %99, i64 1)
  %101 = icmp ne i64 %100, 0
  br i1 %101, label %102, label %154

102:                                              ; preds = %73
  br label %103

103:                                              ; preds = %152, %102
  %104 = load ptr, ptr %10, align 8, !tbaa !5
  %105 = icmp ne ptr %104, null
  br i1 %105, label %106, label %153

106:                                              ; preds = %103
  call void @llvm.lifetime.start.p0(i64 8, ptr %19) #8
  %107 = load ptr, ptr %10, align 8, !tbaa !5
  store ptr %107, ptr %19, align 8, !tbaa !5
  %108 = load ptr, ptr %19, align 8, !tbaa !5
  %109 = getelementptr inbounds %struct.GCstr, ptr %108, i32 0, i32 6
  %110 = load i32, ptr %109, align 4, !tbaa !27
  %111 = load i32, ptr %11, align 4, !tbaa !11
  %112 = icmp eq i32 %110, %111
  br i1 %112, label %113, label %143

113:                                              ; preds = %106
  %114 = load ptr, ptr %6, align 8, !tbaa !5
  %115 = load ptr, ptr %19, align 8, !tbaa !5
  %116 = getelementptr inbounds %struct.GCstr, ptr %115, i64 1
  %117 = load i32, ptr %11, align 4, !tbaa !11
  %118 = call i32 @str_fastcmp(ptr noundef %114, ptr noundef %116, i32 noundef %117)
  %119 = icmp eq i32 %118, 0
  br i1 %119, label %120, label %143

120:                                              ; preds = %113
  %121 = load ptr, ptr %10, align 8, !tbaa !5
  %122 = getelementptr inbounds %struct.GChead, ptr %121, i32 0, i32 1
  %123 = load i8, ptr %122, align 4, !tbaa !13
  %124 = zext i8 %123 to i32
  %125 = load ptr, ptr %8, align 8, !tbaa !5
  %126 = getelementptr inbounds %struct.global_State, ptr %125, i32 0, i32 5
  %127 = getelementptr inbounds %struct.GCState, ptr %126, i32 0, i32 2
  %128 = load i8, ptr %127, align 8, !tbaa !28
  %129 = zext i8 %128 to i32
  %130 = xor i32 %129, 3
  %131 = and i32 %124, %130
  %132 = and i32 %131, 3
  %133 = icmp ne i32 %132, 0
  br i1 %133, label %134, label %141

134:                                              ; preds = %120
  %135 = load ptr, ptr %10, align 8, !tbaa !5
  %136 = getelementptr inbounds %struct.GChead, ptr %135, i32 0, i32 1
  %137 = load i8, ptr %136, align 4, !tbaa !13
  %138 = zext i8 %137 to i32
  %139 = xor i32 %138, 3
  %140 = trunc i32 %139 to i8
  store i8 %140, ptr %136, align 4, !tbaa !13
  br label %141

141:                                              ; preds = %134, %120
  %142 = load ptr, ptr %19, align 8, !tbaa !5
  store ptr %142, ptr %4, align 8
  store i32 1, ptr %18, align 4
  br label %150

143:                                              ; preds = %113, %106
  %144 = load ptr, ptr %10, align 8, !tbaa !5
  %145 = getelementptr inbounds %struct.GChead, ptr %144, i32 0, i32 0
  %146 = getelementptr inbounds %struct.GCRef, ptr %145, i32 0, i32 0
  %147 = load i32, ptr %146, align 8, !tbaa !13
  %148 = zext i32 %147 to i64
  %149 = inttoptr i64 %148 to ptr
  store ptr %149, ptr %10, align 8, !tbaa !5
  store i32 0, ptr %18, align 4
  br label %150

150:                                              ; preds = %143, %141
  call void @llvm.lifetime.end.p0(i64 8, ptr %19) #8
  %151 = load i32, ptr %18, align 4
  switch i32 %151, label %284 [
    i32 0, label %152
  ]

152:                                              ; preds = %150
  br label %103, !llvm.loop !29

153:                                              ; preds = %103
  br label %207

154:                                              ; preds = %73
  br label %155

155:                                              ; preds = %205, %154
  %156 = load ptr, ptr %10, align 8, !tbaa !5
  %157 = icmp ne ptr %156, null
  br i1 %157, label %158, label %206

158:                                              ; preds = %155
  call void @llvm.lifetime.start.p0(i64 8, ptr %20) #8
  %159 = load ptr, ptr %10, align 8, !tbaa !5
  store ptr %159, ptr %20, align 8, !tbaa !5
  %160 = load ptr, ptr %20, align 8, !tbaa !5
  %161 = getelementptr inbounds %struct.GCstr, ptr %160, i32 0, i32 6
  %162 = load i32, ptr %161, align 4, !tbaa !27
  %163 = load i32, ptr %11, align 4, !tbaa !11
  %164 = icmp eq i32 %162, %163
  br i1 %164, label %165, label %196

165:                                              ; preds = %158
  %166 = load ptr, ptr %6, align 8, !tbaa !5
  %167 = load ptr, ptr %20, align 8, !tbaa !5
  %168 = getelementptr inbounds %struct.GCstr, ptr %167, i64 1
  %169 = load i32, ptr %11, align 4, !tbaa !11
  %170 = zext i32 %169 to i64
  %171 = call i32 @memcmp(ptr noundef %166, ptr noundef %168, i64 noundef %170) #10
  %172 = icmp eq i32 %171, 0
  br i1 %172, label %173, label %196

173:                                              ; preds = %165
  %174 = load ptr, ptr %10, align 8, !tbaa !5
  %175 = getelementptr inbounds %struct.GChead, ptr %174, i32 0, i32 1
  %176 = load i8, ptr %175, align 4, !tbaa !13
  %177 = zext i8 %176 to i32
  %178 = load ptr, ptr %8, align 8, !tbaa !5
  %179 = getelementptr inbounds %struct.global_State, ptr %178, i32 0, i32 5
  %180 = getelementptr inbounds %struct.GCState, ptr %179, i32 0, i32 2
  %181 = load i8, ptr %180, align 8, !tbaa !28
  %182 = zext i8 %181 to i32
  %183 = xor i32 %182, 3
  %184 = and i32 %177, %183
  %185 = and i32 %184, 3
  %186 = icmp ne i32 %185, 0
  br i1 %186, label %187, label %194

187:                                              ; preds = %173
  %188 = load ptr, ptr %10, align 8, !tbaa !5
  %189 = getelementptr inbounds %struct.GChead, ptr %188, i32 0, i32 1
  %190 = load i8, ptr %189, align 4, !tbaa !13
  %191 = zext i8 %190 to i32
  %192 = xor i32 %191, 3
  %193 = trunc i32 %192 to i8
  store i8 %193, ptr %189, align 4, !tbaa !13
  br label %194

194:                                              ; preds = %187, %173
  %195 = load ptr, ptr %20, align 8, !tbaa !5
  store ptr %195, ptr %4, align 8
  store i32 1, ptr %18, align 4
  br label %203

196:                                              ; preds = %165, %158
  %197 = load ptr, ptr %10, align 8, !tbaa !5
  %198 = getelementptr inbounds %struct.GChead, ptr %197, i32 0, i32 0
  %199 = getelementptr inbounds %struct.GCRef, ptr %198, i32 0, i32 0
  %200 = load i32, ptr %199, align 8, !tbaa !13
  %201 = zext i32 %200 to i64
  %202 = inttoptr i64 %201 to ptr
  store ptr %202, ptr %10, align 8, !tbaa !5
  store i32 0, ptr %18, align 4
  br label %203

203:                                              ; preds = %196, %194
  call void @llvm.lifetime.end.p0(i64 8, ptr %20) #8
  %204 = load i32, ptr %18, align 4
  switch i32 %204, label %284 [
    i32 0, label %205
  ]

205:                                              ; preds = %203
  br label %155, !llvm.loop !30

206:                                              ; preds = %155
  br label %207

207:                                              ; preds = %206, %153
  %208 = load ptr, ptr %5, align 8, !tbaa !5
  %209 = load i32, ptr %11, align 4, !tbaa !11
  %210 = zext i32 %209 to i64
  %211 = add i64 16, %210
  %212 = add i64 %211, 1
  %213 = trunc i64 %212 to i32
  %214 = call ptr @lj_mem_realloc(ptr noundef %208, ptr noundef null, i32 noundef 0, i32 noundef %213)
  store ptr %214, ptr %9, align 8, !tbaa !5
  %215 = load ptr, ptr %8, align 8, !tbaa !5
  %216 = getelementptr inbounds %struct.global_State, ptr %215, i32 0, i32 5
  %217 = getelementptr inbounds %struct.GCState, ptr %216, i32 0, i32 2
  %218 = load i8, ptr %217, align 8, !tbaa !28
  %219 = zext i8 %218 to i32
  %220 = and i32 %219, 3
  %221 = trunc i32 %220 to i8
  %222 = load ptr, ptr %9, align 8, !tbaa !5
  %223 = getelementptr inbounds %struct.GChead, ptr %222, i32 0, i32 1
  store i8 %221, ptr %223, align 4, !tbaa !13
  %224 = load ptr, ptr %9, align 8, !tbaa !5
  %225 = getelementptr inbounds %struct.GCstr, ptr %224, i32 0, i32 2
  store i8 4, ptr %225, align 1, !tbaa !31
  %226 = load i32, ptr %11, align 4, !tbaa !11
  %227 = load ptr, ptr %9, align 8, !tbaa !5
  %228 = getelementptr inbounds %struct.GCstr, ptr %227, i32 0, i32 6
  store i32 %226, ptr %228, align 4, !tbaa !27
  %229 = load i32, ptr %14, align 4, !tbaa !11
  %230 = load ptr, ptr %9, align 8, !tbaa !5
  %231 = getelementptr inbounds %struct.GCstr, ptr %230, i32 0, i32 5
  store i32 %229, ptr %231, align 4, !tbaa !32
  %232 = load ptr, ptr %9, align 8, !tbaa !5
  %233 = getelementptr inbounds %struct.GCstr, ptr %232, i32 0, i32 3
  store i8 0, ptr %233, align 2, !tbaa !33
  %234 = load ptr, ptr %9, align 8, !tbaa !5
  %235 = getelementptr inbounds %struct.GCstr, ptr %234, i64 1
  %236 = load ptr, ptr %6, align 8, !tbaa !5
  %237 = load i32, ptr %11, align 4, !tbaa !11
  %238 = zext i32 %237 to i64
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %235, ptr align 1 %236, i64 %238, i1 false)
  %239 = load ptr, ptr %9, align 8, !tbaa !5
  %240 = getelementptr inbounds %struct.GCstr, ptr %239, i64 1
  %241 = load i32, ptr %11, align 4, !tbaa !11
  %242 = zext i32 %241 to i64
  %243 = getelementptr inbounds i8, ptr %240, i64 %242
  store i8 0, ptr %243, align 1, !tbaa !13
  %244 = load ptr, ptr %8, align 8, !tbaa !5
  %245 = getelementptr inbounds %struct.global_State, ptr %244, i32 0, i32 1
  %246 = load i32, ptr %245, align 8, !tbaa !25
  %247 = load i32, ptr %14, align 4, !tbaa !11
  %248 = and i32 %247, %246
  store i32 %248, ptr %14, align 4, !tbaa !11
  %249 = load ptr, ptr %9, align 8, !tbaa !5
  %250 = getelementptr inbounds %struct.GCstr, ptr %249, i32 0, i32 0
  %251 = load ptr, ptr %8, align 8, !tbaa !5
  %252 = getelementptr inbounds %struct.global_State, ptr %251, i32 0, i32 0
  %253 = load ptr, ptr %252, align 8, !tbaa !16
  %254 = load i32, ptr %14, align 4, !tbaa !11
  %255 = zext i32 %254 to i64
  %256 = getelementptr inbounds %struct.GCRef, ptr %253, i64 %255
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %250, ptr align 4 %256, i64 4, i1 false), !tbaa.struct !34
  %257 = load ptr, ptr %9, align 8, !tbaa !5
  %258 = ptrtoint ptr %257 to i64
  %259 = trunc i64 %258 to i32
  %260 = load ptr, ptr %8, align 8, !tbaa !5
  %261 = getelementptr inbounds %struct.global_State, ptr %260, i32 0, i32 0
  %262 = load ptr, ptr %261, align 8, !tbaa !16
  %263 = load i32, ptr %14, align 4, !tbaa !11
  %264 = zext i32 %263 to i64
  %265 = getelementptr inbounds %struct.GCRef, ptr %262, i64 %264
  %266 = getelementptr inbounds %struct.GCRef, ptr %265, i32 0, i32 0
  store i32 %259, ptr %266, align 4, !tbaa !26
  %267 = load ptr, ptr %8, align 8, !tbaa !5
  %268 = getelementptr inbounds %struct.global_State, ptr %267, i32 0, i32 2
  %269 = load i32, ptr %268, align 4, !tbaa !35
  %270 = add i32 %269, 1
  store i32 %270, ptr %268, align 4, !tbaa !35
  %271 = load ptr, ptr %8, align 8, !tbaa !5
  %272 = getelementptr inbounds %struct.global_State, ptr %271, i32 0, i32 1
  %273 = load i32, ptr %272, align 8, !tbaa !25
  %274 = icmp ugt i32 %269, %273
  br i1 %274, label %275, label %282

275:                                              ; preds = %207
  %276 = load ptr, ptr %5, align 8, !tbaa !5
  %277 = load ptr, ptr %8, align 8, !tbaa !5
  %278 = getelementptr inbounds %struct.global_State, ptr %277, i32 0, i32 1
  %279 = load i32, ptr %278, align 8, !tbaa !25
  %280 = shl i32 %279, 1
  %281 = add i32 %280, 1
  call void @lj_str_resize(ptr noundef %276, i32 noundef %281)
  br label %282

282:                                              ; preds = %275, %207
  %283 = load ptr, ptr %9, align 8, !tbaa !5
  store ptr %283, ptr %4, align 8
  store i32 1, ptr %18, align 4
  br label %284

284:                                              ; preds = %282, %203, %150, %39
  call void @llvm.lifetime.end.p0(i64 8, ptr %17) #8
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #8
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #8
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #8
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #8
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #8
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #8
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #8
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #8
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #8
  %285 = load ptr, ptr %4, align 8
  ret ptr %285
}

; Function Attrs: noreturn
declare hidden void @lj_err_msg(ptr noundef, i32 noundef) #4

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(none)
declare i64 @llvm.expect.i64(i64, i64) #5

; Function Attrs: alwaysinline nounwind uwtable
declare hidden i32 @str_fastcmp(ptr noundef, ptr noundef, i32 noundef) #6

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { nounwind uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #3 = { "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 = { noreturn "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 = { nocallback nofree nosync nounwind willreturn memory(none) }
attributes #6 = { alwaysinline 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 #7 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #8 = { nounwind }
attributes #9 = { noreturn }
attributes #10 = { 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 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!7, !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = !{!17, !6, i64 0}
!17 = !{!"global_State", !6, i64 0, !12, i64 8, !12, i64 12, !6, i64 16, !6, i64 24, !18, i64 32, !12, i64 88, !21, i64 92, !22, i64 108, !7, i64 124, !7, i64 125, !7, i64 126, !7, i64 127, !19, i64 128, !7, i64 136, !7, i64 144, !7, i64 152, !23, i64 160, !24, i64 184, !12, i64 208, !12, i64 212, !6, i64 216, !6, i64 224, !6, i64 232, !12, i64 240, !12, i64 244, !19, i64 248, !20, i64 252, !20, i64 256, !7, i64 260}
!18 = !{!"GCState", !12, i64 0, !12, i64 4, !7, i64 8, !7, i64 9, !7, i64 10, !7, i64 11, !12, i64 12, !19, i64 16, !20, i64 20, !19, i64 24, !19, i64 28, !19, i64 32, !19, i64 36, !12, i64 40, !12, i64 44, !12, i64 48, !12, i64 52}
!19 = !{!"GCRef", !12, i64 0}
!20 = !{!"MRef", !12, i64 0}
!21 = !{!"SBuf", !20, i64 0, !20, i64 4, !20, i64 8, !20, i64 12}
!22 = !{!"GCstr", !19, i64 0, !7, i64 4, !7, i64 5, !7, i64 6, !7, i64 7, !12, i64 8, !12, i64 12}
!23 = !{!"Node", !7, i64 0, !7, i64 8, !20, i64 16, !20, i64 20}
!24 = !{!"GCupval", !19, i64 0, !7, i64 4, !7, i64 5, !7, i64 6, !7, i64 7, !7, i64 8, !20, i64 16, !12, i64 20}
!25 = !{!17, !12, i64 8}
!26 = !{!19, !12, i64 0}
!27 = !{!22, !12, i64 12}
!28 = !{!17, !7, i64 40}
!29 = distinct !{!29, !15}
!30 = distinct !{!30, !15}
!31 = !{!22, !7, i64 5}
!32 = !{!22, !12, i64 8}
!33 = !{!22, !7, i64 6}
!34 = !{i64 0, i64 4, !11}
!35 = !{!17, !12, i64 12}


; 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.GCRef = type { i32 }

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

declare hidden ptr @lj_mem_realloc(ptr noundef, ptr noundef, i32 noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define hidden ptr @lj_str_new(ptr noundef %0, ptr noundef %1, i64 noundef %2) local_unnamed_addr #0 {
  %4 = trunc i64 %2 to i32
  %5 = icmp ugt i64 %2, 2147483391
  br i1 %5, label %6, label %7

6:                                                ; preds = %3
  tail call void @lj_err_msg(ptr noundef %0, i32 noundef 56) #6
  unreachable

7:                                                ; preds = %3
  %8 = getelementptr inbounds i8, ptr %0, i64 8
  %9 = load i32, ptr %8, align 8, !tbaa !5
  %10 = zext i32 %9 to i64
  %11 = inttoptr i64 %10 to ptr
  %12 = icmp eq i32 %4, 0
  br i1 %12, label %13, label %15

13:                                               ; preds = %7
  %14 = getelementptr inbounds i8, ptr %11, i64 108
  br label %.thread

15:                                               ; preds = %7
  %16 = lshr i32 %4, 5
  %17 = add nuw nsw i32 %16, 1
  %18 = zext nneg i32 %17 to i64
  %invariant.gep = getelementptr i8, ptr %1, i64 -1
  %.not107 = icmp ugt i64 %18, %2
  br i1 %.not107, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %15, %.lr.ph
  %.086109 = phi i64 [ %26, %.lr.ph ], [ %2, %15 ]
  %.087108 = phi i32 [ %25, %.lr.ph ], [ %4, %15 ]
  %19 = shl i32 %.087108, 5
  %20 = lshr i32 %.087108, 2
  %21 = add i32 %19, %20
  %gep = getelementptr i8, ptr %invariant.gep, i64 %.086109
  %22 = load i8, ptr %gep, align 1, !tbaa !5
  %23 = zext i8 %22 to i32
  %24 = add i32 %21, %23
  %25 = xor i32 %24, %.087108
  %26 = sub i64 %.086109, %18
  %.not = icmp ult i64 %26, %18
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !8

._crit_edge:                                      ; preds = %.lr.ph, %15
  %.087.lcssa = phi i32 [ %4, %15 ], [ %25, %.lr.ph ]
  %27 = load ptr, ptr %11, align 8, !tbaa !10
  %28 = getelementptr inbounds i8, ptr %11, i64 8
  %29 = load i32, ptr %28, align 8, !tbaa !21
  %30 = and i32 %29, %.087.lcssa
  %31 = zext i32 %30 to i64
  %32 = getelementptr inbounds %struct.GCRef, ptr %27, i64 %31
  %33 = load i32, ptr %32, align 4, !tbaa !22
  %34 = zext i32 %33 to i64
  %35 = inttoptr i64 %34 to ptr
  %36 = ptrtoint ptr %1 to i64
  %37 = add nuw nsw i64 %2, 4095
  %38 = add i64 %37, %36
  %39 = and i64 %38, 4095
  %40 = icmp ult i64 %39, 4093
  %.not93113 = icmp eq i32 %33, 0
  br i1 %40, label %.preheader, label %.preheader103, !prof !23

.preheader103:                                    ; preds = %._crit_edge
  br i1 %.not93113, label %.loopexit, label %.lr.ph112

.preheader:                                       ; preds = %._crit_edge
  br i1 %.not93113, label %.loopexit, label %.lr.ph115

.lr.ph115:                                        ; preds = %.preheader, %58
  %.080114 = phi ptr [ %61, %58 ], [ %35, %.preheader ]
  %41 = getelementptr inbounds i8, ptr %.080114, i64 12
  %42 = load i32, ptr %41, align 4, !tbaa !24
  %43 = icmp eq i32 %42, %4
  br i1 %43, label %44, label %58

44:                                               ; preds = %.lr.ph115
  %45 = getelementptr inbounds i8, ptr %.080114, i64 16
  %46 = tail call i32 @str_fastcmp(ptr noundef %1, ptr noundef nonnull %45, i32 noundef %4)
  %47 = icmp eq i32 %46, 0
  br i1 %47, label %48, label %58

48:                                               ; preds = %44
  %49 = getelementptr inbounds i8, ptr %.080114, i64 4
  %50 = load i8, ptr %49, align 4, !tbaa !5
  %51 = getelementptr inbounds i8, ptr %11, i64 40
  %52 = load i8, ptr %51, align 8, !tbaa !25
  %53 = xor i8 %52, -1
  %54 = and i8 %50, 3
  %55 = and i8 %54, %53
  %.not94 = icmp eq i8 %55, 0
  br i1 %.not94, label %.thread, label %56

56:                                               ; preds = %48
  %57 = xor i8 %50, 3
  store i8 %57, ptr %49, align 4, !tbaa !5
  br label %.thread

58:                                               ; preds = %.lr.ph115, %44
  %59 = load i32, ptr %.080114, align 8, !tbaa !5
  %60 = zext i32 %59 to i64
  %61 = inttoptr i64 %60 to ptr
  %.not93 = icmp eq i32 %59, 0
  br i1 %.not93, label %.loopexit, label %.lr.ph115, !llvm.loop !26

.lr.ph112:                                        ; preds = %.preheader103, %78
  %.282111 = phi ptr [ %81, %78 ], [ %35, %.preheader103 ]
  %62 = getelementptr inbounds i8, ptr %.282111, i64 12
  %63 = load i32, ptr %62, align 4, !tbaa !24
  %64 = icmp eq i32 %63, %4
  br i1 %64, label %65, label %78

65:                                               ; preds = %.lr.ph112
  %66 = getelementptr inbounds i8, ptr %.282111, i64 16
  %bcmp = tail call i32 @bcmp(ptr %1, ptr nonnull %66, i64 %2)
  %67 = icmp eq i32 %bcmp, 0
  br i1 %67, label %68, label %78

68:                                               ; preds = %65
  %69 = getelementptr inbounds i8, ptr %.282111, i64 4
  %70 = load i8, ptr %69, align 4, !tbaa !5
  %71 = getelementptr inbounds i8, ptr %11, i64 40
  %72 = load i8, ptr %71, align 8, !tbaa !25
  %73 = xor i8 %72, -1
  %74 = and i8 %70, 3
  %75 = and i8 %74, %73
  %.not92 = icmp eq i8 %75, 0
  br i1 %.not92, label %.thread, label %76

76:                                               ; preds = %68
  %77 = xor i8 %70, 3
  store i8 %77, ptr %69, align 4, !tbaa !5
  br label %.thread

78:                                               ; preds = %.lr.ph112, %65
  %79 = load i32, ptr %.282111, align 8, !tbaa !5
  %80 = zext i32 %79 to i64
  %81 = inttoptr i64 %80 to ptr
  %.not91 = icmp eq i32 %79, 0
  br i1 %.not91, label %.loopexit, label %.lr.ph112, !llvm.loop !27

.loopexit:                                        ; preds = %78, %58, %.preheader103, %.preheader
  %82 = add nuw i32 %4, 17
  %83 = tail call ptr @lj_mem_realloc(ptr noundef %0, ptr noundef null, i32 noundef 0, i32 noundef %82) #7
  %84 = getelementptr inbounds i8, ptr %11, i64 40
  %85 = load i8, ptr %84, align 8, !tbaa !25
  %86 = and i8 %85, 3
  %87 = getelementptr inbounds i8, ptr %83, i64 4
  store i8 %86, ptr %87, align 4, !tbaa !5
  %88 = getelementptr inbounds i8, ptr %83, i64 5
  store i8 4, ptr %88, align 1, !tbaa !28
  %89 = getelementptr inbounds i8, ptr %83, i64 12
  store i32 %4, ptr %89, align 4, !tbaa !24
  %90 = getelementptr inbounds i8, ptr %83, i64 8
  store i32 %.087.lcssa, ptr %90, align 4, !tbaa !29
  %91 = getelementptr inbounds i8, ptr %83, i64 6
  store i8 0, ptr %91, align 2, !tbaa !30
  %92 = getelementptr inbounds i8, ptr %83, i64 16
  tail call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 1 %92, ptr align 1 %1, i64 %2, i1 false)
  %93 = getelementptr inbounds i8, ptr %92, i64 %2
  store i8 0, ptr %93, align 1, !tbaa !5
  %94 = load i32, ptr %28, align 8, !tbaa !21
  %95 = and i32 %94, %.087.lcssa
  %96 = load ptr, ptr %11, align 8, !tbaa !10
  %97 = zext i32 %95 to i64
  %98 = getelementptr inbounds %struct.GCRef, ptr %96, i64 %97
  %99 = load i32, ptr %98, align 4, !tbaa !31
  store i32 %99, ptr %83, align 4, !tbaa !31
  %100 = ptrtoint ptr %83 to i64
  %101 = trunc i64 %100 to i32
  store i32 %101, ptr %98, align 4, !tbaa !22
  %102 = getelementptr inbounds i8, ptr %11, i64 12
  %103 = load i32, ptr %102, align 4, !tbaa !32
  %104 = add i32 %103, 1
  store i32 %104, ptr %102, align 4, !tbaa !32
  %105 = load i32, ptr %28, align 8, !tbaa !21
  %106 = icmp ugt i32 %103, %105
  br i1 %106, label %107, label %.thread

107:                                              ; preds = %.loopexit
  %108 = shl i32 %105, 1
  %109 = or disjoint i32 %108, 1
  tail call void @lj_str_resize(ptr noundef %0, i32 noundef %109)
  br label %.thread

.thread:                                          ; preds = %68, %76, %48, %56, %.loopexit, %107, %13
  %.4 = phi ptr [ %14, %13 ], [ %83, %107 ], [ %83, %.loopexit ], [ %.080114, %56 ], [ %.080114, %48 ], [ %.282111, %76 ], [ %.282111, %68 ]
  ret ptr %.4
}

; Function Attrs: noreturn
declare hidden void @lj_err_msg(ptr noundef, i32 noundef) local_unnamed_addr #2

; Function Attrs: alwaysinline nounwind uwtable
declare hidden i32 @str_fastcmp(ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #3

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

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

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 = { "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 = { noreturn "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 = { alwaysinline 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 #4 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #5 = { nofree nounwind willreturn memory(argmem: read) }
attributes #6 = { noreturn nounwind }
attributes #7 = { 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 = distinct !{!8, !9}
!9 = !{!"llvm.loop.mustprogress"}
!10 = !{!11, !12, i64 0}
!11 = !{!"global_State", !12, i64 0, !13, i64 8, !13, i64 12, !12, i64 16, !12, i64 24, !14, i64 32, !13, i64 88, !17, i64 92, !18, i64 108, !6, i64 124, !6, i64 125, !6, i64 126, !6, i64 127, !15, i64 128, !6, i64 136, !6, i64 144, !6, i64 152, !19, i64 160, !20, i64 184, !13, i64 208, !13, i64 212, !12, i64 216, !12, i64 224, !12, i64 232, !13, i64 240, !13, i64 244, !15, i64 248, !16, i64 252, !16, i64 256, !6, i64 260}
!12 = !{!"any pointer", !6, i64 0}
!13 = !{!"int", !6, i64 0}
!14 = !{!"GCState", !13, i64 0, !13, i64 4, !6, i64 8, !6, i64 9, !6, i64 10, !6, i64 11, !13, i64 12, !15, i64 16, !16, i64 20, !15, i64 24, !15, i64 28, !15, i64 32, !15, i64 36, !13, i64 40, !13, i64 44, !13, i64 48, !13, i64 52}
!15 = !{!"GCRef", !13, i64 0}
!16 = !{!"MRef", !13, i64 0}
!17 = !{!"SBuf", !16, i64 0, !16, i64 4, !16, i64 8, !16, i64 12}
!18 = !{!"GCstr", !15, i64 0, !6, i64 4, !6, i64 5, !6, i64 6, !6, i64 7, !13, i64 8, !13, i64 12}
!19 = !{!"Node", !6, i64 0, !6, i64 8, !16, i64 16, !16, i64 20}
!20 = !{!"GCupval", !15, i64 0, !6, i64 4, !6, i64 5, !6, i64 6, !6, i64 7, !6, i64 8, !16, i64 16, !13, i64 20}
!21 = !{!11, !13, i64 8}
!22 = !{!15, !13, i64 0}
!23 = !{!"branch_weights", !"expected", i32 2000, i32 1}
!24 = !{!18, !13, i64 12}
!25 = !{!11, !6, i64 40}
!26 = distinct !{!26, !9}
!27 = distinct !{!27, !9}
!28 = !{!18, !6, i64 5}
!29 = !{!18, !13, i64 8}
!30 = !{!18, !6, i64 6}
!31 = !{!13, !13, i64 0}
!32 = !{!11, !13, i64 12}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,LowerExpectIntrinsicPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass