#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 EOF;
int /*<<< orphan*/ exit(int);
scalar_t__ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int getc(int /*<<< orphan*/ *);
int /*<<< orphan*/ putc(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int main(int argc, char *argv[]) {
  FILE *in, *out;
  int ch;
  char name[40];
  int count = 0;
  if (argc < 2) {
    fprintf(stderr, "Usage: %s filename\n", argv[0]);
    exit(1);
  }
  if ((in = fopen(argv[1], "r")) == NULL) {
    fprintf(stderr, "I couldn't open the file \"%s\"\n", argv[1]);
    exit(2);
  }
  strcpy(name, argv[1]);
  strcat(name, ".red");
  if ((out = fopen(name, "w")) == NULL) {
    fprintf(stderr, "Can't create output file.\n");
    exit(3);
  }
  while ((ch = getc(in)) != EOF)
    if (count++ % 3 == 0)
      putc(ch, out);
  if (fclose(in) != 0 || fclose(out) != 0)
    fprintf(stderr, "Error in closing files\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x54(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    11cf <main+0x4f>
mov    0x2e2a(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe42(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe36(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    121a <main+0x9a>
mov    0x2de0(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xe0d(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0x2,%edi
call   1090 <exit@plt>
lea    -0x50(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
call   1030 <strcpy@plt>
lea    -0x50(%rbp),%rdi
lea    0xdff(%rip),%rsi
call   1080 <strcat@plt>
lea    -0x50(%rbp),%rdi
lea    0xdf4(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    127a <main+0xfa>
mov    0x2d78(%rip),%rax
mov    (%rax),%edi
lea    0xdd3(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0x3,%edi
call   1090 <exit@plt>
jmp    127f <main+0xff>
mov    -0x18(%rbp),%rdi
call   10a0 <getc@plt>
mov    %eax,-0x24(%rbp)
mov    0x2d56(%rip),%rcx
cmp    (%rcx),%eax
je     12c7 <main+0x147>
mov    -0x54(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x54(%rbp)
mov    $0x3,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    12c2 <main+0x142>
mov    -0x24(%rbp),%edi
mov    -0x20(%rbp),%rsi
call   1050 <putc@plt>
jmp    127f <main+0xff>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
cmp    $0x0,%rax
jne    12ed <main+0x16d>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
cmp    $0x0,%rax
je     1304 <main+0x184>
mov    0x2ce4(%rip),%rax
mov    (%rax),%edi
lea    0xd5a(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rsi,%r14
cmp    $0x1,%edi
jle    1290 <main+0x110>
mov    0x8(%r14),%rdi
lea    0xe6f(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     12b4 <main+0x134>
mov    %rax,%r13
mov    0x8(%r14),%rsi
mov    %rsp,%r14
mov    %r14,%rdi
call   1030 <strcpy@plt>
lea    0xe69(%rip),%rsi
mov    %r14,%rdi
call   1080 <strcat@plt>
lea    0xe5f(%rip),%rsi
mov    %r14,%rdi
call   1070 <fopen@plt>
test   %rax,%rax
je     12d9 <main+0x159>
mov    %rax,%r14
mov    %r13,%rdi
call   10a0 <getc@plt>
mov    0x2dea(%rip),%r15
cmp    (%r15),%eax
jne    1245 <main+0xc5>
mov    %r13,%rdi
call   1040 <fclose@plt>
test   %rax,%rax
jne    121d <main+0x9d>
mov    %r14,%rdi
call   1040 <fclose@plt>
test   %rax,%rax
je     1234 <main+0xb4>
mov    0x2db4(%rip),%rax
mov    (%rax),%edi
lea    0xe2a(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %ebp,%ebp
mov    $0xaaaaaaab,%r12d
xor    %ebx,%ebx
jmp    1273 <main+0xf3>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r13,%rdi
call   10a0 <getc@plt>
add    $0xffffffff,%ebp
add    $0x1,%ebx
cmp    (%r15),%eax
je     1203 <main+0x83>
mov    %ebx,%ecx
imul   %r12,%rcx
shr    $0x21,%rcx
lea    (%rcx,%rcx,2),%ecx
add    %ebp,%ecx
jne    1260 <main+0xe0>
mov    %eax,%edi
mov    %r14,%rsi
call   1050 <putc@plt>
jmp    1260 <main+0xe0>
mov    0x2d41(%rip),%rax
mov    (%rax),%edi
mov    (%r14),%rdx
lea    0xd5d(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    0x2d1d(%rip),%rax
mov    (%rax),%edi
mov    0x8(%r14),%rdx
lea    0xd4e(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0x2,%edi
call   1090 <exit@plt>
mov    0x2cf8(%rip),%rax
mov    (%rax),%edi
lea    0xd53(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0x3,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [20 x i8] c"Usage: %s filename\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [31 x i8] c"I couldn't open the file \22%s\22\0A\00"
@.str.3 = [5 x i8] c".red\00"
@.str.4 = [2 x i8] c"w\00"
@.str.5 = [27 x i8] c"Can't create output file.\0A\00"
@EOF = global i32 0
@.str.6 = [24 x i8] c"Error in closing files\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 [40 x i8]
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %10
%11 = load i32, i32* %4
%12 = icmp slt i32 %11, 2
br i1 %12, label %13, label %20
13: ; preds = %2
%14 = load i32, i32* @stderr
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 0
%17 = load i8*, i8** %16
%18 = call i32 (i32, i8*, ...) @fprintf(i32 %14, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %17)
%19 = call i32 @exit(i32 1)
unreachable
20: ; preds = %2
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 1
%23 = load i8*, i8** %22
%24 = call i32* @fopen(i8* %23, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %24, i32** %6
%25 = icmp eq i32* %24, null
br i1 %25, label %26, label %33
26: ; preds = %20
%27 = load i32, i32* @stderr
%28 = load i8**, i8*** %5
%29 = getelementptr inbounds i8*, i8** %28, i64 1
%30 = load i8*, i8** %29
%31 = call i32 (i32, i8*, ...) @fprintf(i32 %27, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i8* %30)
%32 = call i32 @exit(i32 2)
unreachable
33: ; preds = %20
%34 = getelementptr inbounds [40 x i8], [40 x i8]* %9, i64 0, i64 0
%35 = load i8**, i8*** %5
%36 = getelementptr inbounds i8*, i8** %35, i64 1
%37 = load i8*, i8** %36
%38 = call i32 @strcpy(i8* %34, i8* %37)
%39 = getelementptr inbounds [40 x i8], [40 x i8]* %9, i64 0, i64 0
%40 = call i32 @strcat(i8* %39, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%41 = getelementptr inbounds [40 x i8], [40 x i8]* %9, i64 0, i64 0
%42 = call i32* @fopen(i8* %41, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32* %42, i32** %7
%43 = icmp eq i32* %42, null
br i1 %43, label %44, label %48
44: ; preds = %33
%45 = load i32, i32* @stderr
%46 = call i32 (i32, i8*, ...) @fprintf(i32 %45, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0))
%47 = call i32 @exit(i32 3)
unreachable
48: ; preds = %33
br label %49
49: ; preds = %63, %48
%50 = load i32*, i32** %6
%51 = call i32 @getc(i32* %50)
store i32 %51, i32* %8
%52 = load i32, i32* @EOF
%53 = icmp ne i32 %51, %52
br i1 %53, label %54, label %64
54: ; preds = %49
%55 = load i32, i32* %10
%56 = add nsw i32 %55, 1
store i32 %56, i32* %10
%57 = srem i32 %55, 3
%58 = icmp eq i32 %57, 0
br i1 %58, label %59, label %63
59: ; preds = %54
%60 = load i32, i32* %8
%61 = load i32*, i32** %7
%62 = call i32 @putc(i32 %60, i32* %61)
br label %63
63: ; preds = %59, %54
br label %49
64: ; preds = %49
%65 = load i32*, i32** %6
%66 = call i64 @fclose(i32* %65)
%67 = icmp ne i64 %66, 0
br i1 %67, label %72, label %68
68: ; preds = %64
%69 = load i32*, i32** %7
%70 = call i64 @fclose(i32* %69)
%71 = icmp ne i64 %70, 0
br i1 %71, label %72, label %75
72: ; preds = %68, %64
%73 = load i32, i32* @stderr
%74 = call i32 (i32, i8*, ...) @fprintf(i32 %73, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.6, i64 0, i64 0))
br label %75
75: ; preds = %72, %68
ret i32 0
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [20 x i8] c"Usage: %s filename\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [31 x i8] c"I couldn't open the file \22%s\22\0A\00"
@.str.3 = [5 x i8] c".red\00"
@.str.4 = [2 x i8] c"w\00"
@.str.5 = [27 x i8] c"Can't create output file.\0A\00"
@EOF = global i32 0
@.str.6 = [24 x i8] c"Error in closing files\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [40 x i8]
%4 = getelementptr inbounds [40 x i8], [40 x i8]* %3, i64 0, i64 0
%5 = icmp slt i32 %0, 2
br i1 %5, label %6, label %11
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = load i8*, i8** %1
%9 = tail call i32 (i32, i8*, ...) @fprintf(i32 %7, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %8)
%10 = tail call i32 @exit(i32 1)
unreachable
11: ; preds = %2
%12 = getelementptr inbounds i8*, i8** %1, i64 1
%13 = load i8*, i8** %12
%14 = tail call i32* @fopen(i8* %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%15 = icmp eq i32* %14, null
br i1 %15, label %16, label %21
16: ; preds = %11
%17 = load i32, i32* @stderr
%18 = load i8*, i8** %12
%19 = tail call i32 (i32, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i8* %18)
%20 = tail call i32 @exit(i32 2)
unreachable
21: ; preds = %11
%22 = load i8*, i8** %12
%23 = call i32 @strcpy(i8* %4, i8* %22)
%24 = call i32 @strcat(i8* %4, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%25 = call i32* @fopen(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%26 = icmp eq i32* %25, null
br i1 %26, label %31, label %27
27: ; preds = %21
%28 = call i32 @getc(i32* %14)
%29 = load i32, i32* @EOF
%30 = icmp eq i32 %28, %29
br i1 %30, label %47, label %35
31: ; preds = %21
%32 = load i32, i32* @stderr
%33 = call i32 (i32, i8*, ...) @fprintf(i32 %32, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0))
%34 = call i32 @exit(i32 3)
unreachable
35: ; preds = %27, %43
%36 = phi i32 [ %44, %43 ], [ %28, %27 ]
%37 = phi i32 [ %38, %43 ], [ 0, %27 ]
%38 = add nuw nsw i32 %37, 1
%39 = urem i32 %37, 3
%40 = icmp eq i32 %39, 0
br i1 %40, label %41, label %43
41: ; preds = %35
%42 = call i32 @putc(i32 %36, i32* %25)
br label %43
43: ; preds = %41, %35
%44 = call i32 @getc(i32* %14)
%45 = load i32, i32* @EOF
%46 = icmp eq i32 %44, %45
br i1 %46, label %47, label %35
47: ; preds = %43, %27
%48 = call i64 @fclose(i32* %14)
%49 = icmp eq i64 %48, 0
br i1 %49, label %50, label %53
50: ; preds = %47
%51 = call i64 @fclose(i32* %25)
%52 = icmp eq i64 %51, 0
br i1 %52, label %56, label %53
53: ; preds = %50, %47
%54 = load i32, i32* @stderr
%55 = call i32 (i32, i8*, ...) @fprintf(i32 %54, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.6, i64 0, i64 0))
br label %56
56: ; preds = %53, %50
ret i32 0
}