#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 fscanf(int /*<<< orphan*/ *, char *, char *);
int getc(int /*<<< orphan*/ *);
int /*<<< orphan*/ putc(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ rewind(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[80];
  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 %s\n", argv[1]);
    exit(EXIT_FAILURE);
  }
  strncpy(name, argv[1], 80 - 5);
  name[80 - 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);
    }
  }
  rewind(in);
  char word[6];
  if (fscanf(in, "%5s", word) == 1) {
    puts(word);
  }
  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    $0x90,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x84(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    1209 <main+0x59>
mov    0x2df4(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe0c(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    0x2dce(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xdfc(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    1258 <main+0xa8>
mov    0x2da6(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xdd3(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    0x2d7f(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
lea    -0x80(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
mov    $0x4b,%edx
call   1030 <strncpy@plt>
movb   $0x0,-0x35(%rbp)
lea    -0x80(%rbp),%rdi
lea    0xdb6(%rip),%rsi
call   10b0 <strcat@plt>
lea    -0x80(%rbp),%rdi
lea    0xdab(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    12c1 <main+0x111>
mov    0x2d31(%rip),%rax
mov    (%rax),%edi
lea    0xd8a(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    $0x3,%edi
call   10c0 <exit@plt>
jmp    12c6 <main+0x116>
mov    -0x18(%rbp),%rdi
call   10d0 <getc@plt>
mov    %eax,-0x24(%rbp)
mov    0x2d0f(%rip),%rcx
cmp    (%rcx),%eax
je     1314 <main+0x164>
mov    -0x84(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x84(%rbp)
mov    $0x3,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    130f <main+0x15f>
mov    -0x24(%rbp),%edi
mov    -0x20(%rbp),%rsi
call   1080 <putc@plt>
jmp    12c6 <main+0x116>
mov    -0x18(%rbp),%rdi
call   1060 <rewind@plt>
mov    -0x18(%rbp),%rdi
lea    -0x8a(%rbp),%rdx
lea    0xd25(%rip),%rsi
call   1070 <fscanf@plt>
cmp    $0x1,%eax
jne    1349 <main+0x199>
lea    -0x8a(%rbp),%rdi
call   1040 <puts@plt>
mov    -0x18(%rbp),%rdi
call   1050 <fclose@plt>
cmp    $0x0,%rax
jne    136f <main+0x1bf>
mov    -0x20(%rbp),%rdi
call   1050 <fclose@plt>
cmp    $0x0,%rax
je     1386 <main+0x1d6>
mov    0x2c62(%rip),%rax
mov    (%rax),%edi
lea    0xcd9(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
xor    %eax,%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x68,%rsp
mov    %rsi,%r14
cmp    $0x1,%edi
jle    12f4 <main+0x144>
mov    0x8(%r14),%rdi
lea    0xe3f(%rip),%rsi
call   10a0 <fopen@plt>
test   %rax,%rax
je     1309 <main+0x159>
mov    %rax,%r13
mov    0x8(%r14),%rsi
lea    0x10(%rsp),%r14
mov    %r14,%rdi
mov    $0x4b,%edx
call   1030 <strncpy@plt>
movb   $0x0,0x5b(%rsp)
lea    0xe2b(%rip),%rsi
mov    %r14,%rdi
call   10b0 <strcat@plt>
lea    0xe21(%rip),%rsi
mov    %r14,%rdi
call   10a0 <fopen@plt>
test   %rax,%rax
je     1332 <main+0x182>
mov    %rax,%r14
mov    %r13,%rdi
call   10d0 <getc@plt>
mov    0x2dae(%rip),%r15
cmp    (%r15),%eax
jne    12ac <main+0xfc>
mov    %r13,%rdi
call   1060 <rewind@plt>
lea    0xe06(%rip),%rsi
lea    0xa(%rsp),%rdx
mov    %r13,%rdi
call   1070 <fscanf@plt>
cmp    $0x1,%eax
jne    126a <main+0xba>
lea    0xa(%rsp),%rdi
call   1040 <puts@plt>
mov    %r13,%rdi
call   1050 <fclose@plt>
test   %rax,%rax
jne    1284 <main+0xd4>
mov    %r14,%rdi
call   1050 <fclose@plt>
test   %rax,%rax
je     129b <main+0xeb>
mov    0x2d4d(%rip),%rax
mov    (%rax),%edi
lea    0xdc4(%rip),%rsi
xor    %eax,%eax
call   1090 <fprintf@plt>
xor    %eax,%eax
add    $0x68,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %ebp,%ebp
mov    $0xaaaaaaab,%r12d
xor    %ebx,%ebx
jmp    12d7 <main+0x127>
nopl   0x0(%rax,%rax,1)
mov    %r13,%rdi
call   10d0 <getc@plt>
add    $0xffffffff,%ebp
add    $0x1,%ebx
cmp    (%r15),%eax
je     123f <main+0x8f>
mov    %ebx,%ecx
imul   %r12,%rcx
shr    $0x21,%rcx
lea    (%rcx,%rcx,2),%ecx
add    %ebp,%ecx
jne    12c0 <main+0x110>
mov    %eax,%edi
mov    %r14,%rsi
call   1080 <putc@plt>
jmp    12c0 <main+0x110>
mov    0x2cdd(%rip),%rax
mov    (%rax),%edi
mov    (%r14),%rdx
lea    0xcf9(%rip),%rsi
jmp    131d <main+0x16d>
mov    0x2cc8(%rip),%rax
mov    (%rax),%edi
mov    0x8(%r14),%rdx
lea    0xcf9(%rip),%rsi
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    0x2ca5(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
mov    0x2c9f(%rip),%rax
mov    (%rax),%edi
lea    0xcf8(%rip),%rsi
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    $0x3,%edi
call   10c0 <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 = [29 x i8] c"I couldn't open the file %s\0A\00"
@.str.3 = [5 x i8] c".red\00"
@.str.4 = [2 x i8] c"w\00"
@.str.5 = [26 x i8] c"Can't create output file\0A\00"
@EOF = global i32 0
@.str.6 = [4 x i8] c"%5s\00"
@.str.7 = [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 [80 x i8]
%10 = alloca i32
%11 = alloca [6 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %10
%12 = load i32, i32* %4
%13 = icmp slt i32 %12, 2
br i1 %13, label %14, label %22
14: ; preds = %2
%15 = load i32, i32* @stderr
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 0
%18 = load i8*, i8** %17
%19 = call i32 (i32, i8*, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %18)
%20 = load i32, i32* @EXIT_FAILURE
%21 = call i32 @exit(i32 %20)
unreachable
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 = icmp eq i32* %26, null
br i1 %27, label %28, label %36
28: ; preds = %22
%29 = load i32, i32* @stderr
%30 = load i8**, i8*** %5
%31 = getelementptr inbounds i8*, i8** %30, i64 1
%32 = load i8*, i8** %31
%33 = call i32 (i32, i8*, ...) @fprintf(i32 %29, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), i8* %32)
%34 = load i32, i32* @EXIT_FAILURE
%35 = call i32 @exit(i32 %34)
unreachable
36: ; preds = %22
%37 = getelementptr inbounds [80 x i8], [80 x i8]* %9, i64 0, i64 0
%38 = load i8**, i8*** %5
%39 = getelementptr inbounds i8*, i8** %38, i64 1
%40 = load i8*, i8** %39
%41 = call i32 @strncpy(i8* %37, i8* %40, i32 75)
%42 = getelementptr inbounds [80 x i8], [80 x i8]* %9, i64 0, i64 75
store i8 0, i8* %42
%43 = getelementptr inbounds [80 x i8], [80 x i8]* %9, i64 0, i64 0
%44 = call i32 @strcat(i8* %43, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%45 = getelementptr inbounds [80 x i8], [80 x i8]* %9, i64 0, i64 0
%46 = call i32* @fopen(i8* %45, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32* %46, i32** %7
%47 = icmp eq i32* %46, null
br i1 %47, label %48, label %52
48: ; preds = %36
%49 = load i32, i32* @stderr
%50 = call i32 (i32, i8*, ...) @fprintf(i32 %49, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.5, i64 0, i64 0))
%51 = call i32 @exit(i32 3)
unreachable
52: ; preds = %36
br label %53
53: ; preds = %67, %52
%54 = load i32*, i32** %6
%55 = call i32 @getc(i32* %54)
store i32 %55, i32* %8
%56 = load i32, i32* @EOF
%57 = icmp ne i32 %55, %56
br i1 %57, label %58, label %68
58: ; preds = %53
%59 = load i32, i32* %10
%60 = add nsw i32 %59, 1
store i32 %60, i32* %10
%61 = srem i32 %59, 3
%62 = icmp eq i32 %61, 0
br i1 %62, label %63, label %67
63: ; preds = %58
%64 = load i32, i32* %8
%65 = load i32*, i32** %7
%66 = call i32 @putc(i32 %64, i32* %65)
br label %67
67: ; preds = %63, %58
br label %53
68: ; preds = %53
%69 = load i32*, i32** %6
%70 = call i32 @rewind(i32* %69)
%71 = load i32*, i32** %6
%72 = getelementptr inbounds [6 x i8], [6 x i8]* %11, i64 0, i64 0
%73 = call i32 @fscanf(i32* %71, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i8* %72)
%74 = icmp eq i32 %73, 1
br i1 %74, label %75, label %78
75: ; preds = %68
%76 = getelementptr inbounds [6 x i8], [6 x i8]* %11, i64 0, i64 0
%77 = call i32 @puts(i8* %76)
br label %78
78: ; preds = %75, %68
%79 = load i32*, i32** %6
%80 = call i64 @fclose(i32* %79)
%81 = icmp ne i64 %80, 0
br i1 %81, label %86, label %82
82: ; preds = %78
%83 = load i32*, i32** %7
%84 = call i64 @fclose(i32* %83)
%85 = icmp ne i64 %84, 0
br i1 %85, label %86, label %89
86: ; preds = %82, %78
%87 = load i32, i32* @stderr
%88 = call i32 (i32, i8*, ...) @fprintf(i32 %87, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.7, i64 0, i64 0))
br label %89
89: ; preds = %86, %82
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 = [29 x i8] c"I couldn't open the file %s\0A\00"
@.str.3 = [5 x i8] c".red\00"
@.str.4 = [2 x i8] c"w\00"
@.str.5 = [26 x i8] c"Can't create output file\0A\00"
@EOF = global i32 0
@.str.6 = [4 x i8] c"%5s\00"
@.str.7 = [24 x i8] c"Error in closing files\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [80 x i8]
%4 = alloca [6 x i8]
%5 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 0
%6 = icmp slt i32 %0, 2
br i1 %6, label %7, label %13
7: ; preds = %2
%8 = load i32, i32* @stderr
%9 = load i8*, i8** %1
%10 = tail call i32 (i32, i8*, ...) @fprintf(i32 %8, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %9)
%11 = load i32, i32* @EXIT_FAILURE
%12 = tail call i32 @exit(i32 %11)
unreachable
13: ; preds = %2
%14 = getelementptr inbounds i8*, i8** %1, i64 1
%15 = load i8*, i8** %14
%16 = tail call i32* @fopen(i8* %15, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%17 = icmp eq i32* %16, null
br i1 %17, label %18, label %24
18: ; preds = %13
%19 = load i32, i32* @stderr
%20 = load i8*, i8** %14
%21 = tail call i32 (i32, i8*, ...) @fprintf(i32 %19, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), i8* %20)
%22 = load i32, i32* @EXIT_FAILURE
%23 = tail call i32 @exit(i32 %22)
unreachable
24: ; preds = %13
%25 = load i8*, i8** %14
%26 = call i32 @strncpy(i8* %5, i8* %25, i32 75)
%27 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 75
store i8 0, i8* %27
%28 = call i32 @strcat(i8* %5, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%29 = call i32* @fopen(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%30 = icmp eq i32* %29, null
br i1 %30, label %35, label %31
31: ; preds = %24
%32 = call i32 @getc(i32* %16)
%33 = load i32, i32* @EOF
%34 = icmp eq i32 %32, %33
br i1 %34, label %51, label %39
35: ; preds = %24
%36 = load i32, i32* @stderr
%37 = call i32 (i32, i8*, ...) @fprintf(i32 %36, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.5, i64 0, i64 0))
%38 = call i32 @exit(i32 3)
unreachable
39: ; preds = %31, %47
%40 = phi i32 [ %48, %47 ], [ %32, %31 ]
%41 = phi i32 [ %42, %47 ], [ 0, %31 ]
%42 = add nuw nsw i32 %41, 1
%43 = urem i32 %41, 3
%44 = icmp eq i32 %43, 0
br i1 %44, label %45, label %47
45: ; preds = %39
%46 = call i32 @putc(i32 %40, i32* %29)
br label %47
47: ; preds = %45, %39
%48 = call i32 @getc(i32* %16)
%49 = load i32, i32* @EOF
%50 = icmp eq i32 %48, %49
br i1 %50, label %51, label %39
51: ; preds = %47, %31
%52 = call i32 @rewind(i32* %16)
%53 = getelementptr inbounds [6 x i8], [6 x i8]* %4, i64 0, i64 0
%54 = call i32 @fscanf(i32* %16, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i8* %53)
%55 = icmp eq i32 %54, 1
br i1 %55, label %56, label %58
56: ; preds = %51
%57 = call i32 @puts(i8* %53)
br label %58
58: ; preds = %56, %51
%59 = call i64 @fclose(i32* %16)
%60 = icmp eq i64 %59, 0
br i1 %60, label %61, label %64
61: ; preds = %58
%62 = call i64 @fclose(i32* %29)
%63 = icmp eq i64 %62, 0
br i1 %63, label %67, label %64
64: ; preds = %61, %58
%65 = load i32, i32* @stderr
%66 = call i32 (i32, i8*, ...) @fprintf(i32 %65, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.7, i64 0, i64 0))
br label %67
67: ; preds = %64, %61
ret i32 0
}