#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*/ abort();
int /*<<< orphan*/ dla_simulation(int *, int, int, int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, int, int);
int /*<<< orphan*/ free(int **);
scalar_t__ malloc(int);
int /*<<< orphan*/ perror(char *);
int main(void) {
  bool(*lattice)[(1024)] =
      (bool(*)[(1024)])malloc((1024) * (1024) * sizeof(bool));
  FILE *fout = fopen("res", "w");
  int i, j;
  if (fout == NULL) {
    perror("fopen() res");
    abort();
  }
  if (lattice == NULL) {
    perror("malloc() lattice");
    abort();
  }
  dla_simulation((bool *)lattice, (1024), (1024) / 4 - 1, 4096);
  for (i = 0; i < (1024); i++)
    for (j = 0; j < (1024); j++)
      if (lattice[i][j])
        fprintf(fout, "%d %d\n", i, j);
  fclose(fout);
  free(lattice);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x400000,%edi
call   1070 <malloc@plt>
mov    %rax,-0x10(%rbp)
lea    0xe66(%rip),%rdi
lea    0xe55(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11d2 <main+0x52>
lea    0xe3c(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x0,%al
call   1040 <abort@plt>
cmpq   $0x0,-0x10(%rbp)
jne    11f0 <main+0x70>
lea    0xe2a(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x0,%al
call   1040 <abort@plt>
mov    -0x10(%rbp),%rdi
mov    $0x400,%esi
mov    $0xff,%edx
mov    $0x1000,%ecx
call   1090 <dla_simulation@plt>
movl   $0x0,-0x1c(%rbp)
cmpl   $0x400,-0x1c(%rbp)
jge    1289 <main+0x109>
movl   $0x0,-0x20(%rbp)
cmpl   $0x400,-0x20(%rbp)
jge    1276 <main+0xf6>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
shl    $0xc,%rcx
add    %rcx,%rax
movslq -0x20(%rbp),%rcx
cmpl   $0x0,(%rax,%rcx,4)
je     1263 <main+0xe3>
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%edx
mov    -0x20(%rbp),%ecx
lea    0xdc1(%rip),%rsi
call   1060 <fprintf@plt>
jmp    1268 <main+0xe8>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1223 <main+0xa3>
jmp    127b <main+0xfb>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    120f <main+0x8f>
mov    -0x18(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    $0x400000,%edi
call   1070 <malloc@plt>
mov    %rax,%r14
lea    0xe6b(%rip),%rdi
lea    0xe5a(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     1257 <main+0xd7>
test   %r14,%r14
je     1260 <main+0xe0>
mov    %rax,%r15
mov    %r14,%rdi
mov    $0x400,%esi
mov    $0xff,%edx
mov    $0x1000,%ecx
call   1090 <dla_simulation@plt>
xor    %r13d,%r13d
lea    0xe3e(%rip),%r12
mov    %r14,%rbp
jmp    1204 <main+0x84>
cs nopw 0x0(%rax,%rax,1)
add    $0x1,%r13
add    $0x1000,%rbp
cmp    $0x400,%r13
je     1236 <main+0xb6>
xor    %ebx,%ebx
jmp    121d <main+0x9d>
nopl   0x0(%rax,%rax,1)
add    $0x1,%rbx
cmp    $0x400,%rbx
je     11f0 <main+0x70>
cmpl   $0x0,0x0(%rbp,%rbx,4)
je     1210 <main+0x90>
mov    %r15,%rdi
mov    %r12,%rsi
mov    %r13d,%edx
mov    %ebx,%ecx
call   1060 <fprintf@plt>
jmp    1210 <main+0x90>
mov    %r15,%rdi
call   1050 <fclose@plt>
mov    %r14,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xda4(%rip),%rdi
jmp    1267 <main+0xe7>
lea    0xda7(%rip),%rdi
call   10a0 <perror@plt>
xor    %eax,%eax
call   1040 <abort@plt>

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

LLVM IR (-O2):
@.str = [4 x i8] c"res\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [12 x i8] c"fopen() res\00"
@.str.3 = [17 x i8] c"malloc() lattice\00"
@.str.4 = [7 x i8] c"%d %d\0A\00"
define i32 @main() {
%1 = tail call i64 @malloc(i32 4194304)
%2 = inttoptr i64 %1 to [1024 x i32]*
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %5, label %8
5: ; preds = %0
%6 = tail call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
%7 = tail call i32 (...) @abort()
unreachable
8: ; preds = %0
%9 = icmp eq i64 %1, 0
br i1 %9, label %10, label %13
10: ; preds = %8
%11 = tail call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0))
%12 = tail call i32 (...) @abort()
unreachable
13: ; preds = %8
%14 = getelementptr [1024 x i32], [1024 x i32]* %2, i64 0, i64 0
%15 = tail call i32 @dla_simulation(i32* %14, i32 1024, i32 255, i32 4096)
br label %16
16: ; preds = %13, %30
%17 = phi i64 [ 0, %13 ], [ %31, %30 ]
%18 = trunc i64 %17 to i32
br label %19
19: ; preds = %16, %27
%20 = phi i64 [ 0, %16 ], [ %28, %27 ]
%21 = getelementptr inbounds [1024 x i32], [1024 x i32]* %2, i64 %17, i64 %20
%22 = load i32, i32* %21
%23 = icmp eq i32 %22, 0
br i1 %23, label %27, label %24
24: ; preds = %19
%25 = trunc i64 %20 to i32
%26 = tail call i32 @fprintf(i32* %3, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i32 %18, i32 %25)
br label %27
27: ; preds = %19, %24
%28 = add nuw nsw i64 %20, 1
%29 = icmp eq i64 %28, 1024
br i1 %29, label %30, label %19
30: ; preds = %27
%31 = add nuw nsw i64 %17, 1
%32 = icmp eq i64 %31, 1024
br i1 %32, label %33, label %16
33: ; preds = %30
%34 = tail call i32 @fclose(i32* %3)
%35 = inttoptr i64 %1 to i32**
%36 = tail call i32 @free(i32** %35)
ret i32 0
}