• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1; RUN: llvm-as < %s | llvm-dis > %t1.ll
2; RUN: llvm-as %t1.ll -o - | llvm-dis > %t2.ll
3; RUN: diff %t1.ll %t2.ll
4
5; This file contains the output from the following compiled C code:
6; typedef struct list {
7;   struct list *Next;
8;   int Data;
9; } list;
10;
11; // Iterative insert fn
12; void InsertIntoListTail(list **L, int Data) {
13;   while (*L)
14;     L = &(*L)->Next;
15;   *L = (list*)malloc(sizeof(list));
16;   (*L)->Data = Data;
17;   (*L)->Next = 0;
18; }
19;
20; // Recursive list search fn
21; list *FindData(list *L, int Data) {
22;   if (L == 0) return 0;
23;   if (L->Data == Data) return L;
24;   return FindData(L->Next, Data);
25; }
26;
27; void DoListStuff() {
28;   list *MyList = 0;
29;   InsertIntoListTail(&MyList, 100);
30;   InsertIntoListTail(&MyList, 12);
31;   InsertIntoListTail(&MyList, 42);
32;   InsertIntoListTail(&MyList, 1123);
33;   InsertIntoListTail(&MyList, 1213);
34;
35;   if (FindData(MyList, 75)) foundIt();
36;   if (FindData(MyList, 42)) foundIt();
37;   if (FindData(MyList, 700)) foundIt();
38; }
39
40%list = type { %list*, i32 }
41
42declare i8* @malloc(i32)
43
44define void @InsertIntoListTail(%list** %L, i32 %Data) {
45bb1:
46        %reg116 = load %list** %L               ; <%list*> [#uses=1]
47        %cast1004 = inttoptr i64 0 to %list*            ; <%list*> [#uses=1]
48        %cond1000 = icmp eq %list* %reg116, %cast1004           ; <i1> [#uses=1]
49        br i1 %cond1000, label %bb3, label %bb2
50
51bb2:            ; preds = %bb2, %bb1
52        %reg117 = phi %list** [ %reg118, %bb2 ], [ %L, %bb1 ]           ; <%list**> [#uses=1]
53        %cast1010 = bitcast %list** %reg117 to %list***         ; <%list***> [#uses=1]
54        %reg118 = load %list*** %cast1010               ; <%list**> [#uses=3]
55        %reg109 = load %list** %reg118          ; <%list*> [#uses=1]
56        %cast1005 = inttoptr i64 0 to %list*            ; <%list*> [#uses=1]
57        %cond1001 = icmp ne %list* %reg109, %cast1005           ; <i1> [#uses=1]
58        br i1 %cond1001, label %bb2, label %bb3
59
60bb3:            ; preds = %bb2, %bb1
61        %reg119 = phi %list** [ %reg118, %bb2 ], [ %L, %bb1 ]           ; <%list**> [#uses=1]
62        %cast1006 = bitcast %list** %reg119 to i8**             ; <i8**> [#uses=1]
63        %reg111 = call i8* @malloc( i32 16 )            ; <i8*> [#uses=3]
64        store i8* %reg111, i8** %cast1006
65        %reg111.upgrd.1 = ptrtoint i8* %reg111 to i64           ; <i64> [#uses=1]
66        %reg1002 = add i64 %reg111.upgrd.1, 8           ; <i64> [#uses=1]
67        %reg1002.upgrd.2 = inttoptr i64 %reg1002 to i8*         ; <i8*> [#uses=1]
68        %cast1008 = bitcast i8* %reg1002.upgrd.2 to i32*                ; <i32*> [#uses=1]
69        store i32 %Data, i32* %cast1008
70        %cast1003 = inttoptr i64 0 to i64*              ; <i64*> [#uses=1]
71        %cast1009 = bitcast i8* %reg111 to i64**                ; <i64**> [#uses=1]
72        store i64* %cast1003, i64** %cast1009
73        ret void
74}
75
76define %list* @FindData(%list* %L, i32 %Data) {
77bb1:
78        br label %bb2
79
80bb2:            ; preds = %bb6, %bb1
81        %reg115 = phi %list* [ %reg116, %bb6 ], [ %L, %bb1 ]            ; <%list*> [#uses=4]
82        %cast1014 = inttoptr i64 0 to %list*            ; <%list*> [#uses=1]
83        %cond1011 = icmp ne %list* %reg115, %cast1014           ; <i1> [#uses=1]
84        br i1 %cond1011, label %bb4, label %bb3
85
86bb3:            ; preds = %bb2
87        ret %list* null
88
89bb4:            ; preds = %bb2
90        %idx = getelementptr %list* %reg115, i64 0, i32 1               ; <i32*> [#uses=1]
91        %reg111 = load i32* %idx                ; <i32> [#uses=1]
92        %cond1013 = icmp ne i32 %reg111, %Data          ; <i1> [#uses=1]
93        br i1 %cond1013, label %bb6, label %bb5
94
95bb5:            ; preds = %bb4
96        ret %list* %reg115
97
98bb6:            ; preds = %bb4
99        %idx2 = getelementptr %list* %reg115, i64 0, i32 0              ; <%list**> [#uses=1]
100        %reg116 = load %list** %idx2            ; <%list*> [#uses=1]
101        br label %bb2
102}
103
104