; LLVM IR from libxsmm/libxsmm :: samples/utilities/sync (sync_barrier)

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

@stderr = external global ptr, align 8
@.str = external hidden unnamed_addr constant [55 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [19 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [87 x i8], align 1
@__PRETTY_FUNCTION__.main = external hidden unnamed_addr constant [23 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [16 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [50 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 i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i64, align 8
  %11 = alloca ptr, align 8
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  %15 = alloca i32, align 4
  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
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #7
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #7
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #7
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #7
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #7
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #7
  %16 = load i32, ptr %4, align 4, !tbaa !5
  %17 = icmp slt i32 4, %16
  br i1 %17, label %18, label %24

18:                                               ; preds = %2
  %19 = load ptr, ptr @stderr, align 8, !tbaa !9
  %20 = load ptr, ptr %5, align 8, !tbaa !9
  %21 = getelementptr inbounds ptr, ptr %20, i64 0
  %22 = load ptr, ptr %21, align 8, !tbaa !9
  %23 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %19, ptr noundef @.str, ptr noundef %22) #7
  store i32 0, ptr %3, align 4
  store i32 1, ptr %12, align 4
  br label %72

24:                                               ; preds = %2
  store i32 1, ptr %7, align 4, !tbaa !5
  store i32 1, ptr %6, align 4, !tbaa !5
  %25 = load i32, ptr %4, align 4, !tbaa !5
  %26 = icmp slt i32 3, %25
  br i1 %26, label %27, label %32

27:                                               ; preds = %24
  %28 = load ptr, ptr %5, align 8, !tbaa !9
  %29 = getelementptr inbounds ptr, ptr %28, i64 3
  %30 = load ptr, ptr %29, align 8, !tbaa !9
  %31 = call i32 @atoi(ptr noundef %30) #8
  br label %33

32:                                               ; preds = %24
  br label %33

33:                                               ; preds = %32, %27
  %34 = phi i32 [ %31, %27 ], [ 50000, %32 ]
  store i32 %34, ptr %9, align 4, !tbaa !5
  %35 = load i32, ptr %9, align 4, !tbaa !5
  %36 = icmp sgt i32 %35, 0
  br i1 %36, label %37, label %38

37:                                               ; preds = %33
  br label %39

38:                                               ; preds = %33
  call void @__assert_fail(ptr noundef @.str.1, ptr noundef @.str.2, i32 noundef 41, ptr noundef @__PRETTY_FUNCTION__.main) #9
  unreachable

39:                                               ; preds = %37
  %40 = load i32, ptr %6, align 4, !tbaa !5
  %41 = load i32, ptr %7, align 4, !tbaa !5
  %42 = call ptr @libxsmm_barrier_create(i32 noundef %40, i32 noundef %41)
  store ptr %42, ptr %11, align 8, !tbaa !9
  %43 = load ptr, ptr %11, align 8, !tbaa !9
  %44 = icmp ne ptr null, %43
  br i1 %44, label %45, label %46

45:                                               ; preds = %39
  br label %47

46:                                               ; preds = %39
  call void @__assert_fail(ptr noundef @.str.3, ptr noundef @.str.2, i32 noundef 45, ptr noundef @__PRETTY_FUNCTION__.main) #9
  unreachable

47:                                               ; preds = %45
  %48 = load i32, ptr %6, align 4, !tbaa !5
  %49 = load i32, ptr %7, align 4, !tbaa !5
  %50 = mul nsw i32 %48, %49
  store i32 %50, ptr %8, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #7
  store i32 0, ptr %13, align 4, !tbaa !5
  %51 = load ptr, ptr %11, align 8, !tbaa !9
  call void @libxsmm_barrier_init(ptr noundef %51, i32 noundef 0)
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #7
  %52 = call i64 @libxsmm_timer_tick()
  store i64 %52, ptr %10, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #7
  store i32 0, ptr %14, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #7
  store i32 0, ptr %15, align 4, !tbaa !5
  br label %53

53:                                               ; preds = %59, %47
  %54 = load i32, ptr %15, align 4, !tbaa !5
  %55 = load i32, ptr %9, align 4, !tbaa !5
  %56 = icmp slt i32 %54, %55
  br i1 %56, label %57, label %62

57:                                               ; preds = %53
  %58 = load ptr, ptr %11, align 8, !tbaa !9
  call void @libxsmm_barrier_wait(ptr noundef %58, i32 noundef 0)
  br label %59

59:                                               ; preds = %57
  %60 = load i32, ptr %15, align 4, !tbaa !5
  %61 = add nsw i32 %60, 1
  store i32 %61, ptr %15, align 4, !tbaa !5
  br label %53, !llvm.loop !13

62:                                               ; preds = %53
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #7
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #7
  %63 = load i64, ptr %10, align 8, !tbaa !11
  %64 = call i64 @libxsmm_timer_tick()
  %65 = call i64 @libxsmm_timer_ncycles(i64 noundef %63, i64 noundef %64)
  %66 = load i32, ptr %9, align 4, !tbaa !5
  %67 = sext i32 %66 to i64
  %68 = udiv i64 %65, %67
  %69 = load i32, ptr %8, align 4, !tbaa !5
  %70 = call i32 (ptr, ...) @printf(ptr noundef @.str.4, i64 noundef %68, i32 noundef %69)
  %71 = load ptr, ptr %11, align 8, !tbaa !9
  call void @libxsmm_barrier_destroy(ptr noundef %71)
  store i32 0, ptr %3, align 4
  store i32 1, ptr %12, align 4
  br label %72

72:                                               ; preds = %62, %18
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #7
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #7
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #7
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #7
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #7
  %73 = load i32, ptr %3, align 4
  ret i32 %73
}

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

; Function Attrs: nounwind
declare i32 @fprintf(ptr noundef, ptr noundef, ...) #2

; Function Attrs: inlinehint nounwind willreturn memory(read) uwtable
declare i32 @atoi(ptr noundef nonnull) #3

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

declare ptr @libxsmm_barrier_create(i32 noundef, i32 noundef) #5

declare void @libxsmm_barrier_init(ptr noundef, i32 noundef) #5

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

declare i64 @libxsmm_timer_tick() #5

declare void @libxsmm_barrier_wait(ptr noundef, i32 noundef) #5

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden i64 @libxsmm_timer_ncycles(i64 noundef, i64 noundef) #6

declare void @libxsmm_barrier_destroy(ptr noundef) #5

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 = { 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 #3 = { inlinehint nounwind willreturn memory(read) 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 = { "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 = { 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 #7 = { nounwind }
attributes #8 = { nounwind willreturn memory(read) }
attributes #9 = { 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 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long long", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"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"

@stderr = external local_unnamed_addr global ptr, align 8
@.str = external hidden unnamed_addr constant [55 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [19 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [87 x i8], align 1
@__PRETTY_FUNCTION__.main = external hidden unnamed_addr constant [23 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [16 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [50 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @main(i32 noundef %0, ptr nocapture noundef readonly %1) local_unnamed_addr #0 {
  %3 = icmp sgt i32 %0, 4
  br i1 %3, label %4, label %8

4:                                                ; preds = %2
  %5 = load ptr, ptr @stderr, align 8, !tbaa !5
  %6 = load ptr, ptr %1, align 8, !tbaa !5
  %7 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %5, ptr noundef nonnull @.str, ptr noundef %6) #6
  br label %29

8:                                                ; preds = %2
  %9 = icmp eq i32 %0, 4
  br i1 %9, label %10, label %.thread

10:                                               ; preds = %8
  %11 = getelementptr inbounds i8, ptr %1, i64 24
  %12 = load ptr, ptr %11, align 8, !tbaa !5
  %13 = tail call i32 @atoi(ptr nocapture noundef %12) #7
  %14 = icmp sgt i32 %13, 0
  br i1 %14, label %.thread, label %15

15:                                               ; preds = %10
  tail call void @__assert_fail(ptr noundef nonnull @.str.1, ptr noundef nonnull @.str.2, i32 noundef 41, ptr noundef nonnull @__PRETTY_FUNCTION__.main) #8
  unreachable

.thread:                                          ; preds = %8, %10
  %16 = phi i32 [ %13, %10 ], [ 50000, %8 ]
  %17 = tail call ptr @libxsmm_barrier_create(i32 noundef 1, i32 noundef 1) #9
  %.not = icmp eq ptr %17, null
  br i1 %.not, label %18, label %19

18:                                               ; preds = %.thread
  tail call void @__assert_fail(ptr noundef nonnull @.str.3, ptr noundef nonnull @.str.2, i32 noundef 45, ptr noundef nonnull @__PRETTY_FUNCTION__.main) #8
  unreachable

19:                                               ; preds = %.thread
  tail call void @libxsmm_barrier_init(ptr noundef nonnull %17, i32 noundef 0) #9
  %20 = tail call i64 @libxsmm_timer_tick() #9
  br label %21

21:                                               ; preds = %19, %21
  %.023 = phi i32 [ 0, %19 ], [ %22, %21 ]
  tail call void @libxsmm_barrier_wait(ptr noundef nonnull %17, i32 noundef 0) #9
  %22 = add nuw nsw i32 %.023, 1
  %exitcond.not = icmp eq i32 %22, %16
  br i1 %exitcond.not, label %23, label %21, !llvm.loop !9

23:                                               ; preds = %21
  %24 = tail call i64 @libxsmm_timer_tick() #9
  %25 = tail call i64 @libxsmm_timer_ncycles(i64 noundef %20, i64 noundef %24)
  %26 = zext nneg i32 %16 to i64
  %27 = udiv i64 %25, %26
  %28 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.4, i64 noundef %27, i32 noundef 1)
  tail call void @libxsmm_barrier_destroy(ptr noundef nonnull %17) #9
  br label %29

29:                                               ; preds = %23, %4
  ret i32 0
}

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

; Function Attrs: inlinehint mustprogress nofree nounwind willreturn memory(read) uwtable
declare i32 @atoi(ptr nocapture noundef nonnull) local_unnamed_addr #2

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

declare ptr @libxsmm_barrier_create(i32 noundef, i32 noundef) local_unnamed_addr #4

declare void @libxsmm_barrier_init(ptr noundef, i32 noundef) local_unnamed_addr #4

declare i64 @libxsmm_timer_tick() local_unnamed_addr #4

declare void @libxsmm_barrier_wait(ptr noundef, i32 noundef) local_unnamed_addr #4

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

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

declare void @libxsmm_barrier_destroy(ptr noundef) local_unnamed_addr #4

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 = { 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 #2 = { inlinehint mustprogress nofree nounwind willreturn memory(read) 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 = { "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 = { cold nounwind }
attributes #7 = { nounwind willreturn memory(read) }
attributes #8 = { noreturn nounwind }
attributes #9 = { 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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass