; LLVM IR from goldsborough/ipc-bench :: source/mq (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 }
%struct.Message = type { i64, [0 x i8] }

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

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

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

; Function Attrs: nounwind uwtable
define dso_local void @communicate(i32 noundef %0, ptr noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca %struct.Benchmarks, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  store i32 %0, ptr %3, align 4, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 48, ptr %5) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #5
  %8 = load ptr, ptr %4, align 8, !tbaa !9
  %9 = call ptr @create_message(ptr noundef %8)
  store ptr %9, ptr %6, align 8, !tbaa !9
  call void @setup_benchmarks(ptr noundef %5)
  store i32 0, ptr %7, align 4, !tbaa !5
  br label %10

10:                                               ; preds = %52, %2
  %11 = load i32, ptr %7, align 4, !tbaa !5
  %12 = load ptr, ptr %4, align 8, !tbaa !9
  %13 = getelementptr inbounds %struct.Arguments, ptr %12, i32 0, i32 1
  %14 = load i32, ptr %13, align 4, !tbaa !11
  %15 = icmp slt i32 %11, %14
  br i1 %15, label %16, label %55

16:                                               ; preds = %10
  %17 = call i64 (...) @now()
  %18 = getelementptr inbounds %struct.Benchmarks, ptr %5, i32 0, i32 1
  store i64 %17, ptr %18, align 8, !tbaa !13
  %19 = load ptr, ptr %6, align 8, !tbaa !9
  %20 = getelementptr inbounds %struct.Message, ptr %19, i32 0, i32 0
  store i64 2, ptr %20, align 8, !tbaa !16
  %21 = load ptr, ptr %6, align 8, !tbaa !9
  %22 = getelementptr inbounds %struct.Message, ptr %21, i32 0, i32 1
  %23 = getelementptr inbounds [0 x i8], ptr %22, i64 0, i64 0
  %24 = load ptr, ptr %4, align 8, !tbaa !9
  %25 = getelementptr inbounds %struct.Arguments, ptr %24, i32 0, i32 0
  %26 = load i32, ptr %25, align 4, !tbaa !18
  %27 = sext i32 %26 to i64
  call void @llvm.memset.p0.i64(ptr align 8 %23, i8 50, i64 %27, i1 false)
  %28 = load i32, ptr %3, align 4, !tbaa !5
  %29 = load ptr, ptr %6, align 8, !tbaa !9
  %30 = load ptr, ptr %4, align 8, !tbaa !9
  %31 = getelementptr inbounds %struct.Arguments, ptr %30, i32 0, i32 0
  %32 = load i32, ptr %31, align 4, !tbaa !18
  %33 = sext i32 %32 to i64
  %34 = call i32 @msgsnd(i32 noundef %28, ptr noundef %29, i64 noundef %33, i32 noundef 2048)
  %35 = icmp eq i32 %34, -1
  br i1 %35, label %36, label %37

36:                                               ; preds = %16
  call void @throw(ptr noundef @.str.1) #6
  unreachable

37:                                               ; preds = %16
  %38 = load i32, ptr %3, align 4, !tbaa !5
  %39 = load ptr, ptr %6, align 8, !tbaa !9
  %40 = load ptr, ptr %4, align 8, !tbaa !9
  %41 = getelementptr inbounds %struct.Arguments, ptr %40, i32 0, i32 0
  %42 = load i32, ptr %41, align 4, !tbaa !18
  %43 = sext i32 %42 to i64
  %44 = call i64 @msgrcv(i32 noundef %38, ptr noundef %39, i64 noundef %43, i64 noundef 1, i32 noundef 0)
  %45 = load ptr, ptr %4, align 8, !tbaa !9
  %46 = getelementptr inbounds %struct.Arguments, ptr %45, i32 0, i32 0
  %47 = load i32, ptr %46, align 4, !tbaa !18
  %48 = sext i32 %47 to i64
  %49 = icmp slt i64 %44, %48
  br i1 %49, label %50, label %51

50:                                               ; preds = %37
  call void @throw(ptr noundef @.str.2) #6
  unreachable

51:                                               ; preds = %37
  call void @benchmark(ptr noundef %5)
  br label %52

52:                                               ; preds = %51
  %53 = load i32, ptr %7, align 4, !tbaa !5
  %54 = add nsw i32 %53, 1
  store i32 %54, ptr %7, align 4, !tbaa !5
  br label %10, !llvm.loop !19

55:                                               ; preds = %10
  %56 = load ptr, ptr %4, align 8, !tbaa !9
  call void @evaluate(ptr noundef %5, ptr noundef %56)
  %57 = load i32, ptr %3, align 4, !tbaa !5
  %58 = load ptr, ptr %6, align 8, !tbaa !9
  call void @cleanup(i32 noundef %57, ptr noundef %58)
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #5
  call void @llvm.lifetime.end.p0(i64 48, ptr %5) #5
  ret void
}

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

declare ptr @create_message(ptr noundef) #3

declare void @setup_benchmarks(ptr noundef) #3

declare i64 @now(...) #3

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

declare i32 @msgsnd(i32 noundef, ptr noundef, i64 noundef, i32 noundef) #3

declare i64 @msgrcv(i32 noundef, ptr noundef, i64 noundef, i64 noundef, i32 noundef) #3

declare void @benchmark(ptr noundef) #3

declare void @evaluate(ptr noundef, ptr 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 = { 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 = { "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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #5 = { nounwind }
attributes #6 = { 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 = !{!"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, !6, i64 4}
!12 = !{!"Arguments", !6, i64 0, !6, i64 4}
!13 = !{!14, !15, i64 8}
!14 = !{!"Benchmarks", !15, i64 0, !15, i64 8, !15, i64 16, !15, i64 24, !15, i64 32, !15, i64 40}
!15 = !{!"long long", !7, i64 0}
!16 = !{!17, !17, i64 0}
!17 = !{!"long", !7, i64 0}
!18 = !{!12, !6, i64 0}
!19 = distinct !{!19, !20}
!20 = !{!"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.1 = external hidden unnamed_addr constant [29 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [31 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local void @cleanup(i32 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(i32 noundef %0, ptr noundef %1) local_unnamed_addr #0 {
  %3 = alloca %struct.Benchmarks, align 8
  call void @llvm.lifetime.start.p0(i64 48, ptr nonnull %3) #5
  %4 = tail call ptr @create_message(ptr noundef %1) #5
  call void @setup_benchmarks(ptr noundef nonnull %3) #5
  %5 = getelementptr inbounds i8, ptr %1, i64 4
  %6 = load i32, ptr %5, align 4, !tbaa !5
  %7 = icmp sgt i32 %6, 0
  br i1 %7, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %2
  %8 = getelementptr inbounds i8, ptr %3, i64 8
  %9 = getelementptr inbounds i8, ptr %4, i64 8
  br label %10

10:                                               ; preds = %.lr.ph, %27
  %.016 = phi i32 [ 0, %.lr.ph ], [ %28, %27 ]
  %11 = call i64 (...) @now() #5
  store i64 %11, ptr %8, align 8, !tbaa !10
  store i64 2, ptr %4, align 8, !tbaa !13
  %12 = load i32, ptr %1, align 4, !tbaa !15
  %13 = sext i32 %12 to i64
  call void @llvm.memset.p0.i64(ptr nonnull align 8 %9, i8 50, i64 %13, i1 false)
  %14 = load i32, ptr %1, align 4, !tbaa !15
  %15 = sext i32 %14 to i64
  %16 = call i32 @msgsnd(i32 noundef %0, ptr noundef nonnull %4, i64 noundef %15, i32 noundef 2048) #5
  %17 = icmp eq i32 %16, -1
  br i1 %17, label %18, label %19

18:                                               ; preds = %10
  call void @throw(ptr noundef nonnull @.str.1) #6
  unreachable

19:                                               ; preds = %10
  %20 = load i32, ptr %1, align 4, !tbaa !15
  %21 = sext i32 %20 to i64
  %22 = call i64 @msgrcv(i32 noundef %0, ptr noundef nonnull %4, i64 noundef %21, i64 noundef 1, i32 noundef 0) #5
  %23 = load i32, ptr %1, align 4, !tbaa !15
  %24 = sext i32 %23 to i64
  %25 = icmp slt i64 %22, %24
  br i1 %25, label %26, label %27

26:                                               ; preds = %19
  call void @throw(ptr noundef nonnull @.str.2) #6
  unreachable

27:                                               ; preds = %19
  call void @benchmark(ptr noundef nonnull %3) #5
  %28 = add nuw nsw i32 %.016, 1
  %29 = load i32, ptr %5, align 4, !tbaa !5
  %30 = icmp slt i32 %28, %29
  br i1 %30, label %10, label %._crit_edge, !llvm.loop !16

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

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

declare ptr @create_message(ptr noundef) local_unnamed_addr #3

declare void @setup_benchmarks(ptr noundef) local_unnamed_addr #3

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

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

declare i32 @msgsnd(i32 noundef, ptr noundef, i64 noundef, i32 noundef) local_unnamed_addr #3

declare i64 @msgrcv(i32 noundef, ptr noundef, i64 noundef, i64 noundef, i32 noundef) local_unnamed_addr #3

declare void @benchmark(ptr noundef) local_unnamed_addr #3

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

; 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 = { "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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #5 = { nounwind }
attributes #6 = { 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 4}
!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 = !{!11, !12, i64 8}
!11 = !{!"Benchmarks", !12, i64 0, !12, i64 8, !12, i64 16, !12, i64 24, !12, i64 32, !12, i64 40}
!12 = !{!"long long", !8, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"long", !8, i64 0}
!15 = !{!6, !7, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}


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