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

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

@chan_feedback = external dso_local global %struct.ach_channel, align 8
@.str = external hidden unnamed_addr constant [9 x i8], align 1
@chan_control = external dso_local global %struct.ach_channel, align 8
@.str.1 = external hidden unnamed_addr constant [8 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local double @now() #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
define dso_local void @robot() #0 {
  %1 = alloca i32, align 4
  %2 = alloca [3 x double], align 16
  %3 = alloca [1 x double], align 8
  %4 = alloca i64, align 8
  %5 = alloca double, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #5
  %6 = call i32 @ach_open(ptr noundef @chan_feedback, ptr noundef @.str, ptr noundef null)
  store i32 %6, ptr %1, align 4, !tbaa !5
  %7 = load i32, ptr %1, align 4, !tbaa !5
  %8 = icmp ne i32 0, %7
  br i1 %8, label %9, label %10

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

10:                                               ; preds = %0
  %11 = call i32 @ach_open(ptr noundef @chan_control, ptr noundef @.str.1, ptr noundef null)
  store i32 %11, ptr %1, align 4, !tbaa !5
  %12 = load i32, ptr %1, align 4, !tbaa !5
  %13 = icmp ne i32 0, %12
  br i1 %13, label %14, label %15

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

15:                                               ; preds = %10
  call void @llvm.lifetime.start.p0(i64 24, ptr %2) #5
  %16 = call double @now()
  store double %16, ptr %2, align 8, !tbaa !9
  %17 = getelementptr inbounds double, ptr %2, i64 1
  store double 0.000000e+00, ptr %17, align 8, !tbaa !9
  %18 = getelementptr inbounds double, ptr %2, i64 2
  store double 0.000000e+00, ptr %18, align 8, !tbaa !9
  br label %19

19:                                               ; preds = %47, %15
  br label %20

20:                                               ; preds = %19
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #5
  %21 = getelementptr inbounds [1 x double], ptr %3, i64 0, i64 0
  %22 = call i32 @ach_get(ptr noundef @chan_control, ptr noundef %21, i64 noundef 8, ptr noundef %4, ptr noundef null, i32 noundef 3)
  store i32 %22, ptr %1, align 4, !tbaa !5
  %23 = load i32, ptr %1, align 4, !tbaa !5
  %24 = call i32 @ach_status_match(i32 noundef %23, i32 noundef 65)
  %25 = icmp ne i32 %24, 0
  br i1 %25, label %26, label %46

26:                                               ; preds = %20
  %27 = load i64, ptr %4, align 8, !tbaa !11
  %28 = icmp eq i64 8, %27
  br i1 %28, label %29, label %46

29:                                               ; preds = %26
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #5
  %30 = call double @now()
  store double %30, ptr %5, align 8, !tbaa !9
  %31 = getelementptr inbounds [1 x double], ptr %3, i64 0, i64 0
  %32 = load double, ptr %31, align 8, !tbaa !9
  %33 = getelementptr inbounds [3 x double], ptr %2, i64 0, i64 2
  store double %32, ptr %33, align 16, !tbaa !9
  %34 = load double, ptr %5, align 8, !tbaa !9
  %35 = getelementptr inbounds [3 x double], ptr %2, i64 0, i64 0
  %36 = load double, ptr %35, align 16, !tbaa !9
  %37 = fsub double %34, %36
  %38 = getelementptr inbounds [3 x double], ptr %2, i64 0, i64 2
  %39 = load double, ptr %38, align 16, !tbaa !9
  %40 = fmul double %37, %39
  %41 = getelementptr inbounds [3 x double], ptr %2, i64 0, i64 1
  store double %40, ptr %41, align 8, !tbaa !9
  %42 = load double, ptr %5, align 8, !tbaa !9
  %43 = getelementptr inbounds [3 x double], ptr %2, i64 0, i64 0
  store double %42, ptr %43, align 16, !tbaa !9
  %44 = getelementptr inbounds [3 x double], ptr %2, i64 0, i64 0
  %45 = call i32 @ach_put(ptr noundef @chan_feedback, ptr noundef %44, i64 noundef 24)
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #5
  br label %47

46:                                               ; preds = %26, %20
  call void @abort() #6
  unreachable

47:                                               ; preds = %29
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #5
  br label %19
}

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

; Function Attrs: noreturn nounwind
declare void @abort() #3

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

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

declare i32 @ach_put(ptr noundef, ptr noundef, i64 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 = { 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 = { 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 #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, !10, i64 0}
!10 = !{!"double", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"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 }
%union.anon = type { [16 x i64] }

@chan_feedback = external dso_local global %struct.ach_channel, align 8
@.str = external hidden unnamed_addr constant [9 x i8], align 1
@chan_control = external dso_local global %struct.ach_channel, align 8
@.str.1 = external hidden unnamed_addr constant [8 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local double @now() 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: noreturn nounwind uwtable
define dso_local void @robot() local_unnamed_addr #2 {
  %1 = alloca [3 x double], align 16
  %2 = alloca [1 x double], align 8
  %3 = alloca i64, align 8
  %4 = tail call i32 @ach_open(ptr noundef nonnull @chan_feedback, ptr noundef nonnull @.str, ptr noundef null) #7
  %.not = icmp eq i32 %4, 0
  br i1 %.not, label %6, label %5

5:                                                ; preds = %0
  tail call void @abort() #8
  unreachable

6:                                                ; preds = %0
  %7 = tail call i32 @ach_open(ptr noundef nonnull @chan_control, ptr noundef nonnull @.str.1, ptr noundef null) #7
  %.not5 = icmp eq i32 %7, 0
  br i1 %.not5, label %9, label %8

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

9:                                                ; preds = %6
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %1) #7
  %10 = tail call double @now()
  store double %10, ptr %1, align 16, !tbaa !5
  %11 = getelementptr inbounds i8, ptr %1, i64 8
  %12 = getelementptr inbounds i8, ptr %1, i64 16
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %11, i8 0, i64 16, i1 false)
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #7
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #7
  %13 = call i32 @ach_get(ptr noundef nonnull @chan_control, ptr noundef nonnull %2, i64 noundef 8, ptr noundef nonnull %3, ptr noundef null, i32 noundef 3) #7
  %14 = call i32 @ach_status_match(i32 noundef %13, i32 noundef 65)
  %15 = icmp ne i32 %14, 0
  %16 = load i64, ptr %3, align 8
  %17 = icmp eq i64 %16, 8
  %or.cond6 = select i1 %15, i1 %17, i1 false
  br i1 %or.cond6, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %9, %.lr.ph
  %18 = call double @now()
  %19 = load double, ptr %2, align 8, !tbaa !5
  store double %19, ptr %12, align 16, !tbaa !5
  %20 = load double, ptr %1, align 16, !tbaa !5
  %21 = fsub double %18, %20
  %22 = fmul double %19, %21
  store double %22, ptr %11, align 8, !tbaa !5
  store double %18, ptr %1, align 16, !tbaa !5
  %23 = call i32 @ach_put(ptr noundef nonnull @chan_feedback, ptr noundef nonnull %1, i64 noundef 24) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #7
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #7
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #7
  %24 = call i32 @ach_get(ptr noundef nonnull @chan_control, ptr noundef nonnull %2, i64 noundef 8, ptr noundef nonnull %3, ptr noundef null, i32 noundef 3) #7
  %25 = call i32 @ach_status_match(i32 noundef %24, i32 noundef 65)
  %26 = icmp ne i32 %25, 0
  %27 = load i64, ptr %3, align 8
  %28 = icmp eq i64 %27, 8
  %or.cond = select i1 %26, i1 %28, i1 false
  br i1 %or.cond, label %.lr.ph, label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph, %9
  call void @abort() #8
  unreachable
}

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

; Function Attrs: noreturn nounwind
declare void @abort() local_unnamed_addr #4

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

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

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

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

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 = { noreturn 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 = { "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 = { 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 #6 = { nocallback nofree nounwind willreturn memory(argmem: write) }
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 = !{!"double", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}


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