#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 EOF;
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int fscanf(int /*<<< orphan*/ *, char *, int *, int *, int *);
int sscanf(char *, char *, int *, int *, int *);
int mm_read_mtx_crd_size(FILE *f, int *M, int *N, int *nz) {
  char line[1025];
  int num_items_read;
  *M = *N = *nz = 0;
  do {
    if (fgets(line, 1025, f) == NULL)
      return 12;
  } while (line[0] == '%');
  if (sscanf(line, "%d %d %d", M, N, nz) >= 2)
    return 0;
  else
    do {
      num_items_read = fscanf(f, "%d %d %d", M, N, nz);
      if (num_items_read == EOF)
        return 12;
    } while (num_items_read < 2);
  return 0;
}


x86 assembly (clang, -O0):
<mm_read_mtx_crd_size>:
push   %rbp
mov    %rsp,%rbp
sub    $0x440,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x28(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x20(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x18(%rbp),%rax
movl   $0x0,(%rax)
lea    -0x430(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x401,%esi
call   1040 <fgets@plt>
cmp    $0x0,%rax
jne    1194 <mm_read_mtx_crd_size+0x64>
movl   $0xc,-0x4(%rbp)
jmp    1243 <mm_read_mtx_crd_size+0x113>
jmp    1199 <mm_read_mtx_crd_size+0x69>
movsbl -0x430(%rbp),%eax
cmp    $0x25,%eax
je     1169 <mm_read_mtx_crd_size+0x39>
lea    -0x430(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
mov    -0x28(%rbp),%r8
lea    0xe3d(%rip),%rsi
call   1050 <sscanf@plt>
cmp    $0x2,%eax
jl     11dd <mm_read_mtx_crd_size+0xad>
movl   $0x0,-0x4(%rbp)
jmp    1243 <mm_read_mtx_crd_size+0x113>
jmp    11e2 <mm_read_mtx_crd_size+0xb2>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
mov    -0x28(%rbp),%r8
lea    0xe07(%rip),%rsi
call   1030 <fscanf@plt>
mov    %eax,-0x434(%rbp)
mov    -0x434(%rbp),%eax
mov    0x2dd7(%rip),%rcx
cmp    (%rcx),%eax
jne    1225 <mm_read_mtx_crd_size+0xf5>
movl   $0xc,-0x4(%rbp)
jmp    1243 <mm_read_mtx_crd_size+0x113>
jmp    122a <mm_read_mtx_crd_size+0xfa>
cmpl   $0x2,-0x434(%rbp)
jl     11e2 <mm_read_mtx_crd_size+0xb2>
jmp    123c <mm_read_mtx_crd_size+0x10c>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x440,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mm_read_mtx_crd_size>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x408,%rsp
mov    %rcx,%r14
mov    %rdx,%r15
mov    %rsi,%r12
mov    %rdi,%rbx
movl   $0x0,(%rcx)
movl   $0x0,(%rdx)
movl   $0x0,(%rsi)
mov    %rsp,%r13
mov    $0xc,%ebp
nopw   0x0(%rax,%rax,1)
mov    %r13,%rdi
mov    $0x401,%esi
mov    %rbx,%rdx
call   1040 <fgets@plt>
test   %rax,%rax
je     11d5 <mm_read_mtx_crd_size+0xa5>
cmpb   $0x25,(%rsp)
je     1170 <mm_read_mtx_crd_size+0x40>
lea    0xe6e(%rip),%rsi
mov    %rsp,%rdi
mov    %r12,%rdx
mov    %r15,%rcx
mov    %r14,%r8
call   1050 <sscanf@plt>
cmp    $0x1,%eax
jg     11d3 <mm_read_mtx_crd_size+0xa3>
mov    0x2e39(%rip),%r13
nop
mov    %rbx,%rdi
lea    0xe46(%rip),%rsi
mov    %r12,%rdx
mov    %r15,%rcx
mov    %r14,%r8
call   1030 <fscanf@plt>
cmp    0x0(%r13),%eax
je     11d5 <mm_read_mtx_crd_size+0xa5>
cmp    $0x2,%eax
jl     11b0 <mm_read_mtx_crd_size+0x80>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x408,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [9 x i8] c"%d %d %d\00"
@EOF = global i32 0
define i32 @mm_read_mtx_crd_size(i32* %0, i32* %1, i32* %2, i32* %3) {
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i32*
%10 = alloca [1025 x i8]
%11 = alloca i32
store i32* %0, i32** %6
store i32* %1, i32** %7
store i32* %2, i32** %8
store i32* %3, i32** %9
%12 = load i32*, i32** %9
store i32 0, i32* %12
%13 = load i32*, i32** %8
store i32 0, i32* %13
%14 = load i32*, i32** %7
store i32 0, i32* %14
br label %15
15: ; preds = %22, %4
%16 = getelementptr inbounds [1025 x i8], [1025 x i8]* %10, i64 0, i64 0
%17 = load i32*, i32** %6
%18 = call i32* @fgets(i8* %16, i32 1025, i32* %17)
%19 = icmp eq i32* %18, null
br i1 %19, label %20, label %21
20: ; preds = %15
store i32 12, i32* %5
br label %52
21: ; preds = %15
br label %22
22: ; preds = %21
%23 = getelementptr inbounds [1025 x i8], [1025 x i8]* %10, i64 0, i64 0
%24 = load i8, i8* %23
%25 = sext i8 %24 to i32
%26 = icmp eq i32 %25, 37
br i1 %26, label %15, label %27
27: ; preds = %22
%28 = getelementptr inbounds [1025 x i8], [1025 x i8]* %10, i64 0, i64 0
%29 = load i32*, i32** %7
%30 = load i32*, i32** %8
%31 = load i32*, i32** %9
%32 = call i32 @sscanf(i8* %28, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32* %29, i32* %30, i32* %31)
%33 = icmp sge i32 %32, 2
br i1 %33, label %34, label %35
34: ; preds = %27
store i32 0, i32* %5
br label %52
35: ; preds = %27
br label %36
36: ; preds = %47, %35
%37 = load i32*, i32** %6
%38 = load i32*, i32** %7
%39 = load i32*, i32** %8
%40 = load i32*, i32** %9
%41 = call i32 @fscanf(i32* %37, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32* %38, i32* %39, i32* %40)
store i32 %41, i32* %11
%42 = load i32, i32* %11
%43 = load i32, i32* @EOF
%44 = icmp eq i32 %42, %43
br i1 %44, label %45, label %46
45: ; preds = %36
store i32 12, i32* %5
br label %52
46: ; preds = %36
br label %47
47: ; preds = %46
%48 = load i32, i32* %11
%49 = icmp slt i32 %48, 2
br i1 %49, label %36, label %50
50: ; preds = %47
br label %51
51: ; preds = %50
store i32 0, i32* %5
br label %52
52: ; preds = %51, %45, %34, %20
%53 = load i32, i32* %5
ret i32 %53
}

LLVM IR (-O2):
@.str = [9 x i8] c"%d %d %d\00"
@EOF = global i32 0
define i32 @mm_read_mtx_crd_size(i32* nocapture %0, i32* %1, i32* %2, i32* %3) {
%5 = alloca [1025 x i8]
%6 = getelementptr inbounds [1025 x i8], [1025 x i8]* %5, i64 0, i64 0
store i32 0, i32* %3
store i32 0, i32* %2
store i32 0, i32* %1
br label %7
7: ; preds = %10, %4
%8 = call i32* @fgets(i8* %6, i32 1025, i32* %0)
%9 = icmp eq i32* %8, null
br i1 %9, label %22, label %10
10: ; preds = %7
%11 = load i8, i8* %6
%12 = icmp eq i8 %11, 37
br i1 %12, label %7, label %13
13: ; preds = %10
%14 = call i32 @sscanf(i8* %6, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32* %1, i32* %2, i32* %3)
%15 = icmp sgt i32 %14, 1
br i1 %15, label %22, label %16
16: ; preds = %13, %20
%17 = call i32 @fscanf(i32* %0, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32* %1, i32* %2, i32* %3)
%18 = load i32, i32* @EOF
%19 = icmp eq i32 %17, %18
br i1 %19, label %22, label %20
20: ; preds = %16
%21 = icmp slt i32 %17, 2
br i1 %21, label %16, label %22
22: ; preds = %7, %20, %16, %13
%23 = phi i32 [ 0, %13 ], [ 0, %20 ], [ 12, %16 ], [ 12, %7 ]
ret i32 %23
}