; 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.timespec = type { i64, i64 }

@KERNDEV = external dso_local global i32, align 4
@time_chan = external dso_local global %struct.ach_channel, align 8
@.str.3 = external hidden unnamed_addr constant [12 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [60 x i8], align 1
@__PRETTY_FUNCTION__.print_times = external hidden unnamed_addr constant [23 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [17 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [4 x i8], align 1
@stdout = external global ptr, 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
declare hidden { i64, i64 } @get_ticks() #1

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #2

; Function Attrs: nounwind uwtable
define dso_local void @print_times() #1 {
  %1 = alloca float, align 4
  %2 = alloca i64, align 8
  %3 = alloca %struct.timespec, align 8
  %4 = alloca %struct.timespec, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  br label %7

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

10:                                               ; preds = %7
  %11 = getelementptr inbounds %struct.timespec, ptr %3, i32 0, i32 0
  store i64 3, ptr %11, align 8, !tbaa !9
  %12 = getelementptr inbounds %struct.timespec, ptr %3, i32 0, i32 1
  store i64 0, ptr %12, align 8, !tbaa !12
  br label %22

13:                                               ; preds = %7
  call void @llvm.lifetime.start.p0(i64 16, ptr %4) #5
  %14 = call { i64, i64 } @get_ticks()
  %15 = getelementptr inbounds { i64, i64 }, ptr %4, i32 0, i32 0
  %16 = extractvalue { i64, i64 } %14, 0
  store i64 %16, ptr %15, align 8
  %17 = getelementptr inbounds { i64, i64 }, ptr %4, i32 0, i32 1
  %18 = extractvalue { i64, i64 } %14, 1
  store i64 %18, ptr %17, align 8
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %3, ptr align 8 %4, i64 16, i1 false), !tbaa.struct !13
  call void @llvm.lifetime.end.p0(i64 16, ptr %4) #5
  %19 = getelementptr inbounds %struct.timespec, ptr %3, i32 0, i32 0
  %20 = load i64, ptr %19, align 8, !tbaa !9
  %21 = add nsw i64 %20, 3
  store i64 %21, ptr %19, align 8, !tbaa !9
  br label %22

22:                                               ; preds = %13, %10
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #5
  %23 = call i32 @ach_get(ptr noundef @time_chan, ptr noundef %1, i64 noundef 4, ptr noundef %2, ptr noundef %3, i32 noundef 1)
  store i32 %23, ptr %5, align 4, !tbaa !5
  %24 = load i32, ptr %5, align 4, !tbaa !5
  %25 = icmp eq i32 7, %24
  br i1 %25, label %26, label %27

26:                                               ; preds = %22
  store i32 3, ptr %6, align 4
  br label %42

27:                                               ; preds = %22
  %28 = load i32, ptr %5, align 4, !tbaa !5
  %29 = icmp eq i32 0, %28
  br i1 %29, label %30, label %31

30:                                               ; preds = %27
  br label %32

31:                                               ; preds = %27
  call void @__assert_fail(ptr noundef @.str.3, ptr noundef @.str.4, i32 noundef 177, ptr noundef @__PRETTY_FUNCTION__.print_times) #6
  unreachable

32:                                               ; preds = %30
  %33 = load i64, ptr %2, align 8, !tbaa !14
  %34 = icmp eq i64 %33, 4
  br i1 %34, label %35, label %36

35:                                               ; preds = %32
  br label %37

36:                                               ; preds = %32
  call void @__assert_fail(ptr noundef @.str.5, ptr noundef @.str.4, i32 noundef 178, ptr noundef @__PRETTY_FUNCTION__.print_times) #6
  unreachable

37:                                               ; preds = %35
  %38 = load float, ptr %1, align 4, !tbaa !15
  %39 = fpext float %38 to double
  %40 = fmul double %39, 1.000000e+06
  %41 = call i32 (ptr, ...) @printf(ptr noundef @.str.6, double noundef %40)
  store i32 0, ptr %6, align 4
  br label %42

42:                                               ; preds = %37, %26
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #5
  call void @llvm.lifetime.end.p0(i64 16, ptr %3) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #5
  %43 = load i32, ptr %6, align 4
  switch i32 %43, label %48 [
    i32 0, label %44
    i32 3, label %45
  ]

44:                                               ; preds = %42
  br label %7

45:                                               ; preds = %42
  %46 = load ptr, ptr @stdout, align 8, !tbaa !17
  %47 = call i32 @fflush(ptr noundef %46)
  ret void

48:                                               ; preds = %42
  unreachable
}

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

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #4

declare i32 @printf(ptr noundef, ...) #3

declare i32 @fflush(ptr noundef) #3

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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { "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 = !{!10, !11, i64 0}
!10 = !{!"timespec", !11, i64 0, !11, i64 8}
!11 = !{!"long", !7, i64 0}
!12 = !{!10, !11, i64 8}
!13 = !{i64 0, i64 8, !14, i64 8, i64 8, !14}
!14 = !{!11, !11, i64 0}
!15 = !{!16, !16, i64 0}
!16 = !{!"float", !7, i64 0}
!17 = !{!18, !18, i64 0}
!18 = !{!"any pointer", !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.timespec = type { i64, i64 }

@KERNDEV = external dso_local local_unnamed_addr global i32, align 4
@time_chan = external dso_local global %struct.ach_channel, align 8
@.str.3 = external hidden unnamed_addr constant [12 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [60 x i8], align 1
@__PRETTY_FUNCTION__.print_times = external hidden unnamed_addr constant [23 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [17 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [4 x i8], align 1
@stdout = external local_unnamed_addr global ptr, 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
declare hidden { i64, i64 } @get_ticks() local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local void @print_times() local_unnamed_addr #1 {
  %1 = alloca float, align 4
  %2 = alloca i64, align 8
  %3 = alloca %struct.timespec, align 8
  %4 = getelementptr inbounds i8, ptr %3, i64 8
  br label %5

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

7:                                                ; preds = %5
  store i64 0, ptr %4, align 8, !tbaa !9
  br label %13

8:                                                ; preds = %5
  %9 = call { i64, i64 } @get_ticks()
  %10 = extractvalue { i64, i64 } %9, 0
  %11 = extractvalue { i64, i64 } %9, 1
  store i64 %11, ptr %4, align 8, !tbaa !12
  %12 = add nsw i64 %10, 3
  br label %13

13:                                               ; preds = %8, %7
  %.sink = phi i64 [ %12, %8 ], [ 3, %7 ]
  store i64 %.sink, ptr %3, align 8
  %14 = call i32 @ach_get(ptr noundef nonnull @time_chan, ptr noundef nonnull %1, i64 noundef 4, ptr noundef nonnull %2, ptr noundef nonnull %3, i32 noundef 1) #5
  switch i32 %14, label %15 [
    i32 7, label %25
    i32 0, label %16
  ]

15:                                               ; preds = %13
  call void @__assert_fail(ptr noundef nonnull @.str.3, ptr noundef nonnull @.str.4, i32 noundef 177, ptr noundef nonnull @__PRETTY_FUNCTION__.print_times) #6
  unreachable

16:                                               ; preds = %13
  %17 = load i64, ptr %2, align 8, !tbaa !12
  %18 = icmp eq i64 %17, 4
  br i1 %18, label %20, label %19

19:                                               ; preds = %16
  call void @__assert_fail(ptr noundef nonnull @.str.5, ptr noundef nonnull @.str.4, i32 noundef 178, ptr noundef nonnull @__PRETTY_FUNCTION__.print_times) #6
  unreachable

20:                                               ; preds = %16
  %21 = load float, ptr %1, align 4, !tbaa !13
  %22 = fpext float %21 to double
  %23 = fmul double %22, 1.000000e+06
  %24 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.6, double noundef %23)
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %3) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #5
  br label %5

25:                                               ; preds = %13
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %3) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #5
  %26 = load ptr, ptr @stdout, align 8, !tbaa !15
  %27 = call i32 @fflush(ptr noundef %26)
  ret void
}

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

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #3

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

; Function Attrs: nofree nounwind
declare noundef i32 @fflush(ptr nocapture noundef) local_unnamed_addr #4

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 = { 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 = { 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 = { 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 = !{!10, !11, i64 8}
!10 = !{!"timespec", !11, i64 0, !11, i64 8}
!11 = !{!"long", !7, i64 0}
!12 = !{!11, !11, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"float", !7, i64 0}
!15 = !{!16, !16, i64 0}
!16 = !{!"any pointer", !7, i64 0}


; Effective O3 passes: DSEPass,EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,MergedLoadStoreMotionPass,SROAPass,SimplifyCFGPass