; LLVM IR from scvalencia/MNIST_ASCII_challenge :: src (main)

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

@ASCII_colors = external dso_local constant [12 x i8], align 1
@white = external dso_local global i8, align 1
@dots = external dso_local global 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
declare dso_local i32 @randr(i32 noundef, i32 noundef) #1

; Function Attrs: nounwind uwtable
define dso_local signext i8 @classify_brightness(i32 noundef %0) #1 {
  %2 = alloca i32, align 4
  %3 = alloca i8, align 1
  %4 = alloca i8, align 1
  store i32 %0, ptr %2, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 1, ptr %3) #2
  store i8 32, ptr %3, align 1, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 1, ptr %4) #2
  %5 = call i32 @randr(i32 noundef 0, i32 noundef 10)
  %6 = sext i32 %5 to i64
  %7 = getelementptr inbounds [12 x i8], ptr @ASCII_colors, i64 0, i64 %6
  %8 = load i8, ptr %7, align 1, !tbaa !9
  store i8 %8, ptr %4, align 1, !tbaa !9
  %9 = load i8, ptr @white, align 1, !tbaa !10, !range !12, !noundef !13
  %10 = trunc i8 %9 to i1
  br i1 %10, label %24, label %11

11:                                               ; preds = %1
  %12 = load i8, ptr @dots, align 1, !tbaa !10, !range !12, !noundef !13
  %13 = trunc i8 %12 to i1
  br i1 %13, label %24, label %14

14:                                               ; preds = %11
  %15 = load i32, ptr %2, align 4, !tbaa !5
  %16 = icmp eq i32 %15, 0
  br i1 %16, label %17, label %18

17:                                               ; preds = %14
  br label %21

18:                                               ; preds = %14
  %19 = load i8, ptr %4, align 1, !tbaa !9
  %20 = sext i8 %19 to i32
  br label %21

21:                                               ; preds = %18, %17
  %22 = phi i32 [ 32, %17 ], [ %20, %18 ]
  %23 = trunc i32 %22 to i8
  store i8 %23, ptr %3, align 1, !tbaa !9
  br label %60

24:                                               ; preds = %11, %1
  %25 = load i8, ptr @white, align 1, !tbaa !10, !range !12, !noundef !13
  %26 = trunc i8 %25 to i1
  br i1 %26, label %36, label %27

27:                                               ; preds = %24
  %28 = load i8, ptr @dots, align 1, !tbaa !10, !range !12, !noundef !13
  %29 = trunc i8 %28 to i1
  br i1 %29, label %30, label %36

30:                                               ; preds = %27
  %31 = load i32, ptr %2, align 4, !tbaa !5
  %32 = icmp eq i32 %31, 0
  %33 = zext i1 %32 to i64
  %34 = select i1 %32, i32 32, i32 42
  %35 = trunc i32 %34 to i8
  store i8 %35, ptr %3, align 1, !tbaa !9
  br label %59

36:                                               ; preds = %27, %24
  %37 = load i8, ptr @white, align 1, !tbaa !10, !range !12, !noundef !13
  %38 = trunc i8 %37 to i1
  br i1 %38, label %39, label %52

39:                                               ; preds = %36
  %40 = load i8, ptr @dots, align 1, !tbaa !10, !range !12, !noundef !13
  %41 = trunc i8 %40 to i1
  br i1 %41, label %52, label %42

42:                                               ; preds = %39
  %43 = load i32, ptr %2, align 4, !tbaa !5
  %44 = icmp eq i32 %43, 0
  br i1 %44, label %45, label %48

45:                                               ; preds = %42
  %46 = load i8, ptr %4, align 1, !tbaa !9
  %47 = sext i8 %46 to i32
  br label %49

48:                                               ; preds = %42
  br label %49

49:                                               ; preds = %48, %45
  %50 = phi i32 [ %47, %45 ], [ 32, %48 ]
  %51 = trunc i32 %50 to i8
  store i8 %51, ptr %3, align 1, !tbaa !9
  br label %58

52:                                               ; preds = %39, %36
  %53 = load i32, ptr %2, align 4, !tbaa !5
  %54 = icmp eq i32 %53, 0
  %55 = zext i1 %54 to i64
  %56 = select i1 %54, i32 42, i32 32
  %57 = trunc i32 %56 to i8
  store i8 %57, ptr %3, align 1, !tbaa !9
  br label %58

58:                                               ; preds = %52, %49
  br label %59

59:                                               ; preds = %58, %30
  br label %60

60:                                               ; preds = %59, %21
  %61 = load i8, ptr %3, align 1, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 1, ptr %4) #2
  call void @llvm.lifetime.end.p0(i64 1, ptr %3) #2
  ret i8 %61
}

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 = { 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 = !{!7, !7, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"_Bool", !7, i64 0}
!12 = !{i8 0, i8 2}
!13 = !{}


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

@ASCII_colors = external dso_local local_unnamed_addr constant [12 x i8], align 1
@white = external dso_local local_unnamed_addr global i8, align 1
@dots = external dso_local local_unnamed_addr global i8, align 1

; Function Attrs: nounwind uwtable
declare dso_local i32 @randr(i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local signext i8 @classify_brightness(i32 noundef %0) local_unnamed_addr #0 {
  %2 = tail call i32 @randr(i32 noundef 0, i32 noundef 10)
  %3 = sext i32 %2 to i64
  %4 = getelementptr inbounds [12 x i8], ptr @ASCII_colors, i64 0, i64 %3
  %5 = load i8, ptr %4, align 1, !tbaa !5
  %6 = load i8, ptr @white, align 1, !tbaa !8, !range !10, !noundef !11
  %7 = trunc nuw i8 %6 to i1
  %8 = load i8, ptr @dots, align 1, !tbaa !8, !range !10, !noundef !11
  %9 = trunc nuw i8 %8 to i1
  %10 = icmp eq i32 %0, 0
  br i1 %7, label %16, label %11

11:                                               ; preds = %1
  br i1 %9, label %14, label %12

12:                                               ; preds = %11
  %13 = select i1 %10, i8 32, i8 %5
  br label %21

14:                                               ; preds = %11
  %15 = select i1 %10, i8 32, i8 42
  br label %21

16:                                               ; preds = %1
  br i1 %9, label %19, label %17

17:                                               ; preds = %16
  %18 = select i1 %10, i8 %5, i8 32
  br label %21

19:                                               ; preds = %16
  %20 = select i1 %10, i8 42, i8 32
  br label %21

21:                                               ; preds = %14, %19, %17, %12
  %.0 = phi i8 [ %20, %19 ], [ %18, %17 ], [ %15, %14 ], [ %13, %12 ]
  ret i8 %.0
}

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

!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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = !{!9, !9, i64 0}
!9 = !{!"_Bool", !6, i64 0}
!10 = !{i8 0, i8 2}
!11 = !{}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass