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

; 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.3 }
%union.anon.3 = type { [16 x i64] }
%struct.ach_create_attr = type { %union.anon }
%union.anon = type { [16 x i64] }
%struct.anon = type { %union.anon.0, ptr, i32, %union.anon.1 }
%union.anon.0 = type { i32 }
%union.anon.1 = type { i64 }

@KERNDEV = external dso_local global i32, align 4
@chan = external dso_local global %struct.ach_channel, align 8
@.str.11 = external hidden unnamed_addr constant [6 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

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.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: noreturn nounwind
declare void @abort() #3

declare void @ach_create_attr_init(ptr noundef) #1

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

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

; Function Attrs: nounwind uwtable
define dso_local void @setup_ach() #4 {
  %1 = alloca i32, align 4
  %2 = alloca %struct.ach_create_attr, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #5
  %3 = call i32 @ach_unlink(ptr noundef @.str.11)
  store i32 %3, ptr %1, align 4, !tbaa !5
  %4 = load i32, ptr %1, align 4, !tbaa !5
  %5 = call i32 @ach_status_match(i32 noundef %4, i32 noundef 513)
  %6 = icmp ne i32 %5, 0
  br i1 %6, label %8, label %7

7:                                                ; preds = %0
  call void @abort() #6
  unreachable

8:                                                ; preds = %0
  call void @llvm.lifetime.start.p0(i64 128, ptr %2) #5
  %9 = load i32, ptr @KERNDEV, align 4, !tbaa !5
  %10 = icmp ne i32 %9, 0
  br i1 %10, label %11, label %14

11:                                               ; preds = %8
  call void @ach_create_attr_init(ptr noundef %2)
  %12 = getelementptr inbounds %struct.ach_create_attr, ptr %2, i32 0, i32 0
  %13 = getelementptr inbounds %struct.anon, ptr %12, i32 0, i32 0
  store i32 3, ptr %13, align 8, !tbaa !9
  br label %14

14:                                               ; preds = %11, %8
  %15 = load i32, ptr @KERNDEV, align 4, !tbaa !5
  %16 = icmp ne i32 %15, 0
  br i1 %16, label %17, label %18

17:                                               ; preds = %14
  br label %19

18:                                               ; preds = %14
  br label %19

19:                                               ; preds = %18, %17
  %20 = phi ptr [ %2, %17 ], [ null, %18 ]
  %21 = call i32 @ach_create(ptr noundef @.str.11, i64 noundef 10, i64 noundef 256, ptr noundef %20)
  store i32 %21, ptr %1, align 4, !tbaa !5
  %22 = load i32, ptr %1, align 4, !tbaa !5
  %23 = icmp ne i32 0, %22
  br i1 %23, label %24, label %25

24:                                               ; preds = %19
  call void @abort() #6
  unreachable

25:                                               ; preds = %19
  %26 = call i32 @ach_open(ptr noundef @chan, ptr noundef @.str.11, ptr noundef null)
  store i32 %26, ptr %1, align 4, !tbaa !5
  %27 = load i32, ptr %1, align 4, !tbaa !5
  %28 = icmp ne i32 0, %27
  br i1 %28, label %29, label %30

29:                                               ; preds = %25
  call void @abort() #6
  unreachable

30:                                               ; preds = %25
  call void @llvm.lifetime.end.p0(i64 128, ptr %2) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #5
  ret void
}

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 = { 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 #4 = { 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 #5 = { nounwind }
attributes #6 = { 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 = !{!7, !7, i64 0}


; 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.3 }
%union.anon.3 = type { [16 x i64] }
%struct.ach_create_attr = type { %union.anon }
%union.anon = type { [16 x i64] }

@KERNDEV = external dso_local local_unnamed_addr global i32, align 4
@chan = external dso_local global %struct.ach_channel, align 8
@.str.11 = external hidden unnamed_addr constant [6 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

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.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: noreturn nounwind
declare void @abort() local_unnamed_addr #3

declare void @ach_create_attr_init(ptr noundef) local_unnamed_addr #1

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

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

; Function Attrs: nounwind uwtable
define dso_local void @setup_ach() local_unnamed_addr #4 {
  %1 = alloca %struct.ach_create_attr, align 8
  %2 = tail call i32 @ach_unlink(ptr noundef nonnull @.str.11) #5
  %3 = tail call i32 @ach_status_match(i32 noundef %2, i32 noundef 513)
  %.not = icmp eq i32 %3, 0
  br i1 %.not, label %4, label %5

4:                                                ; preds = %0
  tail call void @abort() #6
  unreachable

5:                                                ; preds = %0
  call void @llvm.lifetime.start.p0(i64 128, ptr nonnull %1) #5
  %6 = load i32, ptr @KERNDEV, align 4, !tbaa !5
  %.not3 = icmp eq i32 %6, 0
  br i1 %.not3, label %10, label %7

7:                                                ; preds = %5
  call void @ach_create_attr_init(ptr noundef nonnull %1) #5
  store i32 3, ptr %1, align 8, !tbaa !9
  %.pre = load i32, ptr @KERNDEV, align 4, !tbaa !5
  %8 = icmp eq i32 %.pre, 0
  %9 = select i1 %8, ptr null, ptr %1
  br label %10

10:                                               ; preds = %7, %5
  %.not4 = phi ptr [ %9, %7 ], [ null, %5 ]
  %11 = call i32 @ach_create(ptr noundef nonnull @.str.11, i64 noundef 10, i64 noundef 256, ptr noundef %.not4) #5
  %.not5 = icmp eq i32 %11, 0
  br i1 %.not5, label %13, label %12

12:                                               ; preds = %10
  call void @abort() #6
  unreachable

13:                                               ; preds = %10
  %14 = call i32 @ach_open(ptr noundef nonnull @chan, ptr noundef nonnull @.str.11, ptr noundef null) #5
  %.not6 = icmp eq i32 %14, 0
  br i1 %.not6, label %16, label %15

15:                                               ; preds = %13
  call void @abort() #6
  unreachable

16:                                               ; preds = %13
  call void @llvm.lifetime.end.p0(i64 128, ptr nonnull %1) #5
  ret void
}

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 = { 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 #4 = { 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 #5 = { nounwind }
attributes #6 = { 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 = !{!7, !7, i64 0}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,SROAPass,SimplifyCFGPass,TailCallElimPass