; LLVM IR from golems/ach :: src/test (achtest)

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

@opt_n_sub = external dso_local global i32, align 4
@opt_n_pub = external dso_local global i32, align 4
@opt_channel_name = external dso_local global ptr, align 8
@stderr = external global ptr, align 8
@.str.17 = external hidden unnamed_addr constant [23 x i8], align 1

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

declare i32 @ach_unlink(ptr noundef) #1

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @ach_status_match(i32 noundef, i32 noundef) #2

; Function Attrs: nounwind
declare i32 @fprintf(ptr noundef, ptr noundef, ...) #3

declare ptr @ach_result_to_string(i32 noundef) #1

declare i32 @ach_create(ptr noundef, i64 noundef, i64 noundef, ptr noundef) #1

; Function Attrs: noreturn nounwind
declare void @exit(i32 noundef) #4

; 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
define dso_local i32 @test_multi() #5 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #6
  %9 = load ptr, ptr @opt_channel_name, align 8, !tbaa !5
  %10 = call i32 @ach_unlink(ptr noundef %9)
  store i32 %10, ptr %2, align 4, !tbaa !9
  %11 = load i32, ptr %2, align 4, !tbaa !9
  %12 = call i32 @ach_status_match(i32 noundef %11, i32 noundef 513)
  %13 = icmp ne i32 %12, 0
  br i1 %13, label %19, label %14

14:                                               ; preds = %0
  %15 = load ptr, ptr @stderr, align 8, !tbaa !5
  %16 = load i32, ptr %2, align 4, !tbaa !9
  %17 = call ptr @ach_result_to_string(i32 noundef %16)
  %18 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %15, ptr noundef @.str.17, ptr noundef %17) #6
  store i32 -1, ptr %1, align 4
  store i32 1, ptr %3, align 4
  br label %91

19:                                               ; preds = %0
  %20 = load ptr, ptr @opt_channel_name, align 8, !tbaa !5
  %21 = call i32 @ach_create(ptr noundef %20, i64 noundef 32, i64 noundef 64, ptr noundef null)
  store i32 %21, ptr %2, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #6
  store i32 0, ptr %4, align 4, !tbaa !9
  br label %22

22:                                               ; preds = %42, %19
  %23 = load i32, ptr %4, align 4, !tbaa !9
  %24 = load i32, ptr @opt_n_sub, align 4, !tbaa !9
  %25 = icmp slt i32 %23, %24
  br i1 %25, label %26, label %45

26:                                               ; preds = %22
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #6
  %27 = call i32 @fork() #6
  store i32 %27, ptr %5, align 4, !tbaa !9
  %28 = load i32, ptr %5, align 4, !tbaa !9
  %29 = icmp slt i32 %28, 0
  br i1 %29, label %30, label %31

30:                                               ; preds = %26
  call void @exit(i32 noundef -1) #7
  unreachable

31:                                               ; preds = %26
  %32 = load i32, ptr %5, align 4, !tbaa !9
  %33 = icmp eq i32 0, %32
  br i1 %33, label %34, label %37

34:                                               ; preds = %31
  %35 = load i32, ptr %4, align 4, !tbaa !9
  %36 = call i32 @subscriber(i32 noundef %35)
  store i32 %36, ptr %1, align 4
  store i32 1, ptr %3, align 4
  br label %39

37:                                               ; preds = %31
  br label %38

38:                                               ; preds = %37
  store i32 0, ptr %3, align 4
  br label %39

39:                                               ; preds = %38, %34
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #6
  %40 = load i32, ptr %3, align 4
  switch i32 %40, label %90 [
    i32 0, label %41
  ]

41:                                               ; preds = %39
  br label %42

42:                                               ; preds = %41
  %43 = load i32, ptr %4, align 4, !tbaa !9
  %44 = add nsw i32 %43, 1
  store i32 %44, ptr %4, align 4, !tbaa !9
  br label %22, !llvm.loop !11

45:                                               ; preds = %22
  store i32 0, ptr %4, align 4, !tbaa !9
  br label %46

46:                                               ; preds = %66, %45
  %47 = load i32, ptr %4, align 4, !tbaa !9
  %48 = load i32, ptr @opt_n_pub, align 4, !tbaa !9
  %49 = icmp slt i32 %47, %48
  br i1 %49, label %50, label %69

50:                                               ; preds = %46
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #6
  %51 = call i32 @fork() #6
  store i32 %51, ptr %6, align 4, !tbaa !9
  %52 = load i32, ptr %6, align 4, !tbaa !9
  %53 = icmp slt i32 %52, 0
  br i1 %53, label %54, label %55

54:                                               ; preds = %50
  call void @exit(i32 noundef -1) #7
  unreachable

55:                                               ; preds = %50
  %56 = load i32, ptr %6, align 4, !tbaa !9
  %57 = icmp eq i32 0, %56
  br i1 %57, label %58, label %61

58:                                               ; preds = %55
  %59 = load i32, ptr %4, align 4, !tbaa !9
  %60 = call i32 @publisher(i32 noundef %59)
  store i32 %60, ptr %1, align 4
  store i32 1, ptr %3, align 4
  br label %63

61:                                               ; preds = %55
  br label %62

62:                                               ; preds = %61
  store i32 0, ptr %3, align 4
  br label %63

63:                                               ; preds = %62, %58
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #6
  %64 = load i32, ptr %3, align 4
  switch i32 %64, label %90 [
    i32 0, label %65
  ]

65:                                               ; preds = %63
  br label %66

66:                                               ; preds = %65
  %67 = load i32, ptr %4, align 4, !tbaa !9
  %68 = add nsw i32 %67, 1
  store i32 %68, ptr %4, align 4, !tbaa !9
  br label %46, !llvm.loop !13

69:                                               ; preds = %46
  store i32 0, ptr %4, align 4, !tbaa !9
  br label %70

70:                                               ; preds = %86, %69
  %71 = load i32, ptr %4, align 4, !tbaa !9
  %72 = load i32, ptr @opt_n_sub, align 4, !tbaa !9
  %73 = load i32, ptr @opt_n_pub, align 4, !tbaa !9
  %74 = add nsw i32 %72, %73
  %75 = icmp slt i32 %71, %74
  br i1 %75, label %76, label %89

76:                                               ; preds = %70
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #6
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #6
  %77 = call i32 @wait(ptr noundef %7)
  store i32 %77, ptr %8, align 4, !tbaa !9
  %78 = load i32, ptr %8, align 4, !tbaa !9
  %79 = load i32, ptr %7, align 4, !tbaa !9
  %80 = icmp ne i32 0, %79
  br i1 %80, label %81, label %82

81:                                               ; preds = %76
  store i32 -1, ptr %1, align 4
  store i32 1, ptr %3, align 4
  br label %83

82:                                               ; preds = %76
  store i32 0, ptr %3, align 4
  br label %83

83:                                               ; preds = %82, %81
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #6
  %84 = load i32, ptr %3, align 4
  switch i32 %84, label %90 [
    i32 0, label %85
  ]

85:                                               ; preds = %83
  br label %86

86:                                               ; preds = %85
  %87 = load i32, ptr %4, align 4, !tbaa !9
  %88 = add nsw i32 %87, 1
  store i32 %88, ptr %4, align 4, !tbaa !9
  br label %70, !llvm.loop !14

89:                                               ; preds = %70
  store i32 0, ptr %1, align 4
  store i32 1, ptr %3, align 4
  br label %90

90:                                               ; preds = %89, %83, %63, %39
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #6
  br label %91

91:                                               ; preds = %90, %14
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #6
  %92 = load i32, ptr %1, align 4
  ret i32 %92
}

; Function Attrs: nounwind
declare i32 @fork() #3

; Function Attrs: nounwind uwtable
declare hidden i32 @subscriber(i32 noundef) #5

; Function Attrs: nounwind uwtable
declare hidden i32 @publisher(i32 noundef) #5

declare i32 @wait(ptr noundef) #1

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 "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 = { noreturn 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 #5 = { 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 #6 = { nounwind }
attributes #7 = { 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, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}
!14 = distinct !{!14, !12}


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

@opt_n_sub = external dso_local local_unnamed_addr global i32, align 4
@opt_n_pub = external dso_local local_unnamed_addr global i32, align 4
@opt_channel_name = external dso_local local_unnamed_addr global ptr, align 8
@stderr = external local_unnamed_addr global ptr, align 8
@.str.17 = external hidden unnamed_addr constant [23 x i8], align 1

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

declare i32 @ach_unlink(ptr noundef) local_unnamed_addr #1

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @ach_status_match(i32 noundef, i32 noundef) local_unnamed_addr #2

; Function Attrs: nofree nounwind
declare noundef i32 @fprintf(ptr nocapture noundef, ptr nocapture noundef readonly, ...) local_unnamed_addr #3

declare ptr @ach_result_to_string(i32 noundef) local_unnamed_addr #1

declare i32 @ach_create(ptr noundef, i64 noundef, i64 noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: noreturn nounwind
declare void @exit(i32 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) #0

; Function Attrs: nounwind uwtable
define dso_local i32 @test_multi() local_unnamed_addr #5 {
  %1 = alloca i32, align 4
  %2 = load ptr, ptr @opt_channel_name, align 8, !tbaa !5
  %3 = tail call i32 @ach_unlink(ptr noundef %2) #6
  %4 = tail call i32 @ach_status_match(i32 noundef %3, i32 noundef 513)
  %.not = icmp eq i32 %4, 0
  br i1 %.not, label %5, label %9

5:                                                ; preds = %0
  %6 = load ptr, ptr @stderr, align 8, !tbaa !5
  %7 = tail call ptr @ach_result_to_string(i32 noundef %3) #6
  %8 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %6, ptr noundef nonnull @.str.17, ptr noundef %7) #7
  br label %.loopexit

9:                                                ; preds = %0
  %10 = load ptr, ptr @opt_channel_name, align 8, !tbaa !5
  %11 = tail call i32 @ach_create(ptr noundef %10, i64 noundef 32, i64 noundef 64, ptr noundef null) #6
  %12 = load i32, ptr @opt_n_sub, align 4, !tbaa !9
  %13 = icmp sgt i32 %12, 0
  br i1 %13, label %.lr.ph, label %.preheader35

.preheader35:                                     ; preds = %22, %9
  %14 = phi i32 [ %12, %9 ], [ %24, %22 ]
  %15 = load i32, ptr @opt_n_pub, align 4, !tbaa !9
  %16 = icmp sgt i32 %15, 0
  br i1 %16, label %.lr.ph42, label %.preheader

.lr.ph:                                           ; preds = %9, %22
  %.02440 = phi i32 [ %23, %22 ], [ 0, %9 ]
  %17 = tail call i32 @fork() #6
  %18 = icmp slt i32 %17, 0
  br i1 %18, label %19, label %20

19:                                               ; preds = %.lr.ph
  tail call void @exit(i32 noundef -1) #8
  unreachable

20:                                               ; preds = %.lr.ph
  %.not31 = icmp eq i32 %17, 0
  br i1 %.not31, label %.thread, label %22

.thread:                                          ; preds = %20
  %21 = tail call i32 @subscriber(i32 noundef %.02440)
  br label %.loopexit

22:                                               ; preds = %20
  %23 = add nuw nsw i32 %.02440, 1
  %24 = load i32, ptr @opt_n_sub, align 4, !tbaa !9
  %25 = icmp slt i32 %23, %24
  br i1 %25, label %.lr.ph, label %.preheader35, !llvm.loop !11

.preheader.loopexit:                              ; preds = %35
  %.pre = load i32, ptr @opt_n_sub, align 4, !tbaa !9
  br label %.preheader

.preheader:                                       ; preds = %.preheader.loopexit, %.preheader35
  %26 = phi i32 [ %37, %.preheader.loopexit ], [ %15, %.preheader35 ]
  %27 = phi i32 [ %.pre, %.preheader.loopexit ], [ %14, %.preheader35 ]
  %28 = add nsw i32 %26, %27
  %29 = icmp sgt i32 %28, 0
  br i1 %29, label %.lr.ph44, label %.loopexit

.lr.ph42:                                         ; preds = %.preheader35, %35
  %.12541 = phi i32 [ %36, %35 ], [ 0, %.preheader35 ]
  %30 = tail call i32 @fork() #6
  %31 = icmp slt i32 %30, 0
  br i1 %31, label %32, label %33

32:                                               ; preds = %.lr.ph42
  tail call void @exit(i32 noundef -1) #8
  unreachable

33:                                               ; preds = %.lr.ph42
  %.not30 = icmp eq i32 %30, 0
  br i1 %.not30, label %.thread33, label %35

.thread33:                                        ; preds = %33
  %34 = tail call i32 @publisher(i32 noundef %.12541)
  br label %.loopexit

35:                                               ; preds = %33
  %36 = add nuw nsw i32 %.12541, 1
  %37 = load i32, ptr @opt_n_pub, align 4, !tbaa !9
  %38 = icmp slt i32 %36, %37
  br i1 %38, label %.lr.ph42, label %.preheader.loopexit, !llvm.loop !13

39:                                               ; preds = %.lr.ph44
  %40 = add nuw nsw i32 %.22643, 1
  %41 = load i32, ptr @opt_n_sub, align 4, !tbaa !9
  %42 = load i32, ptr @opt_n_pub, align 4, !tbaa !9
  %43 = add nsw i32 %42, %41
  %44 = icmp slt i32 %40, %43
  br i1 %44, label %.lr.ph44, label %.loopexit, !llvm.loop !14

.lr.ph44:                                         ; preds = %.preheader, %39
  %.22643 = phi i32 [ %40, %39 ], [ 0, %.preheader ]
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #6
  %45 = call i32 @wait(ptr noundef nonnull %1) #6
  %46 = load i32, ptr %1, align 4, !tbaa !9
  %.not29 = icmp eq i32 %46, 0
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #6
  br i1 %.not29, label %39, label %.loopexit

.loopexit:                                        ; preds = %39, %.lr.ph44, %.preheader, %.thread33, %.thread, %5
  %.7 = phi i32 [ -1, %5 ], [ %21, %.thread ], [ %34, %.thread33 ], [ 0, %.preheader ], [ 0, %39 ], [ -1, %.lr.ph44 ]
  ret i32 %.7
}

; Function Attrs: nofree nounwind
declare i32 @fork() local_unnamed_addr #3

; Function Attrs: nounwind uwtable
declare hidden i32 @subscriber(i32 noundef) local_unnamed_addr #5

; Function Attrs: nounwind uwtable
declare hidden i32 @publisher(i32 noundef) local_unnamed_addr #5

declare i32 @wait(ptr noundef) local_unnamed_addr #1

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 #4 = { noreturn 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 #5 = { 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 #6 = { nounwind }
attributes #7 = { cold nounwind }
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, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}
!14 = distinct !{!14, !12}


; Effective O3 passes: CorrelatedValuePropagationPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass