; LLVM IR from t-dillon/tdoku :: other/zerodoku (zerodoku_v2)

; 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.Offsets = type { [81 x i32], [81 x i32], [81 x i32] }

@s = external dso_local global %struct.Offsets, align 4
@g = external dso_local global [27 x [9 x i32]], align 16
@uninitialized = external hidden global i32, align 4

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

4:                                                ; preds = %66, %0
  %5 = load i32, ptr %1, align 4, !tbaa !5
  %6 = icmp slt i32 %5, 81
  br i1 %6, label %8, label %7

7:                                                ; preds = %4
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #2
  br label %69

8:                                                ; preds = %4
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #2
  %9 = load i32, ptr %1, align 4, !tbaa !5
  %10 = sdiv i32 %9, 9
  store i32 %10, ptr %2, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #2
  %11 = load i32, ptr %1, align 4, !tbaa !5
  %12 = srem i32 %11, 9
  store i32 %12, ptr %3, align 4, !tbaa !5
  %13 = load i32, ptr %2, align 4, !tbaa !5
  %14 = load i32, ptr %1, align 4, !tbaa !5
  %15 = sext i32 %14 to i64
  %16 = getelementptr inbounds [81 x i32], ptr @s, i64 0, i64 %15
  store i32 %13, ptr %16, align 4, !tbaa !5
  %17 = load i32, ptr %3, align 4, !tbaa !5
  %18 = load i32, ptr %1, align 4, !tbaa !5
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds [81 x i32], ptr getelementptr inbounds (%struct.Offsets, ptr @s, i32 0, i32 1), i64 0, i64 %19
  store i32 %17, ptr %20, align 4, !tbaa !5
  %21 = load i32, ptr %2, align 4, !tbaa !5
  %22 = sdiv i32 %21, 3
  %23 = mul nsw i32 %22, 3
  %24 = load i32, ptr %3, align 4, !tbaa !5
  %25 = sdiv i32 %24, 3
  %26 = add nsw i32 %23, %25
  %27 = load i32, ptr %1, align 4, !tbaa !5
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds [81 x i32], ptr getelementptr inbounds (%struct.Offsets, ptr @s, i32 0, i32 2), i64 0, i64 %28
  store i32 %26, ptr %29, align 4, !tbaa !5
  %30 = load i32, ptr %1, align 4, !tbaa !5
  %31 = load i32, ptr %2, align 4, !tbaa !5
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds [27 x [9 x i32]], ptr @g, i64 0, i64 %32
  %34 = load i32, ptr %3, align 4, !tbaa !5
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds [9 x i32], ptr %33, i64 0, i64 %35
  store i32 %30, ptr %36, align 4, !tbaa !5
  %37 = load i32, ptr %1, align 4, !tbaa !5
  %38 = load i32, ptr %3, align 4, !tbaa !5
  %39 = add nsw i32 %38, 9
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds [27 x [9 x i32]], ptr @g, i64 0, i64 %40
  %42 = load i32, ptr %2, align 4, !tbaa !5
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds [9 x i32], ptr %41, i64 0, i64 %43
  store i32 %37, ptr %44, align 4, !tbaa !5
  %45 = load i32, ptr %2, align 4, !tbaa !5
  %46 = sdiv i32 %45, 3
  %47 = mul nsw i32 %46, 3
  %48 = load i32, ptr %3, align 4, !tbaa !5
  %49 = sdiv i32 %48, 3
  %50 = add nsw i32 %47, %49
  %51 = mul nsw i32 %50, 9
  %52 = load i32, ptr %2, align 4, !tbaa !5
  %53 = srem i32 %52, 3
  %54 = mul nsw i32 %53, 3
  %55 = add nsw i32 %51, %54
  %56 = load i32, ptr %3, align 4, !tbaa !5
  %57 = srem i32 %56, 3
  %58 = add nsw i32 %55, %57
  %59 = load i32, ptr %2, align 4, !tbaa !5
  %60 = add nsw i32 %59, 18
  %61 = sext i32 %60 to i64
  %62 = getelementptr inbounds [27 x [9 x i32]], ptr @g, i64 0, i64 %61
  %63 = load i32, ptr %3, align 4, !tbaa !5
  %64 = sext i32 %63 to i64
  %65 = getelementptr inbounds [9 x i32], ptr %62, i64 0, i64 %64
  store i32 %58, ptr %65, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #2
  br label %66

66:                                               ; preds = %8
  %67 = load i32, ptr %1, align 4, !tbaa !5
  %68 = add nsw i32 %67, 1
  store i32 %68, ptr %1, align 4, !tbaa !5
  br label %4, !llvm.loop !9

69:                                               ; preds = %7
  store i32 0, ptr @uninitialized, align 4, !tbaa !5
  ret void
}

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 = distinct !{!9, !10}
!10 = !{!"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.Offsets = type { [81 x i32], [81 x i32], [81 x i32] }

@s = external dso_local local_unnamed_addr global %struct.Offsets, align 4
@g = external dso_local local_unnamed_addr global [27 x [9 x i32]], align 16
@uninitialized = external hidden local_unnamed_addr global i32, align 4

; Function Attrs: nofree norecurse nosync nounwind memory(write, argmem: none, inaccessiblemem: none) uwtable
define dso_local void @initializeTables() local_unnamed_addr #0 {
  br label %2

1:                                                ; preds = %2
  store i32 0, ptr @uninitialized, align 4, !tbaa !5
  ret void

2:                                                ; preds = %0, %2
  %indvars.iv = phi i64 [ 0, %0 ], [ %indvars.iv.next, %2 ]
  %3 = trunc nuw nsw i64 %indvars.iv to i32
  %.lhs.trunc = trunc i64 %indvars.iv to i8
  %4 = udiv i8 %.lhs.trunc, 9
  %.zext = zext nneg i8 %4 to i32
  %5 = urem i8 %.lhs.trunc, 9
  %.zext24 = zext nneg i8 %5 to i32
  %6 = getelementptr inbounds [81 x i32], ptr @s, i64 0, i64 %indvars.iv
  store i32 %.zext, ptr %6, align 4, !tbaa !5
  %7 = getelementptr inbounds [81 x i32], ptr getelementptr inbounds (i8, ptr @s, i64 324), i64 0, i64 %indvars.iv
  store i32 %.zext24, ptr %7, align 4, !tbaa !5
  %8 = udiv i8 %.lhs.trunc, 27
  %narrow = mul nuw nsw i8 %8, 3
  %9 = udiv i8 %5, 3
  %narrow33 = add nuw nsw i8 %narrow, %9
  %10 = zext nneg i8 %narrow33 to i32
  %11 = getelementptr inbounds [81 x i32], ptr getelementptr inbounds (i8, ptr @s, i64 648), i64 0, i64 %indvars.iv
  store i32 %10, ptr %11, align 4, !tbaa !5
  %12 = zext nneg i8 %4 to i64
  %13 = zext nneg i8 %5 to i64
  %14 = getelementptr inbounds [27 x [9 x i32]], ptr @g, i64 0, i64 %12, i64 %13
  store i32 %3, ptr %14, align 4, !tbaa !5
  %15 = add nuw nsw i32 %.zext24, 9
  %16 = zext nneg i32 %15 to i64
  %17 = getelementptr inbounds [27 x [9 x i32]], ptr @g, i64 0, i64 %16, i64 %12
  store i32 %3, ptr %17, align 4, !tbaa !5
  %18 = mul nuw nsw i32 %10, 9
  %19 = urem i8 %4, 3
  %narrow34 = mul nuw nsw i8 %19, 3
  %20 = urem i8 %5, 3
  %narrow36 = add nuw nsw i8 %narrow34, %20
  %21 = zext nneg i8 %narrow36 to i32
  %22 = add nuw nsw i32 %18, %21
  %23 = add nuw nsw i32 %.zext, 18
  %24 = zext nneg i32 %23 to i64
  %25 = getelementptr inbounds [27 x [9 x i32]], ptr @g, i64 0, i64 %24, i64 %13
  store i32 %22, ptr %25, align 4, !tbaa !5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, 81
  br i1 %exitcond.not, label %1, label %2, !llvm.loop !9
}

attributes #0 = { nofree norecurse nosync nounwind memory(write, argmem: none, inaccessiblemem: none) 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LoopRotatePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass