; LLVM IR from aagdev/mlimgsynth :: src/ccommon (logging)

; 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.Logger = type { i32, ptr, ptr }
%struct.Stream = type { ptr, ptr, ptr, ptr, ptr, %struct.StreamInt, i64, i32 }
%struct.StreamInt = type { [3 x ptr] }

@g_logger = external dso_local global %struct.Logger, align 8
@g_logger_stream = external dso_local global %struct.Stream, align 8
@.str = external hidden unnamed_addr constant [7 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [7 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local void @log_line_begin_raw(i32 noundef %0) #0 {
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  store i32 %0, ptr %2, align 4, !tbaa !5
  %4 = load ptr, ptr getelementptr inbounds (%struct.Logger, ptr @g_logger, i32 0, i32 1), align 8, !tbaa !9
  %5 = icmp ne ptr %4, null
  br i1 %5, label %8, label %6

6:                                                ; preds = %1
  %7 = call i32 @stream_open_std(ptr noundef @g_logger_stream, i32 noundef 2, i32 noundef 0)
  store ptr @g_logger_stream, ptr getelementptr inbounds (%struct.Logger, ptr @g_logger, i32 0, i32 1), align 8, !tbaa !9
  br label %8

8:                                                ; preds = %6, %1
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #4
  store ptr null, ptr %3, align 8, !tbaa !12
  %9 = load i32, ptr %2, align 4, !tbaa !5
  %10 = icmp sge i32 %9, 50
  br i1 %10, label %11, label %12

11:                                               ; preds = %8
  store ptr @.str, ptr %3, align 8, !tbaa !12
  br label %23

12:                                               ; preds = %8
  %13 = load i32, ptr %2, align 4, !tbaa !5
  %14 = icmp sge i32 %13, 30
  br i1 %14, label %15, label %16

15:                                               ; preds = %12
  br label %22

16:                                               ; preds = %12
  %17 = load i32, ptr %2, align 4, !tbaa !5
  %18 = icmp sge i32 %17, 20
  br i1 %18, label %19, label %20

19:                                               ; preds = %16
  store ptr @.str.1, ptr %3, align 8, !tbaa !12
  br label %21

20:                                               ; preds = %16
  store ptr @.str.2, ptr %3, align 8, !tbaa !12
  br label %21

21:                                               ; preds = %20, %19
  br label %22

22:                                               ; preds = %21, %15
  br label %23

23:                                               ; preds = %22, %11
  %24 = load ptr, ptr getelementptr inbounds (%struct.Logger, ptr @g_logger, i32 0, i32 2), align 8, !tbaa !13
  %25 = icmp ne ptr %24, null
  br i1 %25, label %26, label %30

26:                                               ; preds = %23
  %27 = load ptr, ptr getelementptr inbounds (%struct.Logger, ptr @g_logger, i32 0, i32 1), align 8, !tbaa !9
  %28 = load ptr, ptr getelementptr inbounds (%struct.Logger, ptr @g_logger, i32 0, i32 2), align 8, !tbaa !13
  %29 = call i32 @stream_str_put(ptr noundef %27, ptr noundef %28)
  br label %30

30:                                               ; preds = %26, %23
  %31 = load ptr, ptr %3, align 8, !tbaa !12
  %32 = icmp ne ptr %31, null
  br i1 %32, label %33, label %37

33:                                               ; preds = %30
  %34 = load ptr, ptr getelementptr inbounds (%struct.Logger, ptr @g_logger, i32 0, i32 1), align 8, !tbaa !9
  %35 = load ptr, ptr %3, align 8, !tbaa !12
  %36 = call i32 @stream_str_put(ptr noundef %34, ptr noundef %35)
  br label %37

37:                                               ; preds = %33, %30
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #4
  ret void
}

declare i32 @stream_open_std(ptr noundef, i32 noundef, i32 noundef) #1

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @stream_str_put(ptr noalias noundef, ptr noalias noundef) #3

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { inlinehint 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 #4 = { 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, !11, i64 8}
!10 = !{!"Logger", !6, i64 0, !11, i64 8, !11, i64 16}
!11 = !{!"any pointer", !7, i64 0}
!12 = !{!11, !11, i64 0}
!13 = !{!10, !11, i64 16}


; 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.Logger = type { i32, ptr, ptr }
%struct.Stream = type { ptr, ptr, ptr, ptr, ptr, %struct.StreamInt, i64, i32 }
%struct.StreamInt = type { [3 x ptr] }

@g_logger = external dso_local local_unnamed_addr global %struct.Logger, align 8
@g_logger_stream = external dso_local global %struct.Stream, align 8
@.str = external hidden unnamed_addr constant [7 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [7 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local void @log_line_begin_raw(i32 noundef %0) local_unnamed_addr #0 {
  %2 = load ptr, ptr getelementptr inbounds (i8, ptr @g_logger, i64 8), align 8, !tbaa !5
  %.not = icmp eq ptr %2, null
  br i1 %.not, label %3, label %5

3:                                                ; preds = %1
  %4 = tail call i32 @stream_open_std(ptr noundef nonnull @g_logger_stream, i32 noundef 2, i32 noundef 0) #3
  store ptr @g_logger_stream, ptr getelementptr inbounds (i8, ptr @g_logger, i64 8), align 8, !tbaa !5
  br label %5

5:                                                ; preds = %3, %1
  %6 = phi ptr [ @g_logger_stream, %3 ], [ %2, %1 ]
  %7 = icmp sgt i32 %0, 49
  br i1 %7, label %12, label %8

8:                                                ; preds = %5
  %9 = icmp sgt i32 %0, 29
  br i1 %9, label %12, label %10

10:                                               ; preds = %8
  %11 = icmp sgt i32 %0, 19
  %.str.1..str.2 = select i1 %11, ptr @.str.1, ptr @.str.2
  br label %12

12:                                               ; preds = %10, %5, %8
  %.not7 = phi i1 [ true, %8 ], [ false, %5 ], [ false, %10 ]
  %.0 = phi ptr [ null, %8 ], [ @.str, %5 ], [ %.str.1..str.2, %10 ]
  %13 = load ptr, ptr getelementptr inbounds (i8, ptr @g_logger, i64 16), align 8, !tbaa !11
  %.not6 = icmp eq ptr %13, null
  br i1 %.not6, label %16, label %14

14:                                               ; preds = %12
  %15 = tail call i32 @stream_str_put(ptr noundef nonnull %6, ptr noundef nonnull %13)
  br label %16

16:                                               ; preds = %14, %12
  br i1 %.not7, label %20, label %17

17:                                               ; preds = %16
  %18 = load ptr, ptr getelementptr inbounds (i8, ptr @g_logger, i64 8), align 8, !tbaa !5
  %19 = tail call i32 @stream_str_put(ptr noundef %18, ptr noundef %.0)
  br label %20

20:                                               ; preds = %17, %16
  ret void
}

declare i32 @stream_open_std(ptr noundef, i32 noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @stream_str_put(ptr noalias noundef, ptr noalias noundef) 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 = { "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 = { inlinehint 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 #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, !10, i64 8}
!6 = !{!"Logger", !7, i64 0, !10, i64 8, !10, i64 16}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!6, !10, i64 16}


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