#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 int64_t;
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, int64_t *M, int64_t *N, int64_t *nz,
                         int64_t *numlinesread) {
  char line[1025];
  int64_t num_items_read;
  *M = *N = *nz = 0;
  do {
    (*numlinesread) = (*numlinesread) + 1;
    if (fgets(line, 1025, f) == NULL)
      return 12;
  } while (line[0] == '%');
  if (sscanf(line, "%lld %lld %lld", M, N, nz) == 3)
    return 0;
  else
    do {
      num_items_read = fscanf(f, "%lld %lld %lld", M, N, nz);
      if (num_items_read == EOF)
        return 12;
    } while (num_items_read != 3);
  return 0;
}


x86 assembly (clang, -O0):
<mm_read_mtx_crd_size>:
push   %rbp
mov    %rsp,%rbp
sub    $0x450,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
mov    -0x28(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x20(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x18(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x30(%rbp),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    -0x30(%rbp),%rax
mov    %ecx,(%rax)
lea    -0x440(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x401,%esi
call   1040 <fgets@plt>
cmp    $0x0,%rax
jne    11a7 <mm_read_mtx_crd_size+0x77>
movl   $0xc,-0x4(%rbp)
jmp    1256 <mm_read_mtx_crd_size+0x126>
jmp    11ac <mm_read_mtx_crd_size+0x7c>
movsbl -0x440(%rbp),%eax
cmp    $0x25,%eax
je     116d <mm_read_mtx_crd_size+0x3d>
lea    -0x440(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
mov    -0x28(%rbp),%r8
lea    0xe2a(%rip),%rsi
call   1050 <sscanf@plt>
cmp    $0x3,%eax
jne    11f0 <mm_read_mtx_crd_size+0xc0>
movl   $0x0,-0x4(%rbp)
jmp    1256 <mm_read_mtx_crd_size+0x126>
jmp    11f5 <mm_read_mtx_crd_size+0xc5>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
mov    -0x28(%rbp),%r8
lea    0xdf4(%rip),%rsi
call   1030 <fscanf@plt>
mov    %eax,-0x444(%rbp)
mov    -0x444(%rbp),%eax
mov    0x2dc4(%rip),%rcx
cmp    (%rcx),%eax
jne    1238 <mm_read_mtx_crd_size+0x108>
movl   $0xc,-0x4(%rbp)
jmp    1256 <mm_read_mtx_crd_size+0x126>
jmp    123d <mm_read_mtx_crd_size+0x10d>
cmpl   $0x3,-0x444(%rbp)
jne    11f5 <mm_read_mtx_crd_size+0xc5>
jmp    124f <mm_read_mtx_crd_size+0x11f>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x450,%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    $0x418,%rsp
mov    %r8,%rbx
mov    %rdx,%r15
mov    %rsi,%r12
mov    %rdi,%r13
mov    %rcx,0x8(%rsp)
movl   $0x0,(%rcx)
movl   $0x0,(%rdx)
movl   $0x0,(%rsi)
lea    0x10(%rsp),%r14
mov    $0xc,%ebp
xchg   %ax,%ax
addl   $0x1,(%rbx)
mov    %r14,%rdi
mov    $0x401,%esi
mov    %r13,%rdx
call   1040 <fgets@plt>
test   %rax,%rax
je     11e1 <mm_read_mtx_crd_size+0xb1>
cmpb   $0x25,0x10(%rsp)
je     1170 <mm_read_mtx_crd_size+0x40>
lea    0xe6a(%rip),%rsi
lea    0x10(%rsp),%rdi
mov    %r12,%rdx
mov    %r15,%rcx
mov    0x8(%rsp),%r8
call   1050 <sscanf@plt>
cmp    $0x3,%eax
je     11df <mm_read_mtx_crd_size+0xaf>
lea    0xe49(%rip),%r14
mov    0x2e2a(%rip),%rbx
xchg   %ax,%ax
mov    %r13,%rdi
mov    %r14,%rsi
mov    %r12,%rdx
mov    %r15,%rcx
mov    0x8(%rsp),%r8
call   1030 <fscanf@plt>
cmp    (%rbx),%eax
je     11e1 <mm_read_mtx_crd_size+0xb1>
cmp    $0x3,%eax
jne    11c0 <mm_read_mtx_crd_size+0x90>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x418,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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