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

@FREQUENCY = external dso_local global double, align 8
@SECS = external dso_local global double, align 8
@RECV_RT = external dso_local global i64, align 8
@KERNDEV = external dso_local global i32, align 4
@.str.2 = external hidden unnamed_addr constant [5 x i8], align 1
@time_chan = external dso_local global %struct.ach_channel, align 8

; 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

; Function Attrs: nounwind uwtable
define dso_local void @init_time_chan() #1 {
  %1 = alloca %struct.ach_create_attr, align 8
  %2 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 128, ptr %1) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #5
  %3 = call i32 @ach_unlink(ptr noundef @.str.2)
  store i32 %3, ptr %2, align 4, !tbaa !5
  %4 = load i32, ptr %2, 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
  %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 %1)
  %12 = getelementptr inbounds %struct.ach_create_attr, ptr %1, 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 double, ptr @FREQUENCY, align 8, !tbaa !10
  %16 = fptoui double %15 to i64
  %17 = load double, ptr @SECS, align 8, !tbaa !10
  %18 = fptoui double %17 to i64
  %19 = mul i64 %16, %18
  %20 = load i64, ptr @RECV_RT, align 8, !tbaa !12
  %21 = mul i64 %19, %20
  %22 = load i32, ptr @KERNDEV, align 4, !tbaa !5
  %23 = icmp ne i32 %22, 0
  br i1 %23, label %24, label %25

24:                                               ; preds = %14
  br label %26

25:                                               ; preds = %14
  br label %26

26:                                               ; preds = %25, %24
  %27 = phi ptr [ %1, %24 ], [ null, %25 ]
  %28 = call i32 @ach_create(ptr noundef @.str.2, i64 noundef %21, i64 noundef 4, ptr noundef %27)
  store i32 %28, ptr %2, align 4, !tbaa !5
  %29 = load i32, ptr %2, align 4, !tbaa !5
  %30 = icmp ne i32 0, %29
  br i1 %30, label %31, label %32

31:                                               ; preds = %26
  call void @abort() #6
  unreachable

32:                                               ; preds = %26
  %33 = call i32 @ach_open(ptr noundef @time_chan, ptr noundef @.str.2, ptr noundef null)
  store i32 %33, ptr %2, align 4, !tbaa !5
  %34 = load i32, ptr %2, align 4, !tbaa !5
  %35 = icmp ne i32 0, %34
  br i1 %35, label %36, label %37

36:                                               ; preds = %32
  call void @abort() #6
  unreachable

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

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: noreturn nounwind
declare void @abort() #4

declare void @ach_create_attr_init(ptr noundef) #2

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

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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 = { 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 }
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}
!10 = !{!11, !11, i64 0}
!11 = !{!"double", !7, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"long", !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] }

@FREQUENCY = external dso_local local_unnamed_addr global double, align 8
@SECS = external dso_local local_unnamed_addr global double, align 8
@RECV_RT = external dso_local local_unnamed_addr global i64, align 8
@KERNDEV = external dso_local local_unnamed_addr global i32, align 4
@.str.2 = external hidden unnamed_addr constant [5 x i8], align 1
@time_chan = external dso_local global %struct.ach_channel, align 8

; 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

; Function Attrs: nounwind uwtable
define dso_local void @init_time_chan() local_unnamed_addr #1 {
  %1 = alloca %struct.ach_create_attr, align 8
  call void @llvm.lifetime.start.p0(i64 128, ptr nonnull %1) #5
  %2 = tail call i32 @ach_unlink(ptr noundef nonnull @.str.2) #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
  %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 = load double, ptr @FREQUENCY, align 8, !tbaa !10
  %12 = fptoui double %11 to i64
  %13 = load double, ptr @SECS, align 8, !tbaa !10
  %14 = fptoui double %13 to i64
  %15 = mul i64 %14, %12
  %16 = load i64, ptr @RECV_RT, align 8, !tbaa !12
  %17 = mul i64 %15, %16
  %18 = call i32 @ach_create(ptr noundef nonnull @.str.2, i64 noundef %17, i64 noundef 4, ptr noundef %.not4) #5
  %.not5 = icmp eq i32 %18, 0
  br i1 %.not5, label %20, label %19

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

20:                                               ; preds = %10
  %21 = call i32 @ach_open(ptr noundef nonnull @time_chan, ptr noundef nonnull @.str.2, ptr noundef null) #5
  %.not6 = icmp eq i32 %21, 0
  br i1 %.not6, label %23, label %22

22:                                               ; preds = %20
  call void @abort() #6
  unreachable

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

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: noreturn nounwind
declare void @abort() local_unnamed_addr #4

declare void @ach_create_attr_init(ptr noundef) local_unnamed_addr #2

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

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

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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 = { 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 }
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}
!10 = !{!11, !11, i64 0}
!11 = !{!"double", !7, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"long", !7, i64 0}


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