; LLVM IR from libxsmm/libxsmm :: src (libxsmm_malloc)

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

@.str.1 = external hidden unnamed_addr constant [70 x i8], align 1
@libxsmm_verbosity = external global i32, align 4
@stderr = external global ptr, align 8
@libxsmm_se = external global i32, align 4
@.str.65 = external hidden unnamed_addr constant [63 x i8], align 1
@__PRETTY_FUNCTION__.libxsmm_malloc_xattrib = external hidden unnamed_addr constant [48 x i8], align 1
@libxsmm_malloc_xattrib.error_once = external hidden global i32, align 4
@.str.66 = external hidden unnamed_addr constant [57 x i8], align 1
@.str.67 = external hidden unnamed_addr constant [59 x i8], align 1

; 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: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #1

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

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

12:                                               ; preds = %3
  %13 = load ptr, ptr %4, align 8, !tbaa !5
  %14 = icmp ne ptr inttoptr (i64 -1 to ptr), %13
  br i1 %14, label %18, label %15

15:                                               ; preds = %12, %3
  %16 = load i64, ptr %6, align 8, !tbaa !11
  %17 = icmp eq i64 0, %16
  br i1 %17, label %18, label %19

18:                                               ; preds = %15, %12
  br label %20

19:                                               ; preds = %15
  call void @__assert_fail(ptr noundef @.str.65, ptr noundef @.str.1, i32 noundef 2196, ptr noundef @__PRETTY_FUNCTION__.libxsmm_malloc_xattrib) #5
  unreachable

20:                                               ; preds = %18
  %21 = load i32, ptr %5, align 4, !tbaa !9
  %22 = and i32 128, %21
  %23 = icmp eq i32 0, %22
  br i1 %23, label %28, label %24

24:                                               ; preds = %20
  %25 = load i32, ptr %5, align 4, !tbaa !9
  %26 = and i32 256, %25
  %27 = icmp ne i32 0, %26
  br i1 %27, label %28, label %75

28:                                               ; preds = %24, %20
  %29 = load i32, ptr %5, align 4, !tbaa !9
  %30 = and i32 256, %29
  %31 = icmp eq i32 0, %30
  br i1 %31, label %32, label %37

32:                                               ; preds = %28
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  %33 = load ptr, ptr %4, align 8, !tbaa !5
  %34 = load i64, ptr %6, align 8, !tbaa !11
  %35 = call i32 @mprotect(ptr noundef %33, i64 noundef %34, i32 noundef 1) #4
  store i32 %35, ptr %8, align 4, !tbaa !9
  %36 = load i32, ptr %8, align 4, !tbaa !9
  store i32 %36, ptr %7, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  br label %74

37:                                               ; preds = %28
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  %38 = load ptr, ptr %4, align 8, !tbaa !5
  %39 = load i64, ptr %6, align 8, !tbaa !11
  %40 = call i32 @mprotect(ptr noundef %38, i64 noundef %39, i32 noundef 5) #4
  store i32 %40, ptr %9, align 4, !tbaa !9
  %41 = load i32, ptr %9, align 4, !tbaa !9
  %42 = icmp ne i32 0, %41
  br i1 %42, label %43, label %73

43:                                               ; preds = %37
  %44 = load i32, ptr @libxsmm_se, align 4, !tbaa !9
  %45 = icmp ne i32 0, %44
  br i1 %45, label %46, label %58

46:                                               ; preds = %43
  %47 = load i32, ptr @libxsmm_verbosity, align 4, !tbaa !9
  %48 = icmp ne i32 0, %47
  br i1 %48, label %49, label %56

49:                                               ; preds = %46
  %50 = atomicrmw add ptr @libxsmm_malloc_xattrib.error_once, i32 1 seq_cst, align 4
  %51 = add i32 %50, 1
  %52 = icmp eq i32 1, %51
  br i1 %52, label %53, label %56

53:                                               ; preds = %49
  %54 = load ptr, ptr @stderr, align 8, !tbaa !5
  %55 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %54, ptr noundef @.str.66) #4
  br label %56

56:                                               ; preds = %53, %49, %46
  %57 = load i32, ptr %9, align 4, !tbaa !9
  store i32 %57, ptr %7, align 4, !tbaa !9
  br label %72

58:                                               ; preds = %43
  %59 = load i32, ptr @libxsmm_verbosity, align 4, !tbaa !9
  %60 = icmp sle i32 3, %59
  br i1 %60, label %64, label %61

61:                                               ; preds = %58
  %62 = load i32, ptr @libxsmm_verbosity, align 4, !tbaa !9
  %63 = icmp sgt i32 0, %62
  br i1 %63, label %64, label %71

64:                                               ; preds = %61, %58
  %65 = atomicrmw add ptr @libxsmm_malloc_xattrib.error_once, i32 1 seq_cst, align 4
  %66 = add i32 %65, 1
  %67 = icmp eq i32 1, %66
  br i1 %67, label %68, label %71

68:                                               ; preds = %64
  %69 = load ptr, ptr @stderr, align 8, !tbaa !5
  %70 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %69, ptr noundef @.str.67) #4
  br label %71

71:                                               ; preds = %68, %64, %61
  br label %72

72:                                               ; preds = %71, %56
  br label %73

73:                                               ; preds = %72, %37
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  br label %74

74:                                               ; preds = %73, %32
  br label %75

75:                                               ; preds = %74, %24
  %76 = load i32, ptr %7, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  ret i32 %76
}

; Function Attrs: nounwind
declare i32 @mprotect(ptr noundef, i64 noundef, i32 noundef) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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 = { 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 }
attributes #5 = { 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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !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"

@.str.1 = external hidden unnamed_addr constant [70 x i8], align 1
@libxsmm_verbosity = external local_unnamed_addr global i32, align 4
@stderr = external local_unnamed_addr global ptr, align 8
@libxsmm_se = external local_unnamed_addr global i32, align 4
@.str.65 = external hidden unnamed_addr constant [63 x i8], align 1
@__PRETTY_FUNCTION__.libxsmm_malloc_xattrib = external hidden unnamed_addr constant [48 x i8], align 1
@libxsmm_malloc_xattrib.error_once = external hidden global i32, align 4
@.str.66 = external hidden unnamed_addr constant [57 x i8], align 1
@.str.67 = external hidden unnamed_addr constant [59 x i8], align 1

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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @libxsmm_malloc_xattrib(ptr noundef %0, i32 noundef %1, i64 noundef %2) local_unnamed_addr #2 {
  %4 = icmp ne ptr %0, null
  %5 = icmp ne ptr %0, inttoptr (i64 -1 to ptr)
  %or.cond = and i1 %4, %5
  %6 = icmp eq i64 %2, 0
  %or.cond3 = or i1 %or.cond, %6
  br i1 %or.cond3, label %8, label %7

7:                                                ; preds = %3
  tail call void @__assert_fail(ptr noundef nonnull @.str.65, ptr noundef nonnull @.str.1, i32 noundef 2196, ptr noundef nonnull @__PRETTY_FUNCTION__.libxsmm_malloc_xattrib) #4
  unreachable

8:                                                ; preds = %3
  %9 = and i32 %1, 384
  %or.cond22 = icmp eq i32 %9, 128
  br i1 %or.cond22, label %33, label %10

10:                                               ; preds = %8
  %11 = and i32 %1, 256
  %.not = icmp eq i32 %11, 0
  br i1 %.not, label %12, label %14

12:                                               ; preds = %10
  %13 = tail call i32 @mprotect(ptr noundef %0, i64 noundef %2, i32 noundef 1) #5
  br label %33

14:                                               ; preds = %10
  %15 = tail call i32 @mprotect(ptr noundef %0, i64 noundef %2, i32 noundef 5) #5
  %.not19 = icmp eq i32 %15, 0
  br i1 %.not19, label %33, label %16

16:                                               ; preds = %14
  %17 = load i32, ptr @libxsmm_se, align 4, !tbaa !5
  %.not20 = icmp eq i32 %17, 0
  %18 = load i32, ptr @libxsmm_verbosity, align 4
  br i1 %.not20, label %26, label %19

19:                                               ; preds = %16
  %.not21 = icmp eq i32 %18, 0
  br i1 %.not21, label %33, label %20

20:                                               ; preds = %19
  %21 = atomicrmw add ptr @libxsmm_malloc_xattrib.error_once, i32 1 seq_cst, align 4
  %22 = icmp eq i32 %21, 0
  br i1 %22, label %23, label %33

23:                                               ; preds = %20
  %24 = load ptr, ptr @stderr, align 8, !tbaa !9
  %25 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %24, ptr noundef nonnull @.str.66) #6
  br label %33

26:                                               ; preds = %16
  %or.cond5 = icmp ugt i32 %18, 2
  br i1 %or.cond5, label %27, label %33

27:                                               ; preds = %26
  %28 = atomicrmw add ptr @libxsmm_malloc_xattrib.error_once, i32 1 seq_cst, align 4
  %29 = icmp eq i32 %28, 0
  br i1 %29, label %30, label %33

30:                                               ; preds = %27
  %31 = load ptr, ptr @stderr, align 8, !tbaa !9
  %32 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %31, ptr noundef nonnull @.str.67) #6
  br label %33

33:                                               ; preds = %14, %27, %30, %26, %23, %20, %19, %8, %12
  %.1 = phi i32 [ %13, %12 ], [ 0, %8 ], [ 0, %30 ], [ 0, %27 ], [ 0, %26 ], [ 0, %14 ], [ %15, %23 ], [ %15, %20 ], [ %15, %19 ]
  ret i32 %.1
}

; Function Attrs: nounwind
declare i32 @mprotect(ptr noundef, i64 noundef, i32 noundef) local_unnamed_addr #3

attributes #0 = { 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 #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 = { 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 = { 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 = { noreturn nounwind }
attributes #5 = { nounwind }
attributes #6 = { cold 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}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,SROAPass,SimplifyCFGPass,TailCallElimPass