; 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 }
%struct.internal_sync_core_tag = type { i8, i8, ptr, [2 x ptr], [2 x ptr], i8, i8 }

; 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
define dso_local void @libxsmm_barrier_destroy(ptr noundef %0) #1 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  %5 = load ptr, ptr %2, align 8, !tbaa !5
  %6 = icmp ne ptr null, %5
  br i1 %6, label %7, label %103

7:                                                ; preds = %1
  %8 = load ptr, ptr %2, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct.libxsmm_barrier, ptr %8, i32 0, i32 4
  %10 = load i32, ptr %9, align 8, !tbaa !9
  %11 = icmp slt i32 1, %10
  br i1 %11, label %12, label %103

12:                                               ; preds = %7
  %13 = load ptr, ptr %2, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.libxsmm_barrier, ptr %13, i32 0, i32 7
  %15 = load volatile i8, ptr %14, align 4, !tbaa !12
  %16 = zext i8 %15 to i32
  %17 = icmp eq i32 2, %16
  br i1 %17, label %18, label %96

18:                                               ; preds = %12
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #4
  store i32 0, ptr %3, align 4, !tbaa !13
  br label %19

19:                                               ; preds = %74, %18
  %20 = load i32, ptr %3, align 4, !tbaa !13
  %21 = load ptr, ptr %2, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.libxsmm_barrier, ptr %21, i32 0, i32 2
  %23 = load i32, ptr %22, align 8, !tbaa !14
  %24 = icmp slt i32 %20, %23
  br i1 %24, label %25, label %77

25:                                               ; preds = %19
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  %26 = load ptr, ptr %2, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.libxsmm_barrier, ptr %26, i32 0, i32 0
  %28 = load ptr, ptr %27, align 8, !tbaa !15
  %29 = load i32, ptr %3, align 4, !tbaa !13
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds ptr, ptr %28, i64 %30
  %32 = load ptr, ptr %31, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.internal_sync_core_tag, ptr %32, i32 0, i32 2
  %34 = load ptr, ptr %33, align 8, !tbaa !16
  call void @libxsmm_free(ptr noundef %34)
  store i32 0, ptr %4, align 4, !tbaa !13
  br label %35

35:                                               ; preds = %63, %25
  %36 = load i32, ptr %4, align 4, !tbaa !13
  %37 = icmp slt i32 %36, 2
  br i1 %37, label %38, label %66

38:                                               ; preds = %35
  %39 = load ptr, ptr %2, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.libxsmm_barrier, ptr %39, i32 0, i32 0
  %41 = load ptr, ptr %40, align 8, !tbaa !15
  %42 = load i32, ptr %3, align 4, !tbaa !13
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds ptr, ptr %41, i64 %43
  %45 = load ptr, ptr %44, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.internal_sync_core_tag, ptr %45, i32 0, i32 3
  %47 = load i32, ptr %4, align 4, !tbaa !13
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds [2 x ptr], ptr %46, i64 0, i64 %48
  %50 = load ptr, ptr %49, align 8, !tbaa !5
  call void @libxsmm_free(ptr noundef %50)
  %51 = load ptr, ptr %2, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.libxsmm_barrier, ptr %51, i32 0, i32 0
  %53 = load ptr, ptr %52, align 8, !tbaa !15
  %54 = load i32, ptr %3, align 4, !tbaa !13
  %55 = sext i32 %54 to i64
  %56 = getelementptr inbounds ptr, ptr %53, i64 %55
  %57 = load ptr, ptr %56, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.internal_sync_core_tag, ptr %57, i32 0, i32 4
  %59 = load i32, ptr %4, align 4, !tbaa !13
  %60 = sext i32 %59 to i64
  %61 = getelementptr inbounds [2 x ptr], ptr %58, i64 0, i64 %60
  %62 = load ptr, ptr %61, align 8, !tbaa !5
  call void @libxsmm_free(ptr noundef %62)
  br label %63

63:                                               ; preds = %38
  %64 = load i32, ptr %4, align 4, !tbaa !13
  %65 = add nsw i32 %64, 1
  store i32 %65, ptr %4, align 4, !tbaa !13
  br label %35, !llvm.loop !18

66:                                               ; preds = %35
  %67 = load ptr, ptr %2, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct.libxsmm_barrier, ptr %67, i32 0, i32 0
  %69 = load ptr, ptr %68, align 8, !tbaa !15
  %70 = load i32, ptr %3, align 4, !tbaa !13
  %71 = sext i32 %70 to i64
  %72 = getelementptr inbounds ptr, ptr %69, i64 %71
  %73 = load ptr, ptr %72, align 8, !tbaa !5
  call void @libxsmm_free(ptr noundef %73)
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #4
  br label %74

74:                                               ; preds = %66
  %75 = load i32, ptr %3, align 4, !tbaa !13
  %76 = add nsw i32 %75, 1
  store i32 %76, ptr %3, align 4, !tbaa !13
  br label %19, !llvm.loop !20

77:                                               ; preds = %19
  store i32 0, ptr %3, align 4, !tbaa !13
  br label %78

78:                                               ; preds = %92, %77
  %79 = load i32, ptr %3, align 4, !tbaa !13
  %80 = load ptr, ptr %2, align 8, !tbaa !5
  %81 = getelementptr inbounds %struct.libxsmm_barrier, ptr %80, i32 0, i32 4
  %82 = load i32, ptr %81, align 8, !tbaa !9
  %83 = icmp slt i32 %79, %82
  br i1 %83, label %84, label %95

84:                                               ; preds = %78
  %85 = load ptr, ptr %2, align 8, !tbaa !5
  %86 = getelementptr inbounds %struct.libxsmm_barrier, ptr %85, i32 0, i32 1
  %87 = load ptr, ptr %86, align 8, !tbaa !21
  %88 = load i32, ptr %3, align 4, !tbaa !13
  %89 = sext i32 %88 to i64
  %90 = getelementptr inbounds ptr, ptr %87, i64 %89
  %91 = load ptr, ptr %90, align 8, !tbaa !5
  call void @libxsmm_free(ptr noundef %91)
  br label %92

92:                                               ; preds = %84
  %93 = load i32, ptr %3, align 4, !tbaa !13
  %94 = add nsw i32 %93, 1
  store i32 %94, ptr %3, align 4, !tbaa !13
  br label %78, !llvm.loop !22

95:                                               ; preds = %78
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #4
  br label %96

96:                                               ; preds = %95, %12
  %97 = load ptr, ptr %2, align 8, !tbaa !5
  %98 = getelementptr inbounds %struct.libxsmm_barrier, ptr %97, i32 0, i32 1
  %99 = load ptr, ptr %98, align 8, !tbaa !21
  call void @libxsmm_free(ptr noundef %99)
  %100 = load ptr, ptr %2, align 8, !tbaa !5
  %101 = getelementptr inbounds %struct.libxsmm_barrier, ptr %100, i32 0, i32 0
  %102 = load ptr, ptr %101, align 8, !tbaa !15
  call void @libxsmm_free(ptr noundef %102)
  br label %103

103:                                              ; preds = %96, %7, %1
  %104 = load ptr, ptr %2, align 8, !tbaa !5
  call void @free(ptr noundef %104) #4
  ret void
}

declare void @libxsmm_free(ptr noundef) #2

; Function Attrs: nounwind
declare void @free(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 = { "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 = { 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 = { 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 = !{!10, !11, i64 24}
!10 = !{!"libxsmm_barrier", !6, i64 0, !6, i64 8, !11, i64 16, !11, i64 20, !11, i64 24, !11, i64 28, !11, i64 32, !7, i64 36}
!11 = !{!"int", !7, i64 0}
!12 = !{!10, !7, i64 36}
!13 = !{!11, !11, i64 0}
!14 = !{!10, !11, i64 16}
!15 = !{!10, !6, i64 0}
!16 = !{!17, !6, i64 8}
!17 = !{!"internal_sync_core_tag", !7, i64 0, !7, i64 1, !6, i64 8, !7, i64 16, !7, i64 32, !7, i64 48, !7, i64 49}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}
!20 = distinct !{!20, !19}
!21 = !{!10, !6, i64 8}
!22 = distinct !{!22, !19}


; 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 void @libxsmm_barrier_destroy(ptr noundef %0) local_unnamed_addr #0 {
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %56, label %2

2:                                                ; preds = %1
  %3 = getelementptr inbounds i8, ptr %0, i64 24
  %4 = load i32, ptr %3, align 8, !tbaa !5
  %5 = icmp sgt i32 %4, 1
  br i1 %5, label %6, label %56

6:                                                ; preds = %2
  %7 = getelementptr inbounds i8, ptr %0, i64 36
  %8 = load volatile i8, ptr %7, align 4, !tbaa !11
  %9 = icmp eq i8 %8, 2
  br i1 %9, label %.preheader27, label %.loopexit

.preheader27:                                     ; preds = %6
  %10 = getelementptr inbounds i8, ptr %0, i64 16
  %11 = load i32, ptr %10, align 8, !tbaa !12
  %12 = icmp sgt i32 %11, 0
  br i1 %12, label %.lr.ph, label %.lr.ph31

.preheader:                                       ; preds = %.lr.ph
  %.pre = load i32, ptr %3, align 8, !tbaa !5
  %13 = icmp sgt i32 %.pre, 0
  br i1 %13, label %.lr.ph31, label %.loopexit

.lr.ph31:                                         ; preds = %.preheader27, %.preheader
  %14 = getelementptr inbounds i8, ptr %0, i64 8
  br label %46

.lr.ph:                                           ; preds = %.preheader27, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 0, %.preheader27 ]
  %15 = load ptr, ptr %0, align 8, !tbaa !13
  %16 = getelementptr inbounds ptr, ptr %15, i64 %indvars.iv
  %17 = load ptr, ptr %16, align 8, !tbaa !14
  %18 = getelementptr inbounds i8, ptr %17, i64 8
  %19 = load ptr, ptr %18, align 8, !tbaa !15
  tail call void @libxsmm_free(ptr noundef %19) #3
  %20 = load ptr, ptr %0, align 8, !tbaa !13
  %21 = getelementptr inbounds ptr, ptr %20, i64 %indvars.iv
  %22 = load ptr, ptr %21, align 8, !tbaa !14
  %23 = getelementptr inbounds i8, ptr %22, i64 16
  %24 = load ptr, ptr %23, align 8, !tbaa !14
  tail call void @libxsmm_free(ptr noundef %24) #3
  %25 = load ptr, ptr %0, align 8, !tbaa !13
  %26 = getelementptr inbounds ptr, ptr %25, i64 %indvars.iv
  %27 = load ptr, ptr %26, align 8, !tbaa !14
  %28 = getelementptr inbounds i8, ptr %27, i64 32
  %29 = load ptr, ptr %28, align 8, !tbaa !14
  tail call void @libxsmm_free(ptr noundef %29) #3
  %30 = load ptr, ptr %0, align 8, !tbaa !13
  %31 = getelementptr inbounds ptr, ptr %30, i64 %indvars.iv
  %32 = load ptr, ptr %31, align 8, !tbaa !14
  %33 = getelementptr inbounds i8, ptr %32, i64 24
  %34 = load ptr, ptr %33, align 8, !tbaa !14
  tail call void @libxsmm_free(ptr noundef %34) #3
  %35 = load ptr, ptr %0, align 8, !tbaa !13
  %36 = getelementptr inbounds ptr, ptr %35, i64 %indvars.iv
  %37 = load ptr, ptr %36, align 8, !tbaa !14
  %38 = getelementptr inbounds i8, ptr %37, i64 40
  %39 = load ptr, ptr %38, align 8, !tbaa !14
  tail call void @libxsmm_free(ptr noundef %39) #3
  %40 = load ptr, ptr %0, align 8, !tbaa !13
  %41 = getelementptr inbounds ptr, ptr %40, i64 %indvars.iv
  %42 = load ptr, ptr %41, align 8, !tbaa !14
  tail call void @libxsmm_free(ptr noundef %42) #3
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %43 = load i32, ptr %10, align 8, !tbaa !12
  %44 = sext i32 %43 to i64
  %45 = icmp slt i64 %indvars.iv.next, %44
  br i1 %45, label %.lr.ph, label %.preheader, !llvm.loop !17

46:                                               ; preds = %.lr.ph31, %46
  %indvars.iv34 = phi i64 [ 0, %.lr.ph31 ], [ %indvars.iv.next35, %46 ]
  %47 = load ptr, ptr %14, align 8, !tbaa !19
  %48 = getelementptr inbounds ptr, ptr %47, i64 %indvars.iv34
  %49 = load ptr, ptr %48, align 8, !tbaa !14
  tail call void @libxsmm_free(ptr noundef %49) #3
  %indvars.iv.next35 = add nuw nsw i64 %indvars.iv34, 1
  %50 = load i32, ptr %3, align 8, !tbaa !5
  %51 = sext i32 %50 to i64
  %52 = icmp slt i64 %indvars.iv.next35, %51
  br i1 %52, label %46, label %.loopexit, !llvm.loop !20

.loopexit:                                        ; preds = %46, %.preheader, %6
  %53 = getelementptr inbounds i8, ptr %0, i64 8
  %54 = load ptr, ptr %53, align 8, !tbaa !19
  tail call void @libxsmm_free(ptr noundef %54) #3
  %55 = load ptr, ptr %0, align 8, !tbaa !13
  tail call void @libxsmm_free(ptr noundef %55) #3
  br label %56

56:                                               ; preds = %.loopexit, %2, %1
  tail call void @free(ptr noundef %0) #3
  ret void
}

declare void @libxsmm_free(ptr noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #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 = { "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 = { mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, 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 #3 = { 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 24}
!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, !8, i64 36}
!12 = !{!6, !10, i64 16}
!13 = !{!6, !7, i64 0}
!14 = !{!7, !7, i64 0}
!15 = !{!16, !7, i64 8}
!16 = !{!"internal_sync_core_tag", !8, i64 0, !8, i64 1, !7, i64 8, !8, i64 16, !8, i64 32, !8, i64 48, !8, i64 49}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}
!19 = !{!6, !7, i64 8}
!20 = distinct !{!20, !18}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass