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

/* Variables and functions */
char EOF;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
char *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sscanf(char *, char *, int *, int *, int *);
void get_matrix_size(char *fn, int *rows, int *cols, int *nonzeros) {
  FILE *f;
  char header[64];
  char *rv = NULL;
  if ((f = fopen(fn, "r")) == NULL) {
    printf("can't open file <%s> \n", fn);
    exit(1);
  }
  rv = fgets(header, sizeof(header), f);
  if (*rv == EOF) {
    printf("Error reading file.\n");
    exit(1);
  }
  rv = fgets(header, sizeof(header), f);
  if (*rv == EOF) {
    printf("Error reading file.\n");
    exit(1);
  } else {
    sscanf(header, "%d %d %d", rows, cols, nonzeros);
  }
  printf("Rows: %d, Columns: %d, Non-zeros: %d\n", *rows, *cols, *nonzeros);
  fclose(f);
}


x86 assembly (clang, -O0):
<get_matrix_size>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
movq   $0x0,-0x78(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe72(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    11bd <get_matrix_size+0x5d>
mov    -0x8(%rbp),%rsi
lea    0xe56(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
lea    -0x70(%rbp),%rdi
mov    -0x28(%rbp),%rdx
mov    $0x40,%esi
call   1050 <fgets@plt>
mov    %rax,-0x78(%rbp)
mov    -0x78(%rbp),%rax
movsbl (%rax),%eax
mov    0x2e07(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
jne    1204 <get_matrix_size+0xa4>
lea    0xe26(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
lea    -0x70(%rbp),%rdi
mov    -0x28(%rbp),%rdx
mov    $0x40,%esi
call   1050 <fgets@plt>
mov    %rax,-0x78(%rbp)
mov    -0x78(%rbp),%rax
movsbl (%rax),%eax
mov    0x2dc0(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
jne    124b <get_matrix_size+0xeb>
lea    0xddf(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
lea    -0x70(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
mov    -0x20(%rbp),%r8
lea    0xdcc(%rip),%rsi
call   1060 <sscanf@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%esi
mov    -0x18(%rbp),%rax
mov    (%rax),%edx
mov    -0x20(%rbp),%rax
mov    (%rax),%ecx
lea    0xdb7(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_matrix_size>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x40,%rsp
mov    %rcx,%r14
mov    %rdx,%r15
mov    %rsi,%r12
mov    %rdi,%r13
lea    0xe70(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     1234 <get_matrix_size+0xc4>
mov    %rax,%rbx
mov    %rsp,%rdi
mov    $0x40,%esi
mov    %rax,%rdx
call   1060 <fgets@plt>
mov    (%rax),%al
mov    0x2e2e(%rip),%r13
cmp    0x0(%r13),%al
je     121e <get_matrix_size+0xae>
mov    %rsp,%rdi
mov    $0x40,%esi
mov    %rbx,%rdx
call   1060 <fgets@plt>
mov    (%rax),%al
cmp    0x0(%r13),%al
je     121e <get_matrix_size+0xae>
lea    0xe3a(%rip),%rsi
mov    %rsp,%rdi
mov    %r12,%rdx
mov    %r15,%rcx
mov    %r14,%r8
call   1070 <sscanf@plt>
mov    (%r12),%esi
mov    (%r15),%edx
mov    (%r14),%ecx
lea    0xe21(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
add    $0x40,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
lea    0xe23(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
lea    0xdc7(%rip),%rdi
mov    %r13,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [23 x i8] c"can't open file <%s> \0A\00"
@EOF = global i8 0
@.str.2 = [21 x i8] c"Error reading file.\0A\00"
@.str.3 = [9 x i8] c"%d %d %d\00"
@.str.4 = [38 x i8] c"Rows: %d, Columns: %d, Non-zeros: %d\0A\00"
define void @get_matrix_size(i8* %0, i32* %1, i32* %2, i32* %3) {
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i32*
%10 = alloca [64 x i8]
%11 = alloca i8*
store i8* %0, i8** %5
store i32* %1, i32** %6
store i32* %2, i32** %7
store i32* %3, i32** %8
store i8* null, i8** %11
%12 = load i8*, i8** %5
%13 = call i32* @fopen(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %13, i32** %9
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %19
15: ; preds = %4
%16 = load i8*, i8** %5
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* %16)
%18 = call i32 @exit(i32 1)
unreachable
19: ; preds = %4
%20 = getelementptr inbounds [64 x i8], [64 x i8]* %10, i64 0, i64 0
%21 = load i32*, i32** %9
%22 = call i8* @fgets(i8* %20, i32 64, i32* %21)
store i8* %22, i8** %11
%23 = load i8*, i8** %11
%24 = load i8, i8* %23
%25 = sext i8 %24 to i32
%26 = load i8, i8* @EOF
%27 = sext i8 %26 to i32
%28 = icmp eq i32 %25, %27
br i1 %28, label %29, label %32
29: ; preds = %19
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
%31 = call i32 @exit(i32 1)
unreachable
32: ; preds = %19
%33 = getelementptr inbounds [64 x i8], [64 x i8]* %10, i64 0, i64 0
%34 = load i32*, i32** %9
%35 = call i8* @fgets(i8* %33, i32 64, i32* %34)
store i8* %35, i8** %11
%36 = load i8*, i8** %11
%37 = load i8, i8* %36
%38 = sext i8 %37 to i32
%39 = load i8, i8* @EOF
%40 = sext i8 %39 to i32
%41 = icmp eq i32 %38, %40
br i1 %41, label %42, label %45
42: ; preds = %32
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
%44 = call i32 @exit(i32 1)
unreachable
45: ; preds = %32
%46 = getelementptr inbounds [64 x i8], [64 x i8]* %10, i64 0, i64 0
%47 = load i32*, i32** %6
%48 = load i32*, i32** %7
%49 = load i32*, i32** %8
%50 = call i32 @sscanf(i8* %46, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i32* %47, i32* %48, i32* %49)
br label %51
51: ; preds = %45
%52 = load i32*, i32** %6
%53 = load i32, i32* %52
%54 = load i32*, i32** %7
%55 = load i32, i32* %54
%56 = load i32*, i32** %8
%57 = load i32, i32* %56
%58 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.4, i64 0, i64 0), i32 %53, i32 %55, i32 %57)
%59 = load i32*, i32** %9
%60 = call i32 @fclose(i32* %59)
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [23 x i8] c"can't open file <%s> \0A\00"
@EOF = global i8 0
@.str.3 = [9 x i8] c"%d %d %d\00"
@.str.4 = [38 x i8] c"Rows: %d, Columns: %d, Non-zeros: %d\0A\00"
@str.5 = [20 x i8] c"Error reading file.\00"
define void @get_matrix_size(i8* %0, i32* %1, i32* %2, i32* %3) {
%5 = alloca [64 x i8]
%6 = getelementptr inbounds [64 x i8], [64 x i8]* %5, i64 0, i64 0
%7 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%8 = icmp eq i32* %7, null
br i1 %8, label %9, label %12
9: ; preds = %4
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%11 = tail call i32 @exit(i32 1)
unreachable
12: ; preds = %4
%13 = call i8* @fgets(i8* %6, i32 64, i32* %7)
%14 = load i8, i8* %13
%15 = load i8, i8* @EOF
%16 = icmp eq i8 %14, %15
br i1 %16, label %17, label %20
17: ; preds = %12
%18 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str.5, i64 0, i64 0))
%19 = call i32 @exit(i32 1)
unreachable
20: ; preds = %12
%21 = call i8* @fgets(i8* %6, i32 64, i32* %7)
%22 = load i8, i8* %21
%23 = load i8, i8* @EOF
%24 = icmp eq i8 %22, %23
br i1 %24, label %25, label %28
25: ; preds = %20
%26 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str.5, i64 0, i64 0))
%27 = call i32 @exit(i32 1)
unreachable
28: ; preds = %20
%29 = call i32 @sscanf(i8* %6, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i32* %1, i32* %2, i32* %3)
%30 = load i32, i32* %1
%31 = load i32, i32* %2
%32 = load i32, i32* %3
%33 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str.4, i64 0, i64 0), i32 %30, i32 %31, i32 %32)
%34 = call i32 @fclose(i32* %7)
ret void
}