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

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

; 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 @log_io_dump() #2 {
  %1 = alloca i32, align 4
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #3
  %4 = call i32 (ptr, ...) @printf(ptr noundef @.str.1)
  store i32 0, ptr %1, align 4, !tbaa !5
  br label %5

5:                                                ; preds = %72, %0
  %6 = load i32, ptr %1, align 4, !tbaa !5
  %7 = sext i32 %6 to i64
  %8 = icmp ult i64 %7, 20
  br i1 %8, label %9, label %75

9:                                                ; preds = %5
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #3
  %10 = load i32, ptr %1, align 4, !tbaa !5
  %11 = sext i32 %10 to i64
  %12 = getelementptr inbounds [20 x %struct.io_log_location], ptr @io_locations, i64 0, i64 %11
  store ptr %12, ptr %2, align 8, !tbaa !9
  %13 = load ptr, ptr %2, align 8, !tbaa !9
  %14 = getelementptr inbounds %struct.io_log_location, ptr %13, i32 0, i32 2
  %15 = load i32, ptr %14, align 4, !tbaa !11
  %16 = icmp eq i32 %15, 0
  br i1 %16, label %17, label %43

17:                                               ; preds = %9
  %18 = load ptr, ptr %2, align 8, !tbaa !9
  %19 = getelementptr inbounds %struct.io_log_location, ptr %18, i32 0, i32 3
  %20 = load i32, ptr %19, align 4, !tbaa !13
  %21 = icmp eq i32 %20, 0
  br i1 %21, label %22, label %43

22:                                               ; preds = %17
  %23 = load ptr, ptr %2, align 8, !tbaa !9
  %24 = getelementptr inbounds %struct.io_log_location, ptr %23, i32 0, i32 4
  %25 = load i32, ptr %24, align 4, !tbaa !14
  %26 = icmp eq i32 %25, 0
  br i1 %26, label %27, label %43

27:                                               ; preds = %22
  %28 = load ptr, ptr %2, align 8, !tbaa !9
  %29 = getelementptr inbounds %struct.io_log_location, ptr %28, i32 0, i32 5
  %30 = load i32, ptr %29, align 4, !tbaa !15
  %31 = icmp eq i32 %30, 0
  br i1 %31, label %32, label %43

32:                                               ; preds = %27
  %33 = load ptr, ptr %2, align 8, !tbaa !9
  %34 = getelementptr inbounds %struct.io_log_location, ptr %33, i32 0, i32 6
  %35 = load i32, ptr %34, align 4, !tbaa !16
  %36 = icmp eq i32 %35, 0
  br i1 %36, label %37, label %43

37:                                               ; preds = %32
  %38 = load ptr, ptr %2, align 8, !tbaa !9
  %39 = getelementptr inbounds %struct.io_log_location, ptr %38, i32 0, i32 7
  %40 = load i32, ptr %39, align 4, !tbaa !17
  %41 = icmp eq i32 %40, 0
  br i1 %41, label %42, label %43

42:                                               ; preds = %37
  store i32 4, ptr %3, align 4
  br label %69

43:                                               ; preds = %37, %32, %27, %22, %17, %9
  %44 = load ptr, ptr %2, align 8, !tbaa !9
  %45 = getelementptr inbounds %struct.io_log_location, ptr %44, i32 0, i32 0
  %46 = load i32, ptr %45, align 4, !tbaa !18
  %47 = load ptr, ptr %2, align 8, !tbaa !9
  %48 = getelementptr inbounds %struct.io_log_location, ptr %47, i32 0, i32 1
  %49 = load i32, ptr %48, align 4, !tbaa !19
  %50 = load ptr, ptr %2, align 8, !tbaa !9
  %51 = getelementptr inbounds %struct.io_log_location, ptr %50, i32 0, i32 2
  %52 = load i32, ptr %51, align 4, !tbaa !11
  %53 = load ptr, ptr %2, align 8, !tbaa !9
  %54 = getelementptr inbounds %struct.io_log_location, ptr %53, i32 0, i32 3
  %55 = load i32, ptr %54, align 4, !tbaa !13
  %56 = load ptr, ptr %2, align 8, !tbaa !9
  %57 = getelementptr inbounds %struct.io_log_location, ptr %56, i32 0, i32 4
  %58 = load i32, ptr %57, align 4, !tbaa !14
  %59 = load ptr, ptr %2, align 8, !tbaa !9
  %60 = getelementptr inbounds %struct.io_log_location, ptr %59, i32 0, i32 5
  %61 = load i32, ptr %60, align 4, !tbaa !15
  %62 = load ptr, ptr %2, align 8, !tbaa !9
  %63 = getelementptr inbounds %struct.io_log_location, ptr %62, i32 0, i32 6
  %64 = load i32, ptr %63, align 4, !tbaa !16
  %65 = load ptr, ptr %2, align 8, !tbaa !9
  %66 = getelementptr inbounds %struct.io_log_location, ptr %65, i32 0, i32 7
  %67 = load i32, ptr %66, align 4, !tbaa !17
  %68 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i32 noundef %46, i32 noundef %49, i32 noundef %52, i32 noundef %55, i32 noundef %58, i32 noundef %61, i32 noundef %64, i32 noundef %67)
  store i32 0, ptr %3, align 4
  br label %69

69:                                               ; preds = %43, %42
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #3
  %70 = load i32, ptr %3, align 4
  switch i32 %70, label %77 [
    i32 0, label %71
    i32 4, label %72
  ]

71:                                               ; preds = %69
  br label %72

72:                                               ; preds = %71, %69
  %73 = load i32, ptr %1, align 4, !tbaa !5
  %74 = add nsw i32 %73, 1
  store i32 %74, ptr %1, align 4, !tbaa !5
  br label %5, !llvm.loop !20

75:                                               ; preds = %5
  %76 = call i32 (ptr, ...) @printf(ptr noundef @.str.3)
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #3
  ret void

77:                                               ; preds = %69
  unreachable
}

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

!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}
!11 = !{!12, !6, i64 8}
!12 = !{!"", !6, i64 0, !6, i64 4, !6, i64 8, !6, i64 12, !6, i64 16, !6, i64 20, !6, i64 24, !6, i64 28}
!13 = !{!12, !6, i64 12}
!14 = !{!12, !6, i64 16}
!15 = !{!12, !6, i64 20}
!16 = !{!12, !6, i64 24}
!17 = !{!12, !6, i64 28}
!18 = !{!12, !6, i64 0}
!19 = !{!12, !6, i64 4}
!20 = distinct !{!20, !21}
!21 = !{!"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.1 = external hidden unnamed_addr constant [73 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [39 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [2 x i8], align 1

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

; Function Attrs: nofree nounwind uwtable
define dso_local void @log_io_dump() local_unnamed_addr #1 {
  %1 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1)
  br label %2

2:                                                ; preds = %0, %39
  %indvars.iv = phi i64 [ 0, %0 ], [ %indvars.iv.next, %39 ]
  %3 = getelementptr inbounds [20 x %struct.io_log_location], ptr @io_locations, i64 0, i64 %indvars.iv
  %4 = getelementptr inbounds i8, ptr %3, i64 8
  %5 = load i32, ptr %4, align 8, !tbaa !5
  %6 = icmp eq i32 %5, 0
  %7 = getelementptr inbounds i8, ptr %3, i64 12
  %8 = load i32, ptr %7, align 4, !tbaa !10
  %9 = icmp eq i32 %8, 0
  %or.cond = select i1 %6, i1 %9, i1 false
  br i1 %or.cond, label %10, label %._crit_edge

10:                                               ; preds = %2
  %11 = getelementptr inbounds i8, ptr %3, i64 16
  %12 = load i32, ptr %11, align 16, !tbaa !11
  %13 = icmp eq i32 %12, 0
  br i1 %13, label %14, label %._crit_edge

14:                                               ; preds = %10
  %15 = getelementptr inbounds i8, ptr %3, i64 20
  %16 = load i32, ptr %15, align 4, !tbaa !12
  %17 = icmp eq i32 %16, 0
  br i1 %17, label %18, label %._crit_edge

18:                                               ; preds = %14
  %19 = getelementptr inbounds i8, ptr %3, i64 24
  %20 = load i32, ptr %19, align 8, !tbaa !13
  %21 = icmp eq i32 %20, 0
  br i1 %21, label %22, label %._crit_edge

22:                                               ; preds = %18
  %23 = getelementptr inbounds i8, ptr %3, i64 28
  %24 = load i32, ptr %23, align 4, !tbaa !14
  %25 = icmp eq i32 %24, 0
  br i1 %25, label %39, label %._crit_edge

._crit_edge:                                      ; preds = %2, %22, %18, %14, %10
  %26 = phi i32 [ 0, %22 ], [ 0, %18 ], [ 0, %14 ], [ 0, %10 ], [ %8, %2 ]
  %27 = load i32, ptr %3, align 16, !tbaa !15
  %28 = getelementptr inbounds i8, ptr %3, i64 4
  %29 = load i32, ptr %28, align 4, !tbaa !16
  %30 = getelementptr inbounds i8, ptr %3, i64 16
  %31 = load i32, ptr %30, align 16, !tbaa !11
  %32 = getelementptr inbounds i8, ptr %3, i64 20
  %33 = load i32, ptr %32, align 4, !tbaa !12
  %34 = getelementptr inbounds i8, ptr %3, i64 24
  %35 = load i32, ptr %34, align 8, !tbaa !13
  %36 = getelementptr inbounds i8, ptr %3, i64 28
  %37 = load i32, ptr %36, align 4, !tbaa !14
  %38 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i32 noundef %27, i32 noundef %29, i32 noundef %5, i32 noundef %26, i32 noundef %31, i32 noundef %33, i32 noundef %35, i32 noundef %37)
  br label %39

39:                                               ; preds = %22, %._crit_edge
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, 20
  br i1 %exitcond.not, label %40, label %2, !llvm.loop !17

40:                                               ; preds = %39
  %41 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3)
  ret void
}

attributes #0 = { 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 #1 = { 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" }

!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 8}
!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 12}
!11 = !{!6, !7, i64 16}
!12 = !{!6, !7, i64 20}
!13 = !{!6, !7, i64 24}
!14 = !{!6, !7, i64 28}
!15 = !{!6, !7, i64 0}
!16 = !{!6, !7, i64 4}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}


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