; LLVM IR from matz/streem :: src (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"

%struct.strm_string = type { ptr, i32 }

; 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
define dso_local ptr @strm_str_cstr(i64 noundef %0, ptr noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca i64, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  store i64 %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  %9 = load i64, ptr %4, align 8, !tbaa !5
  %10 = and i64 %9, -281474976710656
  switch i64 %10, label %36 [
    i64 -2533274790395904, label %11
    i64 -2251799813685248, label %24
    i64 -1970324836974592, label %29
    i64 -1688849860263936, label %29
  ]

11:                                               ; preds = %2
  %12 = getelementptr inbounds i8, ptr %4, i64 0
  %13 = load i8, ptr %12, align 8, !tbaa !11
  %14 = sext i8 %13 to i32
  store i32 %14, ptr %6, align 4, !tbaa !12
  %15 = load ptr, ptr %5, align 8, !tbaa !9
  %16 = getelementptr inbounds i8, ptr %4, i64 1
  %17 = load i32, ptr %6, align 4, !tbaa !12
  %18 = sext i32 %17 to i64
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %15, ptr align 1 %16, i64 %18, i1 false)
  %19 = load ptr, ptr %5, align 8, !tbaa !9
  %20 = load i32, ptr %6, align 4, !tbaa !12
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds i8, ptr %19, i64 %21
  store i8 0, ptr %22, align 1, !tbaa !11
  %23 = load ptr, ptr %5, align 8, !tbaa !9
  store ptr %23, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %37

24:                                               ; preds = %2
  %25 = load ptr, ptr %5, align 8, !tbaa !9
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %25, ptr align 8 %4, i64 6, i1 false)
  %26 = load ptr, ptr %5, align 8, !tbaa !9
  %27 = getelementptr inbounds i8, ptr %26, i64 6
  store i8 0, ptr %27, align 1, !tbaa !11
  %28 = load ptr, ptr %5, align 8, !tbaa !9
  store ptr %28, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %37

29:                                               ; preds = %2, %2
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  %30 = load i64, ptr %4, align 8, !tbaa !5
  %31 = and i64 %30, 281474976710655
  %32 = inttoptr i64 %31 to ptr
  store ptr %32, ptr %8, align 8, !tbaa !9
  %33 = load ptr, ptr %8, align 8, !tbaa !9
  %34 = getelementptr inbounds %struct.strm_string, ptr %33, i32 0, i32 0
  %35 = load ptr, ptr %34, align 8, !tbaa !14
  store ptr %35, ptr %3, align 8
  store i32 1, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  br label %37

36:                                               ; preds = %2
  store ptr null, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %37

37:                                               ; preds = %36, %29, %24, %11
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  %38 = load ptr, ptr %3, align 8
  ret ptr %38
}

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

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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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 = !{!"any pointer", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"int", !7, i64 0}
!14 = !{!15, !10, i64 0}
!15 = !{!"strm_string", !10, i64 0, !13, i64 8}


; 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(read, argmem: readwrite, inaccessiblemem: none) uwtable
define dso_local ptr @strm_str_cstr(i64 noundef %0, ptr noundef writeonly %1) local_unnamed_addr #0 {
  %.sroa.5.sroa.0 = alloca i56, align 8
  %.sroa.5.0.extract.shift = lshr i64 %0, 8
  %.sroa.5.0.extract.trunc = trunc nuw i64 %.sroa.5.0.extract.shift to i56
  store i56 %.sroa.5.0.extract.trunc, ptr %.sroa.5.sroa.0, align 8, !tbaa !5
  %3 = add i64 %0, 2533274790395904
  %4 = lshr i64 %3, 48
  %trunc = trunc nuw i64 %4 to i16
  switch i16 %trunc, label %14 [
    i16 0, label %5
    i16 1, label %8
    i16 2, label %10
    i16 3, label %10
  ]

5:                                                ; preds = %2
  %sext = shl i64 %0, 56
  %6 = ashr exact i64 %sext, 56
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %1, ptr nonnull align 8 %.sroa.5.sroa.0, i64 %6, i1 false)
  %7 = getelementptr inbounds i8, ptr %1, i64 %6
  store i8 0, ptr %7, align 1, !tbaa !9
  br label %14

8:                                                ; preds = %2
  %.sroa.0.0.extract.trunc = trunc i64 %0 to i8
  store i8 %.sroa.0.0.extract.trunc, ptr %1, align 1
  %.sroa.5.0..0.5.sroa_idx = getelementptr inbounds i8, ptr %1, i64 1
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 1 dereferenceable(5) %.sroa.5.0..0.5.sroa_idx, ptr noundef nonnull align 8 dereferenceable(5) %.sroa.5.sroa.0, i64 5, i1 false)
  %9 = getelementptr inbounds i8, ptr %1, i64 6
  store i8 0, ptr %9, align 1, !tbaa !9
  br label %14

10:                                               ; preds = %2, %2
  %11 = and i64 %0, 281474976710655
  %12 = inttoptr i64 %11 to ptr
  %13 = load ptr, ptr %12, align 8, !tbaa !10
  br label %14

14:                                               ; preds = %2, %10, %8, %5
  %.0 = phi ptr [ %13, %10 ], [ %1, %8 ], [ %1, %5 ], [ null, %2 ]
  ret ptr %.0
}

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

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

!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 = !{!7, !7, i64 0}
!10 = !{!11, !12, i64 0}
!11 = !{!"strm_string", !12, i64 0, !13, i64 8}
!12 = !{!"any pointer", !7, i64 0}
!13 = !{!"int", !7, i64 0}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass