1; RUN: opt -basic-aa -S -O2 < %s | FileCheck %s
2; RUN: opt -aa-pipeline=basic-aa -S -passes='default<O2>' < %s | FileCheck %s
3; PR5009
4
5; CHECK: define i32 @main()
6; CHECK-NEXT: entry:
7; CHECK-NEXT:  call void @exit(i32 38)
8
9target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
10target triple = "x86_64-apple-darwin10.0.0"
11
12%struct.cont_t = type { void (i8*, i32)*, i8* }
13%struct.foo_sf_t = type { %struct.cont_t*, i32 }
14
15define i32 @main() nounwind ssp {
16entry:
17  %cont = alloca %struct.cont_t, align 8          ; <%struct.cont_t*> [#uses=4]
18  %tmp = getelementptr inbounds %struct.cont_t, %struct.cont_t* %cont, i32 0, i32 0 ; <void (i8*, i32)**> [#uses=1]
19  %tmp1 = getelementptr inbounds %struct.cont_t, %struct.cont_t* %cont, i32 0, i32 0 ; <void (i8*, i32)**> [#uses=2]
20  store void (i8*, i32)* bitcast (void (%struct.cont_t*, i32)* @quit to void (i8*, i32)*), void (i8*, i32)** %tmp1
21  %tmp2 = load void (i8*, i32)*, void (i8*, i32)** %tmp1            ; <void (i8*, i32)*> [#uses=1]
22  store void (i8*, i32)* %tmp2, void (i8*, i32)** %tmp
23  %tmp3 = getelementptr inbounds %struct.cont_t, %struct.cont_t* %cont, i32 0, i32 1 ; <i8**> [#uses=1]
24  store i8* null, i8** %tmp3
25  call void @foo(%struct.cont_t* %cont)
26  ret i32 0
27}
28
29define internal void @quit(%struct.cont_t* %cont, i32 %rcode) nounwind ssp {
30entry:
31  call void @exit(i32 %rcode) noreturn
32  unreachable
33}
34
35define internal void @foo(%struct.cont_t* %c) nounwind ssp {
36entry:
37  %sf = alloca %struct.foo_sf_t, align 8          ; <%struct.foo_sf_t*> [#uses=3]
38  %next = alloca %struct.cont_t, align 8          ; <%struct.cont_t*> [#uses=3]
39  %tmp = getelementptr inbounds %struct.foo_sf_t, %struct.foo_sf_t* %sf, i32 0, i32 0 ; <%struct.cont_t**> [#uses=1]
40  store %struct.cont_t* %c, %struct.cont_t** %tmp
41  %tmp2 = getelementptr inbounds %struct.foo_sf_t, %struct.foo_sf_t* %sf, i32 0, i32 1 ; <i32*> [#uses=1]
42  store i32 2, i32* %tmp2
43  %tmp4 = getelementptr inbounds %struct.cont_t, %struct.cont_t* %next, i32 0, i32 0 ; <void (i8*, i32)**> [#uses=1]
44  store void (i8*, i32)* bitcast (void (%struct.foo_sf_t*, i32)* @foo2 to void (i8*, i32)*), void (i8*, i32)** %tmp4
45  %tmp5 = getelementptr inbounds %struct.cont_t, %struct.cont_t* %next, i32 0, i32 1 ; <i8**> [#uses=1]
46  %conv = bitcast %struct.foo_sf_t* %sf to i8*    ; <i8*> [#uses=1]
47  store i8* %conv, i8** %tmp5
48  call void @bar(%struct.cont_t* %next, i32 14)
49  ret void
50}
51
52define internal void @foo2(%struct.foo_sf_t* %sf, i32 %y) nounwind ssp {
53entry:
54  %tmp1 = getelementptr inbounds %struct.foo_sf_t, %struct.foo_sf_t* %sf, i32 0, i32 0 ; <%struct.cont_t**> [#uses=1]
55  %tmp2 = load %struct.cont_t*, %struct.cont_t** %tmp1             ; <%struct.cont_t*> [#uses=1]
56  %tmp3 = getelementptr inbounds %struct.cont_t, %struct.cont_t* %tmp2, i32 0, i32 0 ; <void (i8*, i32)**> [#uses=1]
57  %tmp4 = load void (i8*, i32)*, void (i8*, i32)** %tmp3            ; <void (i8*, i32)*> [#uses=1]
58  %tmp6 = getelementptr inbounds %struct.foo_sf_t, %struct.foo_sf_t* %sf, i32 0, i32 0 ; <%struct.cont_t**> [#uses=1]
59  %tmp7 = load %struct.cont_t*, %struct.cont_t** %tmp6             ; <%struct.cont_t*> [#uses=1]
60  %conv = bitcast %struct.cont_t* %tmp7 to i8*    ; <i8*> [#uses=1]
61  %tmp9 = getelementptr inbounds %struct.foo_sf_t, %struct.foo_sf_t* %sf, i32 0, i32 1 ; <i32*> [#uses=1]
62  %tmp10 = load i32, i32* %tmp9                        ; <i32> [#uses=1]
63  %mul = mul i32 %tmp10, %y                       ; <i32> [#uses=1]
64  call void %tmp4(i8* %conv, i32 %mul)
65  ret void
66}
67
68define internal void @bar(%struct.cont_t* %c, i32 %y) nounwind ssp {
69entry:
70  %tmp1 = getelementptr inbounds %struct.cont_t, %struct.cont_t* %c, i32 0, i32 0 ; <void (i8*, i32)**> [#uses=1]
71  %tmp2 = load void (i8*, i32)*, void (i8*, i32)** %tmp1            ; <void (i8*, i32)*> [#uses=1]
72  %tmp4 = getelementptr inbounds %struct.cont_t, %struct.cont_t* %c, i32 0, i32 1 ; <i8**> [#uses=1]
73  %tmp5 = load i8*, i8** %tmp4                         ; <i8*> [#uses=1]
74  %add = add nsw i32 %y, 5                        ; <i32> [#uses=1]
75  call void %tmp2(i8* %tmp5, i32 %add)
76  ret void
77}
78
79declare void @exit(i32) noreturn
80
81