#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(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ fwrite(unsigned char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, char *);
void writeIntArrtoFile(char *outfilename, int C1[80][120], int C2[80][120],
                       int C3[80][120], int nx, int ny, char *in) {
  int i, j;
  unsigned char byte;
  FILE *outimage = fopen(outfilename, "w");
  fprintf(outimage, "P6 \n");
  fprintf(outimage, "# Filtered Image\n");
  fprintf(outimage, "# initial image:  %s\n", in);
  fprintf(outimage, "%ld %ld \n255\n", nx, ny);
  for (j = 0; j < ny; j++)
    for (i = 0; i < nx; i++) {
      byte = (unsigned char)(C1[i][j]);
      fwrite(&byte, sizeof(unsigned char), 1, outimage);
      byte = (unsigned char)(C2[i][j]);
      fwrite(&byte, sizeof(unsigned char), 1, outimage);
      byte = (unsigned char)(C3[i][j]);
      fwrite(&byte, sizeof(unsigned char), 1, outimage);
    }
  fclose(outimage);
  printf("output image %s successfully written\n\n", outfilename);
}


x86 assembly (clang, -O0):
<writeIntArrtoFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    0x10(%rbp),%rax
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
mov    %r9d,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe81(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rdi
lea    0xe6f(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x40(%rbp),%rdi
lea    0xe62(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x40(%rbp),%rdi
mov    0x10(%rbp),%rdx
lea    0xe5e(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x40(%rbp),%rdi
mov    -0x24(%rbp),%edx
mov    -0x28(%rbp),%ecx
lea    0xe5c(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0x28(%rbp),%eax
jge    12b1 <writeIntArrtoFile+0x161>
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    129e <writeIntArrtoFile+0x14e>
mov    -0x10(%rbp),%rax
movslq -0x2c(%rbp),%rcx
imul   $0x1e0,%rcx,%rcx
add    %rcx,%rax
movslq -0x30(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    %al,-0x31(%rbp)
mov    -0x40(%rbp),%rcx
lea    -0x31(%rbp),%rdi
mov    $0x1,%edx
mov    %edx,%esi
call   1070 <fwrite@plt>
mov    -0x18(%rbp),%rax
movslq -0x2c(%rbp),%rcx
imul   $0x1e0,%rcx,%rcx
add    %rcx,%rax
movslq -0x30(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    %al,-0x31(%rbp)
mov    -0x40(%rbp),%rcx
lea    -0x31(%rbp),%rdi
mov    $0x1,%edx
mov    %edx,%esi
call   1070 <fwrite@plt>
mov    -0x20(%rbp),%rax
movslq -0x2c(%rbp),%rcx
imul   $0x1e0,%rcx,%rcx
add    %rcx,%rax
movslq -0x30(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    %al,-0x31(%rbp)
mov    -0x40(%rbp),%rcx
lea    -0x31(%rbp),%rdi
mov    $0x1,%edx
mov    %edx,%esi
call   1070 <fwrite@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    11f4 <writeIntArrtoFile+0xa4>
jmp    12a3 <writeIntArrtoFile+0x153>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    11e1 <writeIntArrtoFile+0x91>
mov    -0x40(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x8(%rbp),%rsi
lea    0xd78(%rip),%rdi
call   1040 <printf@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<writeIntArrtoFile>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %r9d,%r14d
mov    %r8d,%r15d
mov    %rcx,%r12
mov    %rdx,%r13
mov    %rsi,%rbx
mov    0x60(%rsp),%rax
mov    %rax,0x10(%rsp)
lea    0xe72(%rip),%rsi
mov    %rdi,0x18(%rsp)
call   1070 <fopen@plt>
mov    %rax,%rbp
lea    0xe60(%rip),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
mov    %rax,%rcx
call   1080 <fwrite@plt>
lea    0xe4c(%rip),%rdi
mov    $0x11,%esi
mov    $0x1,%edx
mov    %rbp,%rcx
call   1080 <fwrite@plt>
lea    0xe45(%rip),%rsi
mov    %rbp,%rdi
mov    0x10(%rsp),%rdx
xor    %eax,%eax
call   1060 <fprintf@plt>
lea    0xe45(%rip),%rsi
mov    %rbp,%rdi
mov    %r15d,0xc(%rsp)
mov    %r15d,%edx
mov    %r14d,%ecx
xor    %eax,%eax
call   1060 <fprintf@plt>
test   %r14d,%r14d
jle    1286 <writeIntArrtoFile+0x126>
mov    %r14d,%eax
mov    %rax,0x20(%rsp)
mov    0xc(%rsp),%eax
imul   $0x1e0,%rax,%r15
xor    %eax,%eax
jmp    123c <writeIntArrtoFile+0xdc>
nop
mov    0x10(%rsp),%rax
add    $0x1,%rax
add    $0x4,%rbx
add    $0x4,%r13
add    $0x4,%r12
cmp    0x20(%rsp),%rax
je     1286 <writeIntArrtoFile+0x126>
mov    %rax,0x10(%rsp)
cmpl   $0x0,0xc(%rsp)
jle    1220 <writeIntArrtoFile+0xc0>
xor    %r14d,%r14d
nopl   0x0(%rax,%rax,1)
movsbl (%rbx,%r14,1),%edi
mov    %rbp,%rsi
call   1050 <fputc@plt>
movsbl 0x0(%r13,%r14,1),%edi
mov    %rbp,%rsi
call   1050 <fputc@plt>
movsbl (%r12,%r14,1),%edi
mov    %rbp,%rsi
call   1050 <fputc@plt>
add    $0x1e0,%r14
cmp    %r14,%r15
jne    1250 <writeIntArrtoFile+0xf0>
jmp    1220 <writeIntArrtoFile+0xc0>
mov    %rbp,%rdi
call   1030 <fclose@plt>
lea    0xda8(%rip),%rdi
mov    0x18(%rsp),%rsi
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <printf@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"w\00"
@.str.1 = [5 x i8] c"P6 \0A\00"
@.str.2 = [18 x i8] c"# Filtered Image\0A\00"
@.str.3 = [22 x i8] c"# initial image: %s\0A\00"
@.str.4 = [14 x i8] c"%ld %ld \0A255\0A\00"
@.str.5 = [39 x i8] c"output image %s successfully written\0A\0A\00"
define void @writeIntArrtoFile(i8* %0, [120 x i32]* %1, [120 x i32]* %2, [120 x i32]* %3, i32 %4, i32 %5, i8* %6) {
%8 = alloca i8*
%9 = alloca [120 x i32]*
%10 = alloca [120 x i32]*
%11 = alloca [120 x i32]*
%12 = alloca i32
%13 = alloca i32
%14 = alloca i8*
%15 = alloca i32
%16 = alloca i32
%17 = alloca i8
%18 = alloca i32*
store i8* %0, i8** %8
store [120 x i32]* %1, [120 x i32]** %9
store [120 x i32]* %2, [120 x i32]** %10
store [120 x i32]* %3, [120 x i32]** %11
store i32 %4, i32* %12
store i32 %5, i32* %13
store i8* %6, i8** %14
%19 = load i8*, i8** %8
%20 = call i32* @fopen(i8* %19, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %20, i32** %18
%21 = load i32*, i32** %18
%22 = call i32 (i32*, i8*, ...) @fprintf(i32* %21, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%23 = load i32*, i32** %18
%24 = call i32 (i32*, i8*, ...) @fprintf(i32* %23, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
%25 = load i32*, i32** %18
%26 = load i8*, i8** %14
%27 = call i32 (i32*, i8*, ...) @fprintf(i32* %25, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i8* %26)
%28 = load i32*, i32** %18
%29 = load i32, i32* %12
%30 = load i32, i32* %13
%31 = call i32 (i32*, i8*, ...) @fprintf(i32* %28, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0), i32 %29, i32 %30)
store i32 0, i32* %16
br label %32
32: ; preds = %79, %7
%33 = load i32, i32* %16
%34 = load i32, i32* %13
%35 = icmp slt i32 %33, %34
br i1 %35, label %36, label %82
36: ; preds = %32
store i32 0, i32* %15
br label %37
37: ; preds = %75, %36
%38 = load i32, i32* %15
%39 = load i32, i32* %12
%40 = icmp slt i32 %38, %39
br i1 %40, label %41, label %78
41: ; preds = %37
%42 = load [120 x i32]*, [120 x i32]** %9
%43 = load i32, i32* %15
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds [120 x i32], [120 x i32]* %42, i64 %44
%46 = load i32, i32* %16
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds [120 x i32], [120 x i32]* %45, i64 0, i64 %47
%49 = load i32, i32* %48
%50 = trunc i32 %49 to i8
store i8 %50, i8* %17
%51 = load i32*, i32** %18
%52 = call i32 @fwrite(i8* %17, i32 1, i32 1, i32* %51)
%53 = load [120 x i32]*, [120 x i32]** %10
%54 = load i32, i32* %15
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds [120 x i32], [120 x i32]* %53, i64 %55
%57 = load i32, i32* %16
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds [120 x i32], [120 x i32]* %56, i64 0, i64 %58
%60 = load i32, i32* %59
%61 = trunc i32 %60 to i8
store i8 %61, i8* %17
%62 = load i32*, i32** %18
%63 = call i32 @fwrite(i8* %17, i32 1, i32 1, i32* %62)
%64 = load [120 x i32]*, [120 x i32]** %11
%65 = load i32, i32* %15
%66 = sext i32 %65 to i64
%67 = getelementptr inbounds [120 x i32], [120 x i32]* %64, i64 %66
%68 = load i32, i32* %16
%69 = sext i32 %68 to i64
%70 = getelementptr inbounds [120 x i32], [120 x i32]* %67, i64 0, i64 %69
%71 = load i32, i32* %70
%72 = trunc i32 %71 to i8
store i8 %72, i8* %17
%73 = load i32*, i32** %18
%74 = call i32 @fwrite(i8* %17, i32 1, i32 1, i32* %73)
br label %75
75: ; preds = %41
%76 = load i32, i32* %15
%77 = add nsw i32 %76, 1
store i32 %77, i32* %15
br label %37
78: ; preds = %37
br label %79
79: ; preds = %78
%80 = load i32, i32* %16
%81 = add nsw i32 %80, 1
store i32 %81, i32* %16
br label %32
82: ; preds = %32
%83 = load i32*, i32** %18
%84 = call i32 @fclose(i32* %83)
%85 = load i8*, i8** %8
%86 = call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.5, i64 0, i64 0), i8* %85)
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"w\00"
@.str.1 = [5 x i8] c"P6 \0A\00"
@.str.2 = [18 x i8] c"# Filtered Image\0A\00"
@.str.3 = [22 x i8] c"# initial image: %s\0A\00"
@.str.4 = [14 x i8] c"%ld %ld \0A255\0A\00"
@.str.5 = [39 x i8] c"output image %s successfully written\0A\0A\00"
define void @writeIntArrtoFile(i8* %0, [120 x i32]* nocapture %1, [120 x i32]* nocapture %2, [120 x i32]* nocapture %3, i32 %4, i32 %5, i8* %6) {
%8 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%9 = tail call i64 bitcast (i32 (i8*, i32, i32, i32*)* @fwrite to i64 (i8*, i64, i64, i32*)*)(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i64 4, i64 1, i32* %8)
%10 = tail call i64 bitcast (i32 (i8*, i32, i32, i32*)* @fwrite to i64 (i8*, i64, i64, i32*)*)(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i64 17, i64 1, i32* %8)
%11 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %8, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i8* %6)
%12 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %8, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0), i32 %4, i32 %5)
%13 = icmp sgt i32 %5, 0
br i1 %13, label %14, label %42
14: ; preds = %7
%15 = icmp sgt i32 %4, 0
%16 = zext i32 %5 to i64
%17 = zext i32 %4 to i64
br label %18
18: ; preds = %14, %39
%19 = phi i64 [ 0, %14 ], [ %40, %39 ]
br i1 %15, label %20, label %39
20: ; preds = %18, %20
%21 = phi i64 [ %37, %20 ], [ 0, %18 ]
%22 = getelementptr inbounds [120 x i32], [120 x i32]* %1, i64 %21, i64 %19
%23 = load i32, i32* %22
%24 = shl i32 %23, 24
%25 = ashr exact i32 %24, 24
%26 = tail call i32 @fputc(i32 %25, i32* %8)
%27 = getelementptr inbounds [120 x i32], [120 x i32]* %2, i64 %21, i64 %19
%28 = load i32, i32* %27
%29 = shl i32 %28, 24
%30 = ashr exact i32 %29, 24
%31 = tail call i32 @fputc(i32 %30, i32* %8)
%32 = getelementptr inbounds [120 x i32], [120 x i32]* %3, i64 %21, i64 %19
%33 = load i32, i32* %32
%34 = shl i32 %33, 24
%35 = ashr exact i32 %34, 24
%36 = tail call i32 @fputc(i32 %35, i32* %8)
%37 = add nuw nsw i64 %21, 1
%38 = icmp eq i64 %37, %17
br i1 %38, label %39, label %20
39: ; preds = %20, %18
%40 = add nuw nsw i64 %19, 1
%41 = icmp eq i64 %40, %16
br i1 %41, label %42, label %18
42: ; preds = %39, %7
%43 = tail call i32 @fclose(i32* %8)
%44 = tail call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.5, i64 0, i64 0), i8* %0)
ret void
}