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

%union.pthread_mutex_t = type { %struct.__pthread_mutex_s }
%struct.__pthread_mutex_s = type { i32, i32, i32, i32, i32, i16, i16, %struct.__pthread_internal_list }
%struct.__pthread_internal_list = type { ptr, ptr }

@strm_event_loop_started = external global i32, align 4
@sym_mutex = external hidden global %union.pthread_mutex_t, align 8

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

; Function Attrs: nounwind
declare i32 @pthread_mutex_lock(ptr noundef) #1

; Function Attrs: nounwind
declare i32 @pthread_mutex_unlock(ptr noundef) #1

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

7:                                                ; preds = %1
  %8 = load i64, ptr %3, align 8, !tbaa !5
  store i64 %8, ptr %2, align 8
  br label %25

9:                                                ; preds = %1
  %10 = load i32, ptr @strm_event_loop_started, align 4, !tbaa !9
  %11 = icmp ne i32 %10, 0
  br i1 %11, label %17, label %12

12:                                               ; preds = %9
  %13 = call ptr @strm_strp_ptr(ptr noundef %3)
  %14 = load i64, ptr %3, align 8, !tbaa !5
  %15 = call i32 @strm_str_len(i64 noundef %14)
  %16 = call i64 @str_intern(ptr noundef %13, i32 noundef %15, i32 noundef 0)
  store i64 %16, ptr %2, align 8
  br label %25

17:                                               ; preds = %9
  %18 = call i32 @pthread_mutex_lock(ptr noundef @sym_mutex) #2
  %19 = call ptr @strm_strp_ptr(ptr noundef %3)
  %20 = load i64, ptr %3, align 8, !tbaa !5
  %21 = call i32 @strm_str_len(i64 noundef %20)
  %22 = call i64 @str_intern(ptr noundef %19, i32 noundef %21, i32 noundef 0)
  store i64 %22, ptr %3, align 8, !tbaa !5
  %23 = call i32 @pthread_mutex_unlock(ptr noundef @sym_mutex) #2
  %24 = load i64, ptr %3, align 8, !tbaa !5
  store i64 %24, ptr %2, align 8
  br label %25

25:                                               ; preds = %17, %12, %7
  %26 = load i64, ptr %2, align 8
  ret i64 %26
}

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

; Function Attrs: nounwind uwtable
declare dso_local ptr @strm_strp_ptr(ptr noundef) #0

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

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 = { 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 #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, !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 = !{!"int", !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"

%union.pthread_mutex_t = type { %struct.__pthread_mutex_s }
%struct.__pthread_mutex_s = type { i32, i32, i32, i32, i32, i16, i16, %struct.__pthread_internal_list }
%struct.__pthread_internal_list = type { ptr, ptr }

@strm_event_loop_started = external local_unnamed_addr global i32, align 4
@sym_mutex = external hidden global %union.pthread_mutex_t, align 8

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

; Function Attrs: nounwind
declare i32 @pthread_mutex_lock(ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind
declare i32 @pthread_mutex_unlock(ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local i64 @strm_str_intern_str(i64 noundef %0) local_unnamed_addr #0 {
  %2 = alloca i64, align 8
  store i64 %0, ptr %2, align 8, !tbaa !5
  %3 = tail call i32 @strm_str_intern_p(i64 noundef %0)
  %.not = icmp eq i32 %3, 0
  br i1 %.not, label %4, label %19

4:                                                ; preds = %1
  %5 = load i32, ptr @strm_event_loop_started, align 4, !tbaa !9
  %.not1 = icmp eq i32 %5, 0
  br i1 %.not1, label %6, label %11

6:                                                ; preds = %4
  %7 = call ptr @strm_strp_ptr(ptr noundef nonnull %2)
  %8 = load i64, ptr %2, align 8, !tbaa !5
  %9 = call i32 @strm_str_len(i64 noundef %8)
  %10 = call i64 @str_intern(ptr noundef %7, i32 noundef %9, i32 noundef 0)
  br label %19

11:                                               ; preds = %4
  %12 = tail call i32 @pthread_mutex_lock(ptr noundef nonnull @sym_mutex) #2
  %13 = call ptr @strm_strp_ptr(ptr noundef nonnull %2)
  %14 = load i64, ptr %2, align 8, !tbaa !5
  %15 = call i32 @strm_str_len(i64 noundef %14)
  %16 = call i64 @str_intern(ptr noundef %13, i32 noundef %15, i32 noundef 0)
  store i64 %16, ptr %2, align 8, !tbaa !5
  %17 = call i32 @pthread_mutex_unlock(ptr noundef nonnull @sym_mutex) #2
  %18 = load i64, ptr %2, align 8, !tbaa !5
  br label %19

19:                                               ; preds = %1, %11, %6
  %.0 = phi i64 [ %18, %11 ], [ %10, %6 ], [ %0, %1 ]
  ret i64 %.0
}

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

; Function Attrs: nounwind uwtable
declare dso_local ptr @strm_strp_ptr(ptr noundef) local_unnamed_addr #0

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

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 = { 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 #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, !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 = !{!"int", !7, i64 0}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InstCombinePass,JumpThreadingPass,SROAPass,TailCallElimPass