#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_write(char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
void write_data_int(char *file_data, int N, int M, int *dat) {
  FILE *file = NULL;
  int i, j;
  file = fopen_write(file_data);
  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
call   1040 <fopen_write@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1205 <write_data_int+0xd5>
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
mov    -0x10(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    11ba <write_data_int+0x8a>
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    0xe5b(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1175 <write_data_int+0x45>
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    0xe26(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x20(%rbp),%rdi
lea    0xe17(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1162 <write_data_int+0x32>
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
call   1050 <fopen_write@plt>
mov    %rax,%rbx
test   %r12d,%r12d
jle    121c <write_data_int+0xdc>
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    11e1 <write_data_int+0xa1>
nopl   (%rax)
add    0x20(%rsp),%r13
mov    0x8(%rsp),%rax
mov    (%rax,%r13,4),%edx
mov    %rbx,%rdi
lea    0xe4c(%rip),%rsi
xor    %eax,%eax
call   1060 <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     121c <write_data_int+0xdc>
mov    %r13,0x30(%rsp)
mov    0x28(%rsp),%rax
imul   %rax,%r13
cmp    $0x2,%eax
lea    0xe07(%rip),%rbp
jl     11a0 <write_data_int+0x60>
xor    %r12d,%r12d
xchg   %ax,%ax
mov    (%r14,%r12,4),%edx
mov    %rbx,%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
add    $0x1,%r12
cmp    %r12,%r15
jne    1200 <write_data_int+0xc0>
jmp    11a0 <write_data_int+0x60>
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 = [4 x i8] c"%d \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [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_write(i8* %12)
store i32* %13, i32** %9
store i32 0, i32* %10
br label %14
14: ; preds = %54, %4
%15 = load i32, i32* %10
%16 = load i32, i32* %6
%17 = icmp slt i32 %15, %16
br i1 %17, label %18, label %57
18: ; preds = %14
store i32 0, i32* %11
br label %19
19: ; preds = %36, %18
%20 = load i32, i32* %11
%21 = load i32, i32* %7
%22 = sub nsw i32 %21, 1
%23 = icmp slt i32 %20, %22
br i1 %23, label %24, label %39
24: ; preds = %19
%25 = load i32*, i32** %9
%26 = load i32*, i32** %8
%27 = load i32, i32* %10
%28 = load i32, i32* %7
%29 = mul nsw i32 %27, %28
%30 = load i32, i32* %11
%31 = add nsw i32 %29, %30
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i32, i32* %26, i64 %32
%34 = load i32, i32* %33
%35 = call i32 (i32*, i8*, ...) @fprintf(i32* %25, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %34)
br label %36
36: ; preds = %24
%37 = load i32, i32* %11
%38 = add nsw i32 %37, 1
store i32 %38, i32* %11
br label %19
39: ; preds = %19
%40 = load i32*, i32** %9
%41 = load i32*, i32** %8
%42 = load i32, i32* %10
%43 = load i32, i32* %7
%44 = mul nsw i32 %42, %43
%45 = load i32, i32* %7
%46 = sub nsw i32 %45, 1
%47 = add nsw i32 %44, %46
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds i32, i32* %41, i64 %48
%50 = load i32, i32* %49
%51 = call i32 (i32*, i8*, ...) @fprintf(i32* %40, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %50)
%52 = load i32*, i32** %9
%53 = call i32 (i32*, i8*, ...) @fprintf(i32* %52, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %54
54: ; preds = %39
%55 = load i32, i32* %10
%56 = add nsw i32 %55, 1
store i32 %56, i32* %10
br label %14
57: ; preds = %14
%58 = load i32*, i32** %9
%59 = call i32 @fclose(i32* %58)
ret void
}

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