#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*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ print_error_global(char *, char *, int /*<<< orphan*/);
void write_data_int(char *file_data, int N, int M, int *dat) {
  FILE *file = NULL;
  int i, j;
  file = fopen(file_data, "w");
  if (!file)
    print_error_global("open", file_data, 0);
  for (i = 0; i < N; i++) {
    for (j = 0; j < M - 1; j++) {
      fprintf(file, "%d ", dat[i * M + j]);
    }
    fprintf(file, "%d", dat[i * M + (M - 1)]);
    fprintf(file, "\n");
  }
  fclose(file);
}


x86 assembly (clang, -O0):
<write_data_int>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe97(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    118f <write_data_int+0x4f>
mov    -0x8(%rbp),%rsi
lea    0xe7a(%rip),%rdi
xor    %edx,%edx
call   1060 <print_error_global@plt>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1239 <write_data_int+0xf9>
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
mov    -0x10(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    11ee <write_data_int+0xae>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rax
mov    -0x24(%rbp),%ecx
imul   -0x10(%rbp),%ecx
add    -0x28(%rbp),%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,4),%edx
lea    0xe2e(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    11a9 <write_data_int+0x69>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rax
mov    -0x24(%rbp),%ecx
imul   -0x10(%rbp),%ecx
mov    -0x10(%rbp),%edx
sub    $0x1,%edx
add    %edx,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,4),%edx
lea    0xdf9(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x20(%rbp),%rdi
lea    0xdea(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1196 <write_data_int+0x56>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_data_int>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %rcx,0x8(%rsp)
mov    %edx,%r15d
mov    %esi,%r12d
mov    %rdi,%rbp
lea    0xe8d(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
je     118a <write_data_int+0x3a>
test   %r12d,%r12d
jg     11a4 <write_data_int+0x54>
jmp    125c <write_data_int+0x10c>
lea    0xe71(%rip),%rdi
mov    %rbp,%rsi
xor    %edx,%edx
call   1070 <print_error_global@plt>
test   %r12d,%r12d
jle    125c <write_data_int+0x10c>
movslq %r15d,%rax
add    $0xffffffff,%r15d
movslq %r15d,%rcx
mov    %rcx,0x20(%rsp)
mov    %r12d,%ecx
mov    %rcx,0x18(%rsp)
mov    %rax,0x28(%rsp)
lea    0x0(,%rax,4),%rax
mov    %rax,0x10(%rsp)
mov    0x8(%rsp),%r14
xor    %r13d,%r13d
jmp    1221 <write_data_int+0xd1>
nopw   0x0(%rax,%rax,1)
add    0x20(%rsp),%r13
mov    0x8(%rsp),%rax
mov    (%rax,%r13,4),%edx
mov    %rbx,%rdi
lea    0xe13(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0xa,%edi
mov    %rbx,%rsi
call   1040 <fputc@plt>
mov    0x30(%rsp),%r13
add    $0x1,%r13
add    0x10(%rsp),%r14
cmp    0x18(%rsp),%r13
je     125c <write_data_int+0x10c>
mov    %r13,0x30(%rsp)
mov    0x28(%rsp),%rax
imul   %rax,%r13
cmp    $0x2,%eax
lea    0xdce(%rip),%rbp
jl     11e0 <write_data_int+0x90>
xor    %r12d,%r12d
xchg   %ax,%ax
mov    (%r14,%r12,4),%edx
mov    %rbx,%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
add    $0x1,%r12
cmp    %r12,%r15
jne    1240 <write_data_int+0xf0>
jmp    11e0 <write_data_int+0x90>
mov    %rbx,%rdi
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <fclose@plt>

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

LLVM IR (-O2):
@.str = [2 x i8] c"w\00"
@.str.1 = [5 x i8] c"open\00"
@.str.2 = [4 x i8] c"%d \00"
@.str.3 = [3 x i8] c"%d\00"
define void @write_data_int(i8* %0, i32 %1, i32 %2, i32* nocapture %3) {
%5 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %9
7: ; preds = %4
%8 = tail call i32 @print_error_global(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %0, i32 0)
br label %9
9: ; preds = %7, %4
%10 = icmp sgt i32 %1, 0
br i1 %10, label %11, label %37
11: ; preds = %9
%12 = add i32 %2, -1
%13 = icmp sgt i32 %2, 1
%14 = sext i32 %2 to i64
%15 = sext i32 %12 to i64
%16 = zext i32 %1 to i64
%17 = zext i32 %12 to i64
br label %18
18: ; preds = %11, %29
%19 = phi i64 [ 0, %11 ], [ %35, %29 ]
%20 = mul nsw i64 %19, %14
br i1 %13, label %21, label %29
21: ; preds = %18, %21
%22 = phi i64 [ %27, %21 ], [ 0, %18 ]
%23 = add nsw i64 %22, %20
%24 = getelementptr inbounds i32, i32* %3, i64 %23
%25 = load i32, i32* %24
%26 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %5, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %25)
%27 = add nuw nsw i64 %22, 1
%28 = icmp eq i64 %27, %17
br i1 %28, label %29, label %21
29: ; preds = %21, %18
%30 = add nsw i64 %20, %15
%31 = getelementptr inbounds i32, i32* %3, i64 %30
%32 = load i32, i32* %31
%33 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 %32)
%34 = tail call i32 @fputc(i32 10, i32* %5)
%35 = add nuw nsw i64 %19, 1
%36 = icmp eq i64 %35, %16
br i1 %36, label %37, label %18
37: ; preds = %29, %9
%38 = tail call i32 @fclose(i32* %5)
ret void
}