; LLVM IR from rantala/string-sorting :: external (adaptive)

; 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.memory = type { [100 x ptr], i32, i32, i32, ptr, ptr, ptr }

; Function Attrs: nounwind uwtable
define dso_local ptr @deallocmem(ptr noundef %0, i32 noundef %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !9
  %5 = load ptr, ptr %3, align 8, !tbaa !5
  %6 = getelementptr inbounds %struct.memory, ptr %5, i32 0, i32 4
  %7 = load ptr, ptr %6, align 8, !tbaa !11
  %8 = load ptr, ptr %3, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct.memory, ptr %8, i32 0, i32 5
  %10 = load ptr, ptr %9, align 8, !tbaa !13
  %11 = icmp ugt ptr %7, %10
  br i1 %11, label %12, label %22

12:                                               ; preds = %2
  %13 = load ptr, ptr %3, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.memory, ptr %13, i32 0, i32 4
  %15 = load ptr, ptr %14, align 8, !tbaa !11
  %16 = load i32, ptr %4, align 4, !tbaa !9
  %17 = sext i32 %16 to i64
  %18 = sub i64 0, %17
  %19 = getelementptr inbounds i8, ptr %15, i64 %18
  %20 = load ptr, ptr %3, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.memory, ptr %20, i32 0, i32 4
  store ptr %19, ptr %21, align 8, !tbaa !11
  br label %66

22:                                               ; preds = %2
  %23 = load ptr, ptr %3, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.memory, ptr %23, i32 0, i32 2
  %25 = load i32, ptr %24, align 4, !tbaa !14
  %26 = add nsw i32 %25, -1
  store i32 %26, ptr %24, align 4, !tbaa !14
  %27 = load ptr, ptr %3, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.memory, ptr %27, i32 0, i32 2
  %29 = load i32, ptr %28, align 4, !tbaa !14
  %30 = icmp sge i32 %29, 0
  br i1 %30, label %31, label %58

31:                                               ; preds = %22
  %32 = load ptr, ptr %3, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.memory, ptr %32, i32 0, i32 0
  %34 = load ptr, ptr %3, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.memory, ptr %34, i32 0, i32 2
  %36 = load i32, ptr %35, align 4, !tbaa !14
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds [100 x ptr], ptr %33, i64 0, i64 %37
  %39 = load ptr, ptr %38, align 8, !tbaa !5
  %40 = load ptr, ptr %3, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.memory, ptr %40, i32 0, i32 5
  store ptr %39, ptr %41, align 8, !tbaa !13
  %42 = load ptr, ptr %3, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.memory, ptr %42, i32 0, i32 5
  %44 = load ptr, ptr %43, align 8, !tbaa !13
  %45 = load ptr, ptr %3, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.memory, ptr %45, i32 0, i32 3
  %47 = load i32, ptr %46, align 8, !tbaa !15
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds i8, ptr %44, i64 %48
  %50 = load i32, ptr %4, align 4, !tbaa !9
  %51 = sext i32 %50 to i64
  %52 = sub i64 0, %51
  %53 = getelementptr inbounds i8, ptr %49, i64 %52
  %54 = load ptr, ptr %3, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.memory, ptr %54, i32 0, i32 6
  store ptr %53, ptr %55, align 8, !tbaa !16
  %56 = load ptr, ptr %3, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.memory, ptr %56, i32 0, i32 4
  store ptr %53, ptr %57, align 8, !tbaa !11
  br label %65

58:                                               ; preds = %22
  %59 = load ptr, ptr %3, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.memory, ptr %59, i32 0, i32 6
  store ptr null, ptr %60, align 8, !tbaa !16
  %61 = load ptr, ptr %3, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.memory, ptr %61, i32 0, i32 5
  store ptr null, ptr %62, align 8, !tbaa !13
  %63 = load ptr, ptr %3, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.memory, ptr %63, i32 0, i32 4
  store ptr null, ptr %64, align 8, !tbaa !11
  br label %65

65:                                               ; preds = %58, %31
  br label %66

66:                                               ; preds = %65, %12
  %67 = load ptr, ptr %3, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct.memory, ptr %67, i32 0, i32 4
  %69 = load ptr, ptr %68, align 8, !tbaa !11
  ret ptr %69
}

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

!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 = !{!12, !6, i64 816}
!12 = !{!"", !7, i64 0, !10, i64 800, !10, i64 804, !10, i64 808, !6, i64 816, !6, i64 824, !6, i64 832}
!13 = !{!12, !6, i64 824}
!14 = !{!12, !10, i64 804}
!15 = !{!12, !10, i64 808}
!16 = !{!12, !6, i64 832}


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

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: readwrite) uwtable
define dso_local ptr @deallocmem(ptr nocapture noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = getelementptr inbounds i8, ptr %0, i64 816
  %4 = load ptr, ptr %3, align 8, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %0, i64 824
  %6 = load ptr, ptr %5, align 8, !tbaa !11
  %7 = icmp ugt ptr %4, %6
  br i1 %7, label %8, label %12

8:                                                ; preds = %2
  %9 = sext i32 %1 to i64
  %10 = sub nsw i64 0, %9
  %11 = getelementptr inbounds i8, ptr %4, i64 %10
  store ptr %11, ptr %3, align 8, !tbaa !5
  br label %30

12:                                               ; preds = %2
  %13 = getelementptr inbounds i8, ptr %0, i64 804
  %14 = load i32, ptr %13, align 4, !tbaa !12
  %15 = add nsw i32 %14, -1
  store i32 %15, ptr %13, align 4, !tbaa !12
  %16 = icmp sgt i32 %14, 0
  br i1 %16, label %17, label %29

17:                                               ; preds = %12
  %18 = zext nneg i32 %15 to i64
  %19 = getelementptr inbounds [100 x ptr], ptr %0, i64 0, i64 %18
  %20 = load ptr, ptr %19, align 8, !tbaa !13
  store ptr %20, ptr %5, align 8, !tbaa !11
  %21 = getelementptr inbounds i8, ptr %0, i64 808
  %22 = load i32, ptr %21, align 8, !tbaa !14
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds i8, ptr %20, i64 %23
  %25 = sext i32 %1 to i64
  %26 = sub nsw i64 0, %25
  %27 = getelementptr inbounds i8, ptr %24, i64 %26
  %28 = getelementptr inbounds i8, ptr %0, i64 832
  store ptr %27, ptr %28, align 8, !tbaa !15
  store ptr %27, ptr %3, align 8, !tbaa !5
  br label %30

29:                                               ; preds = %12
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(24) %3, i8 0, i64 24, i1 false)
  br label %30

30:                                               ; preds = %17, %29, %8
  %31 = phi ptr [ %27, %17 ], [ null, %29 ], [ %11, %8 ]
  ret ptr %31
}

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

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

!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, !10, i64 816}
!6 = !{!"", !7, i64 0, !9, i64 800, !9, i64 804, !9, i64 808, !10, i64 816, !10, i64 824, !10, i64 832}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!"int", !7, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!6, !10, i64 824}
!12 = !{!6, !9, i64 804}
!13 = !{!10, !10, i64 0}
!14 = !{!6, !9, i64 808}
!15 = !{!6, !10, i64 832}


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