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

; 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.sigaction = type { %union.anon.1, %struct.__sigset_t, i32, ptr }
%union.anon.1 = type { ptr }
%struct.__sigset_t = type { [16 x i64] }
%struct.ach_cancel_attr = type { %union.anon.2 }
%union.anon.2 = type { [8 x i64] }
%struct.anon = type { ptr, i64, i32, %union.anon.0, i64, i32, i32, ptr, i32 }
%union.anon.0 = type { %struct.achk_opt }
%struct.achk_opt = type { i32, %struct.timespec }
%struct.timespec = type { i64, i64 }

@.str = external hidden unnamed_addr constant [16 x i8], align 1
@stderr = external global ptr, align 8
@.str.1 = external hidden unnamed_addr constant [23 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [11 x i8], align 1
@channel = external dso_local global %struct.ach_channel, align 8
@.str.3 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [11 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [7 x i8], align 1

; 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 %struct.sigaction, align 8
  %9 = alloca %struct.ach_cancel_attr, align 8
  %10 = 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
  %11 = load i32, ptr %4, align 4, !tbaa !5
  %12 = load ptr, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #7
  %13 = call i32 @ach_unlink(ptr noundef @.str)
  store i32 %13, ptr %6, align 4, !tbaa !5
  %14 = load i32, ptr %6, align 4, !tbaa !5
  %15 = call i32 @ach_status_match(i32 noundef %14, i32 noundef 513)
  %16 = icmp ne i32 %15, 0
  br i1 %16, label %22, label %17

17:                                               ; preds = %2
  %18 = load ptr, ptr @stderr, align 8, !tbaa !9
  %19 = load i32, ptr %6, align 4, !tbaa !5
  %20 = call ptr @ach_result_to_string(i32 noundef %19)
  %21 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %18, ptr noundef @.str.1, ptr noundef %20) #7
  store i32 -1, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %49

22:                                               ; preds = %2
  %23 = call i32 @ach_create(ptr noundef @.str, i64 noundef 32, i64 noundef 64, ptr noundef null)
  store i32 %23, ptr %6, align 4, !tbaa !5
  %24 = load i32, ptr %6, align 4, !tbaa !5
  call void @test(i32 noundef %24, ptr noundef @.str.2)
  %25 = call i32 @ach_open(ptr noundef @channel, ptr noundef @.str, ptr noundef null)
  store i32 %25, ptr %6, align 4, !tbaa !5
  %26 = load i32, ptr %6, align 4, !tbaa !5
  call void @test(i32 noundef %26, ptr noundef @.str.3)
  %27 = call i32 @ach_unlink(ptr noundef @.str)
  store i32 %27, ptr %6, align 4, !tbaa !5
  %28 = load i32, ptr %6, align 4, !tbaa !5
  call void @test(i32 noundef %28, ptr noundef @.str.4)
  call void @llvm.lifetime.start.p0(i64 152, ptr %8) #7
  call void @llvm.memset.p0.i64(ptr align 8 %8, i8 0, i64 152, i1 false)
  %29 = getelementptr inbounds %struct.sigaction, ptr %8, i32 0, i32 0
  store ptr @sighandler, ptr %29, align 8, !tbaa !11
  %30 = call i32 @sigaction(i32 noundef 14, ptr noundef %8, ptr noundef null) #7
  %31 = icmp ne i32 %30, 0
  br i1 %31, label %32, label %33

32:                                               ; preds = %22
  call void @exit(i32 noundef 1) #8
  unreachable

33:                                               ; preds = %22
  call void @llvm.lifetime.end.p0(i64 152, ptr %8) #7
  call void @llvm.lifetime.start.p0(i64 64, ptr %9) #7
  call void @ach_cancel_attr_init(ptr noundef %9)
  %34 = getelementptr inbounds %struct.ach_cancel_attr, ptr %9, i32 0, i32 0
  %35 = load i8, ptr %34, align 8
  %36 = and i8 %35, -2
  %37 = or i8 %36, 1
  store i8 %37, ptr %34, align 8
  %38 = call i32 @ach_cancel(ptr noundef @channel, ptr noundef %9)
  store i32 %38, ptr %6, align 4, !tbaa !5
  %39 = load i32, ptr %6, align 4, !tbaa !5
  call void @test(i32 noundef %39, ptr noundef @.str.5)
  call void @llvm.lifetime.end.p0(i64 64, ptr %9) #7
  call void @check()
  store volatile i32 0, ptr getelementptr inbounds (%struct.anon, ptr @channel, i32 0, i32 6), align 4, !tbaa !11
  %40 = call i32 @alarm(i32 noundef 1) #7
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #7
  store i32 0, ptr %10, align 4, !tbaa !5
  br label %41

41:                                               ; preds = %45, %33
  %42 = load i32, ptr %10, align 4, !tbaa !5
  %43 = icmp slt i32 %42, 2
  br i1 %43, label %44, label %48

44:                                               ; preds = %41
  call void @check()
  br label %45

45:                                               ; preds = %44
  %46 = load i32, ptr %10, align 4, !tbaa !5
  %47 = add nsw i32 %46, 1
  store i32 %47, ptr %10, align 4, !tbaa !5
  br label %41, !llvm.loop !12

48:                                               ; preds = %41
  store i32 0, ptr %3, align 4
  store i32 1, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #7
  br label %49

49:                                               ; preds = %48, %17
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #7
  %50 = load i32, ptr %3, align 4
  ret i32 %50
}

; 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 @ach_create(ptr noundef, i64 noundef, i64 noundef, ptr noundef) #2

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

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

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

; Function Attrs: nounwind uwtable
declare hidden void @sighandler(i32 noundef) #0

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

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

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

declare void @ach_cancel_attr_init(ptr noundef) #2

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

; Function Attrs: nounwind
declare i32 @alarm(i32 noundef) #4

; Function Attrs: nounwind uwtable
declare hidden void @check() #0

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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #6 = { 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 #7 = { 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 = !{!"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 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"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] }
%struct.sigaction = type { %union.anon.1, %struct.__sigset_t, i32, ptr }
%union.anon.1 = type { ptr }
%struct.__sigset_t = type { [16 x i64] }
%struct.ach_cancel_attr = type { %union.anon.2 }
%union.anon.2 = type { [8 x i64] }

@.str = external hidden unnamed_addr constant [16 x i8], align 1
@stderr = external local_unnamed_addr global ptr, align 8
@.str.1 = external hidden unnamed_addr constant [23 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [11 x i8], align 1
@channel = external dso_local global %struct.ach_channel, align 8
@.str.3 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [11 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [7 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local range(i32 -1, 1) i32 @main(i32 noundef %0, ptr nocapture noundef readnone %1) local_unnamed_addr #0 {
  %3 = alloca %struct.sigaction, align 8
  %4 = alloca %struct.ach_cancel_attr, align 8
  %5 = tail call i32 @ach_unlink(ptr noundef nonnull @.str) #8
  %6 = tail call i32 @ach_status_match(i32 noundef %5, i32 noundef 513)
  %.not = icmp eq i32 %6, 0
  br i1 %.not, label %7, label %11

7:                                                ; preds = %2
  %8 = load ptr, ptr @stderr, align 8, !tbaa !5
  %9 = tail call ptr @ach_result_to_string(i32 noundef %5) #8
  %10 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %8, ptr noundef nonnull @.str.1, ptr noundef %9) #9
  br label %.loopexit

11:                                               ; preds = %2
  %12 = tail call i32 @ach_create(ptr noundef nonnull @.str, i64 noundef 32, i64 noundef 64, ptr noundef null) #8
  tail call void @test(i32 noundef %12, ptr noundef nonnull @.str.2)
  %13 = tail call i32 @ach_open(ptr noundef nonnull @channel, ptr noundef nonnull @.str, ptr noundef null) #8
  tail call void @test(i32 noundef %13, ptr noundef nonnull @.str.3)
  %14 = tail call i32 @ach_unlink(ptr noundef nonnull @.str) #8
  tail call void @test(i32 noundef %14, ptr noundef nonnull @.str.4)
  call void @llvm.lifetime.start.p0(i64 152, ptr nonnull %3) #8
  %15 = getelementptr inbounds i8, ptr %3, i64 8
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(152) %15, i8 0, i64 144, i1 false)
  store ptr @sighandler, ptr %3, align 8, !tbaa !9
  %16 = call i32 @sigaction(i32 noundef 14, ptr noundef nonnull %3, ptr noundef null) #8
  %.not11 = icmp eq i32 %16, 0
  br i1 %.not11, label %.loopexit.loopexit, label %17

17:                                               ; preds = %11
  call void @exit(i32 noundef 1) #10
  unreachable

.loopexit.loopexit:                               ; preds = %11
  call void @llvm.lifetime.end.p0(i64 152, ptr nonnull %3) #8
  call void @llvm.lifetime.start.p0(i64 64, ptr nonnull %4) #8
  call void @ach_cancel_attr_init(ptr noundef nonnull %4) #8
  %18 = load i8, ptr %4, align 8
  %19 = or i8 %18, 1
  store i8 %19, ptr %4, align 8
  %20 = call i32 @ach_cancel(ptr noundef nonnull @channel, ptr noundef nonnull %4) #8
  call void @test(i32 noundef %20, ptr noundef nonnull @.str.5)
  call void @llvm.lifetime.end.p0(i64 64, ptr nonnull %4) #8
  call void @check()
  store volatile i32 0, ptr getelementptr inbounds (i8, ptr @channel, i64 60), align 4, !tbaa !9
  %21 = call i32 @alarm(i32 noundef 1) #8
  call void @check()
  call void @check()
  br label %.loopexit

.loopexit:                                        ; preds = %.loopexit.loopexit, %7
  %.010 = phi i32 [ -1, %7 ], [ 0, %.loopexit.loopexit ]
  ret i32 %.010
}

; Function Attrs: mustprogress 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) local_unnamed_addr #2

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

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

declare ptr @ach_result_to_string(i32 noundef) local_unnamed_addr #2

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

; Function Attrs: nounwind uwtable
declare hidden void @test(i32 noundef, ptr noundef) local_unnamed_addr #0

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

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

; Function Attrs: nounwind uwtable
declare hidden void @sighandler(i32 noundef) #0

; Function Attrs: nounwind
declare i32 @sigaction(i32 noundef, ptr noundef, ptr noundef) local_unnamed_addr #6

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

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

declare void @ach_cancel_attr_init(ptr noundef) local_unnamed_addr #2

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

; Function Attrs: nounwind
declare i32 @alarm(i32 noundef) local_unnamed_addr #6

; Function Attrs: nounwind uwtable
declare hidden void @check() local_unnamed_addr #0

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 = { 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 = { 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 #5 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #6 = { 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 #7 = { 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 #8 = { nounwind }
attributes #9 = { cold nounwind }
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 = !{!7, !7, i64 0}


; Effective O3 passes: DSEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,LoopRotatePass,LoopSimplifyPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass