; LLVM IR from goldsborough/ipc-bench :: source/fifo (server)

; 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.Benchmarks = type { i64, i64, i64, i64, i64, i64 }
%struct.Arguments = type { i32, i32 }

@.str.2 = external hidden unnamed_addr constant [21 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local void @cleanup(ptr noundef, ptr noundef) #0

; Function Attrs: noreturn
declare void @throw(ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local void @communicate(ptr noundef %0, ptr noundef %1, ptr noundef %2) #0 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca %struct.Benchmarks, align 8
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store ptr %2, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 48, ptr %7) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #5
  %10 = load ptr, ptr %5, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.Arguments, ptr %10, i32 0, i32 0
  %12 = load i32, ptr %11, align 4, !tbaa !9
  %13 = sext i32 %12 to i64
  %14 = call noalias ptr @malloc(i64 noundef %13) #6
  store ptr %14, ptr %9, align 8, !tbaa !5
  call void @setup_benchmarks(ptr noundef %7)
  %15 = load ptr, ptr %6, align 8, !tbaa !5
  call void @wait_for_signal(ptr noundef %15)
  store i32 0, ptr %8, align 4, !tbaa !12
  br label %16

16:                                               ; preds = %38, %3
  %17 = load i32, ptr %8, align 4, !tbaa !12
  %18 = load ptr, ptr %5, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.Arguments, ptr %18, i32 0, i32 1
  %20 = load i32, ptr %19, align 4, !tbaa !13
  %21 = icmp slt i32 %17, %20
  br i1 %21, label %22, label %41

22:                                               ; preds = %16
  %23 = call i64 (...) @now()
  %24 = getelementptr inbounds %struct.Benchmarks, ptr %7, i32 0, i32 1
  store i64 %23, ptr %24, align 8, !tbaa !14
  %25 = load ptr, ptr %9, align 8, !tbaa !5
  %26 = load ptr, ptr %5, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.Arguments, ptr %26, i32 0, i32 0
  %28 = load i32, ptr %27, align 4, !tbaa !9
  %29 = sext i32 %28 to i64
  %30 = load ptr, ptr %4, align 8, !tbaa !5
  %31 = call i64 @fwrite(ptr noundef %25, i64 noundef %29, i64 noundef 1, ptr noundef %30)
  %32 = icmp eq i64 %31, 0
  br i1 %32, label %33, label %34

33:                                               ; preds = %22
  call void @throw(ptr noundef @.str.2) #7
  unreachable

34:                                               ; preds = %22
  %35 = load ptr, ptr %4, align 8, !tbaa !5
  %36 = call i32 @fflush(ptr noundef %35)
  call void (...) @notify_client()
  %37 = load ptr, ptr %6, align 8, !tbaa !5
  call void @wait_for_signal(ptr noundef %37)
  call void @benchmark(ptr noundef %7)
  br label %38

38:                                               ; preds = %34
  %39 = load i32, ptr %8, align 4, !tbaa !12
  %40 = add nsw i32 %39, 1
  store i32 %40, ptr %8, align 4, !tbaa !12
  br label %16, !llvm.loop !17

41:                                               ; preds = %16
  %42 = load ptr, ptr %5, align 8, !tbaa !5
  call void @evaluate(ptr noundef %7, ptr noundef %42)
  %43 = load ptr, ptr %4, align 8, !tbaa !5
  %44 = load ptr, ptr %9, align 8, !tbaa !5
  call void @cleanup(ptr noundef %43, ptr noundef %44)
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #5
  call void @llvm.lifetime.end.p0(i64 48, ptr %7) #5
  ret void
}

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

; Function Attrs: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #3

declare void @setup_benchmarks(ptr noundef) #4

declare void @wait_for_signal(ptr noundef) #4

declare i64 @now(...) #4

declare i64 @fwrite(ptr noundef, i64 noundef, i64 noundef, ptr noundef) #4

declare i32 @fflush(ptr noundef) #4

declare void @notify_client(...) #4

declare void @benchmark(ptr noundef) #4

declare void @evaluate(ptr noundef, ptr noundef) #4

; 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 = { noreturn "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 = { nounwind allocsize(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 = { "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 allocsize(0) }
attributes #7 = { noreturn }

!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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !11, i64 0}
!10 = !{!"Arguments", !11, i64 0, !11, i64 4}
!11 = !{!"int", !7, i64 0}
!12 = !{!11, !11, i64 0}
!13 = !{!10, !11, i64 4}
!14 = !{!15, !16, i64 8}
!15 = !{!"Benchmarks", !16, i64 0, !16, i64 8, !16, i64 16, !16, i64 24, !16, i64 32, !16, i64 40}
!16 = !{!"long long", !7, i64 0}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}


; 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.Benchmarks = type { i64, i64, i64, i64, i64, i64 }

@.str.2 = external hidden unnamed_addr constant [21 x i8], align 1

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

; Function Attrs: noreturn
declare void @throw(ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local void @communicate(ptr noundef %0, ptr noundef %1, ptr noundef %2) local_unnamed_addr #0 {
  %4 = alloca %struct.Benchmarks, align 8
  call void @llvm.lifetime.start.p0(i64 48, ptr nonnull %4) #6
  %5 = load i32, ptr %1, align 4, !tbaa !5
  %6 = sext i32 %5 to i64
  %7 = tail call noalias ptr @malloc(i64 noundef %6) #7
  call void @setup_benchmarks(ptr noundef nonnull %4) #6
  call void @wait_for_signal(ptr noundef %2) #6
  %8 = getelementptr inbounds i8, ptr %1, i64 4
  %9 = load i32, ptr %8, align 4, !tbaa !10
  %10 = icmp sgt i32 %9, 0
  br i1 %10, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %3
  %11 = getelementptr inbounds i8, ptr %4, i64 8
  br label %12

12:                                               ; preds = %.lr.ph, %19
  %.012 = phi i32 [ 0, %.lr.ph ], [ %21, %19 ]
  %13 = call i64 (...) @now() #6
  store i64 %13, ptr %11, align 8, !tbaa !11
  %14 = load i32, ptr %1, align 4, !tbaa !5
  %15 = sext i32 %14 to i64
  %16 = call i64 @fwrite(ptr noundef %7, i64 noundef %15, i64 noundef 1, ptr noundef %0)
  %17 = icmp eq i64 %16, 0
  br i1 %17, label %18, label %19

18:                                               ; preds = %12
  call void @throw(ptr noundef nonnull @.str.2) #8
  unreachable

19:                                               ; preds = %12
  %20 = call i32 @fflush(ptr noundef %0)
  call void (...) @notify_client() #6
  call void @wait_for_signal(ptr noundef %2) #6
  call void @benchmark(ptr noundef nonnull %4) #6
  %21 = add nuw nsw i32 %.012, 1
  %22 = load i32, ptr %8, align 4, !tbaa !10
  %23 = icmp slt i32 %21, %22
  br i1 %23, label %12, label %._crit_edge, !llvm.loop !14

._crit_edge:                                      ; preds = %19, %3
  call void @evaluate(ptr noundef nonnull %4, ptr noundef nonnull %1) #6
  call void @cleanup(ptr noundef %0, ptr noundef %7)
  call void @llvm.lifetime.end.p0(i64 48, ptr nonnull %4) #6
  ret void
}

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

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #3

declare void @setup_benchmarks(ptr noundef) local_unnamed_addr #4

declare void @wait_for_signal(ptr noundef) local_unnamed_addr #4

declare i64 @now(...) local_unnamed_addr #4

; Function Attrs: nofree nounwind
declare noundef i64 @fwrite(ptr nocapture noundef, i64 noundef, i64 noundef, ptr nocapture noundef) local_unnamed_addr #5

; Function Attrs: nofree nounwind
declare noundef i32 @fflush(ptr nocapture noundef) local_unnamed_addr #5

declare void @notify_client(...) local_unnamed_addr #4

declare void @benchmark(ptr noundef) local_unnamed_addr #4

declare void @evaluate(ptr noundef, ptr noundef) local_unnamed_addr #4

; Function Attrs: mustprogress 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 = { noreturn "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 memory(argmem: readwrite) }
attributes #3 = { mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" "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 = { "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 = { nofree 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 #6 = { nounwind }
attributes #7 = { nounwind allocsize(0) }
attributes #8 = { noreturn 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, !7, i64 0}
!6 = !{!"Arguments", !7, i64 0, !7, i64 4}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!6, !7, i64 4}
!11 = !{!12, !13, i64 8}
!12 = !{!"Benchmarks", !13, i64 0, !13, i64 8, !13, i64 16, !13, i64 24, !13, i64 32, !13, i64 40}
!13 = !{!"long long", !8, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass