; LLVM IR from libxsmm/libxsmm :: src (libxsmm_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"

%struct.libxsmm_barrier = type { ptr, ptr, i32, i32, i32, i32, i32, i8 }

; Function Attrs: nounwind uwtable
define dso_local ptr @libxsmm_barrier_create(i32 noundef %0, i32 noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  store i32 %0, ptr %3, align 4, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #5
  %6 = call noalias ptr @malloc(i64 noundef 40) #6
  store ptr %6, ptr %5, align 8, !tbaa !9
  %7 = load ptr, ptr %5, align 8, !tbaa !9
  %8 = icmp ne ptr null, %7
  br i1 %8, label %9, label %69

9:                                                ; preds = %2
  %10 = load i32, ptr %3, align 4, !tbaa !5
  %11 = icmp slt i32 1, %10
  br i1 %11, label %12, label %69

12:                                               ; preds = %9
  %13 = load i32, ptr %4, align 4, !tbaa !5
  %14 = icmp sle i32 1, %13
  br i1 %14, label %15, label %69

15:                                               ; preds = %12
  %16 = load i32, ptr %3, align 4, !tbaa !5
  %17 = load ptr, ptr %5, align 8, !tbaa !9
  %18 = getelementptr inbounds %struct.libxsmm_barrier, ptr %17, i32 0, i32 2
  store i32 %16, ptr %18, align 8, !tbaa !11
  %19 = load i32, ptr %3, align 4, !tbaa !5
  %20 = icmp ne i32 0, %19
  %21 = zext i1 %20 to i32
  %22 = load i32, ptr %3, align 4, !tbaa !5
  %23 = sext i32 %22 to i64
  %24 = call i64 @llvm.ctlz.i64(i64 %23, i1 true)
  %25 = trunc i64 %24 to i32
  %26 = sub nsw i32 63, %25
  %27 = mul nsw i32 %21, %26
  %28 = load i32, ptr %3, align 4, !tbaa !5
  %29 = icmp slt i32 1, %28
  br i1 %29, label %30, label %31

30:                                               ; preds = %15
  br label %33

31:                                               ; preds = %15
  %32 = load i32, ptr %3, align 4, !tbaa !5
  br label %33

33:                                               ; preds = %31, %30
  %34 = phi i32 [ 1, %30 ], [ %32, %31 ]
  %35 = add nsw i32 %27, %34
  %36 = load ptr, ptr %5, align 8, !tbaa !9
  %37 = getelementptr inbounds %struct.libxsmm_barrier, ptr %36, i32 0, i32 5
  store i32 %35, ptr %37, align 4, !tbaa !13
  %38 = load i32, ptr %4, align 4, !tbaa !5
  %39 = load ptr, ptr %5, align 8, !tbaa !9
  %40 = getelementptr inbounds %struct.libxsmm_barrier, ptr %39, i32 0, i32 3
  store i32 %38, ptr %40, align 4, !tbaa !14
  %41 = load i32, ptr %3, align 4, !tbaa !5
  %42 = load i32, ptr %4, align 4, !tbaa !5
  %43 = mul nsw i32 %41, %42
  %44 = load ptr, ptr %5, align 8, !tbaa !9
  %45 = getelementptr inbounds %struct.libxsmm_barrier, ptr %44, i32 0, i32 4
  store i32 %43, ptr %45, align 8, !tbaa !15
  %46 = load ptr, ptr %5, align 8, !tbaa !9
  %47 = getelementptr inbounds %struct.libxsmm_barrier, ptr %46, i32 0, i32 4
  %48 = load i32, ptr %47, align 8, !tbaa !15
  %49 = sext i32 %48 to i64
  %50 = mul i64 %49, 8
  %51 = call noalias ptr @libxsmm_aligned_malloc(i64 noundef %50, i64 noundef 64)
  %52 = load ptr, ptr %5, align 8, !tbaa !9
  %53 = getelementptr inbounds %struct.libxsmm_barrier, ptr %52, i32 0, i32 1
  store ptr %51, ptr %53, align 8, !tbaa !16
  %54 = load ptr, ptr %5, align 8, !tbaa !9
  %55 = getelementptr inbounds %struct.libxsmm_barrier, ptr %54, i32 0, i32 2
  %56 = load i32, ptr %55, align 8, !tbaa !11
  %57 = sext i32 %56 to i64
  %58 = mul i64 %57, 8
  %59 = call noalias ptr @libxsmm_aligned_malloc(i64 noundef %58, i64 noundef 64)
  %60 = load ptr, ptr %5, align 8, !tbaa !9
  %61 = getelementptr inbounds %struct.libxsmm_barrier, ptr %60, i32 0, i32 0
  store ptr %59, ptr %61, align 8, !tbaa !17
  %62 = load ptr, ptr %5, align 8, !tbaa !9
  %63 = getelementptr inbounds %struct.libxsmm_barrier, ptr %62, i32 0, i32 4
  %64 = load i32, ptr %63, align 8, !tbaa !15
  %65 = load ptr, ptr %5, align 8, !tbaa !9
  %66 = getelementptr inbounds %struct.libxsmm_barrier, ptr %65, i32 0, i32 6
  store volatile i32 %64, ptr %66, align 8, !tbaa !18
  %67 = load ptr, ptr %5, align 8, !tbaa !9
  %68 = getelementptr inbounds %struct.libxsmm_barrier, ptr %67, i32 0, i32 7
  store volatile i8 0, ptr %68, align 4, !tbaa !19
  br label %76

69:                                               ; preds = %12, %9, %2
  %70 = load ptr, ptr %5, align 8, !tbaa !9
  %71 = icmp ne ptr null, %70
  br i1 %71, label %72, label %75

72:                                               ; preds = %69
  %73 = load ptr, ptr %5, align 8, !tbaa !9
  %74 = getelementptr inbounds %struct.libxsmm_barrier, ptr %73, i32 0, i32 4
  store i32 1, ptr %74, align 8, !tbaa !15
  br label %75

75:                                               ; preds = %72, %69
  br label %76

76:                                               ; preds = %75, %33
  %77 = load ptr, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #5
  ret ptr %77
}

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

; Function Attrs: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #2

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.ctlz.i64(i64, i1 immarg) #3

declare noalias ptr @libxsmm_aligned_malloc(i64 noundef, i64 noundef) #4

; 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 = { nounwind allocsize(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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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 = { nounwind }
attributes #6 = { nounwind allocsize(0) }

!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, !6, i64 16}
!12 = !{!"libxsmm_barrier", !10, i64 0, !10, i64 8, !6, i64 16, !6, i64 20, !6, i64 24, !6, i64 28, !6, i64 32, !7, i64 36}
!13 = !{!12, !6, i64 28}
!14 = !{!12, !6, i64 20}
!15 = !{!12, !6, i64 24}
!16 = !{!12, !10, i64 8}
!17 = !{!12, !10, i64 0}
!18 = !{!12, !6, i64 32}
!19 = !{!12, !7, i64 36}


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

; Function Attrs: nounwind uwtable
define dso_local noundef ptr @libxsmm_barrier_create(i32 noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = tail call noalias dereferenceable_or_null(40) ptr @malloc(i64 noundef 40) #4
  %4 = icmp ne ptr %3, null
  %5 = icmp sgt i32 %0, 1
  %6 = icmp sgt i32 %1, 0
  %7 = and i1 %5, %6
  %or.cond3 = and i1 %7, %4
  br i1 %or.cond3, label %8, label %25

8:                                                ; preds = %2
  %9 = getelementptr inbounds i8, ptr %3, i64 16
  store i32 %0, ptr %9, align 8, !tbaa !5
  %10 = tail call range(i32 1, 33) i32 @llvm.ctlz.i32(i32 %0, i1 true)
  %11 = sub nuw nsw i32 32, %10
  %12 = getelementptr inbounds i8, ptr %3, i64 28
  store i32 %11, ptr %12, align 4, !tbaa !11
  %13 = getelementptr inbounds i8, ptr %3, i64 20
  store i32 %1, ptr %13, align 4, !tbaa !12
  %14 = mul nuw nsw i32 %1, %0
  %15 = getelementptr inbounds i8, ptr %3, i64 24
  store i32 %14, ptr %15, align 8, !tbaa !13
  %16 = zext nneg i32 %14 to i64
  %17 = shl nuw nsw i64 %16, 3
  %18 = tail call noalias ptr @libxsmm_aligned_malloc(i64 noundef %17, i64 noundef 64) #5
  %19 = getelementptr inbounds i8, ptr %3, i64 8
  store ptr %18, ptr %19, align 8, !tbaa !14
  %20 = zext nneg i32 %0 to i64
  %21 = shl nuw nsw i64 %20, 3
  %22 = tail call noalias ptr @libxsmm_aligned_malloc(i64 noundef %21, i64 noundef 64) #5
  store ptr %22, ptr %3, align 8, !tbaa !15
  %23 = getelementptr inbounds i8, ptr %3, i64 32
  store volatile i32 %14, ptr %23, align 8, !tbaa !16
  %24 = getelementptr inbounds i8, ptr %3, i64 36
  store volatile i8 0, ptr %24, align 4, !tbaa !17
  br label %28

25:                                               ; preds = %2
  br i1 %4, label %26, label %28

26:                                               ; preds = %25
  %27 = getelementptr inbounds i8, ptr %3, i64 24
  store i32 1, ptr %27, align 8, !tbaa !13
  br label %28

28:                                               ; preds = %25, %26, %8
  ret ptr %3
}

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #1

declare noalias ptr @libxsmm_aligned_malloc(i64 noundef, i64 noundef) local_unnamed_addr #2

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.ctlz.i32(i32, i1 immarg) #3

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 nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" "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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #4 = { nounwind allocsize(0) }
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, !10, i64 16}
!6 = !{!"libxsmm_barrier", !7, i64 0, !7, i64 8, !10, i64 16, !10, i64 20, !10, i64 24, !10, i64 28, !10, i64 32, !8, i64 36}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!6, !10, i64 28}
!12 = !{!6, !10, i64 20}
!13 = !{!6, !10, i64 24}
!14 = !{!6, !7, i64 8}
!15 = !{!6, !7, i64 0}
!16 = !{!6, !10, i64 32}
!17 = !{!6, !8, i64 36}


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