#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 */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ 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];
  if ((f = fopen(fn, "r")) == NULL) {
    printf("can't open file <%s> \n", fn);
    exit(1);
  }
  fgets(header, sizeof(header), f);
  fgets(header, sizeof(header), f);
  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    $0x70,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe7d(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    11b2 <get_matrix_size+0x52>
mov    -0x8(%rbp),%rsi
lea    0xe61(%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>
lea    -0x70(%rbp),%rdi
mov    -0x28(%rbp),%rdx
mov    $0x40,%esi
call   1050 <fgets@plt>
lea    -0x70(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
mov    -0x20(%rbp),%r8
lea    0xe2c(%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    0xe17(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x70,%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    0xe80(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     11f6 <get_matrix_size+0x96>
mov    %rax,%rbx
mov    %rsp,%r13
mov    %r13,%rdi
mov    $0x40,%esi
mov    %rax,%rdx
call   1050 <fgets@plt>
mov    %r13,%rdi
mov    $0x40,%esi
mov    %rbx,%rdx
call   1050 <fgets@plt>
lea    0xe62(%rip),%rsi
mov    %r13,%rdi
mov    %r12,%rdx
mov    %r15,%rcx
mov    %r14,%r8
call   1060 <sscanf@plt>
mov    (%r12),%esi
mov    (%r15),%edx
mov    (%r14),%ecx
lea    0xe49(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
add    $0x40,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
lea    0xe05(%rip),%rdi
mov    %r13,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x1,%edi
call   1080 <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"
@.str.2 = [9 x i8] c"%d %d %d\00"
@.str.3 = [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]
store i8* %0, i8** %5
store i32* %1, i32** %6
store i32* %2, i32** %7
store i32* %3, i32** %8
%11 = load i8*, i8** %5
%12 = call i32* @fopen(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %12, i32** %9
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %18
14: ; preds = %4
%15 = load i8*, i8** %5
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* %15)
%17 = call i32 @exit(i32 1)
unreachable
18: ; preds = %4
%19 = getelementptr inbounds [64 x i8], [64 x i8]* %10, i64 0, i64 0
%20 = load i32*, i32** %9
%21 = call i32 @fgets(i8* %19, i32 64, i32* %20)
%22 = getelementptr inbounds [64 x i8], [64 x i8]* %10, i64 0, i64 0
%23 = load i32*, i32** %9
%24 = call i32 @fgets(i8* %22, i32 64, i32* %23)
%25 = getelementptr inbounds [64 x i8], [64 x i8]* %10, i64 0, i64 0
%26 = load i32*, i32** %6
%27 = load i32*, i32** %7
%28 = load i32*, i32** %8
%29 = call i32 @sscanf(i8* %25, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32* %26, i32* %27, i32* %28)
%30 = load i32*, i32** %6
%31 = load i32, i32* %30
%32 = load i32*, i32** %7
%33 = load i32, i32* %32
%34 = load i32*, i32** %8
%35 = load i32, i32* %34
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.3, i64 0, i64 0), i32 %31, i32 %33, i32 %35)
%37 = load i32*, i32** %9
%38 = call i32 @fclose(i32* %37)
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"
@.str.2 = [9 x i8] c"%d %d %d\00"
@.str.3 = [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 [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 i32 @fgets(i8* %6, i32 64, i32* %7)
%14 = call i32 @fgets(i8* %6, i32 64, i32* %7)
%15 = call i32 @sscanf(i8* %6, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32* %1, i32* %2, i32* %3)
%16 = load i32, i32* %1
%17 = load i32, i32* %2
%18 = load i32, i32* %3
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str.3, i64 0, i64 0), i32 %16, i32 %17, i32 %18)
%20 = call i32 @fclose(i32* %7)
ret void
}