#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*/ assert(int);
int atoi(char *);
int /*<<< orphan*/ convert_ppm(int *, int, int, int, int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
unsigned char fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ fread(unsigned char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, int *, ...);
int /*<<< orphan*/ fwrite(unsigned char *, int, int, int /*<<< orphan*/ *);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char **argv) {
  if (argc != 5) {
    printf("Usage - original_file destination_file color_component "
           "color_change.\n");
    return 1;
  }
  FILE *ppm_file = fopen(argv[1], "r");
  FILE *converted_ppm_file = fopen(argv[2], "w+");
  if (ppm_file == NULL) {
    printf("Cannot open original file.\n");
    return 1;
  }
  if (converted_ppm_file == NULL) {
    printf("Cannot open destination file.\n");
    return 1;
  }
  int color_component = atoi(argv[3]);
  int color_change = atoi(argv[4]);
  printf("%d %d\n", color_component, color_change);
  int *image_array;
  int width, height, max_size;
  unsigned char c;
  while ((c = fgetc(ppm_file)) != '\n')
    ;
  fprintf(converted_ppm_file, "P6\n");
  while ((c = fgetc(ppm_file)) != '\n')
    ;
  fprintf(converted_ppm_file, "#Modified file by as292510.\n");
  fscanf(ppm_file, "%d %d\n", &width, &height);
  printf("%d %d\n", width, height);
  fprintf(converted_ppm_file, "%d %d\n", width, height);
  fscanf(ppm_file, "%d\n", &max_size);
  printf("%d\n", max_size);
  if (color_component > 3 || color_component < 1) {
    printf("Wrong color component number. It should be between 1 and 3.\n");
    return 1;
  }
  fprintf(converted_ppm_file, "%d\n", max_size);
  image_array = (int *)malloc(sizeof(int) * width * height * 3);
  int i, j;
  for (i = 0; i < height; i++) {
    for (j = 0; j < width; j++) {
      int current_component = i * (width * 3) + j * 3;
      fread(&c, 1, 1, ppm_file);
      image_array[current_component] = c;
      fread(&c, 1, 1, ppm_file);
      image_array[current_component + 1] = c;
      fread(&c, 1, 1, ppm_file);
      image_array[current_component + 2] = c;
    }
  }
  printf("end of file\n");
  for (i = 0; i < width * height * 3; i++) {
    assert(image_array[i] >= 0);
  }
  convert_ppm(image_array, width, height, color_component - 1, color_change);
  for (i = 0; i < width * height * 3; i++) {
    assert(image_array[i] >= 0);
  }
  for (i = 0; i < width * height * 3; i++) {
    c = (unsigned char)image_array[i];
    fwrite(&c, sizeof(unsigned char), 1, converted_ppm_file);
  }
  fclose(ppm_file);
  fclose(converted_ppm_file);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x5,-0x8(%rbp)
je     11fa <main+0x3a>
lea    0xe19(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    15b4 <main+0x3f4>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe3d(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe27(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    124f <main+0x8f>
lea    0xe0f(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    15b4 <main+0x3f4>
cmpq   $0x0,-0x20(%rbp)
jne    1274 <main+0xb4>
lea    0xe06(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    15b4 <main+0x3f4>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   10d0 <atoi@plt>
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rdi
call   10d0 <atoi@plt>
mov    %eax,-0x28(%rbp)
mov    -0x24(%rbp),%esi
mov    -0x28(%rbp),%edx
lea    0xde5(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1070 <fgetc@plt>
mov    %al,-0x3d(%rbp)
movzbl %al,%eax
cmp    $0xa,%eax
je     12c5 <main+0x105>
jmp    12a8 <main+0xe8>
mov    -0x20(%rbp),%rdi
lea    0xdbd(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    -0x18(%rbp),%rdi
call   1070 <fgetc@plt>
mov    %al,-0x3d(%rbp)
movzbl %al,%eax
cmp    $0xa,%eax
je     12f4 <main+0x134>
jmp    12d7 <main+0x117>
mov    -0x20(%rbp),%rdi
lea    0xd92(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    -0x18(%rbp),%rdi
lea    0xd75(%rip),%rsi
lea    -0x34(%rbp),%rdx
lea    -0x38(%rbp),%rcx
mov    $0x0,%al
call   1060 <fscanf@plt>
mov    -0x34(%rbp),%esi
mov    -0x38(%rbp),%edx
lea    0xd59(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x20(%rbp),%rdi
mov    -0x34(%rbp),%edx
mov    -0x38(%rbp),%ecx
lea    0xd41(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    -0x18(%rbp),%rdi
lea    0xd32(%rip),%rsi
lea    -0x3c(%rbp),%rdx
mov    $0x0,%al
call   1060 <fscanf@plt>
mov    -0x3c(%rbp),%esi
lea    0xd1d(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
cmpl   $0x3,-0x24(%rbp)
jg     1387 <main+0x1c7>
cmpl   $0x1,-0x24(%rbp)
jge    13a1 <main+0x1e1>
lea    0xd20(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    15b4 <main+0x3f4>
mov    -0x20(%rbp),%rdi
mov    -0x3c(%rbp),%edx
lea    0xcda(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
movslq -0x34(%rbp),%rax
shl    $0x2,%rax
movslq -0x38(%rbp),%rcx
imul   %rcx,%rax
imul   $0x3,%rax,%rax
mov    %eax,%edi
call   10a0 <malloc@plt>
mov    %rax,-0x30(%rbp)
movl   $0x0,-0x44(%rbp)
mov    -0x44(%rbp),%eax
cmp    -0x38(%rbp),%eax
jge    14a2 <main+0x2e2>
movl   $0x0,-0x48(%rbp)
mov    -0x48(%rbp),%eax
cmp    -0x34(%rbp),%eax
jge    148f <main+0x2cf>
mov    -0x44(%rbp),%eax
imul   $0x3,-0x34(%rbp),%ecx
imul   %ecx,%eax
imul   $0x3,-0x48(%rbp),%ecx
add    %ecx,%eax
mov    %eax,-0x4c(%rbp)
mov    -0x18(%rbp),%rcx
lea    -0x3d(%rbp),%rdi
mov    $0x1,%edx
mov    %edx,%esi
call   1030 <fread@plt>
movzbl -0x3d(%rbp),%edx
mov    -0x30(%rbp),%rax
movslq -0x4c(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x18(%rbp),%rcx
lea    -0x3d(%rbp),%rdi
mov    $0x1,%edx
mov    %edx,%esi
call   1030 <fread@plt>
movzbl -0x3d(%rbp),%edx
mov    -0x30(%rbp),%rax
mov    -0x4c(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x18(%rbp),%rcx
lea    -0x3d(%rbp),%rdi
mov    $0x1,%edx
mov    %edx,%esi
call   1030 <fread@plt>
movzbl -0x3d(%rbp),%edx
mov    -0x30(%rbp),%rax
mov    -0x4c(%rbp),%ecx
add    $0x2,%ecx
movslq %ecx,%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x48(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x48(%rbp)
jmp    13ef <main+0x22f>
jmp    1494 <main+0x2d4>
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    13dc <main+0x21c>
lea    0xc42(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x44(%rbp)
mov    -0x44(%rbp),%eax
mov    -0x34(%rbp),%ecx
imul   -0x38(%rbp),%ecx
imul   $0x3,%ecx,%ecx
cmp    %ecx,%eax
jge    14f3 <main+0x333>
mov    -0x30(%rbp),%rax
movslq -0x44(%rbp),%rcx
cmpl   $0x0,(%rax,%rcx,4)
setge  %al
and    $0x1,%al
movzbl %al,%edi
call   1080 <assert@plt>
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    14b7 <main+0x2f7>
mov    -0x30(%rbp),%rdi
mov    -0x34(%rbp),%esi
mov    -0x38(%rbp),%edx
mov    -0x24(%rbp),%ecx
sub    $0x1,%ecx
mov    -0x28(%rbp),%r8d
call   10b0 <convert_ppm@plt>
movl   $0x0,-0x44(%rbp)
mov    -0x44(%rbp),%eax
mov    -0x34(%rbp),%ecx
imul   -0x38(%rbp),%ecx
imul   $0x3,%ecx,%ecx
cmp    %ecx,%eax
jge    154f <main+0x38f>
mov    -0x30(%rbp),%rax
movslq -0x44(%rbp),%rcx
cmpl   $0x0,(%rax,%rcx,4)
setge  %al
and    $0x1,%al
movzbl %al,%edi
call   1080 <assert@plt>
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    1513 <main+0x353>
movl   $0x0,-0x44(%rbp)
mov    -0x44(%rbp),%eax
mov    -0x34(%rbp),%ecx
imul   -0x38(%rbp),%ecx
imul   $0x3,%ecx,%ecx
cmp    %ecx,%eax
jge    159b <main+0x3db>
mov    -0x30(%rbp),%rax
movslq -0x44(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    %al,-0x3d(%rbp)
mov    -0x20(%rbp),%rcx
lea    -0x3d(%rbp),%rdi
mov    $0x1,%edx
mov    %edx,%esi
call   10e0 <fwrite@plt>
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    1556 <main+0x396>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
cmp    $0x5,%edi
jne    1338 <main+0x158>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
lea    0xdfb(%rip),%rsi
call   10e0 <fopen@plt>
mov    %rax,%rbp
mov    0x10(%rbx),%rdi
lea    0xdea(%rip),%rsi
call   10e0 <fopen@plt>
test   %rbp,%rbp
je     1341 <main+0x161>
mov    %rax,%r14
test   %rax,%rax
je     134a <main+0x16a>
mov    0x18(%rbx),%rdi
call   10f0 <atoi@plt>
mov    %eax,%r15d
mov    0x20(%rbx),%rdi
call   10f0 <atoi@plt>
mov    %eax,%r12d
lea    0xdb4(%rip),%rdi
mov    %r15d,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1060 <printf@plt>
nopl   (%rax)
mov    %rbp,%rdi
call   1080 <fgetc@plt>
cmp    $0xa,%al
jne    1260 <main+0x80>
lea    0xd99(%rip),%rdi
mov    $0x3,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   1100 <fwrite@plt>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %rbp,%rdi
call   1080 <fgetc@plt>
cmp    $0xa,%al
jne    1290 <main+0xb0>
movb   $0xa,0x3(%rsp)
lea    0xd68(%rip),%rdi
mov    $0x1c,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   1100 <fwrite@plt>
lea    0xd44(%rip),%rbx
lea    0x8(%rsp),%rdx
lea    0x4(%rsp),%rcx
mov    %rbp,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1070 <fscanf@plt>
mov    0x8(%rsp),%esi
mov    0x4(%rsp),%edx
mov    %rbx,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x8(%rsp),%edx
mov    0x4(%rsp),%ecx
mov    %r14,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   10b0 <fprintf@plt>
lea    0xd02(%rip),%rbx
lea    0xc(%rsp),%rdx
mov    %rbp,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1070 <fscanf@plt>
mov    0xc(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
lea    -0x4(%r15),%eax
cmp    $0xfffffffc,%eax
ja     136a <main+0x18a>
lea    0xd03(%rip),%rdi
jmp    1351 <main+0x171>
lea    0xd6f(%rip),%rdi
jmp    1351 <main+0x171>
lea    0xd4b(%rip),%rdi
jmp    1351 <main+0x171>
lea    0xd24(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %r12d,0x10(%rsp)
mov    %r15,0x28(%rsp)
mov    %rbp,0x18(%rsp)
mov    0xc(%rsp),%edx
lea    0xc84(%rip),%rsi
xor    %ebx,%ebx
mov    %r14,%rdi
xor    %eax,%eax
call   10b0 <fprintf@plt>
mov    0x8(%rsp),%eax
imul   0x4(%rsp),%eax
shl    $0x2,%eax
lea    (%rax,%rax,2),%edi
call   10c0 <malloc@plt>
mov    %rax,%r15
mov    0x4(%rsp),%ecx
test   %ecx,%ecx
jle    1488 <main+0x2a8>
mov    0x8(%rsp),%eax
mov    %r14,0x30(%rsp)
mov    %r15,0x20(%rsp)
mov    0x18(%rsp),%r13
jmp    13db <main+0x1fb>
nopl   0x0(%rax,%rax,1)
add    $0x1,%ebx
cmp    %ecx,%ebx
jge    1488 <main+0x2a8>
test   %eax,%eax
jle    13d0 <main+0x1f0>
xor    %r15d,%r15d
mov    %ebx,0x14(%rsp)
cs nopw 0x0(%rax,%rax,1)
imul   %ebx,%eax
add    %r15d,%eax
lea    (%rax,%rax,2),%r14d
lea    0x3(%rsp),%r12
mov    %r12,%rdi
mov    $0x1,%esi
mov    $0x1,%edx
mov    %r13,%rcx
call   1040 <fread@plt>
movzbl 0x3(%rsp),%eax
movslq %r14d,%rbp
mov    0x20(%rsp),%rbx
mov    %eax,(%rbx,%rbp,4)
mov    %r12,%rdi
mov    $0x1,%esi
mov    $0x1,%edx
mov    %r13,%rcx
call   1040 <fread@plt>
movzbl 0x3(%rsp),%eax
mov    %eax,0x4(%rbx,%rbp,4)
mov    %r12,%rdi
mov    $0x1,%esi
mov    $0x1,%edx
mov    %r13,%rcx
call   1040 <fread@plt>
movzbl 0x3(%rsp),%eax
mov    %eax,0x8(%rbx,%rbp,4)
mov    0x14(%rsp),%ebx
add    $0x1,%r15d
mov    0x8(%rsp),%eax
cmp    %eax,%r15d
jl     13f0 <main+0x210>
mov    0x4(%rsp),%ecx
mov    0x30(%rsp),%r14
mov    0x20(%rsp),%r15
jmp    13d0 <main+0x1f0>
lea    0xb9e(%rip),%rdi
call   1030 <puts@plt>
mov    0x8(%rsp),%esi
mov    0x4(%rsp),%edx
mov    %esi,%eax
imul   %edx,%eax
lea    (%rax,%rax,2),%eax
test   %eax,%eax
jle    14d9 <main+0x2f9>
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
mov    (%r15,%rbx,4),%edi
not    %edi
shr    $0x1f,%edi
call   10a0 <assert@plt>
add    $0x1,%rbx
mov    0x8(%rsp),%esi
mov    0x4(%rsp),%edx
mov    %esi,%eax
imul   %edx,%eax
lea    (%rax,%rax,2),%eax
cltq
cmp    %rax,%rbx
jl     14b0 <main+0x2d0>
mov    0x28(%rsp),%rcx
add    $0xffffffff,%ecx
mov    %r15,%rdi
mov    0x10(%rsp),%r8d
call   10d0 <convert_ppm@plt>
mov    0x8(%rsp),%eax
imul   0x4(%rsp),%eax
lea    (%rax,%rax,2),%eax
test   %eax,%eax
mov    0x18(%rsp),%rbp
jle    1564 <main+0x384>
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nop
mov    (%r15,%rbx,4),%edi
not    %edi
shr    $0x1f,%edi
call   10a0 <assert@plt>
mov    0x8(%rsp),%eax
imul   0x4(%rsp),%eax
add    $0x1,%rbx
lea    (%rax,%rax,2),%eax
movslq %eax,%rcx
cmp    %rcx,%rbx
jl     1510 <main+0x330>
test   %eax,%eax
jle    1564 <main+0x384>
xor    %ebx,%ebx
nopl   0x0(%rax)
movsbl (%r15,%rbx,4),%edi
mov    %r14,%rsi
call   1090 <fputc@plt>
mov    0x8(%rsp),%eax
imul   0x4(%rsp),%eax
add    $0x1,%rbx
lea    (%rax,%rax,2),%eax
cltq
cmp    %rax,%rbx
jl     1540 <main+0x360>
mov    %rbp,%rdi
call   1050 <fclose@plt>
mov    %r14,%rdi
call   1050 <fclose@plt>
xor    %eax,%eax
jmp    135b <main+0x17b>

LLVM IR (-O0):
@.str = [70 x i8] c"Usage - original_file destination_file color_component color_change.\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [3 x i8] c"w+\00"
@.str.3 = [28 x i8] c"Cannot open original file.\0A\00"
@.str.4 = [31 x i8] c"Cannot open destination file.\0A\00"
@.str.5 = [7 x i8] c"%d %d\0A\00"
@.str.6 = [4 x i8] c"P6\0A\00"
@.str.7 = [29 x i8] c"#Modified file by as292510.\0A\00"
@.str.8 = [4 x i8] c"%d\0A\00"
@.str.9 = [61 x i8] c"Wrong color component number. It should be between 1 and 3.\0A\00"
@.str.10 = [13 x i8] c"end of file\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32*
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i8
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%18 = load i32, i32* %4
%19 = icmp ne i32 %18, 5
br i1 %19, label %20, label %22
20: ; preds = %2
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([70 x i8], [70 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %227
22: ; preds = %2
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 1
%25 = load i8*, i8** %24
%26 = call i32* @fopen(i8* %25, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %26, i32** %6
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 2
%29 = load i8*, i8** %28
%30 = call i32* @fopen(i8* %29, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
store i32* %30, i32** %7
%31 = load i32*, i32** %6
%32 = icmp eq i32* %31, null
br i1 %32, label %33, label %35
33: ; preds = %22
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0))
store i32 1, i32* %3
br label %227
35: ; preds = %22
%36 = load i32*, i32** %7
%37 = icmp eq i32* %36, null
br i1 %37, label %38, label %40
38: ; preds = %35
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0))
store i32 1, i32* %3
br label %227
40: ; preds = %35
%41 = load i8**, i8*** %5
%42 = getelementptr inbounds i8*, i8** %41, i64 3
%43 = load i8*, i8** %42
%44 = call i32 @atoi(i8* %43)
store i32 %44, i32* %8
%45 = load i8**, i8*** %5
%46 = getelementptr inbounds i8*, i8** %45, i64 4
%47 = load i8*, i8** %46
%48 = call i32 @atoi(i8* %47)
store i32 %48, i32* %9
%49 = load i32, i32* %8
%50 = load i32, i32* %9
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i32 %49, i32 %50)
br label %52
52: ; preds = %57, %40
%53 = load i32*, i32** %6
%54 = call zeroext i8 @fgetc(i32* %53)
store i8 %54, i8* %14
%55 = zext i8 %54 to i32
%56 = icmp ne i32 %55, 10
br i1 %56, label %57, label %58
57: ; preds = %52
br label %52
58: ; preds = %52
%59 = load i32*, i32** %7
%60 = call i32 (i32*, i8*, ...) @fprintf(i32* %59, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0))
br label %61
61: ; preds = %66, %58
%62 = load i32*, i32** %6
%63 = call zeroext i8 @fgetc(i32* %62)
store i8 %63, i8* %14
%64 = zext i8 %63 to i32
%65 = icmp ne i32 %64, 10
br i1 %65, label %66, label %67
66: ; preds = %61
br label %61
67: ; preds = %61
%68 = load i32*, i32** %7
%69 = call i32 (i32*, i8*, ...) @fprintf(i32* %68, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.7, i64 0, i64 0))
%70 = load i32*, i32** %6
%71 = call i32 (i32*, i8*, i32*, ...) @fscanf(i32* %70, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i32* %11, i32* %12)
%72 = load i32, i32* %11
%73 = load i32, i32* %12
%74 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i32 %72, i32 %73)
%75 = load i32*, i32** %7
%76 = load i32, i32* %11
%77 = load i32, i32* %12
%78 = call i32 (i32*, i8*, ...) @fprintf(i32* %75, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i32 %76, i32 %77)
%79 = load i32*, i32** %6
%80 = call i32 (i32*, i8*, i32*, ...) @fscanf(i32* %79, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0), i32* %13)
%81 = load i32, i32* %13
%82 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0), i32 %81)
%83 = load i32, i32* %8
%84 = icmp sgt i32 %83, 3
br i1 %84, label %88, label %85
85: ; preds = %67
%86 = load i32, i32* %8
%87 = icmp slt i32 %86, 1
br i1 %87, label %88, label %90
88: ; preds = %85, %67
%89 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str.9, i64 0, i64 0))
store i32 1, i32* %3
br label %227
90: ; preds = %85
%91 = load i32*, i32** %7
%92 = load i32, i32* %13
%93 = call i32 (i32*, i8*, ...) @fprintf(i32* %91, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0), i32 %92)
%94 = load i32, i32* %11
%95 = sext i32 %94 to i64
%96 = mul i64 4, %95
%97 = load i32, i32* %12
%98 = sext i32 %97 to i64
%99 = mul i64 %96, %98
%100 = mul i64 %99, 3
%101 = trunc i64 %100 to i32
%102 = call i64 @malloc(i32 %101)
%103 = inttoptr i64 %102 to i32*
store i32* %103, i32** %10
store i32 0, i32* %15
br label %104
104: ; preds = %151, %90
%105 = load i32, i32* %15
%106 = load i32, i32* %12
%107 = icmp slt i32 %105, %106
br i1 %107, label %108, label %154
108: ; preds = %104
store i32 0, i32* %16
br label %109
109: ; preds = %147, %108
%110 = load i32, i32* %16
%111 = load i32, i32* %11
%112 = icmp slt i32 %110, %111
br i1 %112, label %113, label %150
113: ; preds = %109
%114 = load i32, i32* %15
%115 = load i32, i32* %11
%116 = mul nsw i32 %115, 3
%117 = mul nsw i32 %114, %116
%118 = load i32, i32* %16
%119 = mul nsw i32 %118, 3
%120 = add nsw i32 %117, %119
store i32 %120, i32* %17
%121 = load i32*, i32** %6
%122 = call i32 @fread(i8* %14, i32 1, i32 1, i32* %121)
%123 = load i8, i8* %14
%124 = zext i8 %123 to i32
%125 = load i32*, i32** %10
%126 = load i32, i32* %17
%127 = sext i32 %126 to i64
%128 = getelementptr inbounds i32, i32* %125, i64 %127
store i32 %124, i32* %128
%129 = load i32*, i32** %6
%130 = call i32 @fread(i8* %14, i32 1, i32 1, i32* %129)
%131 = load i8, i8* %14
%132 = zext i8 %131 to i32
%133 = load i32*, i32** %10
%134 = load i32, i32* %17
%135 = add nsw i32 %134, 1
%136 = sext i32 %135 to i64
%137 = getelementptr inbounds i32, i32* %133, i64 %136
store i32 %132, i32* %137
%138 = load i32*, i32** %6
%139 = call i32 @fread(i8* %14, i32 1, i32 1, i32* %138)
%140 = load i8, i8* %14
%141 = zext i8 %140 to i32
%142 = load i32*, i32** %10
%143 = load i32, i32* %17
%144 = add nsw i32 %143, 2
%145 = sext i32 %144 to i64
%146 = getelementptr inbounds i32, i32* %142, i64 %145
store i32 %141, i32* %146
br label %147
147: ; preds = %113
%148 = load i32, i32* %16
%149 = add nsw i32 %148, 1
store i32 %149, i32* %16
br label %109
150: ; preds = %109
br label %151
151: ; preds = %150
%152 = load i32, i32* %15
%153 = add nsw i32 %152, 1
store i32 %153, i32* %15
br label %104
154: ; preds = %104
%155 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.10, i64 0, i64 0))
store i32 0, i32* %15
br label %156
156: ; preds = %172, %154
%157 = load i32, i32* %15
%158 = load i32, i32* %11
%159 = load i32, i32* %12
%160 = mul nsw i32 %158, %159
%161 = mul nsw i32 %160, 3
%162 = icmp slt i32 %157, %161
br i1 %162, label %163, label %175
163: ; preds = %156
%164 = load i32*, i32** %10
%165 = load i32, i32* %15
%166 = sext i32 %165 to i64
%167 = getelementptr inbounds i32, i32* %164, i64 %166
%168 = load i32, i32* %167
%169 = icmp sge i32 %168, 0
%170 = zext i1 %169 to i32
%171 = call i32 @assert(i32 %170)
br label %172
172: ; preds = %163
%173 = load i32, i32* %15
%174 = add nsw i32 %173, 1
store i32 %174, i32* %15
br label %156
175: ; preds = %156
%176 = load i32*, i32** %10
%177 = load i32, i32* %11
%178 = load i32, i32* %12
%179 = load i32, i32* %8
%180 = sub nsw i32 %179, 1
%181 = load i32, i32* %9
%182 = call i32 @convert_ppm(i32* %176, i32 %177, i32 %178, i32 %180, i32 %181)
store i32 0, i32* %15
br label %183
183: ; preds = %199, %175
%184 = load i32, i32* %15
%185 = load i32, i32* %11
%186 = load i32, i32* %12
%187 = mul nsw i32 %185, %186
%188 = mul nsw i32 %187, 3
%189 = icmp slt i32 %184, %188
br i1 %189, label %190, label %202
190: ; preds = %183
%191 = load i32*, i32** %10
%192 = load i32, i32* %15
%193 = sext i32 %192 to i64
%194 = getelementptr inbounds i32, i32* %191, i64 %193
%195 = load i32, i32* %194
%196 = icmp sge i32 %195, 0
%197 = zext i1 %196 to i32
%198 = call i32 @assert(i32 %197)
br label %199
199: ; preds = %190
%200 = load i32, i32* %15
%201 = add nsw i32 %200, 1
store i32 %201, i32* %15
br label %183
202: ; preds = %183
store i32 0, i32* %15
br label %203
203: ; preds = %219, %202
%204 = load i32, i32* %15
%205 = load i32, i32* %11
%206 = load i32, i32* %12
%207 = mul nsw i32 %205, %206
%208 = mul nsw i32 %207, 3
%209 = icmp slt i32 %204, %208
br i1 %209, label %210, label %222
210: ; preds = %203
%211 = load i32*, i32** %10
%212 = load i32, i32* %15
%213 = sext i32 %212 to i64
%214 = getelementptr inbounds i32, i32* %211, i64 %213
%215 = load i32, i32* %214
%216 = trunc i32 %215 to i8
store i8 %216, i8* %14
%217 = load i32*, i32** %7
%218 = call i32 @fwrite(i8* %14, i32 1, i32 1, i32* %217)
br label %219
219: ; preds = %210
%220 = load i32, i32* %15
%221 = add nsw i32 %220, 1
store i32 %221, i32* %15
br label %203
222: ; preds = %203
%223 = load i32*, i32** %6
%224 = call i32 @fclose(i32* %223)
%225 = load i32*, i32** %7
%226 = call i32 @fclose(i32* %225)
store i32 0, i32* %3
br label %227
227: ; preds = %222, %88, %38, %33, %20
%228 = load i32, i32* %3
ret i32 %228
}

LLVM IR (-O2):
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [3 x i8] c"w+\00"
@.str.5 = [7 x i8] c"%d %d\0A\00"
@.str.6 = [4 x i8] c"P6\0A\00"
@.str.7 = [29 x i8] c"#Modified file by as292510.\0A\00"
@.str.8 = [4 x i8] c"%d\0A\00"
@str = [12 x i8] c"end of file\00"
@str.11 = [60 x i8] c"Wrong color component number. It should be between 1 and 3.\00"
@str.12 = [30 x i8] c"Cannot open destination file.\00"
@str.13 = [27 x i8] c"Cannot open original file.\00"
@str.14 = [69 x i8] c"Usage - original_file destination_file color_component color_change.\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8
%7 = icmp eq i32 %0, 5
br i1 %7, label %10, label %8
8: ; preds = %2
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([69 x i8], [69 x i8]* @str.14, i64 0, i64 0))
br label %176
10: ; preds = %2
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = tail call i32* @fopen(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%14 = getelementptr inbounds i8*, i8** %1, i64 2
%15 = load i8*, i8** %14
%16 = tail call i32* @fopen(i8* %15, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%17 = icmp eq i32* %13, null
br i1 %17, label %18, label %20
18: ; preds = %10
%19 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str.13, i64 0, i64 0))
br label %176
20: ; preds = %10
%21 = icmp eq i32* %16, null
br i1 %21, label %22, label %24
22: ; preds = %20
%23 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str.12, i64 0, i64 0))
br label %176
24: ; preds = %20
%25 = getelementptr inbounds i8*, i8** %1, i64 3
%26 = load i8*, i8** %25
%27 = tail call i32 @atoi(i8* %26)
%28 = getelementptr inbounds i8*, i8** %1, i64 4
%29 = load i8*, i8** %28
%30 = tail call i32 @atoi(i8* %29)
%31 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i32 %27, i32 %30)
%32 = bitcast i32* %3 to i8*
%33 = bitcast i32* %4 to i8*
%34 = bitcast i32* %5 to i8*
br label %35
35: ; preds = %35, %24
%36 = tail call zeroext i8 @fgetc(i32* %13)
%37 = icmp eq i8 %36, 10
br i1 %37, label %38, label %35
38: ; preds = %35
%39 = tail call i64 bitcast (i32 (i8*, i32, i32, i32*)* @fwrite to i64 (i8*, i64, i64, i32*)*)(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i64 3, i64 1, i32* %16)
br label %40
40: ; preds = %40, %38
%41 = tail call zeroext i8 @fgetc(i32* %13)
%42 = icmp eq i8 %41, 10
br i1 %42, label %43, label %40
43: ; preds = %40
store i8 10, i8* %6
%44 = tail call i64 bitcast (i32 (i8*, i32, i32, i32*)* @fwrite to i64 (i8*, i64, i64, i32*)*)(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.7, i64 0, i64 0), i64 28, i64 1, i32* %16)
%45 = call i32 (i32*, i8*, i32*, ...) @fscanf(i32* %13, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i32* %3, i32* %4)
%46 = load i32, i32* %3
%47 = load i32, i32* %4
%48 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i32 %46, i32 %47)
%49 = load i32, i32* %3
%50 = load i32, i32* %4
%51 = call i32 (i32*, i8*, ...) @fprintf(i32* %16, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i32 %49, i32 %50)
%52 = call i32 (i32*, i8*, i32*, ...) @fscanf(i32* %13, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0), i32* %5)
%53 = load i32, i32* %5
%54 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0), i32 %53)
%55 = add i32 %27, -4
%56 = icmp ult i32 %55, -3
br i1 %56, label %57, label %59
57: ; preds = %43
%58 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([60 x i8], [60 x i8]* @str.11, i64 0, i64 0))
br label %174
59: ; preds = %43
%60 = load i32, i32* %5
%61 = call i32 (i32*, i8*, ...) @fprintf(i32* %16, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0), i32 %60)
%62 = load i32, i32* %3
%63 = load i32, i32* %4
%64 = mul i32 %62, 12
%65 = mul i32 %64, %63
%66 = call i64 @malloc(i32 %65)
%67 = inttoptr i64 %66 to i32*
%68 = load i32, i32* %4
%69 = icmp sgt i32 %68, 0
br i1 %69, label %70, label %110
70: ; preds = %59
%71 = load i32, i32* %3
br label %72
72: ; preds = %70, %105
%73 = phi i32 [ %106, %105 ], [ %68, %70 ]
%74 = phi i32 [ %107, %105 ], [ %71, %70 ]
%75 = phi i32 [ %108, %105 ], [ 0, %70 ]
%76 = icmp sgt i32 %74, 0
br i1 %76, label %77, label %105
77: ; preds = %72, %77
%78 = phi i32 [ %101, %77 ], [ %74, %72 ]
%79 = phi i32 [ %100, %77 ], [ 0, %72 ]
%80 = mul i32 %78, %75
%81 = add i32 %80, %79
%82 = mul i32 %81, 3
%83 = call i32 @fread(i8* %6, i32 1, i32 1, i32* %13)
%84 = load i8, i8* %6
%85 = zext i8 %84 to i32
%86 = sext i32 %82 to i64
%87 = getelementptr inbounds i32, i32* %67, i64 %86
store i32 %85, i32* %87
%88 = call i32 @fread(i8* %6, i32 1, i32 1, i32* %13)
%89 = load i8, i8* %6
%90 = zext i8 %89 to i32
%91 = add nsw i32 %82, 1
%92 = sext i32 %91 to i64
%93 = getelementptr inbounds i32, i32* %67, i64 %92
store i32 %90, i32* %93
%94 = call i32 @fread(i8* %6, i32 1, i32 1, i32* %13)
%95 = load i8, i8* %6
%96 = zext i8 %95 to i32
%97 = add nsw i32 %82, 2
%98 = sext i32 %97 to i64
%99 = getelementptr inbounds i32, i32* %67, i64 %98
store i32 %96, i32* %99
%100 = add nuw nsw i32 %79, 1
%101 = load i32, i32* %3
%102 = icmp slt i32 %100, %101
br i1 %102, label %77, label %103
103: ; preds = %77
%104 = load i32, i32* %4
br label %105
105: ; preds = %103, %72
%106 = phi i32 [ %104, %103 ], [ %73, %72 ]
%107 = phi i32 [ %101, %103 ], [ %74, %72 ]
%108 = add nuw nsw i32 %75, 1
%109 = icmp slt i32 %108, %106
br i1 %109, label %72, label %110
110: ; preds = %105, %59
%111 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str, i64 0, i64 0))
%112 = load i32, i32* %3
%113 = load i32, i32* %4
%114 = mul i32 %112, 3
%115 = mul i32 %114, %113
%116 = icmp sgt i32 %115, 0
br i1 %116, label %117, label %131
117: ; preds = %110, %117
%118 = phi i64 [ %124, %117 ], [ 0, %110 ]
%119 = getelementptr inbounds i32, i32* %67, i64 %118
%120 = load i32, i32* %119
%121 = xor i32 %120, -1
%122 = lshr i32 %121, 31
%123 = call i32 @assert(i32 %122)
%124 = add nuw nsw i64 %118, 1
%125 = load i32, i32* %3
%126 = load i32, i32* %4
%127 = mul i32 %125, 3
%128 = mul i32 %127, %126
%129 = sext i32 %128 to i64
%130 = icmp slt i64 %124, %129
br i1 %130, label %117, label %131
131: ; preds = %117, %110
%132 = phi i32 [ %112, %110 ], [ %125, %117 ]
%133 = phi i32 [ %113, %110 ], [ %126, %117 ]
%134 = add nsw i32 %27, -1
%135 = call i32 @convert_ppm(i32* %67, i32 %132, i32 %133, i32 %134, i32 %30)
%136 = load i32, i32* %3
%137 = load i32, i32* %4
%138 = mul i32 %136, 3
%139 = mul i32 %138, %137
%140 = icmp sgt i32 %139, 0
br i1 %140, label %143, label %171
141: ; preds = %143
%142 = icmp sgt i32 %154, 0
br i1 %142, label %157, label %171
143: ; preds = %131, %143
%144 = phi i64 [ %150, %143 ], [ 0, %131 ]
%145 = getelementptr inbounds i32, i32* %67, i64 %144
%146 = load i32, i32* %145
%147 = xor i32 %146, -1
%148 = lshr i32 %147, 31
%149 = call i32 @assert(i32 %148)
%150 = add nuw nsw i64 %144, 1
%151 = load i32, i32* %3
%152 = load i32, i32* %4
%153 = mul i32 %151, 3
%154 = mul i32 %153, %152
%155 = sext i32 %154 to i64
%156 = icmp slt i64 %150, %155
br i1 %156, label %143, label %141
157: ; preds = %141, %157
%158 = phi i64 [ %164, %157 ], [ 0, %141 ]
%159 = getelementptr inbounds i32, i32* %67, i64 %158
%160 = load i32, i32* %159
%161 = shl i32 %160, 24
%162 = ashr exact i32 %161, 24
%163 = call i32 @fputc(i32 %162, i32* %16)
%164 = add nuw nsw i64 %158, 1
%165 = load i32, i32* %3
%166 = load i32, i32* %4
%167 = mul i32 %165, 3
%168 = mul i32 %167, %166
%169 = sext i32 %168 to i64
%170 = icmp slt i64 %164, %169
br i1 %170, label %157, label %171
171: ; preds = %157, %131, %141
%172 = call i32 @fclose(i32* %13)
%173 = call i32 @fclose(i32* %16)
br label %174
174: ; preds = %171, %57
%175 = phi i32 [ 1, %57 ], [ 0, %171 ]
br label %176
176: ; preds = %18, %22, %174, %8
%177 = phi i32 [ 1, %8 ], [ 1, %18 ], [ 1, %22 ], [ %175, %174 ]
ret i32 %177
}