; LLVM IR from sysprog21/shecc :: src (ssa)

; 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.var = type { [32 x i8], [32 x i8], i32, i8, i8, i32, i32, i32, i32, i32, ptr, i32, [64 x ptr], i32, %struct.rename_t, %struct.ref_block_list, ptr, ptr, ptr, i32, i8, i8, i8 }
%struct.rename_t = type { i32, [64 x i32], i32 }
%struct.ref_block_list = type { ptr, ptr }

@.str.61 = external hidden unnamed_addr constant [21 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
declare dso_local void @error(ptr noundef) #1

; Function Attrs: noreturn nounwind
declare void @abort() #2

; Function Attrs: nounwind uwtable
define dso_local ptr @get_stack_top_subscript_var(ptr noundef %0) #1 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  %7 = load ptr, ptr %3, align 8, !tbaa !5
  %8 = getelementptr inbounds %struct.var, ptr %7, i32 0, i32 10
  %9 = load ptr, ptr %8, align 8, !tbaa !9
  %10 = getelementptr inbounds %struct.var, ptr %9, i32 0, i32 14
  %11 = getelementptr inbounds %struct.rename_t, ptr %10, i32 0, i32 2
  %12 = load i32, ptr %11, align 4, !tbaa !15
  %13 = icmp slt i32 %12, 1
  br i1 %13, label %14, label %15

14:                                               ; preds = %1
  call void @error(ptr noundef @.str.61)
  br label %15

15:                                               ; preds = %14, %1
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  %16 = load ptr, ptr %3, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.var, ptr %16, i32 0, i32 10
  %18 = load ptr, ptr %17, align 8, !tbaa !9
  %19 = getelementptr inbounds %struct.var, ptr %18, i32 0, i32 14
  %20 = getelementptr inbounds %struct.rename_t, ptr %19, i32 0, i32 1
  %21 = load ptr, ptr %3, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.var, ptr %21, i32 0, i32 10
  %23 = load ptr, ptr %22, align 8, !tbaa !9
  %24 = getelementptr inbounds %struct.var, ptr %23, i32 0, i32 14
  %25 = getelementptr inbounds %struct.rename_t, ptr %24, i32 0, i32 2
  %26 = load i32, ptr %25, align 4, !tbaa !15
  %27 = sub nsw i32 %26, 1
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds [64 x i32], ptr %20, i64 0, i64 %28
  %30 = load i32, ptr %29, align 4, !tbaa !16
  store i32 %30, ptr %4, align 4, !tbaa !16
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  store i32 0, ptr %5, align 4, !tbaa !16
  br label %31

31:                                               ; preds = %63, %15
  %32 = load i32, ptr %5, align 4, !tbaa !16
  %33 = load ptr, ptr %3, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.var, ptr %33, i32 0, i32 10
  %35 = load ptr, ptr %34, align 8, !tbaa !9
  %36 = getelementptr inbounds %struct.var, ptr %35, i32 0, i32 13
  %37 = load i32, ptr %36, align 8, !tbaa !17
  %38 = icmp slt i32 %32, %37
  br i1 %38, label %40, label %39

39:                                               ; preds = %31
  store i32 2, ptr %6, align 4
  br label %66

40:                                               ; preds = %31
  %41 = load ptr, ptr %3, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.var, ptr %41, i32 0, i32 10
  %43 = load ptr, ptr %42, align 8, !tbaa !9
  %44 = getelementptr inbounds %struct.var, ptr %43, i32 0, i32 12
  %45 = load i32, ptr %5, align 4, !tbaa !16
  %46 = sext i32 %45 to i64
  %47 = getelementptr inbounds [64 x ptr], ptr %44, i64 0, i64 %46
  %48 = load ptr, ptr %47, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.var, ptr %48, i32 0, i32 11
  %50 = load i32, ptr %49, align 8, !tbaa !18
  %51 = load i32, ptr %4, align 4, !tbaa !16
  %52 = icmp eq i32 %50, %51
  br i1 %52, label %53, label %62

53:                                               ; preds = %40
  %54 = load ptr, ptr %3, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.var, ptr %54, i32 0, i32 10
  %56 = load ptr, ptr %55, align 8, !tbaa !9
  %57 = getelementptr inbounds %struct.var, ptr %56, i32 0, i32 12
  %58 = load i32, ptr %5, align 4, !tbaa !16
  %59 = sext i32 %58 to i64
  %60 = getelementptr inbounds [64 x ptr], ptr %57, i64 0, i64 %59
  %61 = load ptr, ptr %60, align 8, !tbaa !5
  store ptr %61, ptr %2, align 8
  store i32 1, ptr %6, align 4
  br label %66

62:                                               ; preds = %40
  br label %63

63:                                               ; preds = %62
  %64 = load i32, ptr %5, align 4, !tbaa !16
  %65 = add nsw i32 %64, 1
  store i32 %65, ptr %5, align 4, !tbaa !16
  br label %31, !llvm.loop !19

66:                                               ; preds = %53, %39
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  %67 = load i32, ptr %6, align 4
  switch i32 %67, label %69 [
    i32 2, label %68
  ]

68:                                               ; preds = %66
  call void @abort() #4
  unreachable

69:                                               ; preds = %66
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  %70 = load ptr, ptr %2, align 8
  ret ptr %70
}

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 = { noreturn 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 #3 = { nounwind }
attributes #4 = { noreturn 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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !6, i64 96}
!10 = !{!"var", !7, i64 0, !7, i64 32, !11, i64 64, !12, i64 68, !12, i64 69, !11, i64 72, !11, i64 76, !11, i64 80, !11, i64 84, !11, i64 88, !6, i64 96, !11, i64 104, !7, i64 112, !11, i64 624, !13, i64 628, !14, i64 896, !6, i64 912, !6, i64 920, !6, i64 928, !11, i64 936, !12, i64 940, !12, i64 941, !12, i64 942}
!11 = !{!"int", !7, i64 0}
!12 = !{!"_Bool", !7, i64 0}
!13 = !{!"", !11, i64 0, !7, i64 4, !11, i64 260}
!14 = !{!"ref_block_list", !6, i64 0, !6, i64 8}
!15 = !{!10, !11, i64 888}
!16 = !{!11, !11, i64 0}
!17 = !{!10, !11, i64 624}
!18 = !{!10, !11, i64 104}
!19 = distinct !{!19, !20}
!20 = !{!"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"

@.str.61 = external hidden unnamed_addr constant [21 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local void @error(ptr noundef) local_unnamed_addr #0

; Function Attrs: noreturn nounwind
declare void @abort() local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local ptr @get_stack_top_subscript_var(ptr nocapture noundef readonly %0) local_unnamed_addr #0 {
  %2 = getelementptr inbounds i8, ptr %0, i64 96
  %3 = load ptr, ptr %2, align 8, !tbaa !5
  %4 = getelementptr inbounds i8, ptr %3, i64 888
  %5 = load i32, ptr %4, align 4, !tbaa !14
  %6 = icmp slt i32 %5, 1
  br i1 %6, label %7, label %8

7:                                                ; preds = %1
  tail call void @error(ptr noundef nonnull @.str.61)
  %.pre = load ptr, ptr %2, align 8, !tbaa !5
  %.phi.trans.insert = getelementptr inbounds i8, ptr %.pre, i64 888
  %.pre20 = load i32, ptr %.phi.trans.insert, align 4, !tbaa !14
  br label %8

8:                                                ; preds = %7, %1
  %9 = phi i32 [ %.pre20, %7 ], [ %5, %1 ]
  %10 = phi ptr [ %.pre, %7 ], [ %3, %1 ]
  %11 = getelementptr inbounds i8, ptr %10, i64 632
  %12 = add nsw i32 %9, -1
  %13 = sext i32 %12 to i64
  %14 = getelementptr inbounds [64 x i32], ptr %11, i64 0, i64 %13
  %15 = load i32, ptr %14, align 4, !tbaa !15
  %16 = getelementptr inbounds i8, ptr %10, i64 624
  %17 = load i32, ptr %16, align 8, !tbaa !16
  %.not16 = icmp sgt i32 %17, 0
  br i1 %.not16, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %8
  %18 = getelementptr inbounds i8, ptr %10, i64 112
  %wide.trip.count = zext nneg i32 %17 to i64
  br label %20

19:                                               ; preds = %20
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge, label %20, !llvm.loop !17

20:                                               ; preds = %.lr.ph, %19
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %19 ]
  %21 = getelementptr inbounds [64 x ptr], ptr %18, i64 0, i64 %indvars.iv
  %22 = load ptr, ptr %21, align 8, !tbaa !19
  %23 = getelementptr inbounds i8, ptr %22, i64 104
  %24 = load i32, ptr %23, align 8, !tbaa !20
  %25 = icmp eq i32 %24, %15
  br i1 %25, label %26, label %19

._crit_edge:                                      ; preds = %19, %8
  tail call void @abort() #2
  unreachable

26:                                               ; preds = %20
  ret ptr %22
}

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 = { noreturn 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 = { noreturn 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, !11, i64 96}
!6 = !{!"var", !7, i64 0, !7, i64 32, !9, i64 64, !10, i64 68, !10, i64 69, !9, i64 72, !9, i64 76, !9, i64 80, !9, i64 84, !9, i64 88, !11, i64 96, !9, i64 104, !7, i64 112, !9, i64 624, !12, i64 628, !13, i64 896, !11, i64 912, !11, i64 920, !11, i64 928, !9, i64 936, !10, i64 940, !10, i64 941, !10, i64 942}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!"int", !7, i64 0}
!10 = !{!"_Bool", !7, i64 0}
!11 = !{!"any pointer", !7, i64 0}
!12 = !{!"", !9, i64 0, !7, i64 4, !9, i64 260}
!13 = !{!"ref_block_list", !11, i64 0, !11, i64 8}
!14 = !{!6, !9, i64 888}
!15 = !{!9, !9, i64 0}
!16 = !{!6, !9, i64 624}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}
!19 = !{!11, !11, i64 0}
!20 = !{!6, !9, i64 104}


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