#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++) {
      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    11d5 <write_geno+0xa5>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11b5 <write_geno+0x85>
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    0xe60(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1175 <write_geno+0x45>
mov    -0x20(%rbp),%rdi
lea    0xe43(%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    $0x28,%rsp
mov    %rcx,0x10(%rsp)
mov    %edx,%ebx
mov    %esi,0xc(%rsp)
call   1050 <fopen_write@plt>
mov    %rax,%rbp
test   %ebx,%ebx
jle    11db <write_geno+0x9b>
mov    %ebx,%eax
mov    0xc(%rsp),%ecx
mov    %rcx,0x18(%rsp)
mov    %rax,0x20(%rsp)
lea    0x0(,%rax,4),%r13
lea    0xe7c(%rip),%rbx
xor    %r14d,%r14d
jmp    11ae <write_geno+0x6e>
nopl   0x0(%rax)
mov    $0xa,%edi
mov    %rbp,%rsi
call   1040 <fputc@plt>
add    $0x1,%r14
addq   $0x4,0x10(%rsp)
cmp    0x20(%rsp),%r14
je     11db <write_geno+0x9b>
cmpl   $0x0,0xc(%rsp)
jle    1190 <write_geno+0x50>
mov    0x18(%rsp),%r12
mov    0x10(%rsp),%r15
nop
mov    (%r15),%edx
mov    %rbp,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
add    %r13,%r15
add    $0xffffffffffffffff,%r12
jne    11c0 <write_geno+0x80>
jmp    1190 <write_geno+0x50>
mov    %rbp,%rdi
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <fclose@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
@.str.1 = [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 = %41, %4
%15 = load i32, i32* %11
%16 = load i32, i32* %7
%17 = icmp slt i32 %15, %16
br i1 %17, label %18, label %44
18: ; preds = %14
store i32 0, i32* %10
br label %19
19: ; preds = %35, %18
%20 = load i32, i32* %10
%21 = load i32, i32* %6
%22 = icmp slt i32 %20, %21
br i1 %22, label %23, label %38
23: ; preds = %19
%24 = load i32*, i32** %9
%25 = load i32*, i32** %8
%26 = load i32, i32* %10
%27 = load i32, i32* %7
%28 = mul nsw i32 %26, %27
%29 = load i32, i32* %11
%30 = add nsw i32 %28, %29
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i32, i32* %25, i64 %31
%33 = load i32, i32* %32
%34 = call i32 (i32*, i8*, ...) @fprintf(i32* %24, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %33)
br label %35
35: ; preds = %23
%36 = load i32, i32* %10
%37 = add nsw i32 %36, 1
store i32 %37, i32* %10
br label %19
38: ; preds = %19
%39 = load i32*, i32** %9
%40 = call i32 (i32*, i8*, ...) @fprintf(i32* %39, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %41
41: ; preds = %38
%42 = load i32, i32* %11
%43 = add nsw i32 %42, 1
store i32 %43, i32* %11
br label %14
44: ; preds = %14
%45 = load i32*, i32** %9
%46 = call i32 @fclose(i32* %45)
ret void
}

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