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

@sc_log = external dso_local global %struct.sc_log, 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 dso_local void @sc_log_mutex_lock(ptr noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local void @sc_log_mutex_unlock(ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local i32 @sc_log_log(i32 noundef %0, ptr noundef %1, ...) #1 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca [1 x %struct.__va_list_tag], align 16
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  store i32 %0, ptr %4, align 4, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  store i32 0, ptr %6, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 24, ptr %7) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  %11 = load atomic i32, ptr getelementptr inbounds (%struct.sc_log, ptr @sc_log, i32 0, i32 5) monotonic, align 8
  store i32 %11, ptr %9, align 4
  %12 = load i32, ptr %9, align 4, !tbaa !5
  store i32 %12, ptr %8, align 4, !tbaa !5
  %13 = load i32, ptr %4, align 4, !tbaa !5
  %14 = load i32, ptr %8, align 4, !tbaa !5
  %15 = icmp ult i32 %13, %14
  br i1 %15, label %16, label %17

16:                                               ; preds = %2
  store i32 0, ptr %3, align 4
  store i32 1, ptr %10, align 4
  br label %57

17:                                               ; preds = %2
  call void @sc_log_mutex_lock(ptr noundef getelementptr inbounds (%struct.sc_log, ptr @sc_log, i32 0, i32 4))
  %18 = load i8, ptr getelementptr inbounds (%struct.sc_log, ptr @sc_log, i32 0, i32 7), align 1, !tbaa !11, !range !16, !noundef !17
  %19 = trunc i8 %18 to i1
  br i1 %19, label %20, label %29

20:                                               ; preds = %17
  %21 = getelementptr inbounds [1 x %struct.__va_list_tag], ptr %7, i64 0, i64 0
  call void @llvm.va_start.p0(ptr %21)
  %22 = load i32, ptr %4, align 4, !tbaa !5
  %23 = load ptr, ptr %5, align 8, !tbaa !9
  %24 = getelementptr inbounds [1 x %struct.__va_list_tag], ptr %7, i64 0, i64 0
  %25 = call i32 @sc_log_stdout(i32 noundef %22, ptr noundef %23, ptr noundef %24)
  %26 = load i32, ptr %6, align 4, !tbaa !5
  %27 = or i32 %26, %25
  store i32 %27, ptr %6, align 4, !tbaa !5
  %28 = getelementptr inbounds [1 x %struct.__va_list_tag], ptr %7, i64 0, i64 0
  call void @llvm.va_end.p0(ptr %28)
  br label %29

29:                                               ; preds = %20, %17
  %30 = load ptr, ptr @sc_log, align 8, !tbaa !18
  %31 = icmp ne ptr %30, null
  br i1 %31, label %32, label %41

32:                                               ; preds = %29
  %33 = getelementptr inbounds [1 x %struct.__va_list_tag], ptr %7, i64 0, i64 0
  call void @llvm.va_start.p0(ptr %33)
  %34 = load i32, ptr %4, align 4, !tbaa !5
  %35 = load ptr, ptr %5, align 8, !tbaa !9
  %36 = getelementptr inbounds [1 x %struct.__va_list_tag], ptr %7, i64 0, i64 0
  %37 = call i32 @sc_log_file(i32 noundef %34, ptr noundef %35, ptr noundef %36)
  %38 = load i32, ptr %6, align 4, !tbaa !5
  %39 = or i32 %38, %37
  store i32 %39, ptr %6, align 4, !tbaa !5
  %40 = getelementptr inbounds [1 x %struct.__va_list_tag], ptr %7, i64 0, i64 0
  call void @llvm.va_end.p0(ptr %40)
  br label %41

41:                                               ; preds = %32, %29
  %42 = load ptr, ptr getelementptr inbounds (%struct.sc_log, ptr @sc_log, i32 0, i32 9), align 8, !tbaa !19
  %43 = icmp ne ptr %42, null
  br i1 %43, label %44, label %55

44:                                               ; preds = %41
  %45 = getelementptr inbounds [1 x %struct.__va_list_tag], ptr %7, i64 0, i64 0
  call void @llvm.va_start.p0(ptr %45)
  %46 = load ptr, ptr getelementptr inbounds (%struct.sc_log, ptr @sc_log, i32 0, i32 9), align 8, !tbaa !19
  %47 = load ptr, ptr getelementptr inbounds (%struct.sc_log, ptr @sc_log, i32 0, i32 8), align 8, !tbaa !20
  %48 = load i32, ptr %4, align 4, !tbaa !5
  %49 = load ptr, ptr %5, align 8, !tbaa !9
  %50 = getelementptr inbounds [1 x %struct.__va_list_tag], ptr %7, i64 0, i64 0
  %51 = call i32 %46(ptr noundef %47, i32 noundef %48, ptr noundef %49, ptr noundef %50)
  %52 = load i32, ptr %6, align 4, !tbaa !5
  %53 = or i32 %52, %51
  store i32 %53, ptr %6, align 4, !tbaa !5
  %54 = getelementptr inbounds [1 x %struct.__va_list_tag], ptr %7, i64 0, i64 0
  call void @llvm.va_end.p0(ptr %54)
  br label %55

55:                                               ; preds = %44, %41
  call void @sc_log_mutex_unlock(ptr noundef getelementptr inbounds (%struct.sc_log, ptr @sc_log, i32 0, i32 4))
  %56 = load i32, ptr %6, align 4, !tbaa !5
  store i32 %56, ptr %3, align 4
  store i32 1, ptr %10, align 4
  br label %57

57:                                               ; preds = %55, %16
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 24, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  %58 = load i32, ptr %3, align 4
  ret i32 %58
}

; Function Attrs: nocallback nofree nosync nounwind willreturn
declare void @llvm.va_start.p0(ptr) #2

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

; Function Attrs: nocallback nofree nosync nounwind willreturn
declare void @llvm.va_end.p0(ptr) #2

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

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 nosync nounwind willreturn }
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 = !{!"int", !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 = !{!12, !15, i64 573}
!12 = !{!"sc_log", !10, i64 0, !7, i64 8, !7, i64 264, !13, i64 520, !14, i64 528, !7, i64 568, !15, i64 572, !15, i64 573, !10, i64 576, !10, i64 584}
!13 = !{!"long", !7, i64 0}
!14 = !{!"sc_log_mutex", !7, i64 0}
!15 = !{!"_Bool", !7, i64 0}
!16 = !{i8 0, i8 2}
!17 = !{}
!18 = !{!12, !10, i64 0}
!19 = !{!12, !10, i64 584}
!20 = !{!12, !10, i64 576}


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

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

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

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

; Function Attrs: nounwind uwtable
declare dso_local void @sc_log_mutex_lock(ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local void @sc_log_mutex_unlock(ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local i32 @sc_log_log(i32 noundef %0, ptr noundef %1, ...) local_unnamed_addr #1 {
  %3 = alloca [1 x %struct.__va_list_tag], align 16
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %3) #3
  %4 = load atomic i32, ptr getelementptr inbounds (i8, ptr @sc_log, i64 568) monotonic, align 8
  %5 = icmp ugt i32 %4, %0
  br i1 %5, label %24, label %6

6:                                                ; preds = %2
  tail call void @sc_log_mutex_lock(ptr noundef nonnull getelementptr inbounds (i8, ptr @sc_log, i64 528))
  %7 = load i8, ptr getelementptr inbounds (i8, ptr @sc_log, i64 573), align 1, !tbaa !5, !range !13, !noundef !14
  %8 = trunc nuw i8 %7 to i1
  br i1 %8, label %9, label %11

9:                                                ; preds = %6
  call void @llvm.va_start.p0(ptr nonnull %3)
  %10 = call i32 @sc_log_stdout(i32 noundef %0, ptr noundef %1, ptr noundef nonnull %3)
  call void @llvm.va_end.p0(ptr nonnull %3)
  br label %11

11:                                               ; preds = %9, %6
  %.013 = phi i32 [ %10, %9 ], [ 0, %6 ]
  %12 = load ptr, ptr @sc_log, align 8, !tbaa !15
  %.not = icmp eq ptr %12, null
  br i1 %.not, label %16, label %13

13:                                               ; preds = %11
  call void @llvm.va_start.p0(ptr nonnull %3)
  %14 = call i32 @sc_log_file(i32 noundef %0, ptr noundef %1, ptr noundef nonnull %3)
  %15 = or i32 %14, %.013
  call void @llvm.va_end.p0(ptr nonnull %3)
  br label %16

16:                                               ; preds = %13, %11
  %.1 = phi i32 [ %15, %13 ], [ %.013, %11 ]
  %17 = load ptr, ptr getelementptr inbounds (i8, ptr @sc_log, i64 584), align 8, !tbaa !16
  %.not15 = icmp eq ptr %17, null
  br i1 %.not15, label %23, label %18

18:                                               ; preds = %16
  call void @llvm.va_start.p0(ptr nonnull %3)
  %19 = load ptr, ptr getelementptr inbounds (i8, ptr @sc_log, i64 584), align 8, !tbaa !16
  %20 = load ptr, ptr getelementptr inbounds (i8, ptr @sc_log, i64 576), align 8, !tbaa !17
  %21 = call i32 %19(ptr noundef %20, i32 noundef %0, ptr noundef %1, ptr noundef nonnull %3) #3
  %22 = or i32 %21, %.1
  call void @llvm.va_end.p0(ptr nonnull %3)
  br label %23

23:                                               ; preds = %18, %16
  %.2 = phi i32 [ %22, %18 ], [ %.1, %16 ]
  call void @sc_log_mutex_unlock(ptr noundef nonnull getelementptr inbounds (i8, ptr @sc_log, i64 528))
  br label %24

24:                                               ; preds = %2, %23
  %.0 = phi i32 [ %.2, %23 ], [ 0, %2 ]
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %3) #3
  ret i32 %.0
}

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn
declare void @llvm.va_start.p0(ptr) #2

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

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn
declare void @llvm.va_end.p0(ptr) #2

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

attributes #0 = { mustprogress 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 = { mustprogress nocallback nofree nosync nounwind willreturn }
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, !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 = !{i8 0, i8 2}
!14 = !{}
!15 = !{!6, !7, i64 0}
!16 = !{!6, !7, i64 584}
!17 = !{!6, !7, i64 576}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass