; LLVM IR from ksw2000/Data-Structure-in-C :: Stack (04-堆疊解迷宮問題)

; 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.d = type { i16, i16 }
%struct.s = type { i32, i32, i32, ptr }

@maze = external dso_local global [9 x [6 x i32]], align 16
@__const.main.direct = external hidden unnamed_addr constant [8 x %struct.d], align 16
@.str = external hidden unnamed_addr constant [47 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [44 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [6 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i32 @main() #0 {
  %1 = alloca i32, align 4
  %2 = alloca [8 x %struct.d], align 16
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 32, ptr %2) #4
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %2, ptr align 16 @__const.main.direct, i64 32, i1 false)
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #4
  store ptr null, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  store i32 0, ptr %4, align 4, !tbaa !9
  store i32 0, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  store i32 0, ptr %7, align 4, !tbaa !9
  store i32 2, ptr @maze, align 16, !tbaa !9
  br label %9

9:                                                ; preds = %113, %0
  %10 = load i32, ptr %7, align 4, !tbaa !9
  %11 = icmp ne i32 %10, 0
  %12 = xor i1 %11, true
  br i1 %12, label %13, label %114

13:                                               ; preds = %9
  store i32 0, ptr %6, align 4, !tbaa !9
  br label %14

14:                                               ; preds = %94, %13
  %15 = load i32, ptr %6, align 4, !tbaa !9
  %16 = icmp slt i32 %15, 8
  br i1 %16, label %17, label %97

17:                                               ; preds = %14
  %18 = load i32, ptr %4, align 4, !tbaa !9
  %19 = load i32, ptr %6, align 4, !tbaa !9
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds [8 x %struct.d], ptr %2, i64 0, i64 %20
  %22 = getelementptr inbounds %struct.d, ptr %21, i32 0, i32 0
  %23 = load i16, ptr %22, align 4, !tbaa !11
  %24 = sext i16 %23 to i32
  %25 = add nsw i32 %18, %24
  %26 = load i32, ptr %5, align 4, !tbaa !9
  %27 = load i32, ptr %6, align 4, !tbaa !9
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds [8 x %struct.d], ptr %2, i64 0, i64 %28
  %30 = getelementptr inbounds %struct.d, ptr %29, i32 0, i32 1
  %31 = load i16, ptr %30, align 2, !tbaa !14
  %32 = sext i16 %31 to i32
  %33 = add nsw i32 %26, %32
  %34 = call i32 @inBorder(i32 noundef %25, i32 noundef %33)
  %35 = icmp ne i32 %34, 0
  br i1 %35, label %36, label %93

36:                                               ; preds = %17
  %37 = load i32, ptr %4, align 4, !tbaa !9
  %38 = load i32, ptr %6, align 4, !tbaa !9
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds [8 x %struct.d], ptr %2, i64 0, i64 %39
  %41 = getelementptr inbounds %struct.d, ptr %40, i32 0, i32 0
  %42 = load i16, ptr %41, align 4, !tbaa !11
  %43 = sext i16 %42 to i32
  %44 = add nsw i32 %37, %43
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds [9 x [6 x i32]], ptr @maze, i64 0, i64 %45
  %47 = load i32, ptr %5, align 4, !tbaa !9
  %48 = load i32, ptr %6, align 4, !tbaa !9
  %49 = sext i32 %48 to i64
  %50 = getelementptr inbounds [8 x %struct.d], ptr %2, i64 0, i64 %49
  %51 = getelementptr inbounds %struct.d, ptr %50, i32 0, i32 1
  %52 = load i16, ptr %51, align 2, !tbaa !14
  %53 = sext i16 %52 to i32
  %54 = add nsw i32 %47, %53
  %55 = sext i32 %54 to i64
  %56 = getelementptr inbounds [6 x i32], ptr %46, i64 0, i64 %55
  %57 = load i32, ptr %56, align 4, !tbaa !9
  %58 = icmp eq i32 %57, 0
  br i1 %58, label %59, label %92

59:                                               ; preds = %36
  %60 = load i32, ptr %4, align 4, !tbaa !9
  %61 = load i32, ptr %5, align 4, !tbaa !9
  %62 = load i32, ptr %6, align 4, !tbaa !9
  call void @push(ptr noundef %3, i32 noundef %60, i32 noundef %61, i32 noundef %62)
  %63 = load i32, ptr %6, align 4, !tbaa !9
  %64 = sext i32 %63 to i64
  %65 = getelementptr inbounds [8 x %struct.d], ptr %2, i64 0, i64 %64
  %66 = getelementptr inbounds %struct.d, ptr %65, i32 0, i32 0
  %67 = load i16, ptr %66, align 4, !tbaa !11
  %68 = sext i16 %67 to i32
  %69 = load i32, ptr %4, align 4, !tbaa !9
  %70 = add nsw i32 %69, %68
  store i32 %70, ptr %4, align 4, !tbaa !9
  %71 = load i32, ptr %6, align 4, !tbaa !9
  %72 = sext i32 %71 to i64
  %73 = getelementptr inbounds [8 x %struct.d], ptr %2, i64 0, i64 %72
  %74 = getelementptr inbounds %struct.d, ptr %73, i32 0, i32 1
  %75 = load i16, ptr %74, align 2, !tbaa !14
  %76 = sext i16 %75 to i32
  %77 = load i32, ptr %5, align 4, !tbaa !9
  %78 = add nsw i32 %77, %76
  store i32 %78, ptr %5, align 4, !tbaa !9
  %79 = load i32, ptr %4, align 4, !tbaa !9
  %80 = sext i32 %79 to i64
  %81 = getelementptr inbounds [9 x [6 x i32]], ptr @maze, i64 0, i64 %80
  %82 = load i32, ptr %5, align 4, !tbaa !9
  %83 = sext i32 %82 to i64
  %84 = getelementptr inbounds [6 x i32], ptr %81, i64 0, i64 %83
  store i32 2, ptr %84, align 4, !tbaa !9
  store i32 -1, ptr %6, align 4, !tbaa !9
  %85 = load i32, ptr %4, align 4, !tbaa !9
  %86 = icmp eq i32 %85, 8
  br i1 %86, label %87, label %91

87:                                               ; preds = %59
  %88 = load i32, ptr %5, align 4, !tbaa !9
  %89 = icmp eq i32 %88, 5
  br i1 %89, label %90, label %91

90:                                               ; preds = %87
  store i32 2, ptr %7, align 4, !tbaa !9
  br label %97

91:                                               ; preds = %87, %59
  br label %92

92:                                               ; preds = %91, %36
  br label %93

93:                                               ; preds = %92, %17
  br label %94

94:                                               ; preds = %93
  %95 = load i32, ptr %6, align 4, !tbaa !9
  %96 = add nsw i32 %95, 1
  store i32 %96, ptr %6, align 4, !tbaa !9
  br label %14, !llvm.loop !15

97:                                               ; preds = %90, %14
  %98 = load i32, ptr %7, align 4, !tbaa !9
  %99 = icmp eq i32 %98, 2
  br i1 %99, label %100, label %101

100:                                              ; preds = %97
  br label %114

101:                                              ; preds = %97
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  %102 = call ptr @pop(ptr noundef %3)
  store ptr %102, ptr %8, align 8, !tbaa !5
  %103 = load ptr, ptr %8, align 8, !tbaa !5
  %104 = icmp ne ptr %103, null
  br i1 %104, label %105, label %112

105:                                              ; preds = %101
  %106 = load ptr, ptr %8, align 8, !tbaa !5
  %107 = getelementptr inbounds %struct.s, ptr %106, i32 0, i32 0
  %108 = load i32, ptr %107, align 8, !tbaa !17
  store i32 %108, ptr %4, align 4, !tbaa !9
  %109 = load ptr, ptr %8, align 8, !tbaa !5
  %110 = getelementptr inbounds %struct.s, ptr %109, i32 0, i32 1
  %111 = load i32, ptr %110, align 4, !tbaa !19
  store i32 %111, ptr %5, align 4, !tbaa !9
  br label %113

112:                                              ; preds = %101
  store i32 1, ptr %7, align 4, !tbaa !9
  br label %113

113:                                              ; preds = %112, %105
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  br label %9, !llvm.loop !20

114:                                              ; preds = %100, %9
  %115 = load i32, ptr %7, align 4, !tbaa !9
  %116 = icmp eq i32 %115, 2
  br i1 %116, label %117, label %119

117:                                              ; preds = %114
  %118 = call i32 (ptr, ...) @printf(ptr noundef @.str)
  br label %125

119:                                              ; preds = %114
  %120 = load i32, ptr %7, align 4, !tbaa !9
  %121 = icmp eq i32 %120, 1
  br i1 %121, label %122, label %124

122:                                              ; preds = %119
  %123 = call i32 (ptr, ...) @printf(ptr noundef @.str.1)
  br label %124

124:                                              ; preds = %122, %119
  br label %125

125:                                              ; preds = %124, %117
  %126 = call i32 @system(ptr noundef @.str.2)
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #4
  call void @llvm.lifetime.end.p0(i64 32, ptr %2) #4
  ret i32 0
}

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #2

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

; Function Attrs: nounwind uwtable
declare dso_local void @push(ptr noundef, i32 noundef, i32 noundef, i32 noundef) #0

; Function Attrs: nounwind uwtable
declare dso_local ptr @pop(ptr noundef) #0

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

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

declare i32 @system(ptr noundef) #3

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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { "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 #4 = { 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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !13, i64 0}
!12 = !{!"d", !13, i64 0, !13, i64 2}
!13 = !{!"short", !7, i64 0}
!14 = !{!12, !13, i64 2}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = !{!18, !10, i64 0}
!18 = !{!"s", !10, i64 0, !10, i64 4, !10, i64 8, !6, i64 16}
!19 = !{!18, !10, i64 4}
!20 = distinct !{!20, !16}


; 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.d = type { i16, i16 }

@maze = external dso_local local_unnamed_addr global [9 x [6 x i32]], align 16
@__const.main.direct = external hidden unnamed_addr constant [8 x %struct.d], align 16
@.str = external hidden unnamed_addr constant [47 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [44 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [6 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
.split:
  %0 = alloca ptr, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %0) #4
  store ptr null, ptr %0, align 8, !tbaa !5
  store i32 2, ptr @maze, align 16, !tbaa !9
  br label %.preheader

.preheader:                                       ; preds = %.preheader.backedge, %.split
  %.154 = phi i32 [ 0, %.split ], [ %.154.be, %.preheader.backedge ]
  %.03253 = phi i32 [ 0, %.split ], [ %.03253.be, %.preheader.backedge ]
  %.13552 = phi i32 [ 0, %.split ], [ %.13552.be, %.preheader.backedge ]
  %1 = sext i32 %.03253 to i64
  %2 = getelementptr inbounds [8 x %struct.d], ptr @__const.main.direct, i64 0, i64 %1
  %3 = load i16, ptr %2, align 4, !tbaa !11
  %4 = sext i16 %3 to i32
  %5 = add nsw i32 %.154, %4
  %6 = getelementptr inbounds i8, ptr %2, i64 2
  %7 = load i16, ptr %6, align 2, !tbaa !14
  %8 = sext i16 %7 to i32
  %9 = add nsw i32 %.13552, %8
  %10 = call i32 @inBorder(i32 noundef %5, i32 noundef %9)
  %.not42 = icmp eq i32 %10, 0
  br i1 %.not42, label %20, label %11

11:                                               ; preds = %.preheader
  %12 = sext i32 %5 to i64
  %13 = sext i32 %9 to i64
  %14 = getelementptr inbounds [9 x [6 x i32]], ptr @maze, i64 0, i64 %12, i64 %13
  %15 = load i32, ptr %14, align 4, !tbaa !9
  %16 = icmp eq i32 %15, 0
  br i1 %16, label %17, label %20

17:                                               ; preds = %11
  call void @push(ptr noundef nonnull %0, i32 noundef %.154, i32 noundef %.13552, i32 noundef %.03253)
  store i32 2, ptr %14, align 4, !tbaa !9
  %18 = icmp eq i32 %5, 8
  %19 = icmp eq i32 %9, 5
  %or.cond = and i1 %18, %19
  br i1 %or.cond, label %.loopexit, label %20

20:                                               ; preds = %.preheader, %17, %11
  %.236 = phi i32 [ %9, %17 ], [ %.13552, %11 ], [ %.13552, %.preheader ]
  %.133 = phi i32 [ -1, %17 ], [ %.03253, %11 ], [ %.03253, %.preheader ]
  %.2 = phi i32 [ %5, %17 ], [ %.154, %11 ], [ %.154, %.preheader ]
  %21 = add nsw i32 %.133, 1
  %22 = icmp slt i32 %.133, 7
  br i1 %22, label %.preheader.backedge, label %23

.preheader.backedge:                              ; preds = %20, %29
  %.154.be = phi i32 [ %.2, %20 ], [ %.4, %29 ]
  %.03253.be = phi i32 [ %21, %20 ], [ 0, %29 ]
  %.13552.be = phi i32 [ %.236, %20 ], [ %.438, %29 ]
  br label %.preheader, !llvm.loop !15

23:                                               ; preds = %20
  %24 = call ptr @pop(ptr noundef nonnull %0)
  %.not43.not = icmp eq ptr %24, null
  br i1 %.not43.not, label %29, label %25

25:                                               ; preds = %23
  %26 = load i32, ptr %24, align 8, !tbaa !17
  %27 = getelementptr inbounds i8, ptr %24, i64 4
  %28 = load i32, ptr %27, align 4, !tbaa !19
  br label %29

29:                                               ; preds = %23, %25
  %.438 = phi i32 [ %28, %25 ], [ %.236, %23 ]
  %.4 = phi i32 [ %26, %25 ], [ %.2, %23 ]
  br i1 %.not43.not, label %.loopexit, label %.preheader.backedge

.loopexit:                                        ; preds = %29, %17
  %.str.1.sink = phi ptr [ @.str, %17 ], [ @.str.1, %29 ]
  %30 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) %.str.1.sink)
  %31 = call i32 @system(ptr noundef nonnull @.str.2) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %0) #4
  ret i32 0
}

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

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

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

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

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

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

; Function Attrs: nofree
declare noundef i32 @system(ptr nocapture noundef readonly) local_unnamed_addr #3

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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #3 = { nofree "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 #4 = { 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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !13, i64 0}
!12 = !{!"d", !13, i64 0, !13, i64 2}
!13 = !{!"short", !7, i64 0}
!14 = !{!12, !13, i64 2}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = !{!18, !10, i64 0}
!18 = !{!"s", !10, i64 0, !10, i64 4, !10, i64 8, !6, i64 16}
!19 = !{!18, !10, i64 4}


; Effective O3 passes: ConstraintEliminationPass,CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SCCPPass,SROAPass,SimplifyCFGPass