#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(unsigned char *, int, int /*<<< orphan*/ *);
int fscanf(int /*<<< orphan*/ *, char *, int *, int *, int *);
int mm_print_error(int /*<<< orphan*/ *, int);
int sscanf(unsigned char *, char *, int *, int *, int *);
int mm_read_mtx_crd_size(FILE *fp, int *row_dim, int *col_dim,
                         int *num_nonzeros) {
  unsigned char line[4096];
  int num_items_read;
  *row_dim = 0;
  *col_dim = 0;
  *num_nonzeros = 0;
  do {
    if (fgets(line, 4096, fp) == NULL)
      return mm_print_error(NULL, 17);
  } while (line[0] == '%');
  if (sscanf(line, "%d %d %d", row_dim, col_dim, num_nonzeros) == 3) {
    return (0);
  } else {
    do {
      num_items_read = fscanf(fp, "%d %d %d", row_dim, col_dim, num_nonzeros);
      if (num_items_read == EOF)
        return mm_print_error(NULL, 17);
    } while (num_items_read != 3);
  }
  return (0);
}


x86 assembly (clang, -O0):
<mm_read_mtx_crd_size>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1040,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x18(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x20(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x28(%rbp),%rax
movl   $0x0,(%rax)
lea    -0x1030(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x1000,%esi
call   1040 <fgets@plt>
cmp    $0x0,%rax
jne    11ae <mm_read_mtx_crd_size+0x6e>
xor    %eax,%eax
mov    %eax,%edi
mov    $0x11,%esi
call   1060 <mm_print_error@plt>
mov    %eax,-0x4(%rbp)
jmp    1267 <mm_read_mtx_crd_size+0x127>
jmp    11b3 <mm_read_mtx_crd_size+0x73>
movzbl -0x1030(%rbp),%eax
cmp    $0x25,%eax
je     1179 <mm_read_mtx_crd_size+0x39>
lea    -0x1030(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
mov    -0x28(%rbp),%r8
lea    0xe23(%rip),%rsi
call   1050 <sscanf@plt>
cmp    $0x3,%eax
jne    11f7 <mm_read_mtx_crd_size+0xb7>
movl   $0x0,-0x4(%rbp)
jmp    1267 <mm_read_mtx_crd_size+0x127>
jmp    11fc <mm_read_mtx_crd_size+0xbc>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
mov    -0x28(%rbp),%r8
lea    0xded(%rip),%rsi
call   1030 <fscanf@plt>
mov    %eax,-0x1034(%rbp)
mov    -0x1034(%rbp),%eax
mov    0x2dbd(%rip),%rcx
cmp    (%rcx),%eax
jne    1249 <mm_read_mtx_crd_size+0x109>
xor    %eax,%eax
mov    %eax,%edi
mov    $0x11,%esi
call   1060 <mm_print_error@plt>
mov    %eax,-0x4(%rbp)
jmp    1267 <mm_read_mtx_crd_size+0x127>
jmp    124e <mm_read_mtx_crd_size+0x10e>
cmpl   $0x3,-0x1034(%rbp)
jne    11fc <mm_read_mtx_crd_size+0xbc>
jmp    1260 <mm_read_mtx_crd_size+0x120>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1040,%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    $0x1008,%rsp
mov    %rcx,%r14
mov    %rdx,%r15
mov    %rsi,%r12
mov    %rdi,%rbx
movl   $0x0,(%rsi)
movl   $0x0,(%rdx)
movl   $0x0,(%rcx)
mov    %rsp,%rbp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rbp,%rdi
mov    $0x1000,%esi
mov    %rbx,%rdx
call   1040 <fgets@plt>
test   %rax,%rax
je     11f3 <mm_read_mtx_crd_size+0xb3>
cmpb   $0x25,(%rsp)
je     1180 <mm_read_mtx_crd_size+0x40>
lea    0xe5e(%rip),%rsi
mov    %rsp,%rdi
mov    %r12,%rdx
mov    %r15,%rcx
mov    %r14,%r8
call   1050 <sscanf@plt>
xor    %ecx,%ecx
cmp    $0x3,%eax
je     1201 <mm_read_mtx_crd_size+0xc1>
lea    0xe3f(%rip),%rbp
mov    0x2e20(%rip),%r13
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    %r12,%rdx
mov    %r15,%rcx
mov    %r14,%r8
call   1030 <fscanf@plt>
cmp    0x0(%r13),%eax
je     11f3 <mm_read_mtx_crd_size+0xb3>
cmp    $0x3,%eax
jne    11d0 <mm_read_mtx_crd_size+0x90>
xor    %ecx,%ecx
jmp    1201 <mm_read_mtx_crd_size+0xc1>
xor    %edi,%edi
mov    $0x11,%esi
call   1060 <mm_print_error@plt>
mov    %eax,%ecx
mov    %ecx,%eax
add    $0x1008,%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 [4096 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** %7
store i32 0, i32* %12
%13 = load i32*, i32** %8
store i32 0, i32* %13
%14 = load i32*, i32** %9
store i32 0, i32* %14
br label %15
15: ; preds = %23, %4
%16 = getelementptr inbounds [4096 x i8], [4096 x i8]* %10, i64 0, i64 0
%17 = load i32*, i32** %6
%18 = call i32* @fgets(i8* %16, i32 4096, i32* %17)
%19 = icmp eq i32* %18, null
br i1 %19, label %20, label %22
20: ; preds = %15
%21 = call i32 @mm_print_error(i32* null, i32 17)
store i32 %21, i32* %5
br label %54
22: ; preds = %15
br label %23
23: ; preds = %22
%24 = getelementptr inbounds [4096 x i8], [4096 x i8]* %10, i64 0, i64 0
%25 = load i8, i8* %24
%26 = zext i8 %25 to i32
%27 = icmp eq i32 %26, 37
br i1 %27, label %15, label %28
28: ; preds = %23
%29 = getelementptr inbounds [4096 x i8], [4096 x i8]* %10, i64 0, i64 0
%30 = load i32*, i32** %7
%31 = load i32*, i32** %8
%32 = load i32*, i32** %9
%33 = call i32 @sscanf(i8* %29, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32* %30, i32* %31, i32* %32)
%34 = icmp eq i32 %33, 3
br i1 %34, label %35, label %36
35: ; preds = %28
store i32 0, i32* %5
br label %54
36: ; preds = %28
br label %37
37: ; preds = %49, %36
%38 = load i32*, i32** %6
%39 = load i32*, i32** %7
%40 = load i32*, i32** %8
%41 = load i32*, i32** %9
%42 = call i32 @fscanf(i32* %38, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32* %39, i32* %40, i32* %41)
store i32 %42, i32* %11
%43 = load i32, i32* %11
%44 = load i32, i32* @EOF
%45 = icmp eq i32 %43, %44
br i1 %45, label %46, label %48
46: ; preds = %37
%47 = call i32 @mm_print_error(i32* null, i32 17)
store i32 %47, i32* %5
br label %54
48: ; preds = %37
br label %49
49: ; preds = %48
%50 = load i32, i32* %11
%51 = icmp ne i32 %50, 3
br i1 %51, label %37, label %52
52: ; preds = %49
br label %53
53: ; preds = %52
store i32 0, i32* %5
br label %54
54: ; preds = %53, %46, %35, %20
%55 = load i32, i32* %5
ret i32 %55
}

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 [4096 x i8]
%6 = getelementptr inbounds [4096 x i8], [4096 x i8]* %5, i64 0, i64 0
store i32 0, i32* %1
store i32 0, i32* %2
store i32 0, i32* %3
br label %7
7: ; preds = %10, %4
%8 = call i32* @fgets(i8* %6, i32 4096, 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 eq i32 %14, 3
br i1 %15, label %24, 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 eq i32 %17, 3
br i1 %21, label %24, label %16
22: ; preds = %7, %16
%23 = call i32 @mm_print_error(i32* null, i32 17)
br label %24
24: ; preds = %20, %22, %13
%25 = phi i32 [ 0, %13 ], [ %23, %22 ], [ 0, %20 ]
ret i32 %25
}