#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int **alloc_matrix(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ free_matrix(int **, int);
scalar_t__ get_edges(int **, int, int, int /*<<< orphan*/ *);
scalar_t__ read_first_values(int /*<<< orphan*/ *, int *, int *);
scalar_t__ search_tree(int **, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
int main(void) {
  int N = -1, M = -1;
  int **matrix;
  FILE *fIn = fopen("in.txt", "r");
  FILE *fOut = fopen("out.txt", "w");
  if (!fIn || !fOut) {
    fprintf(stderr, "File error!\n");
    return (0);
  }
  if (read_first_values(fIn, &N, &M) || !((matrix = alloc_matrix(N))) ||
      get_edges(matrix, M, N, fIn)) {
    fclose(fIn);
    fclose(fOut);
    return (0);
  }
  if ((M < (N - 1)) || search_tree(matrix, N, fOut))
    fprintf(stdout, "no spanning tree\n");
  free_matrix(matrix, N);
  fclose(fIn);
  fclose(fOut);
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0xffffffff,-0x8(%rbp)
movl   $0xffffffff,-0xc(%rbp)
lea    0xe5c(%rip),%rdi
lea    0xe5c(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x20(%rbp)
lea    0xe4e(%rip),%rdi
lea    0xe4f(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11e1 <main+0x61>
cmpq   $0x0,-0x28(%rbp)
jne    1202 <main+0x82>
mov    0x2df8(%rip),%rax
mov    (%rax),%edi
lea    0xe22(%rip),%rsi
call   1070 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    12d3 <main+0x153>
mov    -0x20(%rbp),%rdi
lea    -0x8(%rbp),%rsi
lea    -0xc(%rbp),%rdx
call   1060 <read_first_values@plt>
cmp    $0x0,%rax
jne    1250 <main+0xd0>
mov    -0x8(%rbp),%edi
call   1050 <alloc_matrix@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     1250 <main+0xd0>
mov    -0x18(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x8(%rbp),%edx
mov    -0x20(%rbp),%rcx
call   1080 <get_edges@plt>
cmp    $0x0,%rax
je     126e <main+0xee>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x28(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x0,-0x4(%rbp)
jmp    12d3 <main+0x153>
mov    -0xc(%rbp),%eax
mov    -0x8(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jl     1299 <main+0x119>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%esi
mov    -0x28(%rbp),%rdx
call   1090 <search_tree@plt>
cmp    $0x0,%rax
je     12ae <main+0x12e>
mov    0x2d38(%rip),%rax
mov    (%rax),%edi
lea    0xd77(%rip),%rsi
call   1070 <fprintf@plt>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%esi
call   1030 <free_matrix@plt>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x28(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
movl   $0xffffffff,0x8(%rsp)
ff
movl   $0xffffffff,0xc(%rsp)
ff
lea    0xe60(%rip),%rdi
lea    0xe60(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,%rbx
lea    0xe53(%rip),%rdi
lea    0xe54(%rip),%rsi
call   10a0 <fopen@plt>
test   %rbx,%rbx
je     11f8 <main+0x78>
mov    %rax,%r14
test   %rax,%rax
je     11f8 <main+0x78>
lea    0x8(%rsp),%rsi
lea    0xc(%rsp),%rdx
mov    %rbx,%rdi
call   1060 <read_first_values@plt>
test   %rax,%rax
je     1219 <main+0x99>
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    %r14,%rdi
call   1040 <fclose@plt>
jmp    120d <main+0x8d>
mov    0x2de1(%rip),%rax
mov    (%rax),%edi
lea    0xe0b(%rip),%rsi
call   1070 <fprintf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
mov    0x8(%rsp),%edi
call   1050 <alloc_matrix@plt>
test   %rax,%rax
je     11e6 <main+0x66>
mov    %rax,%r15
mov    0xc(%rsp),%esi
mov    0x8(%rsp),%edx
mov    %rax,%rdi
mov    %rbx,%rcx
call   1080 <get_edges@plt>
test   %rax,%rax
jne    11e6 <main+0x66>
mov    0x8(%rsp),%esi
lea    -0x1(%rsi),%eax
cmp    %eax,0xc(%rsp)
jl     125f <main+0xdf>
mov    %r15,%rdi
mov    %r14,%rdx
call   1090 <search_tree@plt>
test   %rax,%rax
je     1274 <main+0xf4>
mov    0x2d72(%rip),%rax
mov    (%rax),%edi
lea    0xdb1(%rip),%rsi
call   1070 <fprintf@plt>
mov    0x8(%rsp),%esi
mov    %r15,%rdi
call   1030 <free_matrix@plt>
jmp    11e6 <main+0x66>

LLVM IR (-O0):
@.str = [7 x i8] c"in.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [8 x i8] c"out.txt\00"
@.str.3 = [2 x i8] c"w\00"
@stderr = global i32 0
@.str.4 = [13 x i8] c"File error!\0A\00"
@stdout = global i32 0
@.str.5 = [18 x i8] c"no spanning tree\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32**
%5 = alloca i32*
%6 = alloca i32*
store i32 0, i32* %1
store i32 -1, i32* %2
store i32 -1, i32* %3
%7 = call i32* @fopen(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %7, i32** %5
%8 = call i32* @fopen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %8, i32** %6
%9 = load i32*, i32** %5
%10 = icmp ne i32* %9, null
br i1 %10, label %11, label %14
11: ; preds = %0
%12 = load i32*, i32** %6
%13 = icmp ne i32* %12, null
br i1 %13, label %17, label %14
14: ; preds = %11, %0
%15 = load i32, i32* @stderr
%16 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0))
store i32 0, i32* %1
br label %59
17: ; preds = %11
%18 = load i32*, i32** %5
%19 = call i64 @read_first_values(i32* %18, i32* %2, i32* %3)
%20 = icmp ne i64 %19, 0
br i1 %20, label %32, label %21
21: ; preds = %17
%22 = load i32, i32* %2
%23 = call i32** @alloc_matrix(i32 %22)
store i32** %23, i32*** %4
%24 = icmp ne i32** %23, null
br i1 %24, label %25, label %32
25: ; preds = %21
%26 = load i32**, i32*** %4
%27 = load i32, i32* %3
%28 = load i32, i32* %2
%29 = load i32*, i32** %5
%30 = call i64 @get_edges(i32** %26, i32 %27, i32 %28, i32* %29)
%31 = icmp ne i64 %30, 0
br i1 %31, label %32, label %37
32: ; preds = %25, %21, %17
%33 = load i32*, i32** %5
%34 = call i32 @fclose(i32* %33)
%35 = load i32*, i32** %6
%36 = call i32 @fclose(i32* %35)
store i32 0, i32* %1
br label %59
37: ; preds = %25
%38 = load i32, i32* %3
%39 = load i32, i32* %2
%40 = sub nsw i32 %39, 1
%41 = icmp slt i32 %38, %40
br i1 %41, label %48, label %42
42: ; preds = %37
%43 = load i32**, i32*** %4
%44 = load i32, i32* %2
%45 = load i32*, i32** %6
%46 = call i64 @search_tree(i32** %43, i32 %44, i32* %45)
%47 = icmp ne i64 %46, 0
br i1 %47, label %48, label %51
48: ; preds = %42, %37
%49 = load i32, i32* @stdout
%50 = call i32 @fprintf(i32 %49, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0))
br label %51
51: ; preds = %48, %42
%52 = load i32**, i32*** %4
%53 = load i32, i32* %2
%54 = call i32 @free_matrix(i32** %52, i32 %53)
%55 = load i32*, i32** %5
%56 = call i32 @fclose(i32* %55)
%57 = load i32*, i32** %6
%58 = call i32 @fclose(i32* %57)
store i32 0, i32* %1
br label %59
59: ; preds = %51, %32, %14
%60 = load i32, i32* %1
ret i32 %60
}

LLVM IR (-O2):
@.str = [7 x i8] c"in.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [8 x i8] c"out.txt\00"
@.str.3 = [2 x i8] c"w\00"
@stderr = global i32 0
@.str.4 = [13 x i8] c"File error!\0A\00"
@stdout = global i32 0
@.str.5 = [18 x i8] c"no spanning tree\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = bitcast i32* %1 to i8*
store i32 -1, i32* %1
%4 = bitcast i32* %2 to i8*
store i32 -1, i32* %2
%5 = tail call i32* @fopen(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%6 = tail call i32* @fopen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%7 = icmp ne i32* %5, null
%8 = icmp ne i32* %6, null
%9 = and i1 %7, %8
br i1 %9, label %13, label %10
10: ; preds = %0
%11 = load i32, i32* @stderr
%12 = tail call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0))
br label %44
13: ; preds = %0
%14 = call i64 @read_first_values(i32* %5, i32* %1, i32* %2)
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %25
16: ; preds = %13
%17 = load i32, i32* %1
%18 = call i32** @alloc_matrix(i32 %17)
%19 = icmp eq i32** %18, null
br i1 %19, label %25, label %20
20: ; preds = %16
%21 = load i32, i32* %2
%22 = load i32, i32* %1
%23 = call i64 @get_edges(i32** %18, i32 %21, i32 %22, i32* %5)
%24 = icmp eq i64 %23, 0
br i1 %24, label %28, label %25
25: ; preds = %20, %16, %13
%26 = call i32 @fclose(i32* %5)
%27 = call i32 @fclose(i32* %6)
br label %44
28: ; preds = %20
%29 = load i32, i32* %2
%30 = load i32, i32* %1
%31 = add nsw i32 %30, -1
%32 = icmp slt i32 %29, %31
br i1 %32, label %36, label %33
33: ; preds = %28
%34 = call i64 @search_tree(i32** %18, i32 %30, i32* %6)
%35 = icmp eq i64 %34, 0
br i1 %35, label %39, label %36
36: ; preds = %33, %28
%37 = load i32, i32* @stdout
%38 = call i32 @fprintf(i32 %37, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0))
br label %39
39: ; preds = %36, %33
%40 = load i32, i32* %1
%41 = call i32 @free_matrix(i32** %18, i32 %40)
%42 = call i32 @fclose(i32* %5)
%43 = call i32 @fclose(i32* %6)
br label %44
44: ; preds = %39, %25, %10
ret i32 0
}