#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 EXIT_FAILURE;
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*/ strncpy(char *, char *, int);
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(EXIT_FAILURE);
  }
  if ((in = fopen(argv[1], "r")) == NULL) {
    fprintf(stderr, "I couldn't open the file");
    exit(EXIT_FAILURE);
  }
  strncpy(name, argv[1], 40 - 5);
  name[40 - 5] = '\0';
  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    11d3 <main+0x53>
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    0x2e04(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe32(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    121a <main+0x9a>
mov    0x2ddc(%rip),%rax
mov    (%rax),%edi
lea    0xe11(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2dbd(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
lea    -0x50(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
mov    $0x23,%edx
call   1030 <strncpy@plt>
movb   $0x0,-0x2d(%rbp)
lea    -0x50(%rbp),%rdi
lea    0xdf0(%rip),%rsi
call   1080 <strcat@plt>
lea    -0x50(%rbp),%rdi
lea    0xde5(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    1283 <main+0x103>
mov    0x2d6f(%rip),%rax
mov    (%rax),%edi
lea    0xdc4(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0x3,%edi
call   1090 <exit@plt>
jmp    1288 <main+0x108>
mov    -0x18(%rbp),%rdi
call   10a0 <getc@plt>
mov    %eax,-0x24(%rbp)
mov    0x2d4d(%rip),%rcx
cmp    (%rcx),%eax
je     12d0 <main+0x150>
mov    -0x54(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x54(%rbp)
mov    $0x3,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    12cb <main+0x14b>
mov    -0x24(%rbp),%edi
mov    -0x20(%rbp),%rsi
call   1050 <putc@plt>
jmp    1288 <main+0x108>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
cmp    $0x0,%rax
jne    12f6 <main+0x176>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
cmp    $0x0,%rax
je     130d <main+0x18d>
mov    0x2cdb(%rip),%rax
mov    (%rax),%edi
lea    0xd4b(%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     12ac <main+0x12c>
mov    %rax,%r13
mov    0x8(%r14),%rsi
mov    %rsp,%r14
mov    %r14,%rdi
mov    $0x23,%edx
call   1030 <strncpy@plt>
movb   $0x0,0x23(%rsp)
lea    0xe59(%rip),%rsi
mov    %r14,%rdi
call   1080 <strcat@plt>
lea    0xe4f(%rip),%rsi
mov    %r14,%rdi
call   1070 <fopen@plt>
test   %rax,%rax
je     12d1 <main+0x151>
mov    %rax,%r14
mov    %r13,%rdi
call   10a0 <getc@plt>
mov    0x2de0(%rip),%r15
cmp    (%r15),%eax
jne    124f <main+0xcf>
mov    %r13,%rdi
call   1040 <fclose@plt>
test   %rax,%rax
jne    1227 <main+0xa7>
mov    %r14,%rdi
call   1040 <fclose@plt>
test   %rax,%rax
je     123e <main+0xbe>
mov    0x2daa(%rip),%rax
mov    (%rax),%edi
lea    0xe1a(%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>
nopl   0x0(%rax,%rax,1)
mov    %r13,%rdi
call   10a0 <getc@plt>
add    $0xffffffff,%ebp
add    $0x1,%ebx
cmp    (%r15),%eax
je     120d <main+0x8d>
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>
jmp    12c3 <main+0x143>
mov    0x2d25(%rip),%rax
mov    (%rax),%edi
lea    0xd5a(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    0x2d06(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    0x2d00(%rip),%rax
mov    (%rax),%edi
lea    0xd55(%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"
@EXIT_FAILURE = global i32 0
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [25 x i8] c"I couldn't open the file\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 %21
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 = load i32, i32* @EXIT_FAILURE
%20 = call i32 @exit(i32 %19)
unreachable
21: ; preds = %2
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 1
%24 = load i8*, i8** %23
%25 = call i32* @fopen(i8* %24, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %25, i32** %6
%26 = icmp eq i32* %25, null
br i1 %26, label %27, label %32
27: ; preds = %21
%28 = load i32, i32* @stderr
%29 = call i32 (i32, i8*, ...) @fprintf(i32 %28, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
%30 = load i32, i32* @EXIT_FAILURE
%31 = call i32 @exit(i32 %30)
unreachable
32: ; preds = %21
%33 = getelementptr inbounds [40 x i8], [40 x i8]* %9, i64 0, i64 0
%34 = load i8**, i8*** %5
%35 = getelementptr inbounds i8*, i8** %34, i64 1
%36 = load i8*, i8** %35
%37 = call i32 @strncpy(i8* %33, i8* %36, i32 35)
%38 = getelementptr inbounds [40 x i8], [40 x i8]* %9, i64 0, i64 35
store i8 0, i8* %38
%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 = %32
%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 = %32
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"
@EXIT_FAILURE = global i32 0
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [25 x i8] c"I couldn't open the file\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 %12
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 = load i32, i32* @EXIT_FAILURE
%11 = tail call i32 @exit(i32 %10)
unreachable
12: ; preds = %2
%13 = getelementptr inbounds i8*, i8** %1, i64 1
%14 = load i8*, i8** %13
%15 = tail call i32* @fopen(i8* %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%16 = icmp eq i32* %15, null
br i1 %16, label %17, label %22
17: ; preds = %12
%18 = load i32, i32* @stderr
%19 = tail call i32 (i32, i8*, ...) @fprintf(i32 %18, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
%20 = load i32, i32* @EXIT_FAILURE
%21 = tail call i32 @exit(i32 %20)
unreachable
22: ; preds = %12
%23 = load i8*, i8** %13
%24 = call i32 @strncpy(i8* %4, i8* %23, i32 35)
%25 = getelementptr inbounds [40 x i8], [40 x i8]* %3, i64 0, i64 35
store i8 0, i8* %25
%26 = call i32 @strcat(i8* %4, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%27 = call i32* @fopen(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%28 = icmp eq i32* %27, null
br i1 %28, label %33, label %29
29: ; preds = %22
%30 = call i32 @getc(i32* %15)
%31 = load i32, i32* @EOF
%32 = icmp eq i32 %30, %31
br i1 %32, label %49, label %37
33: ; preds = %22
%34 = load i32, i32* @stderr
%35 = call i32 (i32, i8*, ...) @fprintf(i32 %34, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0))
%36 = call i32 @exit(i32 3)
unreachable
37: ; preds = %29, %45
%38 = phi i32 [ %46, %45 ], [ %30, %29 ]
%39 = phi i32 [ %40, %45 ], [ 0, %29 ]
%40 = add nuw nsw i32 %39, 1
%41 = urem i32 %39, 3
%42 = icmp eq i32 %41, 0
br i1 %42, label %43, label %45
43: ; preds = %37
%44 = call i32 @putc(i32 %38, i32* %27)
br label %45
45: ; preds = %43, %37
%46 = call i32 @getc(i32* %15)
%47 = load i32, i32* @EOF
%48 = icmp eq i32 %46, %47
br i1 %48, label %49, label %37
49: ; preds = %45, %29
%50 = call i64 @fclose(i32* %15)
%51 = icmp eq i64 %50, 0
br i1 %51, label %52, label %55
52: ; preds = %49
%53 = call i64 @fclose(i32* %27)
%54 = icmp eq i64 %53, 0
br i1 %54, label %58, label %55
55: ; preds = %52, %49
%56 = load i32, i32* @stderr
%57 = call i32 (i32, i8*, ...) @fprintf(i32 %56, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.6, i64 0, i64 0))
br label %58
58: ; preds = %55, %52
ret i32 0
}