; LLVM IR from Farama-Foundation/stable-retro :: cores/32x/platform/linux (log_io)

; 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.io_log_location = type { i32, i32, i32, i32, i32, i32, i32, i32 }

@io_locations = external hidden global [20 x %struct.io_log_location], align 16
@.str = external hidden unnamed_addr constant [12 x i8], align 1

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

12:                                               ; preds = %3
  %13 = load i32, ptr %4, align 4, !tbaa !5
  %14 = and i32 %13, -2
  store i32 %14, ptr %4, align 4, !tbaa !5
  br label %15

15:                                               ; preds = %12, %3
  store i32 0, ptr %7, align 4, !tbaa !5
  br label %16

16:                                               ; preds = %90, %15
  %17 = load i32, ptr %7, align 4, !tbaa !5
  %18 = sext i32 %17 to i64
  %19 = icmp ult i64 %18, 20
  br i1 %19, label %20, label %93

20:                                               ; preds = %16
  %21 = load i32, ptr %4, align 4, !tbaa !5
  %22 = load i32, ptr %7, align 4, !tbaa !5
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds [20 x %struct.io_log_location], ptr @io_locations, i64 0, i64 %23
  %25 = getelementptr inbounds %struct.io_log_location, ptr %24, i32 0, i32 0
  %26 = load i32, ptr %25, align 16, !tbaa !9
  %27 = icmp uge i32 %21, %26
  br i1 %27, label %28, label %89

28:                                               ; preds = %20
  %29 = load i32, ptr %4, align 4, !tbaa !5
  %30 = load i32, ptr %7, align 4, !tbaa !5
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds [20 x %struct.io_log_location], ptr @io_locations, i64 0, i64 %31
  %33 = getelementptr inbounds %struct.io_log_location, ptr %32, i32 0, i32 1
  %34 = load i32, ptr %33, align 4, !tbaa !11
  %35 = icmp ule i32 %29, %34
  br i1 %35, label %36, label %89

36:                                               ; preds = %28
  %37 = load i32, ptr %5, align 4, !tbaa !5
  %38 = load i32, ptr %6, align 4, !tbaa !5
  %39 = shl i32 %38, 8
  %40 = or i32 %37, %39
  switch i32 %40, label %83 [
    i32 8, label %41
    i32 16, label %48
    i32 32, label %55
    i32 264, label %62
    i32 272, label %69
    i32 288, label %76
  ]

41:                                               ; preds = %36
  %42 = load i32, ptr %7, align 4, !tbaa !5
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds [20 x %struct.io_log_location], ptr @io_locations, i64 0, i64 %43
  %45 = getelementptr inbounds %struct.io_log_location, ptr %44, i32 0, i32 2
  %46 = load i32, ptr %45, align 8, !tbaa !12
  %47 = add nsw i32 %46, 1
  store i32 %47, ptr %45, align 8, !tbaa !12
  br label %88

48:                                               ; preds = %36
  %49 = load i32, ptr %7, align 4, !tbaa !5
  %50 = sext i32 %49 to i64
  %51 = getelementptr inbounds [20 x %struct.io_log_location], ptr @io_locations, i64 0, i64 %50
  %52 = getelementptr inbounds %struct.io_log_location, ptr %51, i32 0, i32 3
  %53 = load i32, ptr %52, align 4, !tbaa !13
  %54 = add nsw i32 %53, 1
  store i32 %54, ptr %52, align 4, !tbaa !13
  br label %88

55:                                               ; preds = %36
  %56 = load i32, ptr %7, align 4, !tbaa !5
  %57 = sext i32 %56 to i64
  %58 = getelementptr inbounds [20 x %struct.io_log_location], ptr @io_locations, i64 0, i64 %57
  %59 = getelementptr inbounds %struct.io_log_location, ptr %58, i32 0, i32 4
  %60 = load i32, ptr %59, align 16, !tbaa !14
  %61 = add nsw i32 %60, 1
  store i32 %61, ptr %59, align 16, !tbaa !14
  br label %88

62:                                               ; preds = %36
  %63 = load i32, ptr %7, align 4, !tbaa !5
  %64 = sext i32 %63 to i64
  %65 = getelementptr inbounds [20 x %struct.io_log_location], ptr @io_locations, i64 0, i64 %64
  %66 = getelementptr inbounds %struct.io_log_location, ptr %65, i32 0, i32 5
  %67 = load i32, ptr %66, align 4, !tbaa !15
  %68 = add nsw i32 %67, 1
  store i32 %68, ptr %66, align 4, !tbaa !15
  br label %88

69:                                               ; preds = %36
  %70 = load i32, ptr %7, align 4, !tbaa !5
  %71 = sext i32 %70 to i64
  %72 = getelementptr inbounds [20 x %struct.io_log_location], ptr @io_locations, i64 0, i64 %71
  %73 = getelementptr inbounds %struct.io_log_location, ptr %72, i32 0, i32 6
  %74 = load i32, ptr %73, align 8, !tbaa !16
  %75 = add nsw i32 %74, 1
  store i32 %75, ptr %73, align 8, !tbaa !16
  br label %88

76:                                               ; preds = %36
  %77 = load i32, ptr %7, align 4, !tbaa !5
  %78 = sext i32 %77 to i64
  %79 = getelementptr inbounds [20 x %struct.io_log_location], ptr @io_locations, i64 0, i64 %78
  %80 = getelementptr inbounds %struct.io_log_location, ptr %79, i32 0, i32 7
  %81 = load i32, ptr %80, align 4, !tbaa !17
  %82 = add nsw i32 %81, 1
  store i32 %82, ptr %80, align 4, !tbaa !17
  br label %88

83:                                               ; preds = %36
  %84 = load i32, ptr %4, align 4, !tbaa !5
  %85 = load i32, ptr %5, align 4, !tbaa !5
  %86 = load i32, ptr %6, align 4, !tbaa !5
  %87 = call i32 (ptr, ...) @printf(ptr noundef @.str, i32 noundef %84, i32 noundef %85, i32 noundef %86)
  br label %88

88:                                               ; preds = %83, %76, %69, %62, %55, %48, %41
  br label %89

89:                                               ; preds = %88, %28, %20
  br label %90

90:                                               ; preds = %89
  %91 = load i32, ptr %7, align 4, !tbaa !5
  %92 = add nsw i32 %91, 1
  store i32 %92, ptr %7, align 4, !tbaa !5
  br label %16, !llvm.loop !18

93:                                               ; preds = %16
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  ret void
}

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

declare i32 @printf(ptr noundef, ...) #2

; 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 = { "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, !6, i64 0}
!6 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !6, i64 0}
!10 = !{!"", !6, i64 0, !6, i64 4, !6, i64 8, !6, i64 12, !6, i64 16, !6, i64 20, !6, i64 24, !6, i64 28}
!11 = !{!10, !6, i64 4}
!12 = !{!10, !6, i64 8}
!13 = !{!10, !6, i64 12}
!14 = !{!10, !6, i64 16}
!15 = !{!10, !6, i64 20}
!16 = !{!10, !6, i64 24}
!17 = !{!10, !6, i64 28}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}


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

%struct.io_log_location = type { i32, i32, i32, i32, i32, i32, i32, i32 }

@io_locations = external hidden local_unnamed_addr global [20 x %struct.io_log_location], align 16
@.str = external hidden unnamed_addr constant [12 x i8], align 1

; Function Attrs: nofree nounwind uwtable
define dso_local void @log_io(i32 noundef %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = icmp sgt i32 %1, 8
  %spec.select.v = select i1 %4, i32 16777214, i32 16777215
  %spec.select = and i32 %spec.select.v, %0
  %5 = shl i32 %2, 8
  %6 = or i32 %5, %1
  br label %7

7:                                                ; preds = %3, %40
  %indvars.iv = phi i64 [ 0, %3 ], [ %indvars.iv.next, %40 ]
  %8 = getelementptr inbounds [20 x %struct.io_log_location], ptr @io_locations, i64 0, i64 %indvars.iv
  %9 = load i32, ptr %8, align 16, !tbaa !5
  %.not = icmp ult i32 %spec.select, %9
  br i1 %.not, label %40, label %10

10:                                               ; preds = %7
  %11 = getelementptr inbounds i8, ptr %8, i64 4
  %12 = load i32, ptr %11, align 4, !tbaa !10
  %.not22 = icmp ugt i32 %spec.select, %12
  br i1 %.not22, label %40, label %13

13:                                               ; preds = %10
  switch i32 %6, label %38 [
    i32 8, label %14
    i32 16, label %18
    i32 32, label %22
    i32 264, label %26
    i32 272, label %30
    i32 288, label %34
  ]

14:                                               ; preds = %13
  %15 = getelementptr inbounds i8, ptr %8, i64 8
  %16 = load i32, ptr %15, align 8, !tbaa !11
  %17 = add nsw i32 %16, 1
  store i32 %17, ptr %15, align 8, !tbaa !11
  br label %40

18:                                               ; preds = %13
  %19 = getelementptr inbounds i8, ptr %8, i64 12
  %20 = load i32, ptr %19, align 4, !tbaa !12
  %21 = add nsw i32 %20, 1
  store i32 %21, ptr %19, align 4, !tbaa !12
  br label %40

22:                                               ; preds = %13
  %23 = getelementptr inbounds i8, ptr %8, i64 16
  %24 = load i32, ptr %23, align 16, !tbaa !13
  %25 = add nsw i32 %24, 1
  store i32 %25, ptr %23, align 16, !tbaa !13
  br label %40

26:                                               ; preds = %13
  %27 = getelementptr inbounds i8, ptr %8, i64 20
  %28 = load i32, ptr %27, align 4, !tbaa !14
  %29 = add nsw i32 %28, 1
  store i32 %29, ptr %27, align 4, !tbaa !14
  br label %40

30:                                               ; preds = %13
  %31 = getelementptr inbounds i8, ptr %8, i64 24
  %32 = load i32, ptr %31, align 8, !tbaa !15
  %33 = add nsw i32 %32, 1
  store i32 %33, ptr %31, align 8, !tbaa !15
  br label %40

34:                                               ; preds = %13
  %35 = getelementptr inbounds i8, ptr %8, i64 28
  %36 = load i32, ptr %35, align 4, !tbaa !16
  %37 = add nsw i32 %36, 1
  store i32 %37, ptr %35, align 4, !tbaa !16
  br label %40

38:                                               ; preds = %13
  %39 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, i32 noundef %spec.select, i32 noundef %1, i32 noundef %2)
  br label %40

40:                                               ; preds = %7, %10, %38, %34, %30, %26, %22, %18, %14
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, 20
  br i1 %exitcond.not, label %41, label %7, !llvm.loop !17

41:                                               ; preds = %40
  ret void
}

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) 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" }

!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, !7, i64 0}
!6 = !{!"", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12, !7, i64 16, !7, i64 20, !7, i64 24, !7, i64 28}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!6, !7, i64 4}
!11 = !{!6, !7, i64 8}
!12 = !{!6, !7, i64 12}
!13 = !{!6, !7, i64 16}
!14 = !{!6, !7, i64 20}
!15 = !{!6, !7, i64 24}
!16 = !{!6, !7, i64 28}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LICMPass,LoopRotatePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass