Initial checkin
[oota-llvm.git] / test / Feature / recursivetype.ll
1 ; This file contains the output from the following compiled C code:
2 ; typedef struct list {
3 ;   struct list *Next;
4 ;   int Data;
5 ; } list;
6 ;
7 ; // Iterative insert fn
8 ; void InsertIntoListTail(list **L, int Data) {
9 ;   while (*L)
10 ;     L = &(*L)->Next;
11 ;   *L = (list*)malloc(sizeof(list));
12 ;   (*L)->Data = Data;
13 ;   (*L)->Next = 0;
14 ; }
15 ;
16 ; // Recursive list search fn
17 ; list *FindData(list *L, int Data) {
18 ;   if (L == 0) return 0;
19 ;   if (L->Data == Data) return L;
20 ;   return FindData(L->Next, Data);
21 ; }
22 ;
23 ; void DoListStuff() {
24 ;   list *MyList = 0;
25 ;   InsertIntoListTail(&MyList, 100);
26 ;   InsertIntoListTail(&MyList, 12);
27 ;   InsertIntoListTail(&MyList, 42);
28 ;   InsertIntoListTail(&MyList, 1123);
29 ;   InsertIntoListTail(&MyList, 1213);
30 ;
31 ;   if (FindData(MyList, 75)) foundIt();
32 ;   if (FindData(MyList, 42)) foundIt();
33 ;   if (FindData(MyList, 700)) foundIt();
34 ; }
35
36 %list = type { %list*, int }
37
38 declare sbyte *"malloc"(uint)
39
40 ;;**********************
41 implementation
42 ;;**********************
43
44 void "InsertIntoListTail"(%list** %L, int %Data)
45 begin
46 bb1:
47         %reg116 = load %list** %L                               ;;<%list*>
48         %cast1004 = cast ulong 0 to %list*                      ;;<%list*>
49         %cond1000 = seteq %list* %reg116, %cast1004             ;;<bool>
50         br bool %cond1000, label %bb3, label %bb2
51
52 bb2:
53         %reg117 = phi %list** [ %reg118, %bb2 ], [ %L, %bb1 ]   ;;<%list**>
54         %cast1010 = cast %list** %reg117 to %list***            ;;<%list***>
55         %reg118 = load %list*** %cast1010                       ;;<%list**>
56         %reg109 = load %list** %reg118                          ;;<%list*>
57         %cast1005 = cast ulong 0 to %list*                      ;;<%list*>
58         %cond1001 = setne %list* %reg109, %cast1005             ;;<bool>
59         br bool %cond1001, label %bb2, label %bb3
60
61 bb3:
62         %reg119 = phi %list** [ %reg118, %bb2 ], [ %L, %bb1 ]   ;;<%list**>
63         %cast1006 = cast %list** %reg119 to sbyte**             ;;<sbyte**>
64         %reg111 = call sbyte* %malloc(uint 16)                  ;;<sbyte*>
65         store sbyte* %reg111, sbyte** %cast1006                 ;;<void>
66         %reg111 = cast sbyte* %reg111 to ulong
67         %reg1002 = add ulong %reg111, 8
68         %reg1002 = cast ulong %reg1002 to sbyte*             ;;<sbyte*>
69         %cast1008 = cast sbyte* %reg1002 to int*                ;;<int*>
70         store int %Data, int* %cast1008                         ;;<void>
71         %cast1003 = cast ulong 0 to ulong*                      ;;<ulong*>
72         %cast1009 = cast sbyte* %reg111 to ulong**              ;;<ulong**>
73         store ulong* %cast1003, ulong** %cast1009               ;;<void>
74         ret void
75 end
76
77 %list* "FindData"(%list* %L, int %Data)
78 begin
79 bb1:
80         br label %bb2
81
82 bb2:
83         %reg115 = phi %list* [ %reg116, %bb6 ], [ %L, %bb1 ]    ;;<%list*>
84         %cast1014 = cast ulong 0 to %list*                      ;;<%list*>
85         %cond1011 = setne %list* %reg115, %cast1014             ;;<bool>
86         br bool %cond1011, label %bb4, label %bb3
87
88 bb3:
89         ret %list* null
90
91 bb4:
92         %idx = getelementptr %list* %reg115, long 0, ubyte 1                  ;;<int>
93         %reg111 = load int* %idx
94         %cond1013 = setne int %reg111, %Data                    ;;<bool>
95         br bool %cond1013, label %bb6, label %bb5
96
97 bb5:
98         ret %list* %reg115
99
100 bb6:
101         %idx2 = getelementptr %list* %reg115, long 0, ubyte 0                  ;;<%list*>
102         %reg116 = load %list** %idx2
103         br label %bb2
104 end