#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*/ SEEK_CUR;
int /*<<< orphan*/ convertColor(float, float, float, unsigned char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int, int /*<<< orphan*/);
scalar_t__ getc(int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ putc(char, int /*<<< orphan*/ *);
int main(int argc, char **argv) {
  if (argc != 3) {
    printf("wrong arguments!\n");
  }
  FILE *cmyColors;
  FILE *output;
  cmyColors = fopen(argv[1], "r");
  if (cmyColors == NULL) {
    printf("Can't open input file\n");
    return 1;
  }
  output = fopen(argv[2], "w");
  if (output == NULL) {
    printf("Can't open output file\n");
    return 1;
  }
  float cyan;
  float magenta;
  float yellow;
  unsigned char result[] = "123";
  while (1) {
    cyan = (unsigned char)getc(cmyColors);
    magenta = (unsigned char)getc(cmyColors);
    yellow = (unsigned char)getc(cmyColors);
    convertColor(cyan, magenta, yellow, result);
    putc((char)result[0], output);
    putc((char)result[1], output);
    putc((char)result[2], output);
    getc(cmyColors);
    if (feof(cmyColors)) {
      break;
    }
    fseek(cmyColors, -1, SEEK_CUR);
  }
  fclose(cmyColors);
  fclose(output);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     11ac <main+0x2c>
lea    0xe59(%rip),%rdi
call   1040 <printf@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe57(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11e7 <main+0x67>
lea    0xe3e(%rip),%rdi
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1305 <main+0x185>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe35(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1222 <main+0xa2>
lea    0xe1c(%rip),%rdi
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1305 <main+0x185>
mov    0xe1d(%rip),%eax
mov    %eax,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
call   10a0 <getc@plt>
movzbl %al,%eax
cvtsi2ss %eax,%xmm0
movss  %xmm0,-0x24(%rbp)
mov    -0x18(%rbp),%rdi
call   10a0 <getc@plt>
movzbl %al,%eax
cvtsi2ss %eax,%xmm0
movss  %xmm0,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   10a0 <getc@plt>
movzbl %al,%eax
cvtsi2ss %eax,%xmm0
movss  %xmm0,-0x2c(%rbp)
movss  -0x24(%rbp),%xmm0
movss  -0x28(%rbp),%xmm1
movss  -0x2c(%rbp),%xmm2
lea    -0x30(%rbp),%rdi
call   1060 <convertColor@plt>
mov    -0x30(%rbp),%al
mov    -0x20(%rbp),%rsi
movsbl %al,%edi
call   1050 <putc@plt>
mov    -0x2f(%rbp),%al
mov    -0x20(%rbp),%rsi
movsbl %al,%edi
call   1050 <putc@plt>
mov    -0x2e(%rbp),%al
mov    -0x20(%rbp),%rsi
movsbl %al,%edi
call   1050 <putc@plt>
mov    -0x18(%rbp),%rdi
call   10a0 <getc@plt>
mov    -0x18(%rbp),%rdi
call   1070 <feof@plt>
cmp    $0x0,%rax
je     12d0 <main+0x150>
jmp    12ec <main+0x16c>
mov    -0x18(%rbp),%rdi
mov    0x2d0d(%rip),%rax
mov    (%rax),%edx
mov    $0xffffffff,%esi
call   1080 <fseek@plt>
jmp    122b <main+0xab>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r14
cmp    $0x3,%edi
je     119f <main+0x1f>
lea    0xe97(%rip),%rdi
call   1030 <puts@plt>
mov    0x8(%r14),%rdi
lea    0xe56(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     12ac <main+0x12c>
mov    %rax,%rbx
mov    0x10(%r14),%rdi
lea    0xe3c(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     12b5 <main+0x135>
mov    %rax,%r14
movl   $0x333231,0xc(%rsp)
lea    0xc(%rsp),%r15
mov    0x2dfd(%rip),%r12
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   10a0 <getc@plt>
movzbl %al,%eax
xorps  %xmm0,%xmm0
cvtsi2ss %eax,%xmm0
movss  %xmm0,0x14(%rsp)
mov    %rbx,%rdi
call   10a0 <getc@plt>
movzbl %al,%eax
xorps  %xmm0,%xmm0
cvtsi2ss %eax,%xmm0
movss  %xmm0,0x10(%rsp)
mov    %rbx,%rdi
call   10a0 <getc@plt>
movzbl %al,%eax
xorps  %xmm2,%xmm2
cvtsi2ss %eax,%xmm2
movss  0x14(%rsp),%xmm0
movss  0x10(%rsp),%xmm1
mov    %r15,%rdi
call   1060 <convertColor@plt>
movsbl 0xc(%rsp),%edi
mov    %r14,%rsi
call   1050 <putc@plt>
movsbl 0xd(%rsp),%edi
mov    %r14,%rsi
call   1050 <putc@plt>
movsbl 0xe(%rsp),%edi
mov    %r14,%rsi
call   1050 <putc@plt>
mov    %rbx,%rdi
call   10a0 <getc@plt>
mov    %rbx,%rdi
call   1070 <feof@plt>
test   %rax,%rax
jne    1298 <main+0x118>
mov    (%r12),%edx
mov    %rbx,%rdi
mov    $0xffffffff,%esi
call   1080 <fseek@plt>
jmp    11f0 <main+0x70>
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    %r14,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
jmp    12c6 <main+0x146>
lea    0xd68(%rip),%rdi
jmp    12bc <main+0x13c>
lea    0xd48(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [18 x i8] c"wrong arguments!\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [23 x i8] c"Can't open input file\0A\00"
@.str.3 = [2 x i8] c"w\00"
@.str.4 = [24 x i8] c"Can't open output file\0A\00"
@__const.main.result = [4 x i8] c"123\00"
@SEEK_CUR = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca float
%9 = alloca float
%10 = alloca float
%11 = alloca [4 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = load i32, i32* %4
%13 = icmp ne i32 %12, 3
br i1 %13, label %14, label %16
14: ; preds = %2
%15 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
br label %16
16: ; preds = %14, %2
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
%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** %6
%22 = icmp eq i32* %21, null
br i1 %22, label %23, label %25
23: ; preds = %16
%24 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %3
br label %81
25: ; preds = %16
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 2
%28 = load i8*, i8** %27
%29 = call i32* @fopen(i8* %28, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %29, i32** %7
%30 = load i32*, i32** %7
%31 = icmp eq i32* %30, null
br i1 %31, label %32, label %34
32: ; preds = %25
%33 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0))
store i32 1, i32* %3
br label %81
34: ; preds = %25
%35 = bitcast [4 x i8]* %11 to i8*
br label %36
36: ; preds = %34, %72
%37 = load i32*, i32** %6
%38 = call i64 @getc(i32* %37)
%39 = trunc i64 %38 to i8
%40 = uitofp i8 %39 to float
store float %40, float* %8
%41 = load i32*, i32** %6
%42 = call i64 @getc(i32* %41)
%43 = trunc i64 %42 to i8
%44 = uitofp i8 %43 to float
store float %44, float* %9
%45 = load i32*, i32** %6
%46 = call i64 @getc(i32* %45)
%47 = trunc i64 %46 to i8
%48 = uitofp i8 %47 to float
store float %48, float* %10
%49 = load float, float* %8
%50 = load float, float* %9
%51 = load float, float* %10
%52 = getelementptr inbounds [4 x i8], [4 x i8]* %11, i64 0, i64 0
%53 = call i32 @convertColor(float %49, float %50, float %51, i8* %52)
%54 = getelementptr inbounds [4 x i8], [4 x i8]* %11, i64 0, i64 0
%55 = load i8, i8* %54
%56 = load i32*, i32** %7
%57 = call i32 @putc(i8 signext %55, i32* %56)
%58 = getelementptr inbounds [4 x i8], [4 x i8]* %11, i64 0, i64 1
%59 = load i8, i8* %58
%60 = load i32*, i32** %7
%61 = call i32 @putc(i8 signext %59, i32* %60)
%62 = getelementptr inbounds [4 x i8], [4 x i8]* %11, i64 0, i64 2
%63 = load i8, i8* %62
%64 = load i32*, i32** %7
%65 = call i32 @putc(i8 signext %63, i32* %64)
%66 = load i32*, i32** %6
%67 = call i64 @getc(i32* %66)
%68 = load i32*, i32** %6
%69 = call i64 @feof(i32* %68)
%70 = icmp ne i64 %69, 0
br i1 %70, label %71, label %72
71: ; preds = %36
br label %76
72: ; preds = %36
%73 = load i32*, i32** %6
%74 = load i32, i32* @SEEK_CUR
%75 = call i32 @fseek(i32* %73, i32 -1, i32 %74)
br label %36
76: ; preds = %71
%77 = load i32*, i32** %6
%78 = call i32 @fclose(i32* %77)
%79 = load i32*, i32** %7
%80 = call i32 @fclose(i32* %79)
store i32 0, i32* %3
br label %81
81: ; preds = %76, %32, %23
%82 = load i32, i32* %3
ret i32 %82
}

LLVM IR (-O2):
@.str.1 = [2 x i8] c"r\00"
@.str.3 = [2 x i8] c"w\00"
@SEEK_CUR = global i32 0
@str = [23 x i8] c"Can't open output file\00"
@str.5 = [22 x i8] c"Can't open input file\00"
@str.6 = [17 x i8] c"wrong arguments!\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to [4 x i8]*
%5 = icmp eq i32 %0, 3
br i1 %5, label %8, label %6
6: ; preds = %2
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str.6, i64 0, i64 0))
br label %8
8: ; preds = %6, %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = tail call i32* @fopen(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %15
13: ; preds = %8
%14 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str.5, i64 0, i64 0))
br label %52
15: ; preds = %8
%16 = getelementptr inbounds i8*, i8** %1, i64 2
%17 = load i8*, i8** %16
%18 = tail call i32* @fopen(i8* %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%19 = icmp eq i32* %18, null
br i1 %19, label %20, label %22
20: ; preds = %15
%21 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str, i64 0, i64 0))
br label %52
22: ; preds = %15
%23 = bitcast i32* %3 to i8*
store i32 3355185, i32* %3
%24 = getelementptr inbounds [4 x i8], [4 x i8]* %4, i64 0, i64 1
%25 = getelementptr inbounds [4 x i8], [4 x i8]* %4, i64 0, i64 2
br label %26
26: ; preds = %46, %22
%27 = call i64 @getc(i32* %11)
%28 = trunc i64 %27 to i8
%29 = uitofp i8 %28 to float
%30 = call i64 @getc(i32* %11)
%31 = trunc i64 %30 to i8
%32 = uitofp i8 %31 to float
%33 = call i64 @getc(i32* %11)
%34 = trunc i64 %33 to i8
%35 = uitofp i8 %34 to float
%36 = call i32 @convertColor(float %29, float %32, float %35, i8* %23)
%37 = load i8, i8* %23
%38 = call i32 @putc(i8 signext %37, i32* %18)
%39 = load i8, i8* %24
%40 = call i32 @putc(i8 signext %39, i32* %18)
%41 = load i8, i8* %25
%42 = call i32 @putc(i8 signext %41, i32* %18)
%43 = call i64 @getc(i32* %11)
%44 = call i64 @feof(i32* %11)
%45 = icmp eq i64 %44, 0
br i1 %45, label %46, label %49
46: ; preds = %26
%47 = load i32, i32* @SEEK_CUR
%48 = call i32 @fseek(i32* %11, i32 -1, i32 %47)
br label %26
49: ; preds = %26
%50 = call i32 @fclose(i32* %11)
%51 = call i32 @fclose(i32* %18)
br label %52
52: ; preds = %49, %20, %13
%53 = phi i32 [ 1, %13 ], [ 1, %20 ], [ 0, %49 ]
ret i32 %53
}