blob: 302de0544d2b90e0f10c30a37d80c4ec5b7b14ff (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
|
const empty_LS
func Main()
t.0 = HeapAllocZ(8)
if t.0 goto :null1
Error("null pointer")
null1:
t.1 = call :LS.Start(t.0 10)
PrintIntS(t.1)
ret
func LS.Start(this sz)
aux01 = call :LS.Init(this sz)
aux02 = call :LS.Print(this)
PrintIntS(9999)
t.0 = call :LS.Search(this 8)
PrintIntS(t.0)
t.1 = call :LS.Search(this 12)
PrintIntS(t.1)
t.2 = call :LS.Search(this 17)
PrintIntS(t.2)
t.3 = call :LS.Search(this 50)
PrintIntS(t.3)
ret 55
func LS.Print(this)
j = 1
while1_top:
t.0 = [this+4]
t.1 = LtS(j t.0)
if0 t.1 goto :while1_end
t.2 = [this+0]
if t.2 goto :null2
Error("null pointer")
null2:
t.3 = [t.2]
t.3 = Lt(j t.3)
if t.3 goto :bounds1
Error("array index out of bounds")
bounds1:
t.3 = MulS(j 4)
t.3 = Add(t.3 t.2)
t.4 = [t.3+4]
PrintIntS(t.4)
j = Add(j 1)
goto :while1_top
while1_end:
ret 0
func LS.Search(this num)
j = 1
ls01 = 0
ifound = 0
while2_top:
t.0 = [this+4]
t.1 = LtS(j t.0)
if0 t.1 goto :while2_end
t.2 = [this+0]
if t.2 goto :null3
Error("null pointer")
null3:
t.3 = [t.2]
t.3 = Lt(j t.3)
if t.3 goto :bounds2
Error("array index out of bounds")
bounds2:
t.3 = MulS(j 4)
t.3 = Add(t.3 t.2)
aux01 = [t.3+4]
aux02 = Add(num 1)
t.4 = LtS(aux01 num)
if0 t.4 goto :if1_else
nt = 0
goto :if1_end
if1_else:
t.5 = LtS(aux01 aux02)
if t.5 goto :if2_else
nt = 0
goto :if2_end
if2_else:
ls01 = 1
ifound = 1
j = [this+4]
if2_end:
if1_end:
j = Add(j 1)
goto :while2_top
while2_end:
ret ifound
func LS.Init(this sz)
[this+4] = sz
t.0 = call :AllocArray(sz)
[this+0] = t.0
j = 1
t.1 = [this+4]
k = Add(t.1 1)
while3_top:
t.2 = [this+4]
t.3 = LtS(j t.2)
if0 t.3 goto :while3_end
aux01 = MulS(2 j)
aux02 = Sub(k 3)
t.4 = [this+0]
if t.4 goto :null4
Error("null pointer")
null4:
t.5 = [t.4]
t.5 = Lt(j t.5)
if t.5 goto :bounds3
Error("array index out of bounds")
bounds3:
t.5 = MulS(j 4)
t.5 = Add(t.5 t.4)
t.6 = Add(aux01 aux02)
[t.5+4] = t.6
j = Add(j 1)
k = Sub(k 1)
goto :while3_top
while3_end:
ret 0
func AllocArray(size)
bytes = MulS(size 4)
bytes = Add(bytes 4)
v = HeapAllocZ(bytes)
[v] = size
ret v
|