; LLVM IR from Softmotions/iowow :: src/utils (iwxstr)

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

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

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

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

; 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
define dso_local ptr @iwxstr_wrap(ptr noundef %0, i64 noundef %1, i64 noundef %2) #3 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i64 %1, ptr %6, align 8, !tbaa !9
  store i64 %2, ptr %7, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #5
  %10 = call noalias ptr @malloc(i64 noundef 40) #6
  store ptr %10, ptr %8, align 8, !tbaa !5
  %11 = load ptr, ptr %8, align 8, !tbaa !5
  %12 = icmp ne ptr %11, null
  br i1 %12, label %14, label %13

13:                                               ; preds = %3
  store ptr null, ptr %4, align 8
  store i32 1, ptr %9, align 4
  br label %56

14:                                               ; preds = %3
  %15 = load ptr, ptr %8, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.iwxstr, ptr %15, i32 0, i32 4
  store ptr null, ptr %16, align 8, !tbaa !11
  %17 = load ptr, ptr %8, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.iwxstr, ptr %17, i32 0, i32 3
  store ptr null, ptr %18, align 8, !tbaa !13
  %19 = load i64, ptr %6, align 8, !tbaa !9
  %20 = load ptr, ptr %8, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.iwxstr, ptr %20, i32 0, i32 1
  store i64 %19, ptr %21, align 8, !tbaa !14
  %22 = load i64, ptr %7, align 8, !tbaa !9
  %23 = load ptr, ptr %8, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.iwxstr, ptr %23, i32 0, i32 2
  store i64 %22, ptr %24, align 8, !tbaa !15
  %25 = load ptr, ptr %5, align 8, !tbaa !5
  %26 = load ptr, ptr %8, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.iwxstr, ptr %26, i32 0, i32 0
  store ptr %25, ptr %27, align 8, !tbaa !16
  %28 = load i64, ptr %6, align 8, !tbaa !9
  %29 = load i64, ptr %7, align 8, !tbaa !9
  %30 = icmp uge i64 %28, %29
  br i1 %30, label %31, label %49

31:                                               ; preds = %14
  %32 = load ptr, ptr %5, align 8, !tbaa !5
  %33 = load i64, ptr %6, align 8, !tbaa !9
  %34 = add i64 %33, 1
  %35 = call ptr @realloc(ptr noundef %32, i64 noundef %34) #7
  %36 = load ptr, ptr %8, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.iwxstr, ptr %36, i32 0, i32 0
  store ptr %35, ptr %37, align 8, !tbaa !16
  %38 = load ptr, ptr %8, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.iwxstr, ptr %38, i32 0, i32 0
  %40 = load ptr, ptr %39, align 8, !tbaa !16
  %41 = icmp ne ptr %40, null
  br i1 %41, label %44, label %42

42:                                               ; preds = %31
  %43 = load ptr, ptr %8, align 8, !tbaa !5
  call void @free(ptr noundef %43) #5
  store ptr null, ptr %4, align 8
  store i32 1, ptr %9, align 4
  br label %56

44:                                               ; preds = %31
  %45 = load i64, ptr %6, align 8, !tbaa !9
  %46 = add i64 %45, 1
  %47 = load ptr, ptr %8, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.iwxstr, ptr %47, i32 0, i32 2
  store i64 %46, ptr %48, align 8, !tbaa !15
  br label %49

49:                                               ; preds = %44, %14
  %50 = load ptr, ptr %8, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.iwxstr, ptr %50, i32 0, i32 0
  %52 = load ptr, ptr %51, align 8, !tbaa !16
  %53 = load i64, ptr %6, align 8, !tbaa !9
  %54 = getelementptr inbounds i8, ptr %52, i64 %53
  store i8 0, ptr %54, align 1, !tbaa !17
  %55 = load ptr, ptr %8, align 8, !tbaa !5
  store ptr %55, ptr %4, align 8
  store i32 1, ptr %9, align 4
  br label %56

56:                                               ; preds = %49, %42, %13
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #5
  %57 = load ptr, ptr %4, align 8
  ret ptr %57
}

; Function Attrs: nounwind allocsize(1)
declare ptr @realloc(ptr noundef, i64 noundef) #4

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

!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, !6, i64 32}
!12 = !{!"iwxstr", !6, i64 0, !10, i64 8, !10, i64 16, !6, i64 24, !6, i64 32}
!13 = !{!12, !6, i64 24}
!14 = !{!12, !10, i64 8}
!15 = !{!12, !10, i64 16}
!16 = !{!12, !6, i64 0}
!17 = !{!7, !7, i64 0}


; 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 nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nounwind willreturn uwtable
define dso_local noalias noundef ptr @iwxstr_wrap(ptr noundef %0, i64 noundef %1, i64 noundef %2) local_unnamed_addr #2 {
  %4 = tail call noalias dereferenceable_or_null(40) ptr @malloc(i64 noundef 40) #5
  %.not = icmp eq ptr %4, null
  br i1 %.not, label %17, label %5

5:                                                ; preds = %3
  %6 = getelementptr inbounds i8, ptr %4, i64 24
  %7 = getelementptr inbounds i8, ptr %4, i64 8
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %6, i8 0, i64 16, i1 false)
  store i64 %1, ptr %7, align 8, !tbaa !5
  %8 = getelementptr inbounds i8, ptr %4, i64 16
  store i64 %2, ptr %8, align 8, !tbaa !11
  store ptr %0, ptr %4, align 8, !tbaa !12
  %.not23 = icmp ult i64 %1, %2
  br i1 %.not23, label %14, label %9

9:                                                ; preds = %5
  %10 = add i64 %1, 1
  %11 = tail call ptr @realloc(ptr noundef %0, i64 noundef %10) #6
  store ptr %11, ptr %4, align 8, !tbaa !12
  %.not24 = icmp eq ptr %11, null
  br i1 %.not24, label %12, label %13

12:                                               ; preds = %9
  tail call void @free(ptr noundef nonnull %4) #7
  br label %17

13:                                               ; preds = %9
  store i64 %10, ptr %8, align 8, !tbaa !11
  br label %14

14:                                               ; preds = %13, %5
  %15 = phi ptr [ %11, %13 ], [ %0, %5 ]
  %16 = getelementptr inbounds i8, ptr %15, i64 %1
  store i8 0, ptr %16, align 1, !tbaa !13
  br label %17

17:                                               ; preds = %3, %14, %12
  %.0 = phi ptr [ %4, %14 ], [ null, %12 ], [ null, %3 ]
  ret ptr %.0
}

; Function Attrs: mustprogress nounwind willreturn allockind("realloc") allocsize(1) memory(argmem: readwrite, inaccessiblemem: readwrite)
declare noalias noundef ptr @realloc(ptr allocptr nocapture noundef, i64 noundef) local_unnamed_addr #3

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

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 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 #2 = { mustprogress nounwind willreturn 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 = { mustprogress nounwind willreturn allockind("realloc") allocsize(1) 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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #5 = { nounwind allocsize(0) }
attributes #6 = { nounwind allocsize(1) }
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, !10, i64 8}
!6 = !{!"iwxstr", !7, i64 0, !10, i64 8, !10, i64 16, !7, i64 24, !7, i64 32}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"long", !8, i64 0}
!11 = !{!6, !10, i64 16}
!12 = !{!6, !7, i64 0}
!13 = !{!8, !8, i64 0}


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