; LLVM IR from seppo0010/rlite :: src (type_string)

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

; Function Attrs: nounwind uwtable
declare dso_local i32 @rl_set(ptr noundef, ptr noundef, i64 noundef, ptr noundef, i64 noundef, i32 noundef, i64 noundef) #0

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

declare i32 @rl_key_set(ptr noundef, ptr noundef, i64 noundef, i8 noundef zeroext, i64 noundef, i64 noundef, i64 noundef) #2

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

; Function Attrs: nounwind uwtable
declare hidden i32 @rl_string_get_objects(ptr noundef, ptr noundef, i64 noundef, ptr noundef, ptr noundef, ptr noundef) #0

; Function Attrs: nounwind uwtable
declare dso_local i32 @rl_append(ptr noundef, ptr noundef, i64 noundef, ptr noundef, i64 noundef, ptr noundef) #0

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

26:                                               ; preds = %7
  store i32 5, ptr %19, align 4, !tbaa !11
  br label %105

27:                                               ; preds = %7
  %28 = load ptr, ptr %9, align 8, !tbaa !5
  %29 = load ptr, ptr %10, align 8, !tbaa !5
  %30 = load i64, ptr %11, align 8, !tbaa !9
  %31 = call i32 @rl_string_get_objects(ptr noundef %28, ptr noundef %29, i64 noundef %30, ptr noundef %16, ptr noundef %18, ptr noundef %17)
  store i32 %31, ptr %19, align 4, !tbaa !11
  %32 = load i32, ptr %19, align 4, !tbaa !11
  %33 = icmp ne i32 0, %32
  br i1 %33, label %34, label %38

34:                                               ; preds = %27
  %35 = load i32, ptr %19, align 4, !tbaa !11
  %36 = icmp ne i32 3, %35
  br i1 %36, label %37, label %38

37:                                               ; preds = %34
  br label %105

38:                                               ; preds = %34, %27
  %39 = load i32, ptr %19, align 4, !tbaa !11
  %40 = icmp eq i32 %39, 3
  br i1 %40, label %41, label %76

41:                                               ; preds = %38
  call void @llvm.lifetime.start.p0(i64 8, ptr %20) #6
  %42 = load i64, ptr %12, align 8, !tbaa !9
  %43 = mul i64 1, %42
  %44 = call noalias ptr @malloc(i64 noundef %43) #7
  store ptr %44, ptr %20, align 8, !tbaa !5
  %45 = load ptr, ptr %20, align 8, !tbaa !5
  %46 = icmp ne ptr %45, null
  br i1 %46, label %48, label %47

47:                                               ; preds = %41
  store i32 4, ptr %19, align 4, !tbaa !11
  store i32 2, ptr %21, align 4
  br label %73

48:                                               ; preds = %41
  %49 = load ptr, ptr %20, align 8, !tbaa !5
  %50 = load i64, ptr %12, align 8, !tbaa !9
  call void @llvm.memset.p0.i64(ptr align 1 %49, i8 0, i64 %50, i1 false)
  %51 = load ptr, ptr %9, align 8, !tbaa !5
  %52 = load ptr, ptr %10, align 8, !tbaa !5
  %53 = load i64, ptr %11, align 8, !tbaa !9
  %54 = load ptr, ptr %20, align 8, !tbaa !5
  %55 = load i64, ptr %12, align 8, !tbaa !9
  %56 = call i32 @rl_set(ptr noundef %51, ptr noundef %52, i64 noundef %53, ptr noundef %54, i64 noundef %55, i32 noundef 0, i64 noundef 0)
  store i32 %56, ptr %19, align 4, !tbaa !11
  %57 = load i32, ptr %19, align 4, !tbaa !11
  %58 = icmp ne i32 0, %57
  br i1 %58, label %59, label %60

59:                                               ; preds = %48
  store i32 2, ptr %21, align 4
  br label %73

60:                                               ; preds = %48
  %61 = load ptr, ptr %20, align 8, !tbaa !5
  call void @free(ptr noundef %61) #6
  %62 = load ptr, ptr %9, align 8, !tbaa !5
  %63 = load ptr, ptr %10, align 8, !tbaa !5
  %64 = load i64, ptr %11, align 8, !tbaa !9
  %65 = load ptr, ptr %13, align 8, !tbaa !5
  %66 = load i64, ptr %14, align 8, !tbaa !9
  %67 = load ptr, ptr %15, align 8, !tbaa !5
  %68 = call i32 @rl_append(ptr noundef %62, ptr noundef %63, i64 noundef %64, ptr noundef %65, i64 noundef %66, ptr noundef %67)
  store i32 %68, ptr %19, align 4, !tbaa !11
  %69 = load i32, ptr %19, align 4, !tbaa !11
  %70 = icmp ne i32 0, %69
  br i1 %70, label %71, label %72

71:                                               ; preds = %60
  store i32 2, ptr %21, align 4
  br label %73

72:                                               ; preds = %60
  store i32 0, ptr %21, align 4
  br label %73

73:                                               ; preds = %72, %71, %59, %47
  call void @llvm.lifetime.end.p0(i64 8, ptr %20) #6
  %74 = load i32, ptr %21, align 4
  switch i32 %74, label %107 [
    i32 0, label %75
    i32 2, label %105
  ]

75:                                               ; preds = %73
  br label %104

76:                                               ; preds = %38
  %77 = load i32, ptr %19, align 4, !tbaa !11
  %78 = icmp eq i32 %77, 0
  br i1 %78, label %79, label %103

79:                                               ; preds = %76
  %80 = load ptr, ptr %9, align 8, !tbaa !5
  %81 = load ptr, ptr %10, align 8, !tbaa !5
  %82 = load i64, ptr %11, align 8, !tbaa !9
  %83 = load i64, ptr %16, align 8, !tbaa !9
  %84 = load i64, ptr %18, align 8, !tbaa !13
  %85 = load i64, ptr %17, align 8, !tbaa !9
  %86 = add nsw i64 %85, 1
  %87 = call i32 @rl_key_set(ptr noundef %80, ptr noundef %81, i64 noundef %82, i8 noundef zeroext 84, i64 noundef %83, i64 noundef %84, i64 noundef %86)
  store i32 %87, ptr %19, align 4, !tbaa !11
  %88 = load i32, ptr %19, align 4, !tbaa !11
  %89 = icmp ne i32 0, %88
  br i1 %89, label %90, label %91

90:                                               ; preds = %79
  br label %105

91:                                               ; preds = %79
  %92 = load ptr, ptr %9, align 8, !tbaa !5
  %93 = load i64, ptr %16, align 8, !tbaa !9
  %94 = load ptr, ptr %13, align 8, !tbaa !5
  %95 = load i64, ptr %14, align 8, !tbaa !9
  %96 = load i64, ptr %12, align 8, !tbaa !9
  %97 = load ptr, ptr %15, align 8, !tbaa !5
  %98 = call i32 @rl_multi_string_setrange(ptr noundef %92, i64 noundef %93, ptr noundef %94, i64 noundef %95, i64 noundef %96, ptr noundef %97)
  store i32 %98, ptr %19, align 4, !tbaa !11
  %99 = load i32, ptr %19, align 4, !tbaa !11
  %100 = icmp ne i32 0, %99
  br i1 %100, label %101, label %102

101:                                              ; preds = %91
  br label %105

102:                                              ; preds = %91
  br label %103

103:                                              ; preds = %102, %76
  br label %104

104:                                              ; preds = %103, %75
  store i32 0, ptr %19, align 4, !tbaa !11
  br label %105

105:                                              ; preds = %104, %101, %90, %73, %37, %26
  %106 = load i32, ptr %19, align 4, !tbaa !11
  store i32 %106, ptr %8, align 4
  store i32 1, ptr %21, align 4
  br label %107

107:                                              ; preds = %105, %73
  call void @llvm.lifetime.end.p0(i64 4, ptr %19) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %18) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %17) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #6
  %108 = load i32, ptr %8, align 4
  ret i32 %108
}

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

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

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

declare i32 @rl_multi_string_setrange(ptr noundef, i64 noundef, ptr noundef, i64 noundef, i64 noundef, ptr noundef) #2

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { "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 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 #4 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #5 = { 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 #6 = { nounwind }
attributes #7 = { 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 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"long long", !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: nounwind uwtable
declare dso_local i32 @rl_set(ptr noundef, ptr noundef, i64 noundef, ptr noundef, i64 noundef, i32 noundef, i64 noundef) local_unnamed_addr #0

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

declare i32 @rl_key_set(ptr noundef, ptr noundef, i64 noundef, i8 noundef zeroext, i64 noundef, i64 noundef, i64 noundef) local_unnamed_addr #2

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

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

; Function Attrs: nounwind uwtable
declare dso_local i32 @rl_append(ptr noundef, ptr noundef, i64 noundef, ptr noundef, i64 noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local i32 @rl_setrange(ptr noundef %0, ptr noundef %1, i64 noundef %2, i64 noundef %3, ptr noundef %4, i64 noundef %5, ptr noundef %6) local_unnamed_addr #0 {
  %8 = alloca i64, align 8
  %9 = alloca i64, align 8
  %10 = alloca i64, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %8) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %9) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %10) #5
  %11 = add nsw i64 %5, %3
  %12 = icmp sgt i64 %11, 536870912
  br i1 %12, label %.thread, label %13

13:                                               ; preds = %7
  %14 = call i32 @rl_string_get_objects(ptr noundef %0, ptr noundef %1, i64 noundef %2, ptr noundef nonnull %8, ptr noundef nonnull %10, ptr noundef nonnull %9)
  switch i32 %14, label %.thread [
    i32 3, label %15
    i32 0, label %20
  ]

15:                                               ; preds = %13
  %calloc = call ptr @calloc(i64 1, i64 %3)
  %.not51 = icmp eq ptr %calloc, null
  br i1 %.not51, label %.thread, label %16

16:                                               ; preds = %15
  %17 = call i32 @rl_set(ptr noundef %0, ptr noundef %1, i64 noundef %2, ptr noundef nonnull %calloc, i64 noundef %3, i32 noundef 0, i64 noundef 0)
  %.not52 = icmp eq i32 %17, 0
  br i1 %.not52, label %18, label %.thread

18:                                               ; preds = %16
  call void @free(ptr noundef nonnull %calloc) #5
  %19 = call i32 @rl_append(ptr noundef %0, ptr noundef %1, i64 noundef %2, ptr noundef %4, i64 noundef %5, ptr noundef %6)
  %.not53 = icmp eq i32 %19, 0
  br i1 %.not53, label %29, label %.thread

20:                                               ; preds = %13
  %21 = load i64, ptr %8, align 8, !tbaa !5
  %22 = load i64, ptr %10, align 8, !tbaa !9
  %23 = load i64, ptr %9, align 8, !tbaa !5
  %24 = add nsw i64 %23, 1
  %25 = call i32 @rl_key_set(ptr noundef %0, ptr noundef %1, i64 noundef %2, i8 noundef zeroext 84, i64 noundef %21, i64 noundef %22, i64 noundef %24) #5
  %.not = icmp eq i32 %25, 0
  br i1 %.not, label %26, label %.thread

26:                                               ; preds = %20
  %27 = load i64, ptr %8, align 8, !tbaa !5
  %28 = call i32 @rl_multi_string_setrange(ptr noundef %0, i64 noundef %27, ptr noundef %4, i64 noundef %5, i64 noundef %3, ptr noundef %6) #5
  %.not50 = icmp eq i32 %28, 0
  br i1 %.not50, label %29, label %.thread

29:                                               ; preds = %18, %26
  br label %.thread

.thread:                                          ; preds = %18, %16, %15, %29, %20, %26, %7, %13
  %.1 = phi i32 [ %14, %13 ], [ 0, %29 ], [ %25, %20 ], [ %28, %26 ], [ 5, %7 ], [ %19, %18 ], [ %17, %16 ], [ 4, %15 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %10) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %9) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %8) #5
  ret i32 %.1
}

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

declare i32 @rl_multi_string_setrange(ptr noundef, i64 noundef, ptr noundef, i64 noundef, i64 noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: nofree nounwind willreturn allockind("alloc,zeroed") allocsize(0,1) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @calloc(i64 noundef, i64 noundef) local_unnamed_addr #4

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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { "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 = { nofree nounwind willreturn allockind("alloc,zeroed") allocsize(0,1) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" }
attributes #5 = { 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 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long long", !7, i64 0}


; Effective O3 passes: CorrelatedValuePropagationPass,DSEPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,SROAPass,SimplifyCFGPass