#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*/ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, int, int, double);
void printSparseMatrix(double *matrix, int xDim, int yDim, FILE *fout) {
  int i = 0, j = 0;
  for (i = 0; i < xDim; i++) {
    for (j = 0; j < yDim; j++) {
      double element = *(matrix + i * yDim + j);
      if (element != 0.0) {
        fprintf(fout, "(%d %d) %lf\n", i, j, *(matrix + i * yDim + j));
      }
    }
  }
  fclose(fout);
}


x86 assembly (clang, -O0):
<printSparseMatrix>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1204 <printSparseMatrix+0xe4>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    11f1 <printSparseMatrix+0xd1>
mov    -0x8(%rbp),%rax
mov    -0x1c(%rbp),%ecx
imul   -0x10(%rbp),%ecx
movslq %ecx,%rcx
shl    $0x3,%rcx
add    %rcx,%rax
movslq -0x20(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    11aa <printSparseMatrix+0x8a>
jp     11aa <printSparseMatrix+0x8a>
jmp    11de <printSparseMatrix+0xbe>
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%edx
mov    -0x20(%rbp),%ecx
mov    -0x8(%rbp),%rax
mov    -0x1c(%rbp),%esi
imul   -0x10(%rbp),%esi
movslq %esi,%rsi
shl    $0x3,%rsi
add    %rsi,%rax
movslq -0x20(%rbp),%rsi
movsd  (%rax,%rsi,8),%xmm0
lea    0xe27(%rip),%rsi
call   1040 <fprintf@plt>
jmp    11e3 <printSparseMatrix+0xc3>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    115e <printSparseMatrix+0x3e>
jmp    11f6 <printSparseMatrix+0xd6>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    114b <printSparseMatrix+0x2b>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printSparseMatrix>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rcx,%r15
mov    %edx,0x4(%rsp)
test   %esi,%esi
jle    11ad <printSparseMatrix+0x8d>
mov    %rdi,%rbp
movslq 0x4(%rsp),%rax
mov    %esi,%ecx
mov    %rcx,0x8(%rsp)
mov    %eax,%r14d
shl    $0x3,%rax
mov    %rax,0x10(%rsp)
xor    %r13d,%r13d
lea    0xeaa(%rip),%r12
jmp    1170 <printSparseMatrix+0x50>
add    $0x1,%r13
add    0x10(%rsp),%rbp
cmp    0x8(%rsp),%r13
je     11ad <printSparseMatrix+0x8d>
cmpl   $0x0,0x4(%rsp)
jle    1160 <printSparseMatrix+0x40>
xor    %ebx,%ebx
jmp    1189 <printSparseMatrix+0x69>
nopl   0x0(%rax,%rax,1)
add    $0x1,%rbx
cmp    %rbx,%r14
je     1160 <printSparseMatrix+0x40>
movsd  0x0(%rbp,%rbx,8),%xmm0
ucomisd 0xe69(%rip),%xmm0
jne    119b <printSparseMatrix+0x7b>
jnp    1180 <printSparseMatrix+0x60>
mov    %r15,%rdi
mov    %r12,%rsi
mov    %r13d,%edx
mov    %ebx,%ecx
call   1040 <fprintf@plt>
jmp    1180 <printSparseMatrix+0x60>
mov    %r15,%rdi
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <fclose@plt>

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

LLVM IR (-O2):
@.str = [13 x i8] c"(%d %d) %lf\0A\00"
define void @printSparseMatrix(double* nocapture %0, i32 %1, i32 %2, i32* nocapture %3) {
%5 = icmp sgt i32 %1, 0
br i1 %5, label %6, label %31
6: ; preds = %4
%7 = icmp sgt i32 %2, 0
%8 = sext i32 %2 to i64
%9 = zext i32 %1 to i64
%10 = zext i32 %2 to i64
br label %11
11: ; preds = %6, %28
%12 = phi i64 [ 0, %6 ], [ %29, %28 ]
br i1 %7, label %13, label %28
13: ; preds = %11
%14 = mul nsw i64 %12, %8
%15 = getelementptr inbounds double, double* %0, i64 %14
%16 = trunc i64 %12 to i32
br label %17
17: ; preds = %13, %25
%18 = phi i64 [ 0, %13 ], [ %26, %25 ]
%19 = getelementptr inbounds double, double* %15, i64 %18
%20 = load double, double* %19
%21 = fcmp une double %20, 0.000000e+00
br i1 %21, label %22, label %25
22: ; preds = %17
%23 = trunc i64 %18 to i32
%24 = tail call i32 @fprintf(i32* %3, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %16, i32 %23, double %20)
br label %25
25: ; preds = %22, %17
%26 = add nuw nsw i64 %18, 1
%27 = icmp eq i64 %26, %10
br i1 %27, label %28, label %17
28: ; preds = %25, %11
%29 = add nuw nsw i64 %12, 1
%30 = icmp eq i64 %29, %9
br i1 %30, label %31, label %11
31: ; preds = %28, %4
%32 = tail call i32 @fclose(i32* %3)
ret void
}