#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 writeImgChannelstoFile(char *outfilename, float **C1, float **C2,
                            float **C3, 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):
<writeImgChannelstoFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%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    12aa <writeImgChannelstoFile+0x15a>
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    1297 <writeImgChannelstoFile+0x147>
mov    -0x10(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x30(%rbp),%rcx
cvttss2si (%rax,%rcx,4),%eax
mov    %al,-0x31(%rbp)
mov    -0x40(%rbp),%rcx
lea    -0x31(%rbp),%rdi
mov    %rdi,-0x50(%rbp)
mov    $0x1,%edx
mov    %edx,-0x44(%rbp)
mov    %edx,%esi
call   1070 <fwrite@plt>
mov    -0x50(%rbp),%rdi
mov    -0x44(%rbp),%edx
mov    -0x18(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x30(%rbp),%rcx
cvttss2si (%rax,%rcx,4),%eax
mov    %al,-0x31(%rbp)
mov    -0x40(%rbp),%rcx
mov    %edx,%esi
call   1070 <fwrite@plt>
mov    -0x20(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x30(%rbp),%rcx
cvttss2si (%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 <writeImgChannelstoFile+0xa4>
jmp    129c <writeImgChannelstoFile+0x14c>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    11e1 <writeImgChannelstoFile+0x91>
mov    -0x40(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x8(%rbp),%rsi
lea    0xd7f(%rip),%rdi
call   1040 <printf@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<writeImgChannelstoFile>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %r9d,%r14d
mov    %r8d,%r15d
mov    %rcx,0x30(%rsp)
mov    %rdx,0x28(%rsp)
mov    %rsi,0x20(%rsp)
mov    0x70(%rsp),%rbx
lea    0xe71(%rip),%rsi
mov    %rdi,0x10(%rsp)
call   1070 <fopen@plt>
mov    %rax,%rbp
lea    0xe5f(%rip),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
mov    %rax,%rcx
call   1080 <fwrite@plt>
lea    0xe4b(%rip),%rdi
mov    $0x11,%esi
mov    $0x1,%edx
mov    %rbp,%rcx
call   1080 <fwrite@plt>
lea    0xe44(%rip),%rsi
mov    %rbp,%rdi
mov    %rbx,%rdx
xor    %eax,%eax
call   1060 <fprintf@plt>
lea    0xe46(%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    129f <writeImgChannelstoFile+0x13f>
mov    %r14d,%eax
mov    %rax,0x18(%rsp)
mov    0xc(%rsp),%r13d
xor    %r14d,%r14d
mov    0x28(%rsp),%rbx
mov    0x20(%rsp),%r15
jmp    123b <writeImgChannelstoFile+0xdb>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
add    $0x1,%r14
cmp    0x18(%rsp),%r14
je     129f <writeImgChannelstoFile+0x13f>
cmpl   $0x0,0xc(%rsp)
jle    1230 <writeImgChannelstoFile+0xd0>
xor    %r12d,%r12d
cs nopw 0x0(%rax,%rax,1)
nop
mov    (%r15,%r12,8),%rax
cvttss2si (%rax,%r14,4),%eax
movsbl %al,%edi
mov    %rbp,%rsi
call   1050 <fputc@plt>
mov    (%rbx,%r12,8),%rax
cvttss2si (%rax,%r14,4),%eax
movsbl %al,%edi
mov    %rbp,%rsi
call   1050 <fputc@plt>
mov    0x30(%rsp),%rax
mov    (%rax,%r12,8),%rax
cvttss2si (%rax,%r14,4),%eax
movsbl %al,%edi
mov    %rbp,%rsi
call   1050 <fputc@plt>
add    $0x1,%r12
cmp    %r12,%r13
jne    1250 <writeImgChannelstoFile+0xf0>
jmp    1230 <writeImgChannelstoFile+0xd0>
mov    %rbp,%rdi
call   1030 <fclose@plt>
lea    0xd8f(%rip),%rdi
mov    0x10(%rsp),%rsi
add    $0x38,%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 @writeImgChannelstoFile(i8* %0, float** %1, float** %2, float** %3, i32 %4, i32 %5, i8* %6) {
%8 = alloca i8*
%9 = alloca float**
%10 = alloca float**
%11 = alloca float**
%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 float** %1, float*** %9
store float** %2, float*** %10
store float** %3, float*** %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 = %82, %7
%33 = load i32, i32* %16
%34 = load i32, i32* %13
%35 = icmp slt i32 %33, %34
br i1 %35, label %36, label %85
36: ; preds = %32
store i32 0, i32* %15
br label %37
37: ; preds = %78, %36
%38 = load i32, i32* %15
%39 = load i32, i32* %12
%40 = icmp slt i32 %38, %39
br i1 %40, label %41, label %81
41: ; preds = %37
%42 = load float**, float*** %9
%43 = load i32, i32* %15
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds float*, float** %42, i64 %44
%46 = load float*, float** %45
%47 = load i32, i32* %16
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds float, float* %46, i64 %48
%50 = load float, float* %49
%51 = fptoui float %50 to i8
store i8 %51, i8* %17
%52 = load i32*, i32** %18
%53 = call i32 @fwrite(i8* %17, i32 1, i32 1, i32* %52)
%54 = load float**, float*** %10
%55 = load i32, i32* %15
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds float*, float** %54, i64 %56
%58 = load float*, float** %57
%59 = load i32, i32* %16
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds float, float* %58, i64 %60
%62 = load float, float* %61
%63 = fptoui float %62 to i8
store i8 %63, i8* %17
%64 = load i32*, i32** %18
%65 = call i32 @fwrite(i8* %17, i32 1, i32 1, i32* %64)
%66 = load float**, float*** %11
%67 = load i32, i32* %15
%68 = sext i32 %67 to i64
%69 = getelementptr inbounds float*, float** %66, i64 %68
%70 = load float*, float** %69
%71 = load i32, i32* %16
%72 = sext i32 %71 to i64
%73 = getelementptr inbounds float, float* %70, i64 %72
%74 = load float, float* %73
%75 = fptoui float %74 to i8
store i8 %75, i8* %17
%76 = load i32*, i32** %18
%77 = call i32 @fwrite(i8* %17, i32 1, i32 1, i32* %76)
br label %78
78: ; preds = %41
%79 = load i32, i32* %15
%80 = add nsw i32 %79, 1
store i32 %80, i32* %15
br label %37
81: ; preds = %37
br label %82
82: ; preds = %81
%83 = load i32, i32* %16
%84 = add nsw i32 %83, 1
store i32 %84, i32* %16
br label %32
85: ; preds = %32
%86 = load i32*, i32** %18
%87 = call i32 @fclose(i32* %86)
%88 = load i8*, i8** %8
%89 = call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.5, i64 0, i64 0), i8* %88)
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 @writeImgChannelstoFile(i8* %0, float** nocapture %1, float** nocapture %2, float** 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 %48
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, %45
%19 = phi i64 [ 0, %14 ], [ %46, %45 ]
br i1 %15, label %20, label %45
20: ; preds = %18, %20
%21 = phi i64 [ %43, %20 ], [ 0, %18 ]
%22 = getelementptr inbounds float*, float** %1, i64 %21
%23 = load float*, float** %22
%24 = getelementptr inbounds float, float* %23, i64 %19
%25 = load float, float* %24
%26 = fptoui float %25 to i8
%27 = sext i8 %26 to i32
%28 = tail call i32 @fputc(i32 %27, i32* %8)
%29 = getelementptr inbounds float*, float** %2, i64 %21
%30 = load float*, float** %29
%31 = getelementptr inbounds float, float* %30, i64 %19
%32 = load float, float* %31
%33 = fptoui float %32 to i8
%34 = sext i8 %33 to i32
%35 = tail call i32 @fputc(i32 %34, i32* %8)
%36 = getelementptr inbounds float*, float** %3, i64 %21
%37 = load float*, float** %36
%38 = getelementptr inbounds float, float* %37, i64 %19
%39 = load float, float* %38
%40 = fptoui float %39 to i8
%41 = sext i8 %40 to i32
%42 = tail call i32 @fputc(i32 %41, i32* %8)
%43 = add nuw nsw i64 %21, 1
%44 = icmp eq i64 %43, %17
br i1 %44, label %45, label %20
45: ; preds = %20, %18
%46 = add nuw nsw i64 %19, 1
%47 = icmp eq i64 %46, %16
br i1 %47, label %48, label %18
48: ; preds = %45, %7
%49 = tail call i32 @fclose(i32* %8)
%50 = tail call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.5, i64 0, i64 0), i8* %0)
ret void
}