; LLVM IR from matz/streem :: src (value)

; 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_array = type { i32, ptr, i64, ptr }
%struct.strm_misc = type { i32, ptr }

@strm_ns_array = external global ptr, align 8
@strm_ns_string = external global ptr, align 8
@strm_ns_number = external global ptr, align 8

; 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
declare hidden ptr @strm_ptr(i64 noundef) #1

; Function Attrs: nounwind uwtable
declare hidden i32 @strm_ptr_type(ptr noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local i32 @strm_number_p(i64 noundef) #1

declare i32 @strm_string_p(i64 noundef) #2

declare i32 @strm_array_p(i64 noundef) #2

declare ptr @strm_ary_struct(i64 noundef) #2

; Function Attrs: nounwind uwtable
define dso_local ptr @strm_value_ns(i64 noundef %0) #1 {
  %2 = alloca ptr, align 8
  %3 = alloca i64, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  store i64 %0, ptr %3, align 8, !tbaa !5
  %7 = load i64, ptr %3, align 8, !tbaa !5
  %8 = call i32 @strm_array_p(i64 noundef %7)
  %9 = icmp ne i32 %8, 0
  br i1 %9, label %10, label %22

10:                                               ; preds = %1
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  %11 = load i64, ptr %3, align 8, !tbaa !5
  %12 = call ptr @strm_ary_struct(i64 noundef %11)
  %13 = getelementptr inbounds %struct.strm_array, ptr %12, i32 0, i32 3
  %14 = load ptr, ptr %13, align 8, !tbaa !9
  store ptr %14, ptr %4, align 8, !tbaa !13
  %15 = load ptr, ptr %4, align 8, !tbaa !13
  %16 = icmp ne ptr %15, null
  br i1 %16, label %17, label %19

17:                                               ; preds = %10
  %18 = load ptr, ptr %4, align 8, !tbaa !13
  store ptr %18, ptr %2, align 8
  store i32 1, ptr %5, align 4
  br label %21

19:                                               ; preds = %10
  %20 = load ptr, ptr @strm_ns_array, align 8, !tbaa !13
  store ptr %20, ptr %2, align 8
  store i32 1, ptr %5, align 4
  br label %21

21:                                               ; preds = %19, %17
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  br label %57

22:                                               ; preds = %1
  %23 = load i64, ptr %3, align 8, !tbaa !5
  %24 = call i32 @strm_string_p(i64 noundef %23)
  %25 = icmp ne i32 %24, 0
  br i1 %25, label %26, label %28

26:                                               ; preds = %22
  %27 = load ptr, ptr @strm_ns_string, align 8, !tbaa !13
  store ptr %27, ptr %2, align 8
  br label %57

28:                                               ; preds = %22
  %29 = load i64, ptr %3, align 8, !tbaa !5
  %30 = call i32 @strm_number_p(i64 noundef %29)
  %31 = icmp ne i32 %30, 0
  br i1 %31, label %32, label %34

32:                                               ; preds = %28
  %33 = load ptr, ptr @strm_ns_number, align 8, !tbaa !13
  store ptr %33, ptr %2, align 8
  br label %57

34:                                               ; preds = %28
  %35 = load i64, ptr %3, align 8, !tbaa !5
  %36 = and i64 %35, -281474976710656
  %37 = icmp eq i64 %36, -844424930131968
  br i1 %37, label %38, label %56

38:                                               ; preds = %34
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %39 = load i64, ptr %3, align 8, !tbaa !5
  %40 = call ptr @strm_ptr(i64 noundef %39)
  store ptr %40, ptr %6, align 8, !tbaa !13
  %41 = load ptr, ptr %6, align 8, !tbaa !13
  %42 = icmp ne ptr %41, null
  br i1 %42, label %44, label %43

43:                                               ; preds = %38
  store ptr null, ptr %2, align 8
  store i32 1, ptr %5, align 4
  br label %53

44:                                               ; preds = %38
  %45 = load ptr, ptr %6, align 8, !tbaa !13
  %46 = call i32 @strm_ptr_type(ptr noundef %45)
  %47 = icmp eq i32 %46, 4
  br i1 %47, label %48, label %52

48:                                               ; preds = %44
  %49 = load ptr, ptr %6, align 8, !tbaa !13
  %50 = getelementptr inbounds %struct.strm_misc, ptr %49, i32 0, i32 1
  %51 = load ptr, ptr %50, align 8, !tbaa !14
  store ptr %51, ptr %2, align 8
  store i32 1, ptr %5, align 4
  br label %53

52:                                               ; preds = %44
  store i32 0, ptr %5, align 4
  br label %53

53:                                               ; preds = %52, %48, %43
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  %54 = load i32, ptr %5, align 4
  switch i32 %54, label %59 [
    i32 0, label %55
    i32 1, label %57
  ]

55:                                               ; preds = %53
  br label %56

56:                                               ; preds = %55, %34
  store ptr null, ptr %2, align 8
  br label %57

57:                                               ; preds = %56, %53, %32, %26, %21
  %58 = load ptr, ptr %2, align 8
  ret ptr %58

59:                                               ; preds = %53
  unreachable
}

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

!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, !12, i64 24}
!10 = !{!"strm_array", !11, i64 0, !12, i64 8, !6, i64 16, !12, i64 24}
!11 = !{!"int", !7, i64 0}
!12 = !{!"any pointer", !7, i64 0}
!13 = !{!12, !12, i64 0}
!14 = !{!15, !12, i64 8}
!15 = !{!"strm_misc", !11, i64 0, !12, 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"

@strm_ns_array = external local_unnamed_addr global ptr, align 8
@strm_ns_string = external local_unnamed_addr global ptr, align 8
@strm_ns_number = external local_unnamed_addr global ptr, align 8

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

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

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

declare i32 @strm_string_p(i64 noundef) local_unnamed_addr #1

declare i32 @strm_array_p(i64 noundef) local_unnamed_addr #1

declare ptr @strm_ary_struct(i64 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local ptr @strm_value_ns(i64 noundef %0) local_unnamed_addr #0 {
  %2 = tail call i32 @strm_array_p(i64 noundef %0) #2
  %.not = icmp eq i32 %2, 0
  br i1 %.not, label %8, label %3

3:                                                ; preds = %1
  %4 = tail call ptr @strm_ary_struct(i64 noundef %0) #2
  %5 = getelementptr inbounds i8, ptr %4, i64 24
  %6 = load ptr, ptr %5, align 8, !tbaa !5
  %.not18 = icmp eq ptr %6, null
  %7 = load ptr, ptr @strm_ns_array, align 8
  %.0 = select i1 %.not18, ptr %7, ptr %6
  br label %.thread

8:                                                ; preds = %1
  %9 = tail call i32 @strm_string_p(i64 noundef %0) #2
  %.not15 = icmp eq i32 %9, 0
  br i1 %.not15, label %12, label %10

10:                                               ; preds = %8
  %11 = load ptr, ptr @strm_ns_string, align 8, !tbaa !12
  br label %.thread

12:                                               ; preds = %8
  %13 = tail call i32 @strm_number_p(i64 noundef %0)
  %.not16 = icmp eq i32 %13, 0
  br i1 %.not16, label %16, label %14

14:                                               ; preds = %12
  %15 = load ptr, ptr @strm_ns_number, align 8, !tbaa !12
  br label %.thread

16:                                               ; preds = %12
  %17 = and i64 %0, -281474976710656
  %18 = icmp eq i64 %17, -844424930131968
  br i1 %18, label %19, label %.thread

19:                                               ; preds = %16
  %20 = tail call ptr @strm_ptr(i64 noundef %0)
  %.not17 = icmp eq ptr %20, null
  br i1 %.not17, label %.thread, label %21

21:                                               ; preds = %19
  %22 = tail call i32 @strm_ptr_type(ptr noundef nonnull %20)
  %23 = icmp eq i32 %22, 4
  br i1 %23, label %24, label %.thread

24:                                               ; preds = %21
  %25 = getelementptr inbounds i8, ptr %20, i64 8
  %26 = load ptr, ptr %25, align 8, !tbaa !13
  br label %.thread

.thread:                                          ; preds = %19, %24, %16, %21, %14, %10, %3
  %.2 = phi ptr [ %.0, %3 ], [ %11, %10 ], [ %15, %14 ], [ null, %21 ], [ null, %16 ], [ null, %19 ], [ %26, %24 ]
  ret ptr %.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 = { "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 }

!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 24}
!6 = !{!"strm_array", !7, i64 0, !10, i64 8, !11, i64 16, !10, i64 24}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!"long", !8, i64 0}
!12 = !{!10, !10, i64 0}
!13 = !{!14, !10, i64 8}
!14 = !{!"strm_misc", !7, i64 0, !10, i64 8}


; Effective O3 passes: GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,SROAPass,SimplifyCFGPass,TailCallElimPass