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

; 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 = external hidden unnamed_addr constant [14 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [11 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: nounwind uwtable
define dso_local void @libxsmm_cpuid_model(ptr noundef %0, ptr noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i64, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  %9 = load ptr, ptr %4, align 8, !tbaa !5
  %10 = icmp ne ptr null, %9
  br i1 %10, label %11, label %90

11:                                               ; preds = %2
  %12 = load ptr, ptr %4, align 8, !tbaa !5
  %13 = load i64, ptr %12, align 8, !tbaa !9
  %14 = icmp ne i64 0, %13
  br i1 %14, label %15, label %90

15:                                               ; preds = %11
  %16 = load ptr, ptr %3, align 8, !tbaa !5
  %17 = icmp ne ptr null, %16
  br i1 %17, label %18, label %87

18:                                               ; preds = %15
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #6
  %19 = load ptr, ptr %4, align 8, !tbaa !5
  %20 = load i64, ptr %19, align 8, !tbaa !9
  store i64 %20, ptr %5, align 8, !tbaa !9
  %21 = load ptr, ptr %4, align 8, !tbaa !5
  store i64 0, ptr %21, align 8, !tbaa !9
  %22 = load ptr, ptr %3, align 8, !tbaa !5
  store i8 0, ptr %22, align 1, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #6
  %23 = call noalias ptr @fopen(ptr noundef @.str, ptr noundef @.str.1)
  store ptr %23, ptr %6, align 8, !tbaa !5
  %24 = load ptr, ptr %6, align 8, !tbaa !5
  %25 = icmp ne ptr null, %24
  br i1 %25, label %26, label %86

26:                                               ; preds = %18
  br label %27

27:                                               ; preds = %82, %26
  %28 = load ptr, ptr %3, align 8, !tbaa !5
  %29 = load i64, ptr %5, align 8, !tbaa !9
  %30 = trunc i64 %29 to i32
  %31 = load ptr, ptr %6, align 8, !tbaa !5
  %32 = call ptr @fgets(ptr noundef %28, i32 noundef %30, ptr noundef %31)
  %33 = icmp ne ptr null, %32
  br i1 %33, label %34, label %83

34:                                               ; preds = %27
  %35 = load ptr, ptr %3, align 8, !tbaa !5
  %36 = call i32 @strncmp(ptr noundef @.str.2, ptr noundef %35, i64 noundef 10) #7
  %37 = icmp ne i32 0, %36
  br i1 %37, label %38, label %40

38:                                               ; preds = %34
  %39 = load ptr, ptr %3, align 8, !tbaa !5
  store i8 0, ptr %39, align 1, !tbaa !11
  br label %82

40:                                               ; preds = %34
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #6
  %41 = load ptr, ptr %3, align 8, !tbaa !5
  %42 = call ptr @strchr(ptr noundef %41, i32 noundef 58) #7
  store ptr %42, ptr %7, align 8, !tbaa !5
  %43 = load ptr, ptr %7, align 8, !tbaa !5
  %44 = icmp ne ptr null, %43
  br i1 %44, label %45, label %78

45:                                               ; preds = %40
  %46 = load ptr, ptr %7, align 8, !tbaa !5
  %47 = getelementptr inbounds i8, ptr %46, i32 1
  store ptr %47, ptr %7, align 8, !tbaa !5
  br label %48

48:                                               ; preds = %60, %45
  %49 = call ptr @__ctype_b_loc() #8
  %50 = load ptr, ptr %49, align 8, !tbaa !5
  %51 = load ptr, ptr %7, align 8, !tbaa !5
  %52 = load i8, ptr %51, align 1, !tbaa !11
  %53 = sext i8 %52 to i32
  %54 = sext i32 %53 to i64
  %55 = getelementptr inbounds i16, ptr %50, i64 %54
  %56 = load i16, ptr %55, align 2, !tbaa !12
  %57 = zext i16 %56 to i32
  %58 = and i32 %57, 8192
  %59 = icmp ne i32 %58, 0
  br i1 %59, label %60, label %63

60:                                               ; preds = %48
  %61 = load ptr, ptr %7, align 8, !tbaa !5
  %62 = getelementptr inbounds i8, ptr %61, i32 1
  store ptr %62, ptr %7, align 8, !tbaa !5
  br label %48, !llvm.loop !14

63:                                               ; preds = %48
  %64 = load ptr, ptr %7, align 8, !tbaa !5
  %65 = call i64 @strlen(ptr noundef %64) #7
  %66 = load ptr, ptr %4, align 8, !tbaa !5
  store i64 %65, ptr %66, align 8, !tbaa !9
  %67 = load ptr, ptr %3, align 8, !tbaa !5
  %68 = load ptr, ptr %7, align 8, !tbaa !5
  %69 = load ptr, ptr %4, align 8, !tbaa !5
  %70 = load i64, ptr %69, align 8, !tbaa !9
  call void @llvm.memmove.p0.p0.i64(ptr align 1 %67, ptr align 1 %68, i64 %70, i1 false)
  %71 = load ptr, ptr %3, align 8, !tbaa !5
  %72 = call ptr @strchr(ptr noundef %71, i32 noundef 10) #7
  store ptr %72, ptr %7, align 8, !tbaa !5
  %73 = load ptr, ptr %7, align 8, !tbaa !5
  %74 = icmp ne ptr null, %73
  br i1 %74, label %75, label %77

75:                                               ; preds = %63
  %76 = load ptr, ptr %7, align 8, !tbaa !5
  store i8 0, ptr %76, align 1, !tbaa !11
  br label %77

77:                                               ; preds = %75, %63
  store i32 3, ptr %8, align 4
  br label %79

78:                                               ; preds = %40
  store i32 0, ptr %8, align 4
  br label %79

79:                                               ; preds = %78, %77
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #6
  %80 = load i32, ptr %8, align 4
  switch i32 %80, label %91 [
    i32 0, label %81
    i32 3, label %83
  ]

81:                                               ; preds = %79
  br label %82

82:                                               ; preds = %81, %38
  br label %27, !llvm.loop !16

83:                                               ; preds = %79, %27
  %84 = load ptr, ptr %6, align 8, !tbaa !5
  %85 = call i32 @fclose(ptr noundef %84)
  br label %86

86:                                               ; preds = %83, %18
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #6
  br label %89

87:                                               ; preds = %15
  %88 = load ptr, ptr %4, align 8, !tbaa !5
  store i64 0, ptr %88, align 8, !tbaa !9
  br label %89

89:                                               ; preds = %87, %86
  br label %90

90:                                               ; preds = %89, %11, %2
  ret void

91:                                               ; preds = %79
  unreachable
}

declare noalias ptr @fopen(ptr noundef, ptr noundef) #2

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

; Function Attrs: nounwind willreturn memory(read)
declare i32 @strncmp(ptr noundef, ptr noundef, i64 noundef) #3

; Function Attrs: nounwind willreturn memory(read)
declare ptr @strchr(ptr noundef, i32 noundef) #3

; Function Attrs: nounwind willreturn memory(none)
declare ptr @__ctype_b_loc() #4

; Function Attrs: nounwind willreturn memory(read)
declare i64 @strlen(ptr noundef) #3

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memmove.p0.p0.i64(ptr nocapture writeonly, ptr nocapture readonly, i64, i1 immarg) #5

declare i32 @fclose(ptr noundef) #2

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 willreturn memory(read) "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 willreturn memory(none) "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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #6 = { nounwind }
attributes #7 = { nounwind willreturn memory(read) }
attributes #8 = { nounwind willreturn memory(none) }

!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 = !{!"long", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"short", !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = distinct !{!16, !15}


; 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 = external hidden unnamed_addr constant [14 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [11 x i8], align 1

; Function Attrs: nofree nounwind uwtable
define dso_local void @libxsmm_cpuid_model(ptr noundef %0, ptr noundef %1) local_unnamed_addr #0 {
  %.not = icmp eq ptr %1, null
  br i1 %.not, label %29, label %3

3:                                                ; preds = %2
  %4 = load i64, ptr %1, align 8, !tbaa !5
  %.not33 = icmp eq i64 %4, 0
  br i1 %.not33, label %29, label %5

5:                                                ; preds = %3
  %.not34 = icmp eq ptr %0, null
  store i64 0, ptr %1, align 8, !tbaa !5
  br i1 %.not34, label %29, label %6

6:                                                ; preds = %5
  store i8 0, ptr %0, align 1, !tbaa !9
  %7 = tail call noalias ptr @fopen(ptr noundef nonnull @.str, ptr noundef nonnull @.str.1)
  %.not35 = icmp eq ptr %7, null
  br i1 %.not35, label %29, label %.preheader43

.preheader43:                                     ; preds = %6
  %8 = trunc i64 %4 to i32
  %9 = tail call ptr @fgets(ptr noundef nonnull %0, i32 noundef %8, ptr noundef nonnull %7)
  %.not3644 = icmp eq ptr %9, null
  br i1 %.not3644, label %.thread, label %.lr.ph

.lr.ph:                                           ; preds = %.preheader43, %26
  %10 = tail call i32 @strncmp(ptr noundef nonnull dereferenceable(1) @.str.2, ptr noundef nonnull dereferenceable(1) %0, i64 noundef 10) #5
  %.not37 = icmp eq i32 %10, 0
  br i1 %.not37, label %12, label %11

11:                                               ; preds = %.lr.ph
  store i8 0, ptr %0, align 1, !tbaa !9
  br label %26

12:                                               ; preds = %.lr.ph
  %13 = tail call ptr @strchr(ptr noundef nonnull dereferenceable(1) %0, i32 noundef 58) #5
  %.not38 = icmp eq ptr %13, null
  br i1 %.not38, label %26, label %.preheader

.preheader:                                       ; preds = %12
  %14 = tail call ptr @__ctype_b_loc() #6
  %15 = load ptr, ptr %14, align 8, !tbaa !10
  br label %16

16:                                               ; preds = %.preheader, %16
  %.pn = phi ptr [ %.027, %16 ], [ %13, %.preheader ]
  %.027 = getelementptr inbounds i8, ptr %.pn, i64 1
  %17 = load i8, ptr %.027, align 1, !tbaa !9
  %18 = sext i8 %17 to i64
  %19 = getelementptr inbounds i16, ptr %15, i64 %18
  %20 = load i16, ptr %19, align 2, !tbaa !12
  %21 = and i16 %20, 8192
  %.not39 = icmp eq i16 %21, 0
  br i1 %.not39, label %22, label %16, !llvm.loop !14

22:                                               ; preds = %16
  %23 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %.027) #5
  store i64 %23, ptr %1, align 8, !tbaa !5
  tail call void @llvm.memmove.p0.p0.i64(ptr nonnull align 1 %0, ptr nonnull align 1 %.027, i64 %23, i1 false)
  %24 = tail call ptr @strchr(ptr noundef nonnull dereferenceable(1) %0, i32 noundef 10) #5
  %.not40 = icmp eq ptr %24, null
  br i1 %.not40, label %.thread, label %25

25:                                               ; preds = %22
  store i8 0, ptr %24, align 1, !tbaa !9
  br label %.thread

26:                                               ; preds = %12, %11
  %27 = tail call ptr @fgets(ptr noundef nonnull %0, i32 noundef %8, ptr noundef nonnull %7)
  %.not36 = icmp eq ptr %27, null
  br i1 %.not36, label %.thread, label %.lr.ph, !llvm.loop !16

.thread:                                          ; preds = %26, %.preheader43, %22, %25
  %28 = tail call i32 @fclose(ptr noundef nonnull %7)
  br label %29

29:                                               ; preds = %5, %6, %.thread, %3, %2
  ret void
}

; Function Attrs: nofree nounwind
declare noalias noundef ptr @fopen(ptr nocapture noundef readonly, ptr nocapture noundef readonly) local_unnamed_addr #1

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

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare i32 @strncmp(ptr nocapture noundef, ptr nocapture noundef, i64 noundef) local_unnamed_addr #2

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare ptr @strchr(ptr noundef, i32 noundef) local_unnamed_addr #2

; Function Attrs: mustprogress nofree nosync nounwind willreturn memory(none)
declare ptr @__ctype_b_loc() local_unnamed_addr #3

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare i64 @strlen(ptr nocapture noundef) local_unnamed_addr #2

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memmove.p0.p0.i64(ptr nocapture writeonly, ptr nocapture readonly, i64, i1 immarg) #4

; Function Attrs: nofree nounwind
declare noundef i32 @fclose(ptr nocapture noundef) local_unnamed_addr #1

attributes #0 = { nofree 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 = { mustprogress nofree nounwind willreturn memory(argmem: read) "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 = { mustprogress nofree nosync nounwind willreturn memory(none) "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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #5 = { nounwind willreturn memory(read) }
attributes #6 = { nounwind willreturn memory(none) }

!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 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!7, !7, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"any pointer", !7, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"short", !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = distinct !{!16, !15}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass