#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 scalar_t__ uint32_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int countnnz32tri(int, int, int, scalar_t__ ***, scalar_t__);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ ferror(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, int, ...);
int /*<<< orphan*/ yap_sysquit(char *, char *);
void write_u32sparsetri(int ns, int nr, int nc, uint32_t ***x, char *fname,
                        uint32_t cutoff) {
  FILE *fp = fopen(fname, "w");
  int i, j, k;
  if (!fp)
    yap_sysquit("Cannot open file '%s' for write\n", fname);
  fprintf(fp, "%d\n", ns);
  fprintf(fp, "%d\n", nr);
  fprintf(fp, "%d\n", nc);
  fprintf(fp, "%d\n", countnnz32tri(ns, nr, nc, x, cutoff));
  for (k = 0; k < ns; k++)
    for (i = 0; i < nr; i++)
      for (j = 0; j < nc; j++)
        if (x[k][i][j] > cutoff)
          fprintf(fp, "%d %d %d %u\n", k, i, j, (unsigned)x[k][i][j]);
  if (ferror(fp))
    yap_sysquit("Error on writing file '%s' ", fname);
  fclose(fp);
}


x86 assembly (clang, -O0):
<write_u32sparsetri>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    %rcx,-0x18(%rbp)
mov    %r8,-0x20(%rbp)
mov    %r9,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xe78(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    11ac <write_u32sparsetri+0x4c>
mov    -0x20(%rbp),%rsi
lea    0xe5b(%rip),%rdi
call   1070 <yap_sysquit@plt>
mov    -0x30(%rbp),%rdi
mov    -0x4(%rbp),%edx
lea    0xe69(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x30(%rbp),%rdi
mov    -0x8(%rbp),%edx
lea    0xe54(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x30(%rbp),%rdi
mov    -0xc(%rbp),%edx
lea    0xe3f(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x30(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
mov    -0x18(%rbp),%rcx
mov    -0x28(%rbp),%r8
call   1080 <countnnz32tri@plt>
mov    -0x48(%rbp),%rdi
mov    %eax,%edx
lea    0xe0d(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0x0,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    12f0 <write_u32sparsetri+0x190>
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    12dd <write_u32sparsetri+0x17d>
movl   $0x0,-0x38(%rbp)
mov    -0x38(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    12ca <write_u32sparsetri+0x16a>
mov    -0x18(%rbp),%rax
movslq -0x3c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x34(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x38(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
cmp    -0x28(%rbp),%rax
jle    12b7 <write_u32sparsetri+0x157>
mov    -0x30(%rbp),%rdi
mov    -0x3c(%rbp),%edx
mov    -0x34(%rbp),%ecx
mov    -0x38(%rbp),%r8d
mov    -0x18(%rbp),%rax
movslq -0x3c(%rbp),%rsi
mov    (%rax,%rsi,8),%rax
movslq -0x34(%rbp),%rsi
mov    (%rax,%rsi,8),%rax
movslq -0x38(%rbp),%rsi
mov    (%rax,%rsi,8),%rax
mov    %eax,%r9d
lea    0xd77(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
jmp    12bc <write_u32sparsetri+0x15c>
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    124a <write_u32sparsetri+0xea>
jmp    12cf <write_u32sparsetri+0x16f>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1237 <write_u32sparsetri+0xd7>
jmp    12e2 <write_u32sparsetri+0x182>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    1224 <write_u32sparsetri+0xc4>
mov    -0x30(%rbp),%rdi
call   1030 <ferror@plt>
cmp    $0x0,%rax
je     1313 <write_u32sparsetri+0x1b3>
mov    -0x20(%rbp),%rsi
lea    0xd26(%rip),%rdi
call   1070 <yap_sysquit@plt>
mov    -0x30(%rbp),%rdi
call   1040 <fclose@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_u32sparsetri>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %r9,%r12
mov    %r8,%r14
mov    %rcx,%rbx
mov    %edx,%r13d
mov    %esi,(%rsp)
mov    %edi,%r15d
lea    0xe79(%rip),%rsi
mov    %r8,%rdi
call   1060 <fopen@plt>
mov    %rax,%rbp
test   %rax,%rax
jne    11a6 <write_u32sparsetri+0x46>
lea    0xe64(%rip),%rdi
mov    %r14,%rsi
call   1070 <yap_sysquit@plt>
mov    %r14,0x10(%rsp)
lea    0xe71(%rip),%r14
mov    %rbp,%rdi
mov    %r14,%rsi
mov    %r15d,%edx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    %rbp,%rdi
mov    %r14,%rsi
mov    (%rsp),%r14d
mov    %r14d,%edx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    %rbp,%rdi
lea    0xe43(%rip),%rsi
mov    %r13d,%edx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    %r15d,%edi
mov    %r14d,%esi
mov    %r13d,0x4(%rsp)
mov    %r13d,%edx
mov    %rbx,%rcx
mov    %r12,%r8
call   1080 <countnnz32tri@plt>
mov    %rbp,0x8(%rsp)
mov    %rbp,%rdi
lea    0xe11(%rip),%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1050 <fprintf@plt>
test   %r15d,%r15d
jle    12b8 <write_u32sparsetri+0x158>
mov    %r15d,%ecx
mov    %rcx,0x18(%rsp)
mov    %r14d,%ecx
mov    %rcx,0x20(%rsp)
mov    0x4(%rsp),%r15d
xor    %r13d,%r13d
jmp    124f <write_u32sparsetri+0xef>
xchg   %ax,%ax
add    $0x1,%r13
cmp    0x18(%rsp),%r13
mov    (%rsp),%r14d
je     12b8 <write_u32sparsetri+0x158>
test   %r14d,%r14d
jle    1240 <write_u32sparsetri+0xe0>
xor    %r14d,%r14d
jmp    126b <write_u32sparsetri+0x10b>
nopl   0x0(%rax)
add    $0x1,%r14
cmp    0x20(%rsp),%r14
je     1240 <write_u32sparsetri+0xe0>
cmpl   $0x0,0x4(%rsp)
jle    1260 <write_u32sparsetri+0x100>
xor    %ebp,%ebp
jmp    1289 <write_u32sparsetri+0x129>
cs nopw 0x0(%rax,%rax,1)
add    $0x1,%rbp
cmp    %rbp,%r15
je     1260 <write_u32sparsetri+0x100>
mov    (%rbx,%r13,8),%rax
mov    (%rax,%r14,8),%rax
mov    (%rax,%rbp,8),%r9
cmp    %r12,%r9
jle    1280 <write_u32sparsetri+0x120>
mov    0x8(%rsp),%rdi
lea    0xd81(%rip),%rsi
mov    %r13d,%edx
mov    %r14d,%ecx
mov    %ebp,%r8d
xor    %eax,%eax
call   1050 <fprintf@plt>
jmp    1280 <write_u32sparsetri+0x120>
mov    0x8(%rsp),%rbx
mov    %rbx,%rdi
call   1030 <ferror@plt>
test   %rax,%rax
je     12db <write_u32sparsetri+0x17b>
lea    0xd63(%rip),%rdi
mov    0x10(%rsp),%rsi
call   1070 <yap_sysquit@plt>
mov    %rbx,%rdi
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <fclose@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"w\00"
@.str.1 = [33 x i8] c"Cannot open file '%s' for write\0A\00"
@.str.2 = [4 x i8] c"%d\0A\00"
@.str.3 = [13 x i8] c"%d %d %d %u\0A\00"
@.str.4 = [28 x i8] c"Error on writing file '%s' \00"
define void @write_u32sparsetri(i32 %0, i32 %1, i32 %2, i64*** %3, i8* %4, i64 %5) {
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i64***
%11 = alloca i8*
%12 = alloca i64
%13 = alloca i32*
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
store i32 %0, i32* %7
store i32 %1, i32* %8
store i32 %2, i32* %9
store i64*** %3, i64**** %10
store i8* %4, i8** %11
store i64 %5, i64* %12
%17 = load i8*, i8** %11
%18 = call i32* @fopen(i8* %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %18, i32** %13
%19 = load i32*, i32** %13
%20 = icmp ne i32* %19, null
br i1 %20, label %24, label %21
21: ; preds = %6
%22 = load i8*, i8** %11
%23 = call i32 @yap_sysquit(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), i8* %22)
br label %24
24: ; preds = %21, %6
%25 = load i32*, i32** %13
%26 = load i32, i32* %7
%27 = call i32 (i32*, i8*, i32, ...) @fprintf(i32* %25, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %26)
%28 = load i32*, i32** %13
%29 = load i32, i32* %8
%30 = call i32 (i32*, i8*, i32, ...) @fprintf(i32* %28, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %29)
%31 = load i32*, i32** %13
%32 = load i32, i32* %9
%33 = call i32 (i32*, i8*, i32, ...) @fprintf(i32* %31, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %32)
%34 = load i32*, i32** %13
%35 = load i32, i32* %7
%36 = load i32, i32* %8
%37 = load i32, i32* %9
%38 = load i64***, i64**** %10
%39 = load i64, i64* %12
%40 = call i32 @countnnz32tri(i32 %35, i32 %36, i32 %37, i64*** %38, i64 %39)
%41 = call i32 (i32*, i8*, i32, ...) @fprintf(i32* %34, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %40)
store i32 0, i32* %16
br label %42
42: ; preds = %101, %24
%43 = load i32, i32* %16
%44 = load i32, i32* %7
%45 = icmp slt i32 %43, %44
br i1 %45, label %46, label %104
46: ; preds = %42
store i32 0, i32* %14
br label %47
47: ; preds = %97, %46
%48 = load i32, i32* %14
%49 = load i32, i32* %8
%50 = icmp slt i32 %48, %49
br i1 %50, label %51, label %100
51: ; preds = %47
store i32 0, i32* %15
br label %52
52: ; preds = %93, %51
%53 = load i32, i32* %15
%54 = load i32, i32* %9
%55 = icmp slt i32 %53, %54
br i1 %55, label %56, label %96
56: ; preds = %52
%57 = load i64***, i64**** %10
%58 = load i32, i32* %16
%59 = sext i32 %58 to i64
%60 = getelementptr inbounds i64**, i64*** %57, i64 %59
%61 = load i64**, i64*** %60
%62 = load i32, i32* %14
%63 = sext i32 %62 to i64
%64 = getelementptr inbounds i64*, i64** %61, i64 %63
%65 = load i64*, i64** %64
%66 = load i32, i32* %15
%67 = sext i32 %66 to i64
%68 = getelementptr inbounds i64, i64* %65, i64 %67
%69 = load i64, i64* %68
%70 = load i64, i64* %12
%71 = icmp sgt i64 %69, %70
br i1 %71, label %72, label %92
72: ; preds = %56
%73 = load i32*, i32** %13
%74 = load i32, i32* %16
%75 = load i32, i32* %14
%76 = load i32, i32* %15
%77 = load i64***, i64**** %10
%78 = load i32, i32* %16
%79 = sext i32 %78 to i64
%80 = getelementptr inbounds i64**, i64*** %77, i64 %79
%81 = load i64**, i64*** %80
%82 = load i32, i32* %14
%83 = sext i32 %82 to i64
%84 = getelementptr inbounds i64*, i64** %81, i64 %83
%85 = load i64*, i64** %84
%86 = load i32, i32* %15
%87 = sext i32 %86 to i64
%88 = getelementptr inbounds i64, i64* %85, i64 %87
%89 = load i64, i64* %88
%90 = trunc i64 %89 to i32
%91 = call i32 (i32*, i8*, i32, ...) @fprintf(i32* %73, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i32 %74, i32 %75, i32 %76, i32 %90)
br label %92
92: ; preds = %72, %56
br label %93
93: ; preds = %92
%94 = load i32, i32* %15
%95 = add nsw i32 %94, 1
store i32 %95, i32* %15
br label %52
96: ; preds = %52
br label %97
97: ; preds = %96
%98 = load i32, i32* %14
%99 = add nsw i32 %98, 1
store i32 %99, i32* %14
br label %47
100: ; preds = %47
br label %101
101: ; preds = %100
%102 = load i32, i32* %16
%103 = add nsw i32 %102, 1
store i32 %103, i32* %16
br label %42
104: ; preds = %42
%105 = load i32*, i32** %13
%106 = call i64 @ferror(i32* %105)
%107 = icmp ne i64 %106, 0
br i1 %107, label %108, label %111
108: ; preds = %104
%109 = load i8*, i8** %11
%110 = call i32 @yap_sysquit(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0), i8* %109)
br label %111
111: ; preds = %108, %104
%112 = load i32*, i32** %13
%113 = call i32 @fclose(i32* %112)
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"w\00"
@.str.1 = [33 x i8] c"Cannot open file '%s' for write\0A\00"
@.str.2 = [4 x i8] c"%d\0A\00"
@.str.3 = [13 x i8] c"%d %d %d %u\0A\00"
@.str.4 = [28 x i8] c"Error on writing file '%s' \00"
define void @write_u32sparsetri(i32 %0, i32 %1, i32 %2, i64*** %3, i8* %4, i64 %5) {
%7 = tail call i32* @fopen(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%8 = icmp eq i32* %7, null
br i1 %8, label %9, label %11
9: ; preds = %6
%10 = tail call i32 @yap_sysquit(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), i8* %4)
br label %11
11: ; preds = %9, %6
%12 = tail call i32 (i32*, i8*, i32, ...) @fprintf(i32* %7, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %0)
%13 = tail call i32 (i32*, i8*, i32, ...) @fprintf(i32* %7, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %1)
%14 = tail call i32 (i32*, i8*, i32, ...) @fprintf(i32* %7, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %2)
%15 = tail call i32 @countnnz32tri(i32 %0, i32 %1, i32 %2, i64*** %3, i64 %5)
%16 = tail call i32 (i32*, i8*, i32, ...) @fprintf(i32* %7, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %15)
%17 = icmp sgt i32 %0, 0
br i1 %17, label %18, label %54
18: ; preds = %11
%19 = icmp sgt i32 %1, 0
%20 = icmp sgt i32 %2, 0
%21 = zext i32 %0 to i64
%22 = zext i32 %1 to i64
%23 = zext i32 %2 to i64
br label %24
24: ; preds = %18, %51
%25 = phi i64 [ 0, %18 ], [ %52, %51 ]
br i1 %19, label %26, label %51
26: ; preds = %24
%27 = getelementptr inbounds i64**, i64*** %3, i64 %25
%28 = trunc i64 %25 to i32
br label %29
29: ; preds = %26, %48
%30 = phi i64 [ 0, %26 ], [ %49, %48 ]
br i1 %20, label %31, label %48
31: ; preds = %29
%32 = trunc i64 %30 to i32
br label %33
33: ; preds = %31, %45
%34 = phi i64 [ 0, %31 ], [ %46, %45 ]
%35 = load i64**, i64*** %27
%36 = getelementptr inbounds i64*, i64** %35, i64 %30
%37 = load i64*, i64** %36
%38 = getelementptr inbounds i64, i64* %37, i64 %34
%39 = load i64, i64* %38
%40 = icmp sgt i64 %39, %5
br i1 %40, label %41, label %45
41: ; preds = %33
%42 = trunc i64 %39 to i32
%43 = trunc i64 %34 to i32
%44 = tail call i32 (i32*, i8*, i32, ...) @fprintf(i32* %7, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i32 %28, i32 %32, i32 %43, i32 %42)
br label %45
45: ; preds = %33, %41
%46 = add nuw nsw i64 %34, 1
%47 = icmp eq i64 %46, %23
br i1 %47, label %48, label %33
48: ; preds = %45, %29
%49 = add nuw nsw i64 %30, 1
%50 = icmp eq i64 %49, %22
br i1 %50, label %51, label %29
51: ; preds = %48, %24
%52 = add nuw nsw i64 %25, 1
%53 = icmp eq i64 %52, %21
br i1 %53, label %54, label %24
54: ; preds = %51, %11
%55 = tail call i64 @ferror(i32* %7)
%56 = icmp eq i64 %55, 0
br i1 %56, label %59, label %57
57: ; preds = %54
%58 = tail call i32 @yap_sysquit(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0), i8* %4)
br label %59
59: ; preds = %57, %54
%60 = tail call i32 @fclose(i32* %7)
ret void
}