#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_geno(char *output_file, int N, int M, int *data) {
  FILE *file = NULL;
  int i, j;
  file = fopen_write(output_file);
  for (j = 0; j < M; j++) {
    for (i = 0; i < N; i++) {
      if (i < N - 1)
        fprintf(file, "%d ", data[i * M + j]);
      if (i == (N - 1))
        fprintf(file, "%d", data[i * M + j]);
    }
    fprintf(file, "\n");
  }
  fclose(file);
}


x86 assembly (clang, -O0):
<write_geno>:
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,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    1222 <write_geno+0xf2>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1202 <write_geno+0xd2>
mov    -0x24(%rbp),%eax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    11b8 <write_geno+0x88>
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    0xe4f(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x24(%rbp),%eax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jne    11ef <write_geno+0xbf>
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    0xe1c(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
jmp    11f4 <write_geno+0xc4>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1175 <write_geno+0x45>
mov    -0x20(%rbp),%rdi
lea    0xdfa(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1162 <write_geno+0x32>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_geno>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    %rcx,0x28(%rsp)
mov    %edx,%r12d
mov    %rsi,0x18(%rsp)
call   1050 <fopen_write@plt>
mov    %rax,0x8(%rsp)
test   %r12d,%r12d
jle    124e <write_geno+0x10e>
mov    0x18(%rsp),%rax
lea    -0x1(%rax),%ebp
mov    %r12d,%ecx
movslq %ebp,%r14
mov    %eax,%r12d
mov    %rbp,%rax
imul   %rcx,%rax
mov    %rax,0x30(%rsp)
mov    %rcx,0x38(%rsp)
lea    0x0(,%rcx,4),%r13
mov    0x28(%rsp),%rax
mov    %rax,0x20(%rsp)
xor    %eax,%eax
mov    %rax,0x10(%rsp)
jmp    11dd <write_geno+0x9d>
nopl   0x0(%rax,%rax,1)
mov    $0xa,%edi
mov    0x8(%rsp),%rsi
call   1040 <fputc@plt>
mov    0x10(%rsp),%rcx
add    $0x1,%rcx
addq   $0x4,0x20(%rsp)
mov    %rcx,%rax
mov    %rcx,0x10(%rsp)
cmp    0x38(%rsp),%rcx
je     124e <write_geno+0x10e>
cmpl   $0x0,0x18(%rsp)
jle    11b0 <write_geno+0x70>
mov    0x30(%rsp),%rax
mov    0x10(%rsp),%rcx
add    %rcx,%rax
mov    %rax,0x40(%rsp)
mov    0x20(%rsp),%r15
xor    %ebx,%ebx
jmp    120c <write_geno+0xcc>
nop
add    $0x1,%rbx
add    %r13,%r15
cmp    %rbx,%r12
je     11b0 <write_geno+0x70>
cmp    %r14,%rbx
jge    1227 <write_geno+0xe7>
mov    (%r15),%edx
mov    0x8(%rsp),%rdi
lea    0xde0(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
cmp    %rbx,%rbp
jne    1200 <write_geno+0xc0>
mov    0x28(%rsp),%rax
mov    0x40(%rsp),%rcx
mov    (%rax,%rcx,4),%edx
mov    0x8(%rsp),%rdi
lea    0xdbf(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
jmp    1200 <write_geno+0xc0>
mov    0x8(%rsp),%rdi
add    $0x48,%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_geno(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* %11
br label %14
14: ; preds = %64, %4
%15 = load i32, i32* %11
%16 = load i32, i32* %7
%17 = icmp slt i32 %15, %16
br i1 %17, label %18, label %67
18: ; preds = %14
store i32 0, i32* %10
br label %19
19: ; preds = %58, %18
%20 = load i32, i32* %10
%21 = load i32, i32* %6
%22 = icmp slt i32 %20, %21
br i1 %22, label %23, label %61
23: ; preds = %19
%24 = load i32, i32* %10
%25 = load i32, i32* %6
%26 = sub nsw i32 %25, 1
%27 = icmp slt i32 %24, %26
br i1 %27, label %28, label %40
28: ; preds = %23
%29 = load i32*, i32** %9
%30 = load i32*, i32** %8
%31 = load i32, i32* %10
%32 = load i32, i32* %7
%33 = mul nsw i32 %31, %32
%34 = load i32, i32* %11
%35 = add nsw i32 %33, %34
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i32, i32* %30, i64 %36
%38 = load i32, i32* %37
%39 = call i32 (i32*, i8*, ...) @fprintf(i32* %29, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %38)
br label %40
40: ; preds = %28, %23
%41 = load i32, i32* %10
%42 = load i32, i32* %6
%43 = sub nsw i32 %42, 1
%44 = icmp eq i32 %41, %43
br i1 %44, label %45, label %57
45: ; preds = %40
%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* %11
%52 = add nsw i32 %50, %51
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds i32, i32* %47, i64 %53
%55 = load i32, i32* %54
%56 = call i32 (i32*, i8*, ...) @fprintf(i32* %46, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %55)
br label %57
57: ; preds = %45, %40
br label %58
58: ; preds = %57
%59 = load i32, i32* %10
%60 = add nsw i32 %59, 1
store i32 %60, i32* %10
br label %19
61: ; preds = %19
%62 = load i32*, i32** %9
%63 = call i32 (i32*, i8*, ...) @fprintf(i32* %62, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %64
64: ; preds = %61
%65 = load i32, i32* %11
%66 = add nsw i32 %65, 1
store i32 %66, i32* %11
br label %14
67: ; preds = %14
%68 = load i32*, i32** %9
%69 = call i32 @fclose(i32* %68)
ret void
}

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