; LLVM IR from golems/ach :: src (achcat)

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

@g_shutdown = external dso_local global i32, align 4
@stderr = external global ptr, align 8
@.str.4 = external hidden unnamed_addr constant [34 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [34 x i8], align 1
@fout = external dso_local global ptr, align 8

; Function Attrs: nounwind uwtable
declare dso_local void @sighandler_install() #0

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

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

; Function Attrs: nounwind
declare ptr @strerror(i32 noundef) #2

; Function Attrs: nounwind willreturn memory(none)
declare ptr @__errno_location() #3

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

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

declare i32 @ach_close(ptr noundef) #5

declare ptr @ach_result_to_string(i32 noundef) #5

; Function Attrs: nounwind uwtable
define dso_local i32 @subscribe(ptr noundef %0) #0 {
  %2 = alloca ptr, align 8
  %3 = alloca i64, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #7
  store i64 8, ptr %3, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #7
  %10 = load i64, ptr %3, align 8, !tbaa !9
  %11 = call noalias ptr @malloc(i64 noundef %10) #8
  store ptr %11, ptr %4, align 8, !tbaa !5
  call void @sighandler_install()
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #7
  %12 = call ptr @__errno_location() #9
  store i32 0, ptr %12, align 4, !tbaa !11
  br label %13

13:                                               ; preds = %57, %55, %1
  %14 = load volatile i32, ptr @g_shutdown, align 4, !tbaa !11
  %15 = icmp ne i32 %14, 0
  %16 = xor i1 %15, true
  br i1 %16, label %17, label %58

17:                                               ; preds = %13
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #7
  store i64 0, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #7
  %18 = load ptr, ptr %2, align 8, !tbaa !5
  %19 = load ptr, ptr %4, align 8, !tbaa !5
  %20 = load i64, ptr %3, align 8, !tbaa !9
  %21 = call i32 @ach_get(ptr noundef %18, ptr noundef %19, i64 noundef %20, ptr noundef %6, ptr noundef null, i32 noundef 1)
  store i32 %21, ptr %5, align 4, !tbaa !11
  %22 = load i32, ptr %5, align 4, !tbaa !11
  switch i32 %22, label %32 [
    i32 0, label %23
    i32 6, label %23
    i32 5, label %24
    i32 1, label %26
    i32 16, label %31
  ]

23:                                               ; preds = %17, %17
  br label %43

24:                                               ; preds = %17
  %25 = call i32 @usleep(i32 noundef 1000)
  store i32 2, ptr %8, align 4
  br label %55, !llvm.loop !13

26:                                               ; preds = %17
  %27 = load ptr, ptr %4, align 8, !tbaa !5
  call void @free(ptr noundef %27) #7
  %28 = load i64, ptr %6, align 8, !tbaa !9
  store i64 %28, ptr %3, align 8, !tbaa !9
  %29 = load i64, ptr %6, align 8, !tbaa !9
  %30 = call noalias ptr @malloc(i64 noundef %29) #8
  store ptr %30, ptr %4, align 8, !tbaa !5
  store i32 2, ptr %8, align 4
  br label %55, !llvm.loop !13

31:                                               ; preds = %17
  store i32 2, ptr %8, align 4
  br label %55, !llvm.loop !13

32:                                               ; preds = %17
  %33 = load ptr, ptr @stderr, align 8, !tbaa !5
  %34 = load i32, ptr %5, align 4, !tbaa !11
  %35 = call ptr @ach_result_to_string(i32 noundef %34)
  %36 = load i32, ptr %5, align 4, !tbaa !11
  %37 = call ptr @__errno_location() #9
  %38 = load i32, ptr %37, align 4, !tbaa !11
  %39 = call ptr @strerror(i32 noundef %38) #7
  %40 = call ptr @__errno_location() #9
  %41 = load i32, ptr %40, align 4, !tbaa !11
  %42 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %33, ptr noundef @.str.5, ptr noundef %35, i32 noundef %36, ptr noundef %39, i32 noundef %41) #7
  call void @exit(i32 noundef -1) #10
  unreachable

43:                                               ; preds = %23
  %44 = load ptr, ptr %4, align 8, !tbaa !5
  %45 = load i64, ptr %6, align 8, !tbaa !9
  %46 = load ptr, ptr @fout, align 8, !tbaa !5
  %47 = call i64 @fwrite(ptr noundef %44, i64 noundef 1, i64 noundef %45, ptr noundef %46)
  store i64 %47, ptr %7, align 8, !tbaa !9
  %48 = load i64, ptr %7, align 8, !tbaa !9
  %49 = load i64, ptr %6, align 8, !tbaa !9
  %50 = icmp ne i64 %48, %49
  br i1 %50, label %51, label %52

51:                                               ; preds = %43
  store i32 0, ptr %5, align 4, !tbaa !11
  store i32 3, ptr %8, align 4
  br label %55

52:                                               ; preds = %43
  %53 = load ptr, ptr @fout, align 8, !tbaa !5
  %54 = call i32 @fflush(ptr noundef %53)
  store i32 0, ptr %8, align 4
  br label %55

55:                                               ; preds = %52, %51, %31, %26, %24
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #7
  %56 = load i32, ptr %8, align 4
  switch i32 %56, label %76 [
    i32 0, label %57
    i32 2, label %13
    i32 3, label %58
  ]

57:                                               ; preds = %55
  br label %13, !llvm.loop !13

58:                                               ; preds = %55, %13
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #7
  %59 = load ptr, ptr %2, align 8, !tbaa !5
  %60 = call i32 @ach_close(ptr noundef %59)
  store i32 %60, ptr %9, align 4, !tbaa !11
  %61 = load i32, ptr %9, align 4, !tbaa !11
  %62 = icmp ne i32 0, %61
  br i1 %62, label %63, label %68

63:                                               ; preds = %58
  %64 = load ptr, ptr @stderr, align 8, !tbaa !5
  %65 = load i32, ptr %5, align 4, !tbaa !11
  %66 = call ptr @ach_result_to_string(i32 noundef %65)
  %67 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %64, ptr noundef @.str.4, ptr noundef %66) #7
  br label %68

68:                                               ; preds = %63, %58
  %69 = load volatile i32, ptr @g_shutdown, align 4, !tbaa !11
  %70 = icmp ne i32 %69, 0
  br i1 %70, label %71, label %72

71:                                               ; preds = %68
  br label %74

72:                                               ; preds = %68
  %73 = load i32, ptr %5, align 4, !tbaa !11
  br label %74

74:                                               ; preds = %72, %71
  %75 = phi i32 [ 0, %71 ], [ %73, %72 ]
  store i32 1, ptr %8, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #7
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #7
  ret i32 %75

76:                                               ; preds = %55
  unreachable
}

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

declare i32 @ach_get(ptr noundef, ptr noundef, i64 noundef, ptr noundef, ptr noundef, i32 noundef) #5

declare i32 @usleep(i32 noundef) #5

; Function Attrs: nounwind
declare void @free(ptr noundef) #2

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

declare i32 @fflush(ptr noundef) #5

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 = { 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 #3 = { nounwind willreturn memory(none) "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 = { "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 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 #7 = { nounwind }
attributes #8 = { nounwind allocsize(0) }
attributes #9 = { nounwind willreturn memory(none) }
attributes #10 = { 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 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"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"

@g_shutdown = external dso_local global i32, align 4
@stderr = external local_unnamed_addr global ptr, align 8
@.str.4 = external hidden unnamed_addr constant [34 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [34 x i8], align 1
@fout = external dso_local local_unnamed_addr global ptr, align 8

; Function Attrs: nounwind uwtable
declare dso_local void @sighandler_install() local_unnamed_addr #0

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

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

; Function Attrs: nounwind
declare ptr @strerror(i32 noundef) local_unnamed_addr #3

; Function Attrs: mustprogress nofree nosync nounwind willreturn memory(none)
declare ptr @__errno_location() 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) #1

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

declare i32 @ach_close(ptr noundef) local_unnamed_addr #6

declare ptr @ach_result_to_string(i32 noundef) local_unnamed_addr #6

; Function Attrs: nounwind uwtable
define dso_local i32 @subscribe(ptr noundef %0) local_unnamed_addr #0 {
  %2 = alloca i64, align 8
  %3 = tail call noalias dereferenceable_or_null(8) ptr @malloc(i64 noundef 8) #9
  tail call void @sighandler_install()
  %4 = tail call ptr @__errno_location() #10
  store i32 0, ptr %4, align 4, !tbaa !5
  %5 = load volatile i32, ptr @g_shutdown, align 4, !tbaa !5
  %.not34 = icmp eq i32 %5, 0
  br i1 %.not34, label %.lr.ph, label %.loopexit

.lr.ph:                                           ; preds = %1, %27
  %.036 = phi i64 [ %.1, %27 ], [ 8, %1 ]
  %.01535 = phi ptr [ %.116, %27 ], [ %3, %1 ]
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #11
  store i64 0, ptr %2, align 8, !tbaa !9
  %6 = call i32 @ach_get(ptr noundef %0, ptr noundef %.01535, i64 noundef %.036, ptr noundef nonnull %2, ptr noundef null, i32 noundef 1) #11
  switch i32 %6, label %12 [
    i32 0, label %19
    i32 6, label %19
    i32 5, label %7
    i32 1, label %9
    i32 16, label %27
  ], !llvm.loop !11

7:                                                ; preds = %.lr.ph
  %8 = call i32 @usleep(i32 noundef 1000) #11
  br label %27, !llvm.loop !11

9:                                                ; preds = %.lr.ph
  call void @free(ptr noundef %.01535) #11
  %10 = load i64, ptr %2, align 8, !tbaa !9
  %11 = call noalias ptr @malloc(i64 noundef %10) #9
  br label %27, !llvm.loop !11

12:                                               ; preds = %.lr.ph
  %13 = load ptr, ptr @stderr, align 8, !tbaa !13
  %14 = call ptr @ach_result_to_string(i32 noundef %6) #11
  %15 = load i32, ptr %4, align 4, !tbaa !5
  %16 = call ptr @strerror(i32 noundef %15) #11
  %17 = load i32, ptr %4, align 4, !tbaa !5
  %18 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %13, ptr noundef nonnull @.str.5, ptr noundef %14, i32 noundef %6, ptr noundef %16, i32 noundef %17) #12
  call void @exit(i32 noundef -1) #13
  unreachable

19:                                               ; preds = %.lr.ph, %.lr.ph
  %20 = load i64, ptr %2, align 8, !tbaa !9
  %21 = load ptr, ptr @fout, align 8, !tbaa !13
  %22 = call i64 @fwrite(ptr noundef %.01535, i64 noundef 1, i64 noundef %20, ptr noundef %21)
  %23 = load i64, ptr %2, align 8, !tbaa !9
  %.not22 = icmp eq i64 %22, %23
  br i1 %.not22, label %24, label %.thread

.thread:                                          ; preds = %19
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #11
  br label %.loopexit

24:                                               ; preds = %19
  %25 = load ptr, ptr @fout, align 8, !tbaa !13
  %26 = call i32 @fflush(ptr noundef %25)
  br label %27

27:                                               ; preds = %.lr.ph, %24, %9, %7
  %.116 = phi ptr [ %11, %9 ], [ %.01535, %7 ], [ %.01535, %24 ], [ %.01535, %.lr.ph ]
  %.1 = phi i64 [ %10, %9 ], [ %.036, %7 ], [ %.036, %24 ], [ %.036, %.lr.ph ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #11
  %28 = load volatile i32, ptr @g_shutdown, align 4, !tbaa !5
  %.not = icmp eq i32 %28, 0
  br i1 %.not, label %.lr.ph, label %.loopexit

.loopexit:                                        ; preds = %27, %1, %.thread
  %.2 = phi i32 [ 0, %.thread ], [ undef, %1 ], [ %6, %27 ]
  %29 = call i32 @ach_close(ptr noundef %0) #11
  %.not23 = icmp eq i32 %29, 0
  br i1 %.not23, label %34, label %30

30:                                               ; preds = %.loopexit
  %31 = load ptr, ptr @stderr, align 8, !tbaa !13
  %32 = call ptr @ach_result_to_string(i32 noundef %.2) #11
  %33 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %31, ptr noundef nonnull @.str.4, ptr noundef %32) #12
  br label %34

34:                                               ; preds = %30, %.loopexit
  %35 = load volatile i32, ptr @g_shutdown, align 4, !tbaa !5
  %.not24 = icmp eq i32 %35, 0
  %36 = select i1 %.not24, i32 %.2, i32 0
  ret i32 %36
}

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

declare i32 @ach_get(ptr noundef, ptr noundef, i64 noundef, ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #6

declare i32 @usleep(i32 noundef) local_unnamed_addr #6

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #8

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

; Function Attrs: nofree nounwind
declare noundef i32 @fflush(ptr nocapture 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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #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 = { mustprogress nofree nosync nounwind willreturn memory(none) "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 = { "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 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 #8 = { mustprogress nounwind willreturn allockind("free") 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 #9 = { nounwind allocsize(0) }
attributes #10 = { nounwind willreturn memory(none) }
attributes #11 = { nounwind }
attributes #12 = { cold nounwind }
attributes #13 = { 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 = !{!"long", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{!14, !14, i64 0}
!14 = !{!"any pointer", !7, i64 0}


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