; LLVM IR from DimitrisJim/leetcode_solutions :: C/Algorithms (1370)

; 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.tablet = type { i32, i32, ptr, ptr }

@.str = external hidden unnamed_addr constant [1 x i8], align 1

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

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

; Function Attrs: nounwind uwtable
declare dso_local ptr @tablet_new(i32 noundef) #1

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

; Function Attrs: nounwind uwtable
declare dso_local void @tablet_free(ptr noundef) #1

; Function Attrs: nounwind
declare void @free(ptr noundef) #3

; Function Attrs: nounwind uwtable
declare dso_local i32 @tablet_get(ptr noundef, i8 noundef signext) #1

; Function Attrs: nounwind uwtable
declare dso_local i32 @tablet_has(ptr noundef, i8 noundef signext) #1

; Function Attrs: nounwind uwtable
declare dso_local void @tablet_set(ptr noundef, i8 noundef signext, i32 noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local i32 @tablet_del(ptr noundef, i8 noundef signext) #1

; Function Attrs: nounwind uwtable
declare dso_local ptr @tablet_keys(ptr noundef, ptr noundef) #1

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

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

; Function Attrs: nounwind uwtable
define dso_local ptr @sortString(ptr noundef %0) #1 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i8, align 1
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca i32, align 4
  %13 = alloca ptr, align 8
  %14 = alloca ptr, align 8
  %15 = alloca i32, align 4
  %16 = alloca i32, align 4
  %17 = alloca i32, align 4
  %18 = alloca i32, align 4
  %19 = alloca i8, align 1
  %20 = alloca i32, align 4
  %21 = alloca i32, align 4
  %22 = alloca ptr, align 8
  %23 = alloca i8, align 1
  %24 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #7
  %25 = load ptr, ptr %3, align 8, !tbaa !5
  %26 = call i64 @strlen(ptr noundef %25) #8
  %27 = trunc i64 %26 to i32
  store i32 %27, ptr %4, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #7
  %28 = load i32, ptr %4, align 4, !tbaa !9
  %29 = add nsw i32 %28, 1
  %30 = call ptr @tablet_new(i32 noundef %29)
  store ptr %30, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #7
  store i32 0, ptr %6, align 4, !tbaa !9
  br label %31

31:                                               ; preds = %58, %1
  %32 = load i32, ptr %6, align 4, !tbaa !9
  %33 = load i32, ptr %4, align 4, !tbaa !9
  %34 = icmp slt i32 %32, %33
  br i1 %34, label %36, label %35

35:                                               ; preds = %31
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #7
  br label %61

36:                                               ; preds = %31
  call void @llvm.lifetime.start.p0(i64 1, ptr %7) #7
  %37 = load ptr, ptr %3, align 8, !tbaa !5
  %38 = load i32, ptr %6, align 4, !tbaa !9
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds i8, ptr %37, i64 %39
  %41 = load i8, ptr %40, align 1, !tbaa !11
  store i8 %41, ptr %7, align 1, !tbaa !11
  %42 = load ptr, ptr %5, align 8, !tbaa !5
  %43 = load i8, ptr %7, align 1, !tbaa !11
  %44 = call i32 @tablet_has(ptr noundef %42, i8 noundef signext %43)
  %45 = icmp ne i32 %44, 0
  br i1 %45, label %46, label %54

46:                                               ; preds = %36
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #7
  %47 = load ptr, ptr %5, align 8, !tbaa !5
  %48 = load i8, ptr %7, align 1, !tbaa !11
  %49 = call i32 @tablet_get(ptr noundef %47, i8 noundef signext %48)
  store i32 %49, ptr %8, align 4, !tbaa !9
  %50 = load ptr, ptr %5, align 8, !tbaa !5
  %51 = load i8, ptr %7, align 1, !tbaa !11
  %52 = load i32, ptr %8, align 4, !tbaa !9
  %53 = add nsw i32 %52, 1
  call void @tablet_set(ptr noundef %50, i8 noundef signext %51, i32 noundef %53)
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #7
  br label %57

54:                                               ; preds = %36
  %55 = load ptr, ptr %5, align 8, !tbaa !5
  %56 = load i8, ptr %7, align 1, !tbaa !11
  call void @tablet_set(ptr noundef %55, i8 noundef signext %56, i32 noundef 1)
  br label %57

57:                                               ; preds = %54, %46
  call void @llvm.lifetime.end.p0(i64 1, ptr %7) #7
  br label %58

58:                                               ; preds = %57
  %59 = load i32, ptr %6, align 4, !tbaa !9
  %60 = add nsw i32 %59, 1
  store i32 %60, ptr %6, align 4, !tbaa !9
  br label %31, !llvm.loop !12

61:                                               ; preds = %35
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #7
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #7
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #7
  %62 = load ptr, ptr %5, align 8, !tbaa !5
  %63 = call ptr @tablet_keys(ptr noundef %62, ptr noundef %9)
  store ptr %63, ptr %11, align 8, !tbaa !5
  %64 = load i32, ptr %9, align 4, !tbaa !9
  %65 = icmp eq i32 %64, 1
  br i1 %65, label %66, label %70

66:                                               ; preds = %61
  %67 = load ptr, ptr %11, align 8, !tbaa !5
  call void @free(ptr noundef %67) #7
  %68 = load ptr, ptr %5, align 8, !tbaa !5
  call void @tablet_free(ptr noundef %68)
  %69 = load ptr, ptr %3, align 8, !tbaa !5
  store ptr %69, ptr %2, align 8
  store i32 1, ptr %12, align 4
  br label %224

70:                                               ; preds = %61
  %71 = load i32, ptr %9, align 4, !tbaa !9
  %72 = load i32, ptr %4, align 4, !tbaa !9
  %73 = icmp eq i32 %71, %72
  br i1 %73, label %74, label %90

74:                                               ; preds = %70
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #7
  %75 = load i32, ptr %4, align 4, !tbaa !9
  %76 = add nsw i32 %75, 1
  %77 = sext i32 %76 to i64
  %78 = call noalias ptr @malloc(i64 noundef %77) #9
  store ptr %78, ptr %13, align 8, !tbaa !5
  %79 = load ptr, ptr %13, align 8, !tbaa !5
  %80 = load ptr, ptr %3, align 8, !tbaa !5
  %81 = load i32, ptr %4, align 4, !tbaa !9
  %82 = add nsw i32 %81, 1
  %83 = sext i32 %82 to i64
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %79, ptr align 1 %80, i64 %83, i1 false)
  %84 = load ptr, ptr %13, align 8, !tbaa !5
  %85 = load i32, ptr %4, align 4, !tbaa !9
  %86 = sext i32 %85 to i64
  call void @qsort(ptr noundef %84, i64 noundef %86, i64 noundef 1, ptr noundef @ascending)
  %87 = load ptr, ptr %11, align 8, !tbaa !5
  call void @free(ptr noundef %87) #7
  %88 = load ptr, ptr %5, align 8, !tbaa !5
  call void @tablet_free(ptr noundef %88)
  %89 = load ptr, ptr %13, align 8, !tbaa !5
  store ptr %89, ptr %2, align 8
  store i32 1, ptr %12, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #7
  br label %224

90:                                               ; preds = %70
  %91 = load ptr, ptr %11, align 8, !tbaa !5
  %92 = load i32, ptr %9, align 4, !tbaa !9
  %93 = sext i32 %92 to i64
  call void @qsort(ptr noundef %91, i64 noundef %93, i64 noundef 1, ptr noundef @ascending)
  %94 = load i32, ptr %9, align 4, !tbaa !9
  %95 = sext i32 %94 to i64
  %96 = call noalias ptr @malloc(i64 noundef %95) #9
  store ptr %96, ptr %10, align 8, !tbaa !5
  %97 = load ptr, ptr %10, align 8, !tbaa !5
  %98 = load ptr, ptr %11, align 8, !tbaa !5
  %99 = load i32, ptr %9, align 4, !tbaa !9
  %100 = sext i32 %99 to i64
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %97, ptr align 1 %98, i64 %100, i1 false)
  %101 = load ptr, ptr %10, align 8, !tbaa !5
  %102 = load i32, ptr %9, align 4, !tbaa !9
  %103 = sext i32 %102 to i64
  call void @qsort(ptr noundef %101, i64 noundef %103, i64 noundef 1, ptr noundef @descending)
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #7
  %104 = load i32, ptr %4, align 4, !tbaa !9
  %105 = add nsw i32 %104, 1
  %106 = sext i32 %105 to i64
  %107 = call noalias ptr @malloc(i64 noundef %106) #9
  store ptr %107, ptr %14, align 8, !tbaa !5
  %108 = load ptr, ptr %14, align 8, !tbaa !5
  %109 = load i32, ptr %4, align 4, !tbaa !9
  %110 = sext i32 %109 to i64
  %111 = getelementptr inbounds i8, ptr %108, i64 %110
  store i8 0, ptr %111, align 1, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #7
  store i32 0, ptr %15, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %16) #7
  store i32 1, ptr %16, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %17) #7
  store i32 0, ptr %17, align 4, !tbaa !9
  br label %112

112:                                              ; preds = %180, %90
  %113 = load i32, ptr %16, align 4, !tbaa !9
  %114 = icmp ne i32 %113, 0
  br i1 %114, label %115, label %183

115:                                              ; preds = %112
  call void @llvm.lifetime.start.p0(i64 4, ptr %18) #7
  store i32 0, ptr %18, align 4, !tbaa !9
  br label %116

116:                                              ; preds = %177, %115
  %117 = load i32, ptr %18, align 4, !tbaa !9
  %118 = load i32, ptr %9, align 4, !tbaa !9
  %119 = icmp slt i32 %117, %118
  br i1 %119, label %121, label %120

120:                                              ; preds = %116
  store i32 7, ptr %12, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %18) #7
  br label %180

121:                                              ; preds = %116
  call void @llvm.lifetime.start.p0(i64 1, ptr %19) #7
  %122 = load i32, ptr %15, align 4, !tbaa !9
  %123 = icmp ne i32 %122, 0
  br i1 %123, label %124, label %131

124:                                              ; preds = %121
  %125 = load ptr, ptr %10, align 8, !tbaa !5
  %126 = load i32, ptr %18, align 4, !tbaa !9
  %127 = sext i32 %126 to i64
  %128 = getelementptr inbounds i8, ptr %125, i64 %127
  %129 = load i8, ptr %128, align 1, !tbaa !11
  %130 = sext i8 %129 to i32
  br label %138

131:                                              ; preds = %121
  %132 = load ptr, ptr %11, align 8, !tbaa !5
  %133 = load i32, ptr %18, align 4, !tbaa !9
  %134 = sext i32 %133 to i64
  %135 = getelementptr inbounds i8, ptr %132, i64 %134
  %136 = load i8, ptr %135, align 1, !tbaa !11
  %137 = sext i8 %136 to i32
  br label %138

138:                                              ; preds = %131, %124
  %139 = phi i32 [ %130, %124 ], [ %137, %131 ]
  %140 = trunc i32 %139 to i8
  store i8 %140, ptr %19, align 1, !tbaa !11
  %141 = load ptr, ptr %5, align 8, !tbaa !5
  %142 = load i8, ptr %19, align 1, !tbaa !11
  %143 = call i32 @tablet_has(ptr noundef %141, i8 noundef signext %142)
  %144 = icmp ne i32 %143, 0
  br i1 %144, label %145, label %176

145:                                              ; preds = %138
  call void @llvm.lifetime.start.p0(i64 4, ptr %20) #7
  %146 = load ptr, ptr %5, align 8, !tbaa !5
  %147 = load i8, ptr %19, align 1, !tbaa !11
  %148 = call i32 @tablet_get(ptr noundef %146, i8 noundef signext %147)
  store i32 %148, ptr %20, align 4, !tbaa !9
  %149 = load i32, ptr %20, align 4, !tbaa !9
  %150 = icmp eq i32 %149, 1
  br i1 %150, label %151, label %163

151:                                              ; preds = %145
  %152 = load ptr, ptr %5, align 8, !tbaa !5
  %153 = load i8, ptr %19, align 1, !tbaa !11
  %154 = call i32 @tablet_del(ptr noundef %152, i8 noundef signext %153)
  %155 = load ptr, ptr %5, align 8, !tbaa !5
  %156 = getelementptr inbounds %struct.tablet, ptr %155, i32 0, i32 1
  %157 = load i32, ptr %156, align 4, !tbaa !14
  %158 = icmp eq i32 %157, 1
  br i1 %158, label %159, label %162

159:                                              ; preds = %151
  %160 = load i32, ptr %16, align 4, !tbaa !9
  %161 = xor i32 %160, 1
  store i32 %161, ptr %16, align 4, !tbaa !9
  br label %162

162:                                              ; preds = %159, %151
  br label %168

163:                                              ; preds = %145
  %164 = load ptr, ptr %5, align 8, !tbaa !5
  %165 = load i8, ptr %19, align 1, !tbaa !11
  %166 = load i32, ptr %20, align 4, !tbaa !9
  %167 = sub nsw i32 %166, 1
  call void @tablet_set(ptr noundef %164, i8 noundef signext %165, i32 noundef %167)
  br label %168

168:                                              ; preds = %163, %162
  %169 = load i8, ptr %19, align 1, !tbaa !11
  %170 = load ptr, ptr %14, align 8, !tbaa !5
  %171 = load i32, ptr %17, align 4, !tbaa !9
  %172 = zext i32 %171 to i64
  %173 = getelementptr inbounds i8, ptr %170, i64 %172
  store i8 %169, ptr %173, align 1, !tbaa !11
  %174 = load i32, ptr %17, align 4, !tbaa !9
  %175 = add i32 %174, 1
  store i32 %175, ptr %17, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %20) #7
  br label %176

176:                                              ; preds = %168, %138
  call void @llvm.lifetime.end.p0(i64 1, ptr %19) #7
  br label %177

177:                                              ; preds = %176
  %178 = load i32, ptr %18, align 4, !tbaa !9
  %179 = add nsw i32 %178, 1
  store i32 %179, ptr %18, align 4, !tbaa !9
  br label %116, !llvm.loop !16

180:                                              ; preds = %120
  %181 = load i32, ptr %15, align 4, !tbaa !9
  %182 = xor i32 %181, 1
  store i32 %182, ptr %15, align 4, !tbaa !9
  br label %112, !llvm.loop !17

183:                                              ; preds = %112
  %184 = load ptr, ptr %5, align 8, !tbaa !5
  %185 = getelementptr inbounds %struct.tablet, ptr %184, i32 0, i32 1
  %186 = load i32, ptr %185, align 4, !tbaa !14
  %187 = icmp eq i32 %186, 1
  br i1 %187, label %188, label %218

188:                                              ; preds = %183
  call void @llvm.lifetime.start.p0(i64 4, ptr %21) #7
  call void @llvm.lifetime.start.p0(i64 8, ptr %22) #7
  %189 = load ptr, ptr %5, align 8, !tbaa !5
  %190 = call ptr @tablet_keys(ptr noundef %189, ptr noundef %21)
  store ptr %190, ptr %22, align 8, !tbaa !5
  %191 = load i32, ptr %21, align 4, !tbaa !9
  %192 = icmp ne i32 %191, 1
  br i1 %192, label %193, label %194

193:                                              ; preds = %188
  store ptr @.str, ptr %2, align 8
  store i32 1, ptr %12, align 4
  br label %215

194:                                              ; preds = %188
  call void @llvm.lifetime.start.p0(i64 1, ptr %23) #7
  %195 = load ptr, ptr %22, align 8, !tbaa !5
  %196 = getelementptr inbounds i8, ptr %195, i64 0
  %197 = load i8, ptr %196, align 1, !tbaa !11
  store i8 %197, ptr %23, align 1, !tbaa !11
  %198 = load ptr, ptr %22, align 8, !tbaa !5
  call void @free(ptr noundef %198) #7
  call void @llvm.lifetime.start.p0(i64 4, ptr %24) #7
  %199 = load i32, ptr %17, align 4, !tbaa !9
  store i32 %199, ptr %24, align 4, !tbaa !9
  br label %200

200:                                              ; preds = %211, %194
  %201 = load i32, ptr %24, align 4, !tbaa !9
  %202 = load i32, ptr %4, align 4, !tbaa !9
  %203 = icmp slt i32 %201, %202
  br i1 %203, label %205, label %204

204:                                              ; preds = %200
  store i32 10, ptr %12, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %24) #7
  br label %214

205:                                              ; preds = %200
  %206 = load i8, ptr %23, align 1, !tbaa !11
  %207 = load ptr, ptr %14, align 8, !tbaa !5
  %208 = load i32, ptr %24, align 4, !tbaa !9
  %209 = sext i32 %208 to i64
  %210 = getelementptr inbounds i8, ptr %207, i64 %209
  store i8 %206, ptr %210, align 1, !tbaa !11
  br label %211

211:                                              ; preds = %205
  %212 = load i32, ptr %24, align 4, !tbaa !9
  %213 = add nsw i32 %212, 1
  store i32 %213, ptr %24, align 4, !tbaa !9
  br label %200, !llvm.loop !18

214:                                              ; preds = %204
  call void @llvm.lifetime.end.p0(i64 1, ptr %23) #7
  store i32 0, ptr %12, align 4
  br label %215

215:                                              ; preds = %214, %193
  call void @llvm.lifetime.end.p0(i64 8, ptr %22) #7
  call void @llvm.lifetime.end.p0(i64 4, ptr %21) #7
  %216 = load i32, ptr %12, align 4
  switch i32 %216, label %223 [
    i32 0, label %217
  ]

217:                                              ; preds = %215
  br label %218

218:                                              ; preds = %217, %183
  %219 = load ptr, ptr %11, align 8, !tbaa !5
  call void @free(ptr noundef %219) #7
  %220 = load ptr, ptr %10, align 8, !tbaa !5
  call void @free(ptr noundef %220) #7
  %221 = load ptr, ptr %5, align 8, !tbaa !5
  call void @tablet_free(ptr noundef %221)
  %222 = load ptr, ptr %14, align 8, !tbaa !5
  store ptr %222, ptr %2, align 8
  store i32 1, ptr %12, align 4
  br label %223

223:                                              ; preds = %218, %215
  call void @llvm.lifetime.end.p0(i64 4, ptr %17) #7
  call void @llvm.lifetime.end.p0(i64 4, ptr %16) #7
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #7
  br label %224

224:                                              ; preds = %223, %74, %66
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #7
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #7
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #7
  %225 = load ptr, ptr %2, align 8
  ret ptr %225
}

; Function Attrs: nounwind willreturn memory(read)
declare i64 @strlen(ptr noundef) #4

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

declare void @qsort(ptr noundef, i64 noundef, i64 noundef, ptr noundef) #6

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nounwind uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #2 = { 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 #3 = { 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 #4 = { 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 #5 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #6 = { "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) }
attributes #9 = { 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 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = !{!15, !10, i64 4}
!15 = !{!"tablet", !10, i64 0, !10, i64 4, !6, i64 8, !6, i64 16}
!16 = distinct !{!16, !13}
!17 = distinct !{!17, !13}
!18 = distinct !{!18, !13}


; 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"

@.str = external hidden unnamed_addr constant [1 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 nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nounwind uwtable
declare dso_local ptr @tablet_new(i32 noundef) local_unnamed_addr #1

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

; Function Attrs: nounwind uwtable
declare dso_local void @tablet_free(ptr noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #3

; Function Attrs: nounwind uwtable
declare dso_local i32 @tablet_get(ptr noundef, i8 noundef signext) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local i32 @tablet_has(ptr noundef, i8 noundef signext) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local void @tablet_set(ptr noundef, i8 noundef signext, i32 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local i32 @tablet_del(ptr noundef, i8 noundef signext) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local ptr @tablet_keys(ptr noundef, ptr noundef) local_unnamed_addr #1

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

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

; Function Attrs: nounwind uwtable
define dso_local noundef ptr @sortString(ptr noundef readonly %0) local_unnamed_addr #1 {
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %0) #8
  %5 = trunc i64 %4 to i32
  %6 = add nsw i32 %5, 1
  %7 = tail call ptr @tablet_new(i32 noundef %6)
  %8 = icmp sgt i32 %5, 0
  br i1 %8, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %1
  %wide.trip.count = and i64 %4, 2147483647
  br label %.lr.ph

._crit_edge:                                      ; preds = %18, %1
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %2) #9
  %9 = call ptr @tablet_keys(ptr noundef %7, ptr noundef nonnull %2)
  %10 = load i32, ptr %2, align 4, !tbaa !5
  %11 = icmp eq i32 %10, 1
  br i1 %11, label %19, label %20

.lr.ph:                                           ; preds = %.lr.ph.preheader, %18
  %indvars.iv = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next, %18 ]
  %12 = getelementptr inbounds i8, ptr %0, i64 %indvars.iv
  %13 = load i8, ptr %12, align 1, !tbaa !9
  %14 = tail call i32 @tablet_has(ptr noundef %7, i8 noundef signext %13)
  %.not97 = icmp eq i32 %14, 0
  br i1 %.not97, label %18, label %15

15:                                               ; preds = %.lr.ph
  %16 = tail call i32 @tablet_get(ptr noundef %7, i8 noundef signext %13)
  %17 = add nsw i32 %16, 1
  br label %18

18:                                               ; preds = %.lr.ph, %15
  %.sink = phi i32 [ %17, %15 ], [ 1, %.lr.ph ]
  tail call void @tablet_set(ptr noundef %7, i8 noundef signext %13, i32 noundef %.sink)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !10

19:                                               ; preds = %._crit_edge
  call void @free(ptr noundef %9) #9
  call void @tablet_free(ptr noundef %7)
  br label %76

20:                                               ; preds = %._crit_edge
  %21 = icmp eq i32 %10, %5
  br i1 %21, label %22, label %26

22:                                               ; preds = %20
  %23 = sext i32 %6 to i64
  %24 = call noalias ptr @malloc(i64 noundef %23) #10
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %24, ptr align 1 %0, i64 %23, i1 false)
  %sext96 = shl i64 %4, 32
  %25 = ashr exact i64 %sext96, 32
  call void @qsort(ptr noundef %24, i64 noundef %25, i64 noundef 1, ptr noundef nonnull @ascending) #9
  call void @free(ptr noundef %9) #9
  call void @tablet_free(ptr noundef %7)
  br label %76

26:                                               ; preds = %20
  %27 = sext i32 %10 to i64
  call void @qsort(ptr noundef %9, i64 noundef %27, i64 noundef 1, ptr noundef nonnull @ascending) #9
  %28 = load i32, ptr %2, align 4, !tbaa !5
  %29 = sext i32 %28 to i64
  %30 = call noalias ptr @malloc(i64 noundef %29) #10
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %30, ptr align 1 %9, i64 %29, i1 false)
  call void @qsort(ptr noundef %30, i64 noundef %29, i64 noundef 1, ptr noundef nonnull @descending) #9
  %31 = sext i32 %6 to i64
  %32 = call noalias ptr @malloc(i64 noundef %31) #10
  %sext = shl i64 %4, 32
  %33 = ashr exact i64 %sext, 32
  %34 = getelementptr inbounds i8, ptr %32, i64 %33
  store i8 0, ptr %34, align 1, !tbaa !9
  %35 = getelementptr inbounds i8, ptr %7, i64 4
  %36 = load i32, ptr %2, align 4, !tbaa !5
  %37 = icmp sgt i32 %36, 0
  br i1 %37, label %.preheader, label %.preheader.us

.preheader.us:                                    ; preds = %26, %.preheader.us
  br label %.preheader.us

.preheader:                                       ; preds = %26, %._crit_edge103
  %38 = phi i32 [ %40, %._crit_edge103 ], [ %36, %26 ]
  %.081106 = phi i32 [ %41, %._crit_edge103 ], [ 0, %26 ]
  %.083105 = phi i32 [ %.184.lcssa, %._crit_edge103 ], [ 0, %26 ]
  %39 = icmp sgt i32 %38, 0
  br i1 %39, label %.lr.ph102, label %._crit_edge103

.lr.ph102:                                        ; preds = %.preheader
  %.not93 = icmp eq i32 %.081106, 0
  %.in.in.v = select i1 %.not93, ptr %9, ptr %30
  br label %42

._crit_edge103:                                   ; preds = %58, %.preheader
  %40 = phi i32 [ %38, %.preheader ], [ %59, %58 ]
  %.187.lcssa = phi i32 [ 1, %.preheader ], [ %.3, %58 ]
  %.184.lcssa = phi i32 [ %.083105, %.preheader ], [ %.285, %58 ]
  %41 = xor i32 %.081106, 1
  %.not = icmp eq i32 %.187.lcssa, 0
  br i1 %.not, label %.split108, label %.preheader, !llvm.loop !12

42:                                               ; preds = %.lr.ph102, %58
  %indvars.iv114 = phi i64 [ 0, %.lr.ph102 ], [ %indvars.iv.next115, %58 ]
  %.184100 = phi i32 [ %.083105, %.lr.ph102 ], [ %.285, %58 ]
  %.18799 = phi i32 [ 1, %.lr.ph102 ], [ %.3, %58 ]
  %.in.in = getelementptr inbounds i8, ptr %.in.in.v, i64 %indvars.iv114
  %.in94 = load i8, ptr %.in.in, align 1, !tbaa !9
  %43 = call i32 @tablet_has(ptr noundef %7, i8 noundef signext %.in94)
  %.not95 = icmp eq i32 %43, 0
  br i1 %.not95, label %58, label %44

44:                                               ; preds = %42
  %45 = call i32 @tablet_get(ptr noundef %7, i8 noundef signext %.in94)
  %46 = icmp eq i32 %45, 1
  br i1 %46, label %47, label %52

47:                                               ; preds = %44
  %48 = call i32 @tablet_del(ptr noundef %7, i8 noundef signext %.in94)
  %49 = load i32, ptr %35, align 4, !tbaa !14
  %50 = icmp eq i32 %49, 1
  %51 = zext i1 %50 to i32
  %spec.select = xor i32 %.18799, %51
  br label %54

52:                                               ; preds = %44
  %53 = add nsw i32 %45, -1
  call void @tablet_set(ptr noundef %7, i8 noundef signext %.in94, i32 noundef %53)
  br label %54

54:                                               ; preds = %47, %52
  %.288 = phi i32 [ %.18799, %52 ], [ %spec.select, %47 ]
  %55 = zext i32 %.184100 to i64
  %56 = getelementptr inbounds i8, ptr %32, i64 %55
  store i8 %.in94, ptr %56, align 1, !tbaa !9
  %57 = add i32 %.184100, 1
  br label %58

58:                                               ; preds = %54, %42
  %.3 = phi i32 [ %.288, %54 ], [ %.18799, %42 ]
  %.285 = phi i32 [ %57, %54 ], [ %.184100, %42 ]
  %indvars.iv.next115 = add nuw nsw i64 %indvars.iv114, 1
  %59 = load i32, ptr %2, align 4, !tbaa !5
  %60 = sext i32 %59 to i64
  %61 = icmp slt i64 %indvars.iv.next115, %60
  br i1 %61, label %42, label %._crit_edge103, !llvm.loop !17

.split108:                                        ; preds = %._crit_edge103
  %62 = load i32, ptr %35, align 4, !tbaa !14
  %63 = icmp eq i32 %62, 1
  br i1 %63, label %64, label %75

64:                                               ; preds = %.split108
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %3) #9
  %65 = call ptr @tablet_keys(ptr noundef nonnull %7, ptr noundef nonnull %3)
  %66 = load i32, ptr %3, align 4, !tbaa !5
  %.not92 = icmp eq i32 %66, 1
  br i1 %.not92, label %67, label %.critedge

67:                                               ; preds = %64
  %68 = load i8, ptr %65, align 1, !tbaa !9
  call void @free(ptr noundef %65) #9
  %69 = icmp slt i32 %.184.lcssa, %5
  br i1 %69, label %.lr.ph111.preheader, label %._crit_edge112

.lr.ph111.preheader:                              ; preds = %67
  %70 = sext i32 %.184.lcssa to i64
  %scevgep = getelementptr i8, ptr %32, i64 %70
  %71 = xor i32 %.184.lcssa, -1
  %72 = add i32 %71, %5
  %73 = zext i32 %72 to i64
  %74 = add nuw nsw i64 %73, 1
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 1 dereferenceable(1) %scevgep, i8 %68, i64 %74, i1 false), !tbaa !9
  br label %._crit_edge112

._crit_edge112:                                   ; preds = %.lr.ph111.preheader, %67
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %3) #9
  br label %75

75:                                               ; preds = %._crit_edge112, %.split108
  call void @free(ptr noundef %9) #9
  call void @free(ptr noundef %30) #9
  call void @tablet_free(ptr noundef nonnull %7)
  br label %76

.critedge:                                        ; preds = %64
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %3) #9
  br label %76

76:                                               ; preds = %75, %.critedge, %22, %19
  %.2 = phi ptr [ %0, %19 ], [ %24, %22 ], [ %32, %75 ], [ @.str, %.critedge ]
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %2) #9
  ret ptr %.2
}

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare i64 @strlen(ptr nocapture noundef) local_unnamed_addr #4

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

; Function Attrs: nofree
declare void @qsort(ptr noundef, i64 noundef, i64 noundef, ptr nocapture noundef) local_unnamed_addr #6

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #7

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nounwind uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #2 = { mustprogress 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 #3 = { mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, 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 #4 = { mustprogress nofree nounwind willreturn memory(argmem: 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 #5 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #6 = { nofree "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: write) }
attributes #8 = { nounwind willreturn memory(read) }
attributes #9 = { nounwind }
attributes #10 = { 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!7, !7, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}
!12 = distinct !{!12, !11, !13}
!13 = !{!"llvm.loop.unswitch.partial.disable"}
!14 = !{!15, !6, i64 4}
!15 = !{!"tablet", !6, i64 0, !6, i64 4, !16, i64 8, !16, i64 16}
!16 = !{!"any pointer", !7, i64 0}
!17 = distinct !{!17, !11}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopIdiomRecognizePass,LoopInstSimplifyPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimpleLoopUnswitchPass,SimplifyCFGPass,TailCallElimPass