#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 /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ ferror(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int fscanf(int /*<<< orphan*/ *, char *, int *, int *, float *);
int /*<<< orphan*/ yap_sysquit(char *, char *);
void read_fmat(char *dfile, int N, int C, float **f) {
  float val;
  int n, c;
  FILE *fp = fopen(dfile, "r");
  if (!fp)
    yap_sysquit("Cannot open file '%s' for read\n", dfile);
  while (fscanf(fp, "%d %d %g", &n, &c, &val) == 3) {
    if (n >= 0 && c >= 0 && n < N && c < C)
      f[n][c] = val;
  }
  if (ferror(fp))
    yap_sysquit("Error on reading file '%s' ", dfile);
  fclose(fp);
}


x86 assembly (clang, -O0):
<read_fmat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe8f(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    1195 <read_fmat+0x45>
mov    -0x8(%rbp),%rsi
lea    0xe72(%rip),%rdi
call   1070 <yap_sysquit@plt>
jmp    119a <read_fmat+0x4a>
mov    -0x30(%rbp),%rdi
lea    0xe7d(%rip),%rsi
lea    -0x20(%rbp),%rdx
lea    -0x24(%rbp),%rcx
lea    -0x1c(%rbp),%r8
call   1050 <fscanf@plt>
cmp    $0x3,%eax
jne    120a <read_fmat+0xba>
cmpl   $0x0,-0x20(%rbp)
jl     1205 <read_fmat+0xb5>
cmpl   $0x0,-0x24(%rbp)
jl     1205 <read_fmat+0xb5>
mov    -0x20(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1205 <read_fmat+0xb5>
mov    -0x24(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    1205 <read_fmat+0xb5>
movss  -0x1c(%rbp),%xmm0
mov    -0x18(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x24(%rbp),%rcx
movss  %xmm0,(%rax,%rcx,4)
jmp    119a <read_fmat+0x4a>
mov    -0x30(%rbp),%rdi
call   1030 <ferror@plt>
cmp    $0x0,%rax
je     122d <read_fmat+0xdd>
mov    -0x8(%rbp),%rsi
lea    0xe03(%rip),%rdi
call   1070 <yap_sysquit@plt>
mov    -0x30(%rbp),%rdi
call   1040 <fclose@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_fmat>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rcx,0x20(%rsp)
mov    %edx,0x14(%rsp)
mov    %esi,%ebp
mov    %rdi,%r14
lea    0xe8d(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    118f <read_fmat+0x3f>
lea    0xe7b(%rip),%rdi
mov    %r14,%rsi
call   1070 <yap_sysquit@plt>
mov    %r14,0x18(%rsp)
lea    0xe87(%rip),%rsi
lea    0xc(%rsp),%rdx
lea    0x8(%rsp),%rcx
lea    0x10(%rsp),%r8
mov    %rbx,%rdi
call   1050 <fscanf@plt>
cmp    $0x3,%eax
jne    1219 <read_fmat+0xc9>
lea    0xe64(%rip),%r13
lea    0xc(%rsp),%r14
lea    0x8(%rsp),%r15
lea    0x10(%rsp),%r12
jmp    11e9 <read_fmat+0x99>
nop
mov    %rbx,%rdi
mov    %r13,%rsi
mov    %r14,%rdx
mov    %r15,%rcx
mov    %r12,%r8
call   1050 <fscanf@plt>
cmp    $0x3,%eax
jne    1219 <read_fmat+0xc9>
mov    0xc(%rsp),%eax
cmp    %ebp,%eax
jge    11d0 <read_fmat+0x80>
test   %eax,%eax
js     11d0 <read_fmat+0x80>
mov    0x8(%rsp),%ecx
test   %ecx,%ecx
js     11d0 <read_fmat+0x80>
cmp    0x14(%rsp),%ecx
jge    11d0 <read_fmat+0x80>
movss  0x10(%rsp),%xmm0
mov    0x20(%rsp),%rdx
mov    (%rdx,%rax,8),%rax
movss  %xmm0,(%rax,%rcx,4)
jmp    11d0 <read_fmat+0x80>
mov    %rbx,%rdi
call   1030 <ferror@plt>
test   %rax,%rax
je     1237 <read_fmat+0xe7>
lea    0xdfe(%rip),%rdi
mov    0x18(%rsp),%rsi
call   1070 <yap_sysquit@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [32 x i8] c"Cannot open file '%s' for read\0A\00"
@.str.2 = [9 x i8] c"%d %d %g\00"
@.str.3 = [28 x i8] c"Error on reading file '%s' \00"
define void @read_fmat(i8* %0, i32 %1, i32 %2, float** %3) {
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca float**
%9 = alloca float
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32*
store i8* %0, i8** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store float** %3, float*** %8
%13 = load i8*, i8** %5
%14 = call i32* @fopen(i8* %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %14, i32** %12
%15 = load i32*, i32** %12
%16 = icmp ne i32* %15, null
br i1 %16, label %20, label %17
17: ; preds = %4
%18 = load i8*, i8** %5
%19 = call i32 @yap_sysquit(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i8* %18)
br label %20
20: ; preds = %17, %4
br label %21
21: ; preds = %49, %20
%22 = load i32*, i32** %12
%23 = call i32 @fscanf(i32* %22, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32* %10, i32* %11, float* %9)
%24 = icmp eq i32 %23, 3
br i1 %24, label %25, label %50
25: ; preds = %21
%26 = load i32, i32* %10
%27 = icmp sge i32 %26, 0
br i1 %27, label %28, label %49
28: ; preds = %25
%29 = load i32, i32* %11
%30 = icmp sge i32 %29, 0
br i1 %30, label %31, label %49
31: ; preds = %28
%32 = load i32, i32* %10
%33 = load i32, i32* %6
%34 = icmp slt i32 %32, %33
br i1 %34, label %35, label %49
35: ; preds = %31
%36 = load i32, i32* %11
%37 = load i32, i32* %7
%38 = icmp slt i32 %36, %37
br i1 %38, label %39, label %49
39: ; preds = %35
%40 = load float, float* %9
%41 = load float**, float*** %8
%42 = load i32, i32* %10
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds float*, float** %41, i64 %43
%45 = load float*, float** %44
%46 = load i32, i32* %11
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds float, float* %45, i64 %47
store float %40, float* %48
br label %49
49: ; preds = %39, %35, %31, %28, %25
br label %21
50: ; preds = %21
%51 = load i32*, i32** %12
%52 = call i64 @ferror(i32* %51)
%53 = icmp ne i64 %52, 0
br i1 %53, label %54, label %57
54: ; preds = %50
%55 = load i8*, i8** %5
%56 = call i32 @yap_sysquit(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0), i8* %55)
br label %57
57: ; preds = %54, %50
%58 = load i32*, i32** %12
%59 = call i32 @fclose(i32* %58)
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [32 x i8] c"Cannot open file '%s' for read\0A\00"
@.str.2 = [9 x i8] c"%d %d %g\00"
@.str.3 = [28 x i8] c"Error on reading file '%s' \00"
define void @read_fmat(i8* %0, i32 %1, i32 %2, float** nocapture %3) {
%5 = alloca float
%6 = alloca i32
%7 = alloca i32
%8 = bitcast float* %5 to i8*
%9 = bitcast i32* %6 to i8*
%10 = bitcast i32* %7 to i8*
%11 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %15
13: ; preds = %4
%14 = tail call i32 @yap_sysquit(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %15
15: ; preds = %13, %4
%16 = call i32 @fscanf(i32* %11, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32* %6, i32* %7, float* %5)
%17 = icmp eq i32 %16, 3
br i1 %17, label %18, label %38
18: ; preds = %15, %35
%19 = load i32, i32* %6
%20 = icmp sgt i32 %19, -1
%21 = load i32, i32* %7
%22 = icmp sgt i32 %21, -1
%23 = select i1 %20, i1 %22, i1 false
%24 = icmp slt i32 %19, %1
%25 = and i1 %24, %23
%26 = icmp slt i32 %21, %2
%27 = select i1 %25, i1 %26, i1 false
br i1 %27, label %28, label %35
28: ; preds = %18
%29 = load float, float* %5
%30 = zext i32 %19 to i64
%31 = getelementptr inbounds float*, float** %3, i64 %30
%32 = load float*, float** %31
%33 = zext i32 %21 to i64
%34 = getelementptr inbounds float, float* %32, i64 %33
store float %29, float* %34
br label %35
35: ; preds = %28, %18
%36 = call i32 @fscanf(i32* %11, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32* %6, i32* %7, float* %5)
%37 = icmp eq i32 %36, 3
br i1 %37, label %18, label %38
38: ; preds = %35, %15
%39 = call i64 @ferror(i32* %11)
%40 = icmp eq i64 %39, 0
br i1 %40, label %43, label %41
41: ; preds = %38
%42 = call i32 @yap_sysquit(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0), i8* %0)
br label %43
43: ; preds = %41, %38
%44 = call i32 @fclose(i32* %11)
ret void
}