; 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 allocsize(0)
declare noalias ptr @malloc(i64 noundef) #0

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

13:                                               ; preds = %2
  %14 = load ptr, ptr %4, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.memory, ptr %14, i32 0, i32 4
  %16 = load ptr, ptr %15, align 8, !tbaa !11
  %17 = load i32, ptr %5, align 4, !tbaa !9
  %18 = sext i32 %17 to i64
  %19 = getelementptr inbounds i8, ptr %16, i64 %18
  %20 = load ptr, ptr %4, 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 %81

22:                                               ; preds = %2
  %23 = load ptr, ptr %4, 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 = icmp sge i32 %26, 100
  br i1 %27, label %28, label %29

28:                                               ; preds = %22
  store ptr null, ptr %3, align 8
  br label %85

29:                                               ; preds = %22
  %30 = load ptr, ptr %4, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.memory, ptr %30, i32 0, i32 2
  %32 = load i32, ptr %31, align 4, !tbaa !14
  %33 = load ptr, ptr %4, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.memory, ptr %33, i32 0, i32 1
  %35 = load i32, ptr %34, align 8, !tbaa !15
  %36 = icmp sgt i32 %32, %35
  br i1 %36, label %37, label %54

37:                                               ; preds = %29
  %38 = load ptr, ptr %4, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.memory, ptr %38, i32 0, i32 3
  %40 = load i32, ptr %39, align 8, !tbaa !16
  %41 = sext i32 %40 to i64
  %42 = call noalias ptr @malloc(i64 noundef %41) #2
  %43 = load ptr, ptr %4, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.memory, ptr %43, i32 0, i32 0
  %45 = load ptr, ptr %4, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.memory, ptr %45, i32 0, i32 2
  %47 = load i32, ptr %46, align 4, !tbaa !14
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds [100 x ptr], ptr %44, i64 0, i64 %48
  store ptr %42, ptr %49, align 8, !tbaa !5
  %50 = load ptr, ptr %4, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.memory, ptr %50, i32 0, i32 1
  %52 = load i32, ptr %51, align 8, !tbaa !15
  %53 = add nsw i32 %52, 1
  store i32 %53, ptr %51, align 8, !tbaa !15
  br label %54

54:                                               ; preds = %37, %29
  %55 = load ptr, ptr %4, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.memory, ptr %55, i32 0, i32 0
  %57 = load ptr, ptr %4, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.memory, ptr %57, i32 0, i32 2
  %59 = load i32, ptr %58, align 4, !tbaa !14
  %60 = sext i32 %59 to i64
  %61 = getelementptr inbounds [100 x ptr], ptr %56, i64 0, i64 %60
  %62 = load ptr, ptr %61, align 8, !tbaa !5
  %63 = load ptr, ptr %4, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.memory, ptr %63, i32 0, i32 5
  store ptr %62, ptr %64, align 8, !tbaa !17
  %65 = load ptr, ptr %4, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.memory, ptr %65, i32 0, i32 4
  store ptr %62, ptr %66, align 8, !tbaa !11
  %67 = load ptr, ptr %4, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct.memory, ptr %67, i32 0, i32 5
  %69 = load ptr, ptr %68, align 8, !tbaa !17
  %70 = load ptr, ptr %4, align 8, !tbaa !5
  %71 = getelementptr inbounds %struct.memory, ptr %70, i32 0, i32 3
  %72 = load i32, ptr %71, align 8, !tbaa !16
  %73 = sext i32 %72 to i64
  %74 = getelementptr inbounds i8, ptr %69, i64 %73
  %75 = load i32, ptr %5, align 4, !tbaa !9
  %76 = sext i32 %75 to i64
  %77 = sub i64 0, %76
  %78 = getelementptr inbounds i8, ptr %74, i64 %77
  %79 = load ptr, ptr %4, align 8, !tbaa !5
  %80 = getelementptr inbounds %struct.memory, ptr %79, i32 0, i32 6
  store ptr %78, ptr %80, align 8, !tbaa !13
  br label %81

81:                                               ; preds = %54, %13
  %82 = load ptr, ptr %4, align 8, !tbaa !5
  %83 = getelementptr inbounds %struct.memory, ptr %82, i32 0, i32 4
  %84 = load ptr, ptr %83, align 8, !tbaa !11
  store ptr %84, ptr %3, align 8
  br label %85

85:                                               ; preds = %81, %28
  %86 = load ptr, ptr %3, align 8
  ret ptr %86
}

attributes #0 = { 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 #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) }

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


; 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 nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #0

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

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

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

16:                                               ; preds = %11
  %17 = getelementptr inbounds i8, ptr %0, i64 800
  %18 = load i32, ptr %17, align 8, !tbaa !13
  %.not = icmp slt i32 %13, %18
  br i1 %.not, label %._crit_edge, label %19

._crit_edge:                                      ; preds = %16
  %.phi.trans.insert = sext i32 %14 to i64
  %.phi.trans.insert23 = getelementptr inbounds [100 x ptr], ptr %0, i64 0, i64 %.phi.trans.insert
  %.pre = load ptr, ptr %.phi.trans.insert23, align 8, !tbaa !14
  %.phi.trans.insert24 = getelementptr inbounds i8, ptr %0, i64 808
  %.pre25 = load i32, ptr %.phi.trans.insert24, align 8, !tbaa !15
  %.pre26 = sext i32 %.pre25 to i64
  br label %27

19:                                               ; preds = %16
  %20 = getelementptr inbounds i8, ptr %0, i64 808
  %21 = load i32, ptr %20, align 8, !tbaa !15
  %22 = sext i32 %21 to i64
  %23 = tail call noalias ptr @malloc(i64 noundef %22) #2
  %24 = sext i32 %14 to i64
  %25 = getelementptr inbounds [100 x ptr], ptr %0, i64 0, i64 %24
  store ptr %23, ptr %25, align 8, !tbaa !14
  %26 = add nsw i32 %18, 1
  store i32 %26, ptr %17, align 8, !tbaa !13
  br label %27

27:                                               ; preds = %._crit_edge, %19
  %.pre-phi27 = phi i64 [ %.pre26, %._crit_edge ], [ %22, %19 ]
  %28 = phi ptr [ %.pre, %._crit_edge ], [ %23, %19 ]
  %29 = getelementptr inbounds i8, ptr %0, i64 824
  store ptr %28, ptr %29, align 8, !tbaa !16
  store ptr %28, ptr %3, align 8, !tbaa !5
  %30 = getelementptr inbounds i8, ptr %28, i64 %.pre-phi27
  %31 = sext i32 %1 to i64
  %32 = sub nsw i64 0, %31
  %33 = getelementptr inbounds i8, ptr %30, i64 %32
  store ptr %33, ptr %5, align 8, !tbaa !11
  br label %34

34:                                               ; preds = %8, %27, %11
  %.0 = phi ptr [ null, %11 ], [ %28, %27 ], [ %10, %8 ]
  ret ptr %.0
}

attributes #0 = { 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 #1 = { mustprogress nofree nounwind willreturn memory(argmem: readwrite, inaccessiblemem: 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 #2 = { 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, !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 832}
!12 = !{!6, !9, i64 804}
!13 = !{!6, !9, i64 800}
!14 = !{!10, !10, i64 0}
!15 = !{!6, !9, i64 808}
!16 = !{!6, !10, i64 824}


; Effective O3 passes: BDCEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass