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

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

@opt_msg_cnt = external dso_local global i64, align 8
@opt_msg_size = external dso_local global i64, align 8
@.str = external hidden unnamed_addr constant [9 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [21 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [11 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [15 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.6 = 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 i64, align 8
  %7 = alloca i32, align 4
  %8 = alloca %struct.ach_create_attr, align 8
  %9 = alloca %struct.ach_channel, align 8
  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
  %10 = load i32, ptr %4, align 4, !tbaa !5
  %11 = load ptr, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  store i64 0, ptr %6, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  call void @llvm.lifetime.start.p0(i64 128, ptr %8) #4
  call void @ach_create_attr_init(ptr noundef %8)
  %12 = getelementptr inbounds %struct.ach_create_attr, ptr %8, i32 0, i32 0
  %13 = getelementptr inbounds %struct.anon, ptr %12, i32 0, i32 0
  store i32 3, ptr %13, align 8, !tbaa !13
  %14 = call i32 @ach_unlink(ptr noundef @.str)
  store i32 %14, ptr %7, align 4, !tbaa !5
  %15 = load i32, ptr %7, align 4, !tbaa !5
  %16 = call i32 @ach_status_match(i32 noundef %15, i32 noundef 513)
  %17 = icmp ne i32 %16, 0
  br i1 %17, label %20, label %18

18:                                               ; preds = %2
  %19 = load i32, ptr %7, align 4, !tbaa !5
  call void @fail_ach(ptr noundef @.str.1, i32 noundef %19)
  br label %20

20:                                               ; preds = %18, %2
  %21 = load i64, ptr @opt_msg_cnt, align 8, !tbaa !11
  %22 = load i64, ptr @opt_msg_size, align 8, !tbaa !11
  %23 = call i32 @ach_create(ptr noundef @.str, i64 noundef %21, i64 noundef %22, ptr noundef %8)
  call void @check_ach(ptr noundef @.str.2, i32 noundef %23)
  br label %24

24:                                               ; preds = %50, %20
  %25 = load i64, ptr %6, align 8, !tbaa !11
  %26 = add i64 %25, 1
  store i64 %26, ptr %6, align 8, !tbaa !11
  %27 = icmp ult i64 %25, 1000000
  br i1 %27, label %28, label %56

28:                                               ; preds = %24
  %29 = load i64, ptr %6, align 8, !tbaa !11
  %30 = urem i64 %29, 1000
  %31 = icmp eq i64 0, %30
  br i1 %31, label %32, label %35

32:                                               ; preds = %28
  %33 = load i64, ptr %6, align 8, !tbaa !11
  %34 = call i32 (ptr, ...) @printf(ptr noundef @.str.3, i64 noundef %33)
  br label %35

35:                                               ; preds = %32, %28
  call void @llvm.lifetime.start.p0(i64 128, ptr %9) #4
  br label %36

36:                                               ; preds = %49, %41, %35
  %37 = call i32 @usleep(i32 noundef 1000)
  %38 = call i32 @ach_open(ptr noundef %9, ptr noundef @.str, ptr noundef null)
  store i32 %38, ptr %7, align 4, !tbaa !5
  %39 = load i32, ptr %7, align 4, !tbaa !5
  %40 = icmp eq i32 15, %39
  br i1 %40, label %41, label %42

41:                                               ; preds = %36
  br label %36

42:                                               ; preds = %36
  %43 = load i32, ptr %7, align 4, !tbaa !5
  %44 = icmp eq i32 0, %43
  br i1 %44, label %45, label %46

45:                                               ; preds = %42
  br label %50

46:                                               ; preds = %42
  %47 = load i32, ptr %7, align 4, !tbaa !5
  call void @fail_ach(ptr noundef @.str.4, i32 noundef %47)
  br label %48

48:                                               ; preds = %46
  br label %49

49:                                               ; preds = %48
  br label %36

50:                                               ; preds = %45
  %51 = call i32 @ach_close(ptr noundef %9)
  call void @check_ach(ptr noundef @.str.5, i32 noundef %51)
  %52 = call i32 @ach_unlink(ptr noundef @.str)
  call void @check_ach(ptr noundef @.str.6, i32 noundef %52)
  %53 = load i64, ptr @opt_msg_cnt, align 8, !tbaa !11
  %54 = load i64, ptr @opt_msg_size, align 8, !tbaa !11
  %55 = call i32 @ach_create(ptr noundef @.str, i64 noundef %53, i64 noundef %54, ptr noundef %8)
  call void @check_ach(ptr noundef @.str.2, i32 noundef %55)
  call void @llvm.lifetime.end.p0(i64 128, ptr %9) #4
  br label %24, !llvm.loop !14

56:                                               ; preds = %24
  %57 = call i32 @ach_unlink(ptr noundef @.str)
  call void @check_ach(ptr noundef @.str.6, i32 noundef %57)
  call void @llvm.lifetime.end.p0(i64 128, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  ret i32 0
}

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

declare void @ach_create_attr_init(ptr noundef) #2

declare i32 @ach_unlink(ptr noundef) #2

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

declare void @fail_ach(ptr noundef, i32 noundef) #2

declare void @check_ach(ptr noundef, i32 noundef) #2

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

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

declare i32 @usleep(i32 noundef) #2

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

declare i32 @ach_close(ptr noundef) #2

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

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 }

!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 = !{!12, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!7, !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"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_create_attr = type { %union.anon }
%union.anon = type { [16 x i64] }
%struct.ach_channel = type { %union.anon.3 }
%union.anon.3 = type { [16 x i64] }

@opt_msg_cnt = external dso_local local_unnamed_addr global i64, align 8
@opt_msg_size = external dso_local local_unnamed_addr global i64, align 8
@.str = external hidden unnamed_addr constant [9 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [21 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [11 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [15 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [7 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @main(i32 noundef %0, ptr nocapture noundef readnone %1) local_unnamed_addr #0 {
  %3 = alloca %struct.ach_create_attr, align 8
  %4 = alloca %struct.ach_channel, align 8
  call void @llvm.lifetime.start.p0(i64 128, ptr nonnull %3) #5
  call void @ach_create_attr_init(ptr noundef nonnull %3) #5
  store i32 3, ptr %3, align 8, !tbaa !5
  %5 = call i32 @ach_unlink(ptr noundef nonnull @.str) #5
  %6 = call i32 @ach_status_match(i32 noundef %5, i32 noundef 513)
  %.not = icmp eq i32 %6, 0
  br i1 %.not, label %7, label %8

7:                                                ; preds = %2
  call void @fail_ach(ptr noundef nonnull @.str.1, i32 noundef %5) #5
  br label %8

8:                                                ; preds = %7, %2
  %9 = load i64, ptr @opt_msg_cnt, align 8, !tbaa !8
  %10 = load i64, ptr @opt_msg_size, align 8, !tbaa !8
  %11 = call i32 @ach_create(ptr noundef nonnull @.str, i64 noundef %9, i64 noundef %10, ptr noundef nonnull %3) #5
  call void @check_ach(ptr noundef nonnull @.str.2, i32 noundef %11) #5
  br label %12

12:                                               ; preds = %8, %22
  %13 = phi i64 [ 1, %8 ], [ %28, %22 ]
  %.lhs.trunc = trunc nuw i64 %13 to i32
  %14 = urem i32 %.lhs.trunc, 1000
  %15 = icmp eq i32 %14, 0
  br i1 %15, label %16, label %18

16:                                               ; preds = %12
  %17 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3, i64 noundef %13)
  br label %18

18:                                               ; preds = %16, %12
  call void @llvm.lifetime.start.p0(i64 128, ptr nonnull %4) #5
  br label %.backedge

.backedge:                                        ; preds = %.backedge.backedge, %18
  %19 = call i32 @usleep(i32 noundef 1000) #5
  %20 = call i32 @ach_open(ptr noundef nonnull %4, ptr noundef nonnull @.str, ptr noundef null) #5
  switch i32 %20, label %21 [
    i32 15, label %.backedge.backedge
    i32 0, label %22
  ]

21:                                               ; preds = %.backedge
  call void @fail_ach(ptr noundef nonnull @.str.4, i32 noundef %20) #5
  br label %.backedge.backedge

.backedge.backedge:                               ; preds = %21, %.backedge
  br label %.backedge

22:                                               ; preds = %.backedge
  %23 = call i32 @ach_close(ptr noundef nonnull %4) #5
  call void @check_ach(ptr noundef nonnull @.str.5, i32 noundef %23) #5
  %24 = call i32 @ach_unlink(ptr noundef nonnull @.str) #5
  call void @check_ach(ptr noundef nonnull @.str.6, i32 noundef %24) #5
  %25 = load i64, ptr @opt_msg_cnt, align 8, !tbaa !8
  %26 = load i64, ptr @opt_msg_size, align 8, !tbaa !8
  %27 = call i32 @ach_create(ptr noundef nonnull @.str, i64 noundef %25, i64 noundef %26, ptr noundef nonnull %3) #5
  call void @check_ach(ptr noundef nonnull @.str.2, i32 noundef %27) #5
  call void @llvm.lifetime.end.p0(i64 128, ptr nonnull %4) #5
  %28 = add nuw nsw i64 %13, 1
  %exitcond.not = icmp eq i64 %28, 1000001
  br i1 %exitcond.not, label %29, label %12, !llvm.loop !10

29:                                               ; preds = %22
  %30 = call i32 @ach_unlink(ptr noundef nonnull @.str) #5
  call void @check_ach(ptr noundef nonnull @.str.6, i32 noundef %30) #5
  call void @llvm.lifetime.end.p0(i64 128, ptr nonnull %3) #5
  ret i32 0
}

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

declare void @ach_create_attr_init(ptr noundef) local_unnamed_addr #2

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

declare void @fail_ach(ptr noundef, i32 noundef) local_unnamed_addr #2

declare void @check_ach(ptr noundef, i32 noundef) local_unnamed_addr #2

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

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

declare i32 @usleep(i32 noundef) local_unnamed_addr #2

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

declare i32 @ach_close(ptr noundef) local_unnamed_addr #2

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

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 = { 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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = !{!9, !9, i64 0}
!9 = !{!"long", !6, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass