#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
int /*<<< orphan*/ getgraph(int, int **, int);
int /*<<< orphan*/ initialize(int, int **, int *, int *);
int /*<<< orphan*/ path(int, int, int **, int *, int *);
int /*<<< orphan*/ printgraph(int, int, int *);
int /*<<< orphan*/ scanf(char *, int *, ...);
int main(void) {
  int T;
  scanf("%d", &T);
  while (T--) {
    int N, E, S;
    scanf("%d %d", &N, &E);
    int G[N][N], D[N], B[N];
    initialize(N, G, D, B);
    getgraph(N, G, E);
    scanf("%d", &S);
    S--;
    path(S, N, G, D, B);
    printgraph(S, N, D);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe9d(%rip),%rdi
lea    -0x8(%rbp),%rsi
mov    $0x0,%al
call   1060 <scanf@plt>
mov    -0x8(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x8(%rbp)
cmp    $0x0,%eax
je     1271 <main+0x121>
lea    0xe74(%rip),%rdi
xor    %eax,%eax
lea    -0xc(%rbp),%rsi
lea    -0x10(%rbp),%rdx
call   1060 <scanf@plt>
mov    -0xc(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
mov    %rax,%rcx
imul   %rcx,%rcx
lea    0xf(,%rcx,4),%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rsi
sub    %rcx,%rsi
mov    %rsi,-0x58(%rbp)
mov    %rsi,%rsp
mov    %rax,-0x28(%rbp)
mov    %rax,-0x30(%rbp)
mov    -0xc(%rbp),%eax
lea    0xf(,%rax,4),%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdx
sub    %rcx,%rdx
mov    %rdx,-0x48(%rbp)
mov    %rdx,%rsp
mov    %rax,-0x38(%rbp)
mov    -0xc(%rbp),%eax
lea    0xf(,%rax,4),%rdi
and    $0xfffffffffffffff0,%rdi
mov    %rsp,%rcx
sub    %rdi,%rcx
mov    %rcx,-0x50(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x40(%rbp)
mov    -0xc(%rbp),%edi
call   1040 <initialize@plt>
mov    -0x58(%rbp),%rsi
mov    -0xc(%rbp),%edi
mov    -0x10(%rbp),%edx
call   1030 <getgraph@plt>
lea    0xdd8(%rip),%rdi
lea    -0x14(%rbp),%rsi
mov    $0x0,%al
call   1060 <scanf@plt>
mov    -0x58(%rbp),%rdx
mov    -0x50(%rbp),%r8
mov    -0x48(%rbp),%rcx
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
mov    -0xc(%rbp),%esi
call   1050 <path@plt>
mov    -0x48(%rbp),%rdx
mov    -0x14(%rbp),%edi
mov    -0xc(%rbp),%esi
call   1070 <printgraph@plt>
mov    -0x20(%rbp),%rax
mov    %rax,%rsp
jmp    1171 <main+0x21>
xor    %eax,%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
lea    0xe9b(%rip),%rdi
lea    -0x34(%rbp),%rsi
xor    %eax,%eax
call   1060 <scanf@plt>
subl   $0x1,-0x34(%rbp)
jb     1248 <main+0xf8>
lea    -0x30(%rbp),%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
lea    0xe69(%rip),%rdi
lea    -0x2c(%rbp),%rsi
lea    -0x38(%rbp),%rdx
xor    %eax,%eax
call   1060 <scanf@plt>
mov    %rsp,%r13
mov    -0x2c(%rbp),%eax
imul   %rax,%rax
mov    %rsp,%r14
lea    0xf(,%rax,4),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r14
mov    %r14,%rsp
mov    -0x2c(%rbp),%edi
mov    %rsp,%r15
lea    0xf(,%rdi,4),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r15
mov    %r15,%rsp
mov    %rsp,%r12
sub    %rax,%r12
mov    %r12,%rsp
mov    %r14,%rsi
mov    %r15,%rdx
mov    %r12,%rcx
call   1040 <initialize@plt>
mov    -0x2c(%rbp),%edi
mov    -0x38(%rbp),%edx
mov    %r14,%rsi
call   1030 <getgraph@plt>
lea    0xdfa(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1060 <scanf@plt>
mov    -0x30(%rbp),%edi
add    $0xffffffff,%edi
mov    %edi,-0x30(%rbp)
mov    -0x2c(%rbp),%esi
mov    %r14,%rdx
mov    %r15,%rcx
mov    %r12,%r8
call   1050 <path@plt>
mov    -0x30(%rbp),%edi
mov    -0x2c(%rbp),%esi
mov    %r15,%rdx
call   1070 <printgraph@plt>
mov    %r13,%rsp
subl   $0x1,-0x34(%rbp)
jae    1190 <main+0x40>
xor    %eax,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
@.str.1 = [6 x i8] c"%d %d\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i64
%9 = alloca i64
%10 = alloca i64
store i32 0, i32* %1
%11 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
br label %12
12: ; preds = %16, %0
%13 = load i32, i32* %2
%14 = add nsw i32 %13, -1
store i32 %14, i32* %2
%15 = icmp ne i32 %13, 0
br i1 %15, label %16, label %49
16: ; preds = %12
%17 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32* %3, i32* %4)
%18 = load i32, i32* %3
%19 = zext i32 %18 to i64
%20 = load i32, i32* %3
%21 = zext i32 %20 to i64
%22 = call i8* @llvm.stacksave()
store i8* %22, i8** %6
%23 = mul nuw i64 %19, %21
%24 = alloca i32, i64 %23
store i64 %19, i64* %7
store i64 %21, i64* %8
%25 = load i32, i32* %3
%26 = zext i32 %25 to i64
%27 = alloca i32, i64 %26
store i64 %26, i64* %9
%28 = load i32, i32* %3
%29 = zext i32 %28 to i64
%30 = alloca i32, i64 %29
store i64 %29, i64* %10
%31 = load i32, i32* %3
%32 = bitcast i32* %24 to i32**
%33 = call i32 @initialize(i32 %31, i32** %32, i32* %27, i32* %30)
%34 = load i32, i32* %3
%35 = bitcast i32* %24 to i32**
%36 = load i32, i32* %4
%37 = call i32 @getgraph(i32 %34, i32** %35, i32 %36)
%38 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %5)
%39 = load i32, i32* %5
%40 = add nsw i32 %39, -1
store i32 %40, i32* %5
%41 = load i32, i32* %5
%42 = load i32, i32* %3
%43 = bitcast i32* %24 to i32**
%44 = call i32 @path(i32 %41, i32 %42, i32** %43, i32* %27, i32* %30)
%45 = load i32, i32* %5
%46 = load i32, i32* %3
%47 = call i32 @printgraph(i32 %45, i32 %46, i32* %27)
%48 = load i8*, i8** %6
br label %12
49: ; preds = %12
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@.str.1 = [6 x i8] c"%d %d\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = bitcast i32* %1 to i8*
%6 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %1)
%7 = load i32, i32* %1
%8 = add nsw i32 %7, -1
store i32 %8, i32* %1
%9 = icmp eq i32 %7, 0
br i1 %9, label %41, label %10
10: ; preds = %0
%11 = bitcast i32* %2 to i8*
%12 = bitcast i32* %3 to i8*
%13 = bitcast i32* %4 to i8*
br label %14
14: ; preds = %10, %14
%15 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32* %2, i32* %3)
%16 = load i32, i32* %2
%17 = zext i32 %16 to i64
%18 = call i8* @llvm.stacksave()
%19 = mul nuw i64 %17, %17
%20 = alloca i32, i64 %19
%21 = load i32, i32* %2
%22 = zext i32 %21 to i64
%23 = alloca i32, i64 %22
%24 = alloca i32, i64 %22
%25 = bitcast i32* %20 to i32**
%26 = call i32 @initialize(i32 %21, i32** %25, i32* %23, i32* %24)
%27 = load i32, i32* %2
%28 = load i32, i32* %3
%29 = call i32 @getgraph(i32 %27, i32** %25, i32 %28)
%30 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %4)
%31 = load i32, i32* %4
%32 = add nsw i32 %31, -1
store i32 %32, i32* %4
%33 = load i32, i32* %2
%34 = call i32 @path(i32 %32, i32 %33, i32** %25, i32* %23, i32* %24)
%35 = load i32, i32* %4
%36 = load i32, i32* %2
%37 = call i32 @printgraph(i32 %35, i32 %36, i32* %23)
%38 = load i32, i32* %1
%39 = add nsw i32 %38, -1
store i32 %39, i32* %1
%40 = icmp eq i32 %38, 0
br i1 %40, label %41, label %14
41: ; preds = %14, %0
ret i32 0
}