; 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_pub_sleep_us = external dso_local global i32, align 4
@opt_n_msgs = external dso_local global i32, align 4
@.str = external hidden unnamed_addr constant [9 x i8], align 1
@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
@.str.18 = external hidden unnamed_addr constant [11 x i8], align 1
@optarg = external global ptr, align 8
@.str.19 = external hidden unnamed_addr constant [330 x i8], align 1
@.str.20 = external hidden unnamed_addr constant [25 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local i32 @test_basic() #0

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

declare i32 @ach_unlink(ptr noundef) #2

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

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

declare ptr @ach_result_to_string(i32 noundef) #2

declare i32 @printf(ptr noundef, ...) #2

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

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

; Function Attrs: nounwind uwtable
declare dso_local i32 @test_multi() #0

; Function Attrs: nounwind uwtable
define dso_local i32 @main(i32 noundef %0, ptr noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  store i32 0, ptr %3, 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) #7
  br label %10

10:                                               ; preds = %34, %2
  %11 = load i32, ptr %4, align 4, !tbaa !5
  %12 = load ptr, ptr %5, align 8, !tbaa !9
  %13 = call i32 @getopt(i32 noundef %11, ptr noundef %12, ptr noundef @.str.18) #7
  store i32 %13, ptr %6, align 4, !tbaa !5
  %14 = icmp ne i32 %13, -1
  br i1 %14, label %15, label %35

15:                                               ; preds = %10
  %16 = load i32, ptr %6, align 4, !tbaa !5
  switch i32 %16, label %34 [
    i32 117, label %17
    i32 112, label %20
    i32 115, label %23
    i32 110, label %26
    i32 99, label %29
    i32 63, label %32
    i32 104, label %32
    i32 72, label %32
  ]

17:                                               ; preds = %15
  %18 = load ptr, ptr @optarg, align 8, !tbaa !9
  %19 = call i32 @atoi(ptr noundef %18) #8
  store i32 %19, ptr @opt_pub_sleep_us, align 4, !tbaa !5
  br label %34

20:                                               ; preds = %15
  %21 = load ptr, ptr @optarg, align 8, !tbaa !9
  %22 = call i32 @atoi(ptr noundef %21) #8
  store i32 %22, ptr @opt_n_pub, align 4, !tbaa !5
  br label %34

23:                                               ; preds = %15
  %24 = load ptr, ptr @optarg, align 8, !tbaa !9
  %25 = call i32 @atoi(ptr noundef %24) #8
  store i32 %25, ptr @opt_n_sub, align 4, !tbaa !5
  br label %34

26:                                               ; preds = %15
  %27 = load ptr, ptr @optarg, align 8, !tbaa !9
  %28 = call i32 @atoi(ptr noundef %27) #8
  store i32 %28, ptr @opt_n_msgs, align 4, !tbaa !5
  br label %34

29:                                               ; preds = %15
  %30 = load ptr, ptr @optarg, align 8, !tbaa !9
  %31 = call noalias ptr @strdup(ptr noundef %30) #7
  store ptr %31, ptr @opt_channel_name, align 8, !tbaa !9
  br label %34

32:                                               ; preds = %15, %15, %15
  %33 = call i32 (ptr, ...) @printf(ptr noundef @.str.19, i32 noundef 500, i32 noundef 4, i32 noundef 4, i32 noundef 1024, ptr noundef @.str)
  call void @exit(i32 noundef 0) #9
  unreachable

34:                                               ; preds = %29, %26, %23, %20, %17, %15
  br label %10, !llvm.loop !11

35:                                               ; preds = %10
  %36 = load i32, ptr @opt_n_pub, align 4, !tbaa !5
  %37 = load i32, ptr @opt_n_sub, align 4, !tbaa !5
  %38 = load i32, ptr @opt_n_msgs, align 4, !tbaa !5
  %39 = load i32, ptr @opt_pub_sleep_us, align 4, !tbaa !5
  %40 = call i32 (ptr, ...) @printf(ptr noundef @.str.20, i32 noundef %36, i32 noundef %37, i32 noundef %38, i32 noundef %39)
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #7
  %41 = call i32 @test_basic()
  store i32 %41, ptr %7, align 4, !tbaa !5
  %42 = load i32, ptr %7, align 4, !tbaa !5
  %43 = icmp ne i32 0, %42
  br i1 %43, label %44, label %46

44:                                               ; preds = %35
  %45 = load i32, ptr %7, align 4, !tbaa !5
  store i32 %45, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %53

46:                                               ; preds = %35
  %47 = call i32 @test_multi()
  store i32 %47, ptr %7, align 4, !tbaa !5
  %48 = load i32, ptr %7, align 4, !tbaa !5
  %49 = icmp ne i32 0, %48
  br i1 %49, label %50, label %52

50:                                               ; preds = %46
  %51 = load i32, ptr %7, align 4, !tbaa !5
  store i32 %51, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %53

52:                                               ; preds = %46
  store i32 0, ptr %8, align 4
  br label %53

53:                                               ; preds = %52, %50, %44
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #7
  %54 = load i32, ptr %8, align 4
  switch i32 %54, label %70 [
    i32 0, label %55
  ]

55:                                               ; preds = %53
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #7
  %56 = load ptr, ptr @opt_channel_name, align 8, !tbaa !9
  %57 = call i32 @ach_unlink(ptr noundef %56)
  store i32 %57, ptr %9, align 4, !tbaa !5
  %58 = load i32, ptr %9, align 4, !tbaa !5
  %59 = call i32 @ach_status_match(i32 noundef %58, i32 noundef 513)
  %60 = icmp ne i32 %59, 0
  br i1 %60, label %66, label %61

61:                                               ; preds = %55
  %62 = load ptr, ptr @stderr, align 8, !tbaa !9
  %63 = load i32, ptr %9, align 4, !tbaa !5
  %64 = call ptr @ach_result_to_string(i32 noundef %63)
  %65 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %62, ptr noundef @.str.17, ptr noundef %64) #7
  store i32 -1, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %67

66:                                               ; preds = %55
  store i32 0, ptr %8, align 4
  br label %67

67:                                               ; preds = %66, %61
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #7
  %68 = load i32, ptr %8, align 4
  switch i32 %68, label %70 [
    i32 0, label %69
  ]

69:                                               ; preds = %67
  store i32 0, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %70

70:                                               ; preds = %69, %67, %53
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #7
  %71 = load i32, ptr %3, align 4
  ret i32 %71
}

; Function Attrs: nounwind
declare i32 @getopt(i32 noundef, ptr noundef, ptr noundef) #4

; Function Attrs: inlinehint nounwind willreturn memory(read) uwtable
declare i32 @atoi(ptr noundef nonnull) #6

; Function Attrs: nounwind
declare noalias ptr @strdup(ptr noundef) #4

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { "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 = { 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 "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 = { 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 #6 = { inlinehint nounwind willreturn memory(read) 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 #7 = { nounwind }
attributes #8 = { nounwind willreturn memory(read) }
attributes #9 = { 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 = !{!"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 = distinct !{!11, !12}
!12 = !{!"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"

@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_pub_sleep_us = external dso_local local_unnamed_addr global i32, align 4
@opt_n_msgs = external dso_local local_unnamed_addr global i32, align 4
@.str = external hidden unnamed_addr constant [9 x i8], align 1
@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
@.str.18 = external hidden unnamed_addr constant [11 x i8], align 1
@optarg = external local_unnamed_addr global ptr, align 8
@.str.19 = external hidden unnamed_addr constant [330 x i8], align 1
@.str.20 = external hidden unnamed_addr constant [25 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local i32 @test_basic() local_unnamed_addr #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

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

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

; Function Attrs: nounwind uwtable
declare dso_local i32 @test_multi() local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local i32 @main(i32 noundef %0, ptr noundef %1) local_unnamed_addr #0 {
  br label %3

3:                                                ; preds = %.backedge, %2
  %4 = tail call i32 @getopt(i32 noundef %0, ptr noundef %1, ptr noundef nonnull @.str.18) #8
  switch i32 %4, label %.backedge [
    i32 -1, label %22
    i32 117, label %5
    i32 112, label %8
    i32 115, label %11
    i32 110, label %14
    i32 99, label %17
    i32 63, label %20
    i32 104, label %20
    i32 72, label %20
  ]

.backedge:                                        ; preds = %3, %17, %14, %11, %8, %5
  br label %3, !llvm.loop !5

5:                                                ; preds = %3
  %6 = load ptr, ptr @optarg, align 8, !tbaa !7
  %7 = tail call i32 @atoi(ptr nocapture noundef %6) #9
  store i32 %7, ptr @opt_pub_sleep_us, align 4, !tbaa !11
  br label %.backedge

8:                                                ; preds = %3
  %9 = load ptr, ptr @optarg, align 8, !tbaa !7
  %10 = tail call i32 @atoi(ptr nocapture noundef %9) #9
  store i32 %10, ptr @opt_n_pub, align 4, !tbaa !11
  br label %.backedge

11:                                               ; preds = %3
  %12 = load ptr, ptr @optarg, align 8, !tbaa !7
  %13 = tail call i32 @atoi(ptr nocapture noundef %12) #9
  store i32 %13, ptr @opt_n_sub, align 4, !tbaa !11
  br label %.backedge

14:                                               ; preds = %3
  %15 = load ptr, ptr @optarg, align 8, !tbaa !7
  %16 = tail call i32 @atoi(ptr nocapture noundef %15) #9
  store i32 %16, ptr @opt_n_msgs, align 4, !tbaa !11
  br label %.backedge

17:                                               ; preds = %3
  %18 = load ptr, ptr @optarg, align 8, !tbaa !7
  %19 = tail call noalias ptr @strdup(ptr noundef %18) #8
  store ptr %19, ptr @opt_channel_name, align 8, !tbaa !7
  br label %.backedge

20:                                               ; preds = %3, %3, %3
  %21 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.19, i32 noundef 500, i32 noundef 4, i32 noundef 4, i32 noundef 1024, ptr noundef nonnull @.str)
  tail call void @exit(i32 noundef 0) #10
  unreachable

22:                                               ; preds = %3
  %23 = load i32, ptr @opt_n_pub, align 4, !tbaa !11
  %24 = load i32, ptr @opt_n_sub, align 4, !tbaa !11
  %25 = load i32, ptr @opt_n_msgs, align 4, !tbaa !11
  %26 = load i32, ptr @opt_pub_sleep_us, align 4, !tbaa !11
  %27 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.20, i32 noundef %23, i32 noundef %24, i32 noundef %25, i32 noundef %26)
  %28 = tail call i32 @test_basic()
  %.not17 = icmp eq i32 %28, 0
  br i1 %.not17, label %29, label %.thread

29:                                               ; preds = %22
  %30 = tail call i32 @test_multi()
  %.not18 = icmp eq i32 %30, 0
  br i1 %.not18, label %31, label %.thread

31:                                               ; preds = %29
  %32 = load ptr, ptr @opt_channel_name, align 8, !tbaa !7
  %33 = tail call i32 @ach_unlink(ptr noundef %32) #8
  %34 = tail call i32 @ach_status_match(i32 noundef %33, i32 noundef 513)
  %.not19.not = icmp eq i32 %34, 0
  br i1 %.not19.not, label %35, label %.thread

35:                                               ; preds = %31
  %36 = load ptr, ptr @stderr, align 8, !tbaa !7
  %37 = tail call ptr @ach_result_to_string(i32 noundef %33) #8
  %38 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %36, ptr noundef nonnull @.str.17, ptr noundef %37) #11
  br label %.thread

.thread:                                          ; preds = %35, %31, %22, %29
  %.2 = phi i32 [ %30, %29 ], [ %28, %22 ], [ -1, %35 ], [ 0, %31 ]
  ret i32 %.2
}

; Function Attrs: nounwind
declare i32 @getopt(i32 noundef, ptr noundef, ptr noundef) local_unnamed_addr #5

; Function Attrs: inlinehint mustprogress nofree nounwind willreturn memory(read) uwtable
declare i32 @atoi(ptr nocapture noundef nonnull) local_unnamed_addr #6

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: readwrite, inaccessiblemem: readwrite)
declare noalias ptr @strdup(ptr nocapture noundef readonly) local_unnamed_addr #7

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


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