; LLVM IR from tezc/sc :: logger (sc_log)

; 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.sc_log = type { ptr, [256 x i8], [256 x i8], i64, %struct.sc_log_mutex, i32, i8, i8, ptr, ptr }
%struct.sc_log_mutex = type { %union.pthread_mutex_t }
%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 }

@sc_log = external dso_local global %struct.sc_log, align 8

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

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

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

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

; 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
define dso_local i32 @sc_log_init() #0 {
  %1 = alloca i32, align 4
  %2 = alloca %struct.sc_log, align 8
  %3 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #5
  call void @llvm.memset.p0.i64(ptr align 8 %2, i8 0, i64 592, i1 false)
  %4 = getelementptr inbounds %struct.sc_log, ptr %2, i32 0, i32 0
  %5 = getelementptr inbounds %struct.sc_log, ptr %2, i32 0, i32 1
  %6 = getelementptr inbounds %struct.sc_log, ptr %2, i32 0, i32 2
  %7 = getelementptr inbounds %struct.sc_log, ptr %2, i32 0, i32 3
  %8 = getelementptr inbounds %struct.sc_log, ptr %2, i32 0, i32 4
  %9 = getelementptr inbounds %struct.sc_log, ptr %2, i32 0, i32 5
  %10 = getelementptr inbounds %struct.sc_log, ptr %2, i32 0, i32 6
  %11 = getelementptr inbounds %struct.sc_log, ptr %2, i32 0, i32 7
  %12 = getelementptr inbounds %struct.sc_log, ptr %2, i32 0, i32 8
  %13 = getelementptr inbounds %struct.sc_log, ptr %2, i32 0, i32 9
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 @sc_log, ptr align 8 %2, i64 592, i1 false), !tbaa.struct !5
  store i32 1, ptr %3, align 4, !tbaa !15
  %14 = load i32, ptr %3, align 4
  store atomic i32 %14, ptr getelementptr inbounds (%struct.sc_log, ptr @sc_log, i32 0, i32 5) monotonic, align 8
  store i8 1, ptr getelementptr inbounds (%struct.sc_log, ptr @sc_log, i32 0, i32 7), align 1, !tbaa !17
  %15 = call i32 @sc_log_mutex_init(ptr noundef getelementptr inbounds (%struct.sc_log, ptr @sc_log, i32 0, i32 4))
  store i32 %15, ptr %1, align 4, !tbaa !15
  %16 = load i32, ptr %1, align 4, !tbaa !15
  %17 = icmp ne i32 %16, 0
  br i1 %17, label %18, label %21

18:                                               ; preds = %0
  %19 = load i32, ptr %1, align 4, !tbaa !15
  %20 = call ptr @__errno_location() #6
  store i32 %19, ptr %20, align 4, !tbaa !15
  br label %21

21:                                               ; preds = %18, %0
  store i8 1, ptr getelementptr inbounds (%struct.sc_log, ptr @sc_log, i32 0, i32 6), align 4, !tbaa !20
  %22 = load i32, ptr %1, align 4, !tbaa !15
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #5
  ret i32 %22
}

; Function Attrs: nounwind willreturn memory(none)
declare ptr @__errno_location() #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #3 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { nounwind willreturn memory(none) "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 willreturn memory(none) }

!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 = !{i64 0, i64 8, !6, i64 8, i64 256, !10, i64 264, i64 256, !10, i64 520, i64 8, !11, i64 528, i64 40, !10, i64 568, i64 4, !10, i64 572, i64 1, !13, i64 573, i64 1, !13, i64 576, i64 8, !6, i64 584, i64 8, !6}
!6 = !{!7, !7, i64 0}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!8, !8, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long", !8, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"_Bool", !8, i64 0}
!15 = !{!16, !16, i64 0}
!16 = !{!"int", !8, i64 0}
!17 = !{!18, !14, i64 573}
!18 = !{!"sc_log", !7, i64 0, !8, i64 8, !8, i64 264, !12, i64 520, !19, i64 528, !8, i64 568, !14, i64 572, !14, i64 573, !7, i64 576, !7, i64 584}
!19 = !{!"sc_log_mutex", !8, i64 0}
!20 = !{!18, !14, i64 572}


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

%struct.sc_log = type { ptr, [256 x i8], [256 x i8], i64, %struct.sc_log_mutex, i32, i8, i8, ptr, ptr }
%struct.sc_log_mutex = type { %union.pthread_mutex_t }
%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 }

@sc_log = external dso_local global %struct.sc_log, align 8

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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @sc_log_init() local_unnamed_addr #0 {
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(592) @sc_log, i8 0, i64 592, i1 false)
  store atomic i32 1, ptr getelementptr inbounds (i8, ptr @sc_log, i64 568) monotonic, align 8
  store i8 1, ptr getelementptr inbounds (i8, ptr @sc_log, i64 573), align 1, !tbaa !5
  %1 = tail call i32 @sc_log_mutex_init(ptr noundef nonnull getelementptr inbounds (i8, ptr @sc_log, i64 528))
  %.not = icmp eq i32 %1, 0
  br i1 %.not, label %4, label %2

2:                                                ; preds = %0
  %3 = tail call ptr @__errno_location() #3
  store i32 %1, ptr %3, align 4, !tbaa !13
  br label %4

4:                                                ; preds = %2, %0
  store i8 1, ptr getelementptr inbounds (i8, ptr @sc_log, i64 572), align 4, !tbaa !15
  ret i32 %1
}

; Function Attrs: mustprogress nofree nosync nounwind willreturn memory(none)
declare ptr @__errno_location() local_unnamed_addr #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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #2 = { mustprogress nofree nosync nounwind willreturn memory(none) "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 willreturn memory(none) }

!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, !12, i64 573}
!6 = !{!"sc_log", !7, i64 0, !8, i64 8, !8, i64 264, !10, i64 520, !11, i64 528, !8, i64 568, !12, i64 572, !12, i64 573, !7, i64 576, !7, i64 584}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"long", !8, i64 0}
!11 = !{!"sc_log_mutex", !8, i64 0}
!12 = !{!"_Bool", !8, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"int", !8, i64 0}
!15 = !{!6, !12, i64 572}


; Effective O3 passes: CorrelatedValuePropagationPass,DSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,MemCpyOptPass,SROAPass,TailCallElimPass