#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*/ arrayadd(long, long, long, long, long, long *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
long numbread(int /*<<< orphan*/ *);
void journey(char *inputfilename, char *outputfilename) {
  FILE *inputfile;
  FILE *outputfile;
  inputfile = fopen(inputfilename, "r");
  outputfile = fopen(outputfilename, "w");
  long n = numbread(inputfile);
  long m = numbread(inputfile);
  long h = numbread(inputfile);
  long i, j, k, o;
  long consty = n * m;
  long a[consty];
  for (o = 0; o < n * m; o++) {
    a[o] = 0;
  }
  for (i = 0; i < n - 1; i++) {
    for (o = 0; o < h; o++) {
      j = numbread(inputfile);
      k = numbread(inputfile);
      if ((i < j) && (j < n)) {
        arrayadd(i, j, k, m, n, a);
      }
    }
  }
  for (o = n * m - m; o < n * m; o++) {
    fprintf(outputfile, "%ld ", a[o]);
  }
  fprintf(outputfile, "\n");
  fclose(inputfile);
  fclose(outputfile);
}


x86 assembly (clang, -O0):
<journey>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe92(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe80(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1060 <numbread@plt>
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   1060 <numbread@plt>
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
call   1060 <numbread@plt>
mov    %rax,-0x38(%rbp)
mov    -0x28(%rbp),%rax
mov    -0x30(%rbp),%rcx
imul   %rcx,%rax
mov    %rax,-0x60(%rbp)
mov    -0x60(%rbp),%rax
mov    %rsp,%rcx
mov    %rcx,-0x68(%rbp)
lea    0xf(,%rax,8),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x78(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x70(%rbp)
movq   $0x0,-0x58(%rbp)
mov    -0x58(%rbp),%rax
mov    -0x28(%rbp),%rcx
imul   -0x30(%rbp),%rcx
cmp    %rcx,%rax
jge    1229 <journey+0xd9>
mov    -0x78(%rbp),%rax
mov    -0x58(%rbp),%rcx
movq   $0x0,(%rax,%rcx,8)
mov    -0x58(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x58(%rbp)
jmp    11f2 <journey+0xa2>
movq   $0x0,-0x40(%rbp)
mov    -0x40(%rbp),%rax
mov    -0x28(%rbp),%rcx
sub    $0x1,%rcx
cmp    %rcx,%rax
jge    12db <journey+0x18b>
movq   $0x0,-0x58(%rbp)
mov    -0x58(%rbp),%rax
cmp    -0x38(%rbp),%rax
jge    12c5 <journey+0x175>
mov    -0x18(%rbp),%rdi
call   1060 <numbread@plt>
mov    %rax,-0x48(%rbp)
mov    -0x18(%rbp),%rdi
call   1060 <numbread@plt>
mov    %rax,-0x50(%rbp)
mov    -0x40(%rbp),%rax
cmp    -0x48(%rbp),%rax
jge    12af <journey+0x15f>
mov    -0x48(%rbp),%rax
cmp    -0x28(%rbp),%rax
jge    12af <journey+0x15f>
mov    -0x78(%rbp),%r9
mov    -0x40(%rbp),%rdi
mov    -0x48(%rbp),%rsi
mov    -0x50(%rbp),%rdx
mov    -0x30(%rbp),%rcx
mov    -0x28(%rbp),%r8
call   1070 <arrayadd@plt>
jmp    12b4 <journey+0x164>
mov    -0x58(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x58(%rbp)
jmp    124e <journey+0xfe>
jmp    12ca <journey+0x17a>
mov    -0x40(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x40(%rbp)
jmp    1231 <journey+0xe1>
mov    -0x28(%rbp),%rax
imul   -0x30(%rbp),%rax
sub    -0x30(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    -0x58(%rbp),%rax
mov    -0x28(%rbp),%rcx
imul   -0x30(%rbp),%rcx
cmp    %rcx,%rax
jge    1331 <journey+0x1e1>
mov    -0x78(%rbp),%rax
mov    -0x20(%rbp),%rdi
mov    -0x58(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
lea    0xceb(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x58(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x58(%rbp)
jmp    12ec <journey+0x19c>
mov    -0x20(%rbp),%rdi
lea    0xccd(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x68(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<journey>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %rsi,%r14
lea    0xe75(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%rbx
lea    0xe68(%rip),%rsi
mov    %r14,%rdi
call   1070 <fopen@plt>
mov    %rax,-0x50(%rbp)
mov    %rbx,%rdi
call   1080 <numbread@plt>
mov    %rax,%r13
mov    %rbx,%rdi
call   1080 <numbread@plt>
mov    %rax,%r14
mov    %rbx,%rdi
call   1080 <numbread@plt>
mov    %rax,-0x30(%rbp)
mov    %r14,-0x38(%rbp)
imul   %r13,%r14
lea    0xf(,%r14,8),%rax
and    $0xfffffffffffffff0,%rax
mov    %rsp,%r15
sub    %rax,%r15
mov    %r15,%rsp
test   %r14,%r14
jle    11fc <journey+0x8c>
lea    0x0(,%r14,8),%rdx
mov    %r15,%rdi
xor    %esi,%esi
call   1040 <memset@plt>
mov    %r15,-0x40(%rbp)
mov    %r14,-0x48(%rbp)
cmp    $0x2,%r13
jl     127e <journey+0x10e>
lea    -0x1(%r13),%rax
mov    %rax,-0x58(%rbp)
xor    %r14d,%r14d
jmp    122a <journey+0xba>
nopw   0x0(%rax,%rax,1)
add    $0x1,%r14
cmp    -0x58(%rbp),%r14
je     127e <journey+0x10e>
cmpq   $0x0,-0x30(%rbp)
jle    1220 <journey+0xb0>
mov    -0x30(%rbp),%r15
jmp    1246 <journey+0xd6>
nopw   0x0(%rax,%rax,1)
add    $0xffffffffffffffff,%r15
je     1220 <journey+0xb0>
mov    %rbx,%rdi
call   1080 <numbread@plt>
mov    %rax,%r12
mov    %rbx,%rdi
call   1080 <numbread@plt>
cmp    %r12,%r14
jge    1240 <journey+0xd0>
cmp    %r13,%r12
jge    1240 <journey+0xd0>
mov    %r14,%rdi
mov    %r12,%rsi
mov    %rax,%rdx
mov    -0x38(%rbp),%rcx
mov    %r13,%r8
mov    -0x40(%rbp),%r9
call   1090 <arrayadd@plt>
jmp    1240 <journey+0xd0>
mov    -0x38(%rbp),%rax
test   %rax,%rax
mov    -0x50(%rbp),%r12
mov    -0x48(%rbp),%r13
mov    -0x40(%rbp),%r14
jle    12be <journey+0x14e>
mov    %r13,%r15
sub    %rax,%r15
nopl   0x0(%rax)
mov    (%r14,%r15,8),%rdx
mov    %r12,%rdi
lea    0xd56(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
add    $0x1,%r15
cmp    %r13,%r15
jl     12a0 <journey+0x130>
mov    $0xa,%edi
mov    %r12,%rsi
call   1050 <fputc@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    %r12,%rdi
call   1030 <fclose@plt>
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [5 x i8] c"%ld \00"
@.str.3 = [2 x i8] c"\0A\00"
define void @journey(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i64
%8 = alloca i64
%9 = alloca i64
%10 = alloca i64
%11 = alloca i64
%12 = alloca i64
%13 = alloca i64
%14 = alloca i64
%15 = alloca i8*
%16 = alloca i64
store i8* %0, i8** %3
store i8* %1, i8** %4
%17 = load i8*, i8** %3
%18 = call i32* @fopen(i8* %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %18, i32** %5
%19 = load i8*, i8** %4
%20 = call i32* @fopen(i8* %19, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %20, i32** %6
%21 = load i32*, i32** %5
%22 = call i64 @numbread(i32* %21)
store i64 %22, i64* %7
%23 = load i32*, i32** %5
%24 = call i64 @numbread(i32* %23)
store i64 %24, i64* %8
%25 = load i32*, i32** %5
%26 = call i64 @numbread(i32* %25)
store i64 %26, i64* %9
%27 = load i64, i64* %7
%28 = load i64, i64* %8
%29 = mul nsw i64 %27, %28
store i64 %29, i64* %14
%30 = load i64, i64* %14
%31 = call i8* @llvm.stacksave()
store i8* %31, i8** %15
%32 = alloca i64, i64 %30
store i64 %30, i64* %16
store i64 0, i64* %13
br label %33
33: ; preds = %42, %2
%34 = load i64, i64* %13
%35 = load i64, i64* %7
%36 = load i64, i64* %8
%37 = mul nsw i64 %35, %36
%38 = icmp slt i64 %34, %37
br i1 %38, label %39, label %45
39: ; preds = %33
%40 = load i64, i64* %13
%41 = getelementptr inbounds i64, i64* %32, i64 %40
store i64 0, i64* %41
br label %42
42: ; preds = %39
%43 = load i64, i64* %13
%44 = add nsw i64 %43, 1
store i64 %44, i64* %13
br label %33
45: ; preds = %33
store i64 0, i64* %10
br label %46
46: ; preds = %80, %45
%47 = load i64, i64* %10
%48 = load i64, i64* %7
%49 = sub nsw i64 %48, 1
%50 = icmp slt i64 %47, %49
br i1 %50, label %51, label %83
51: ; preds = %46
store i64 0, i64* %13
br label %52
52: ; preds = %76, %51
%53 = load i64, i64* %13
%54 = load i64, i64* %9
%55 = icmp slt i64 %53, %54
br i1 %55, label %56, label %79
56: ; preds = %52
%57 = load i32*, i32** %5
%58 = call i64 @numbread(i32* %57)
store i64 %58, i64* %11
%59 = load i32*, i32** %5
%60 = call i64 @numbread(i32* %59)
store i64 %60, i64* %12
%61 = load i64, i64* %10
%62 = load i64, i64* %11
%63 = icmp slt i64 %61, %62
br i1 %63, label %64, label %75
64: ; preds = %56
%65 = load i64, i64* %11
%66 = load i64, i64* %7
%67 = icmp slt i64 %65, %66
br i1 %67, label %68, label %75
68: ; preds = %64
%69 = load i64, i64* %10
%70 = load i64, i64* %11
%71 = load i64, i64* %12
%72 = load i64, i64* %8
%73 = load i64, i64* %7
%74 = call i32 @arrayadd(i64 %69, i64 %70, i64 %71, i64 %72, i64 %73, i64* %32)
br label %75
75: ; preds = %68, %64, %56
br label %76
76: ; preds = %75
%77 = load i64, i64* %13
%78 = add nsw i64 %77, 1
store i64 %78, i64* %13
br label %52
79: ; preds = %52
br label %80
80: ; preds = %79
%81 = load i64, i64* %10
%82 = add nsw i64 %81, 1
store i64 %82, i64* %10
br label %46
83: ; preds = %46
%84 = load i64, i64* %7
%85 = load i64, i64* %8
%86 = mul nsw i64 %84, %85
%87 = load i64, i64* %8
%88 = sub nsw i64 %86, %87
store i64 %88, i64* %13
br label %89
89: ; preds = %101, %83
%90 = load i64, i64* %13
%91 = load i64, i64* %7
%92 = load i64, i64* %8
%93 = mul nsw i64 %91, %92
%94 = icmp slt i64 %90, %93
br i1 %94, label %95, label %104
95: ; preds = %89
%96 = load i32*, i32** %6
%97 = load i64, i64* %13
%98 = getelementptr inbounds i64, i64* %32, i64 %97
%99 = load i64, i64* %98
%100 = call i32 (i32*, i8*, ...) @fprintf(i32* %96, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i64 %99)
br label %101
101: ; preds = %95
%102 = load i64, i64* %13
%103 = add nsw i64 %102, 1
store i64 %103, i64* %13
br label %89
104: ; preds = %89
%105 = load i32*, i32** %6
%106 = call i32 (i32*, i8*, ...) @fprintf(i32* %105, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%107 = load i32*, i32** %5
%108 = call i32 @fclose(i32* %107)
%109 = load i32*, i32** %6
%110 = call i32 @fclose(i32* %109)
%111 = load i8*, i8** %15
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [5 x i8] c"%ld \00"
define void @journey(i8* nocapture %0, i8* nocapture %1) {
%3 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%4 = tail call i32* @fopen(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%5 = tail call i64 @numbread(i32* %3)
%6 = tail call i64 @numbread(i32* %3)
%7 = tail call i64 @numbread(i32* %3)
%8 = mul i64 %6, %5
%9 = alloca i64, i64 %8
%10 = icmp sgt i64 %8, 0
br i1 %10, label %11, label %14
11: ; preds = %2
%12 = bitcast i64* %9 to i8*
%13 = shl i64 %8, 3
br label %14
14: ; preds = %11, %2
%15 = add i64 %5, -1
%16 = icmp sgt i64 %5, 1
br i1 %16, label %17, label %36
17: ; preds = %14
%18 = icmp sgt i64 %7, 0
br label %19
19: ; preds = %17, %33
%20 = phi i64 [ 0, %17 ], [ %34, %33 ]
br i1 %18, label %21, label %33
21: ; preds = %19, %30
%22 = phi i64 [ %31, %30 ], [ 0, %19 ]
%23 = call i64 @numbread(i32* %3)
%24 = call i64 @numbread(i32* %3)
%25 = icmp slt i64 %20, %23
%26 = icmp slt i64 %23, %5
%27 = select i1 %25, i1 %26, i1 false
br i1 %27, label %28, label %30
28: ; preds = %21
%29 = call i32 @arrayadd(i64 %20, i64 %23, i64 %24, i64 %6, i64 %5, i64* %9)
br label %30
30: ; preds = %21, %28
%31 = add nuw nsw i64 %22, 1
%32 = icmp eq i64 %31, %7
br i1 %32, label %33, label %21
33: ; preds = %30, %19
%34 = add nuw nsw i64 %20, 1
%35 = icmp eq i64 %34, %15
br i1 %35, label %36, label %19
36: ; preds = %33, %14
%37 = icmp sgt i64 %6, 0
br i1 %37, label %38, label %47
38: ; preds = %36
%39 = sub nsw i64 %8, %6
br label %40
40: ; preds = %38, %40
%41 = phi i64 [ %45, %40 ], [ %39, %38 ]
%42 = getelementptr inbounds i64, i64* %9, i64 %41
%43 = load i64, i64* %42
%44 = call i32 (i32*, i8*, ...) @fprintf(i32* %4, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i64 %43)
%45 = add nsw i64 %41, 1
%46 = icmp slt i64 %45, %8
br i1 %46, label %40, label %47
47: ; preds = %40, %36
%48 = call i32 @fputc(i32 10, i32* %4)
%49 = call i32 @fclose(i32* %3)
%50 = call i32 @fclose(i32* %4)
ret void
}