; LLVM IR from golems/ach :: src (achpipe-bin)

; 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.ach_channel = type { %union.anon }
%union.anon = type { [16 x i64] }
%struct.ach_pipe_frame_t = type { [8 x i8], [8 x i8], [1 x i8] }

@sig_received = external dso_local global i32, align 4
@.str.2 = external hidden unnamed_addr constant [14 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [43 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [15 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [8 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [20 x i8], align 1

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

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

; 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 void @hard_assert(i32 noundef, ptr noundef, ...) #0

; Function Attrs: nounwind uwtable
define dso_local void @publish(ptr noundef %0, ptr noundef %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca %struct.ach_channel, align 8
  %6 = alloca i32, align 4
  %7 = alloca i64, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i64, align 8
  %10 = alloca i32, align 4
  %11 = alloca i64, align 8
  %12 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  call void (i32, ptr, ...) @verbprintf(i32 noundef 1, ptr noundef @.str.2)
  call void @llvm.lifetime.start.p0(i64 128, ptr %5) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #5
  %13 = load ptr, ptr %4, align 8, !tbaa !5
  %14 = call i32 @ach_open(ptr noundef %5, ptr noundef %13, ptr noundef null)
  store i32 %14, ptr %6, align 4, !tbaa !9
  %15 = load i32, ptr %6, align 4, !tbaa !9
  %16 = icmp eq i32 0, %15
  %17 = zext i1 %16 to i32
  %18 = load ptr, ptr %4, align 8, !tbaa !5
  %19 = load i32, ptr %6, align 4, !tbaa !9
  %20 = call ptr @ach_result_to_string(i32 noundef %19)
  call void (i32, ptr, ...) @hard_assert(i32 noundef %17, ptr noundef @.str.3, ptr noundef %18, ptr noundef %20)
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #5
  store i64 512, ptr %7, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #5
  %21 = load i64, ptr %7, align 8, !tbaa !11
  %22 = call ptr @ach_pipe_alloc(i64 noundef %21)
  store ptr %22, ptr %8, align 8, !tbaa !5
  br label %23

23:                                               ; preds = %78, %2
  %24 = load i32, ptr @sig_received, align 4, !tbaa !9
  %25 = icmp ne i32 %24, 0
  %26 = xor i1 %25, true
  br i1 %26, label %27, label %79

27:                                               ; preds = %23
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #5
  %28 = load ptr, ptr %8, align 8, !tbaa !5
  %29 = load ptr, ptr %3, align 8, !tbaa !5
  %30 = call i64 @fread(ptr noundef %28, i64 noundef 1, i64 noundef 16, ptr noundef %29)
  store i64 %30, ptr %9, align 8, !tbaa !11
  %31 = load i64, ptr %9, align 8, !tbaa !11
  call void (i32, ptr, ...) @verbprintf(i32 noundef 2, ptr noundef @.str.4, i64 noundef %31)
  %32 = load i64, ptr %9, align 8, !tbaa !11
  %33 = icmp ne i64 16, %32
  br i1 %33, label %34, label %35

34:                                               ; preds = %27
  store i32 3, ptr %10, align 4
  br label %76

35:                                               ; preds = %27
  %36 = load ptr, ptr %8, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.ach_pipe_frame_t, ptr %36, i32 0, i32 0
  %38 = getelementptr inbounds [8 x i8], ptr %37, i64 0, i64 0
  %39 = call i32 @memcmp(ptr noundef @.str.5, ptr noundef %38, i64 noundef 8) #6
  %40 = icmp ne i32 %39, 0
  br i1 %40, label %41, label %42

41:                                               ; preds = %35
  store i32 3, ptr %10, align 4
  br label %76

42:                                               ; preds = %35
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #5
  %43 = load ptr, ptr %8, align 8, !tbaa !5
  %44 = call i64 @ach_pipe_get_size(ptr noundef %43)
  store i64 %44, ptr %11, align 8, !tbaa !11
  %45 = load i64, ptr %11, align 8, !tbaa !11
  %46 = load i64, ptr %7, align 8, !tbaa !11
  %47 = icmp ugt i64 %45, %46
  br i1 %47, label %48, label %53

48:                                               ; preds = %42
  %49 = load i64, ptr %11, align 8, !tbaa !11
  store i64 %49, ptr %7, align 8, !tbaa !11
  %50 = load ptr, ptr %8, align 8, !tbaa !5
  call void @free(ptr noundef %50) #5
  %51 = load i64, ptr %7, align 8, !tbaa !11
  %52 = call ptr @ach_pipe_alloc(i64 noundef %51)
  store ptr %52, ptr %8, align 8, !tbaa !5
  br label %53

53:                                               ; preds = %48, %42
  %54 = load ptr, ptr %8, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.ach_pipe_frame_t, ptr %54, i32 0, i32 2
  %56 = getelementptr inbounds [1 x i8], ptr %55, i64 0, i64 0
  %57 = load i64, ptr %11, align 8, !tbaa !11
  %58 = load ptr, ptr %3, align 8, !tbaa !5
  %59 = call i64 @fread(ptr noundef %56, i64 noundef 1, i64 noundef %57, ptr noundef %58)
  store i64 %59, ptr %9, align 8, !tbaa !11
  %60 = load i64, ptr %11, align 8, !tbaa !11
  %61 = load i64, ptr %9, align 8, !tbaa !11
  %62 = icmp ne i64 %60, %61
  br i1 %62, label %63, label %64

63:                                               ; preds = %53
  store i32 3, ptr %10, align 4
  br label %75

64:                                               ; preds = %53
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #5
  %65 = load ptr, ptr %8, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.ach_pipe_frame_t, ptr %65, i32 0, i32 2
  %67 = getelementptr inbounds [1 x i8], ptr %66, i64 0, i64 0
  %68 = load i64, ptr %11, align 8, !tbaa !11
  %69 = call i32 @ach_put(ptr noundef %5, ptr noundef %67, i64 noundef %68)
  store i32 %69, ptr %12, align 4, !tbaa !9
  %70 = load i32, ptr %12, align 4, !tbaa !9
  %71 = icmp eq i32 %70, 0
  %72 = zext i1 %71 to i32
  %73 = load i32, ptr %12, align 4, !tbaa !9
  %74 = call ptr @ach_result_to_string(i32 noundef %73)
  call void (i32, ptr, ...) @hard_assert(i32 noundef %72, ptr noundef @.str.6, ptr noundef %74)
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #5
  store i32 0, ptr %10, align 4
  br label %75

75:                                               ; preds = %64, %63
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #5
  br label %76

76:                                               ; preds = %75, %41, %34
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #5
  %77 = load i32, ptr %10, align 4
  switch i32 %77, label %82 [
    i32 0, label %78
    i32 3, label %79
  ]

78:                                               ; preds = %76
  br label %23, !llvm.loop !13

79:                                               ; preds = %76, %23
  %80 = load ptr, ptr %8, align 8, !tbaa !5
  call void @free(ptr noundef %80) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #5
  %81 = call i32 @ach_close(ptr noundef %5)
  call void @llvm.lifetime.end.p0(i64 128, ptr %5) #5
  ret void

82:                                               ; preds = %76
  unreachable
}

declare i32 @ach_open(ptr noundef, ptr noundef, ptr noundef) #2

declare ptr @ach_result_to_string(i32 noundef) #2

declare ptr @ach_pipe_alloc(i64 noundef) #2

declare i64 @fread(ptr noundef, i64 noundef, i64 noundef, ptr noundef) #2

; Function Attrs: nounwind willreturn memory(read)
declare i32 @memcmp(ptr noundef, ptr noundef, i64 noundef) #3

declare i64 @ach_pipe_get_size(ptr noundef) #2

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

declare i32 @ach_put(ptr noundef, ptr noundef, i64 noundef) #2

declare i32 @ach_close(ptr noundef) #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 = { 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 = { nounwind willreturn memory(read) "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 = { nounwind }
attributes #6 = { nounwind willreturn memory(read) }

!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 = !{!12, !12, i64 0}
!12 = !{!"long", !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"

%struct.ach_channel = type { %union.anon }
%union.anon = type { [16 x i64] }

@sig_received = external dso_local local_unnamed_addr global i32, align 4
@.str.2 = external hidden unnamed_addr constant [14 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [43 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [15 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [8 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [20 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local void @verbprintf(i32 noundef, ptr noundef, ...) 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: mustprogress 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 void @hard_assert(i32 noundef, ptr noundef, ...) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @publish(ptr nocapture noundef %0, ptr noundef %1) local_unnamed_addr #0 {
  %3 = alloca %struct.ach_channel, align 8
  tail call void (i32, ptr, ...) @verbprintf(i32 noundef 1, ptr noundef nonnull @.str.2)
  call void @llvm.lifetime.start.p0(i64 128, ptr nonnull %3) #6
  %4 = call i32 @ach_open(ptr noundef nonnull %3, ptr noundef %1, ptr noundef null) #6
  %5 = icmp eq i32 %4, 0
  %6 = zext i1 %5 to i32
  %7 = call ptr @ach_result_to_string(i32 noundef %4) #6
  call void (i32, ptr, ...) @hard_assert(i32 noundef %6, ptr noundef nonnull @.str.3, ptr noundef %1, ptr noundef %7)
  %8 = call ptr @ach_pipe_alloc(i64 noundef 512) #6
  %9 = load i32, ptr @sig_received, align 4, !tbaa !5
  %.not40 = icmp eq i32 %9, 0
  br i1 %.not40, label %.lr.ph, label %.thread

.lr.ph:                                           ; preds = %2, %20
  %.042 = phi i64 [ %.1, %20 ], [ 512, %2 ]
  %.02641 = phi ptr [ %.127, %20 ], [ %8, %2 ]
  %10 = call i64 @fread(ptr noundef %.02641, i64 noundef 1, i64 noundef 16, ptr noundef %0)
  call void (i32, ptr, ...) @verbprintf(i32 noundef 2, ptr noundef nonnull @.str.4, i64 noundef %10)
  %.not33 = icmp eq i64 %10, 16
  br i1 %.not33, label %11, label %.thread

11:                                               ; preds = %.lr.ph
  %bcmp = call i32 @bcmp(ptr noundef nonnull dereferenceable(8) @.str.5, ptr noundef nonnull dereferenceable(8) %.02641, i64 8)
  %.not34 = icmp eq i32 %bcmp, 0
  br i1 %.not34, label %12, label %.thread

12:                                               ; preds = %11
  %13 = call i64 @ach_pipe_get_size(ptr noundef %.02641) #6
  %14 = icmp ugt i64 %13, %.042
  br i1 %14, label %15, label %17

15:                                               ; preds = %12
  call void @free(ptr noundef %.02641) #6
  %16 = call ptr @ach_pipe_alloc(i64 noundef %13) #6
  br label %17

17:                                               ; preds = %15, %12
  %.127 = phi ptr [ %16, %15 ], [ %.02641, %12 ]
  %.1 = phi i64 [ %13, %15 ], [ %.042, %12 ]
  %18 = getelementptr inbounds i8, ptr %.127, i64 16
  %19 = call i64 @fread(ptr noundef nonnull %18, i64 noundef 1, i64 noundef %13, ptr noundef %0)
  %.not35 = icmp eq i64 %13, %19
  br i1 %.not35, label %20, label %.thread

20:                                               ; preds = %17
  %21 = call i32 @ach_put(ptr noundef nonnull %3, ptr noundef nonnull %18, i64 noundef %13) #6
  %22 = icmp eq i32 %21, 0
  %23 = zext i1 %22 to i32
  %24 = call ptr @ach_result_to_string(i32 noundef %21) #6
  call void (i32, ptr, ...) @hard_assert(i32 noundef %23, ptr noundef nonnull @.str.6, ptr noundef %24)
  %25 = load i32, ptr @sig_received, align 4, !tbaa !5
  %.not = icmp eq i32 %25, 0
  br i1 %.not, label %.lr.ph, label %.thread

.thread:                                          ; preds = %20, %.lr.ph, %11, %17, %2
  %.3 = phi ptr [ %8, %2 ], [ %.127, %17 ], [ %.02641, %11 ], [ %.02641, %.lr.ph ], [ %.127, %20 ]
  call void @free(ptr noundef %.3) #6
  %26 = call i32 @ach_close(ptr noundef nonnull %3) #6
  call void @llvm.lifetime.end.p0(i64 128, ptr nonnull %3) #6
  ret void
}

declare i32 @ach_open(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

declare ptr @ach_result_to_string(i32 noundef) local_unnamed_addr #2

declare ptr @ach_pipe_alloc(i64 noundef) local_unnamed_addr #2

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

declare i64 @ach_pipe_get_size(ptr noundef) local_unnamed_addr #2

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

declare i32 @ach_put(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #2

declare i32 @ach_close(ptr noundef) local_unnamed_addr #2

; Function Attrs: nofree nounwind willreturn memory(argmem: read)
declare i32 @bcmp(ptr nocapture, ptr nocapture, i64) local_unnamed_addr #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 = { mustprogress 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 = { 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 = { 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 #5 = { nofree nounwind willreturn memory(argmem: read) }
attributes #6 = { 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"}


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