#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ scot(int /*<<< orphan*/ *, int /*<<< orphan*/ *, char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ *stdin;
int main(int argc, char **argv) {
  FILE *infile = NULL, *outfile = NULL;
  char *name = NULL, *outname = "score";
  if (argc == 2 || argc == 3) {
    if (argc == 3)
      outname = argv[2];
    if (!(infile = fopen(argv[1], "r"))) {
      fprintf(stderr, "Can't open input file \"%s\"\n", argv[1]);
      return -1;
    }
    name = argv[1];
  } else if (argc == 1) {
    infile = stdin;
    name = "";
  } else {
    fprintf(stderr, "Usage:  scot [<infile> [<outfile>]]\n");
    return -1;
  }
  if (!(outfile = fopen(outname, "w"))) {
    fprintf(stderr, "Can't open output file \"%s\"\n", outname);
    return -1;
  }
  scot(infile, outfile, name);
  fclose(infile);
  fclose(outfile);
  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)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
lea    0xe8b(%rip),%rax
mov    %rax,-0x30(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     118d <main+0x4d>
cmpl   $0x3,-0x8(%rbp)
jne    1201 <main+0xc1>
cmpl   $0x3,-0x8(%rbp)
jne    11a3 <main+0x63>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe54(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11f0 <main+0xb0>
mov    0x2e0c(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xe2b(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12c0 <main+0x180>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x28(%rbp)
jmp    1251 <main+0x111>
cmpl   $0x1,-0x8(%rbp)
jne    1229 <main+0xe9>
mov    0x2dd6(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
lea    0xe03(%rip),%rax
mov    %rax,-0x28(%rbp)
jmp    124c <main+0x10c>
mov    0x2da8(%rip),%rax
mov    (%rax),%edi
lea    0xdeb(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12c0 <main+0x180>
jmp    1251 <main+0x111>
mov    -0x30(%rbp),%rdi
lea    0xded(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    1296 <main+0x156>
mov    0x2d62(%rip),%rax
mov    (%rax),%edi
mov    -0x30(%rbp),%rdx
lea    0xdc8(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12c0 <main+0x180>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   1060 <scot@plt>
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
push   %rax
mov    %edi,%eax
and    $0xfffffffe,%eax
cmp    $0x2,%eax
jne    1160 <main+0x20>
mov    %rsi,%rbx
cmp    $0x3,%edi
jne    117f <main+0x3f>
mov    0x10(%rbx),%r14
jmp    1186 <main+0x46>
cmp    $0x1,%edi
jne    11db <main+0x9b>
mov    0x2e7c(%rip),%rax
mov    (%rax),%r15
lea    0xe8a(%rip),%r14
lea    0xea6(%rip),%r12
jmp    11a2 <main+0x62>
lea    0xe7a(%rip),%r14
mov    0x8(%rbx),%rdi
lea    0xe75(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     1209 <main+0xc9>
mov    %rax,%r15
mov    0x8(%rbx),%r12
lea    0xea0(%rip),%rsi
mov    %r14,%rdi
call   1050 <fopen@plt>
test   %rax,%rax
je     11f4 <main+0xb4>
mov    %rax,%rbx
mov    %r15,%rdi
mov    %rax,%rsi
mov    %r12,%rdx
call   1060 <scot@plt>
mov    %r15,%rdi
call   1030 <fclose@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
jmp    1229 <main+0xe9>
mov    0x2df6(%rip),%rax
mov    (%rax),%edi
lea    0xe39(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
jmp    1224 <main+0xe4>
mov    0x2ddd(%rip),%rax
mov    (%rax),%edi
lea    0xe47(%rip),%rsi
mov    %r14,%rdx
jmp    121d <main+0xdd>
mov    0x2dc8(%rip),%rax
mov    (%rax),%edi
mov    0x8(%rbx),%rdx
lea    0xdeb(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [6 x i8] c"score\00"
@.str.1 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.2 = [28 x i8] c"Can't open input file \22%s\22\0A\00"
@stdin = global i32* null
@.str.3 = [1 x i8] zeroinitializer
@.str.4 = [37 x i8] c"Usage: scot [<infile> [<outfile>]]\0A\00"
@.str.5 = [2 x i8] c"w\00"
@.str.6 = [29 x i8] c"Can't open output file \22%s\22\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 i8*
%9 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32* null, i32** %6
store i32* null, i32** %7
store i8* null, i8** %8
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8** %9
%10 = load i32, i32* %4
%11 = icmp eq i32 %10, 2
br i1 %11, label %15, label %12
12: ; preds = %2
%13 = load i32, i32* %4
%14 = icmp eq i32 %13, 3
br i1 %14, label %15, label %38
15: ; preds = %12, %2
%16 = load i32, i32* %4
%17 = icmp eq i32 %16, 3
br i1 %17, label %18, label %22
18: ; preds = %15
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 2
%21 = load i8*, i8** %20
store i8* %21, i8** %9
br label %22
22: ; preds = %18, %15
%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 ne i32* %26, null
br i1 %27, label %34, label %28
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 ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i8* %32)
store i32 -1, i32* %3
br label %64
34: ; preds = %22
%35 = load i8**, i8*** %5
%36 = getelementptr inbounds i8*, i8** %35, i64 1
%37 = load i8*, i8** %36
store i8* %37, i8** %8
br label %47
38: ; preds = %12
%39 = load i32, i32* %4
%40 = icmp eq i32 %39, 1
br i1 %40, label %41, label %43
41: ; preds = %38
%42 = load i32*, i32** @stdin
store i32* %42, i32** %6
store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.3, i64 0, i64 0), i8** %8
br label %46
43: ; preds = %38
%44 = load i32, i32* @stderr
%45 = call i32 (i32, i8*, ...) @fprintf(i32 %44, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.4, i64 0, i64 0))
store i32 -1, i32* %3
br label %64
46: ; preds = %41
br label %47
47: ; preds = %46, %34
%48 = load i8*, i8** %9
%49 = call i32* @fopen(i8* %48, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
store i32* %49, i32** %7
%50 = icmp ne i32* %49, null
br i1 %50, label %55, label %51
51: ; preds = %47
%52 = load i32, i32* @stderr
%53 = load i8*, i8** %9
%54 = call i32 (i32, i8*, ...) @fprintf(i32 %52, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.6, i64 0, i64 0), i8* %53)
store i32 -1, i32* %3
br label %64
55: ; preds = %47
%56 = load i32*, i32** %6
%57 = load i32*, i32** %7
%58 = load i8*, i8** %8
%59 = call i32 @scot(i32* %56, i32* %57, i8* %58)
%60 = load i32*, i32** %6
%61 = call i32 @fclose(i32* %60)
%62 = load i32*, i32** %7
%63 = call i32 @fclose(i32* %62)
store i32 0, i32* %3
br label %64
64: ; preds = %55, %51, %43, %28
%65 = load i32, i32* %3
ret i32 %65
}

LLVM IR (-O2):
@.str = [6 x i8] c"score\00"
@.str.1 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.2 = [28 x i8] c"Can't open input file \22%s\22\0A\00"
@stdin = global i32* null
@.str.3 = [1 x i8] zeroinitializer
@.str.4 = [37 x i8] c"Usage: scot [<infile> [<outfile>]]\0A\00"
@.str.5 = [2 x i8] c"w\00"
@.str.6 = [29 x i8] c"Can't open output file \22%s\22\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = and i32 %0, -2
%4 = icmp eq i32 %3, 2
br i1 %4, label %5, label %22
5: ; preds = %2
%6 = icmp eq i32 %0, 3
br i1 %6, label %7, label %10
7: ; preds = %5
%8 = getelementptr inbounds i8*, i8** %1, i64 2
%9 = load i8*, i8** %8
br label %10
10: ; preds = %7, %5
%11 = phi i8* [ %9, %7 ], [ getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), %5 ]
%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 %20
16: ; preds = %10
%17 = load i32, i32* @stderr
%18 = load i8*, i8** %12
%19 = tail call i32 (i32, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i8* %18)
br label %42
20: ; preds = %10
%21 = load i8*, i8** %12
br label %29
22: ; preds = %2
%23 = icmp eq i32 %0, 1
br i1 %23, label %24, label %26
24: ; preds = %22
%25 = load i32*, i32** @stdin
br label %29
26: ; preds = %22
%27 = load i32, i32* @stderr
%28 = tail call i32 (i32, i8*, ...) @fprintf(i32 %27, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.4, i64 0, i64 0))
br label %42
29: ; preds = %24, %20
%30 = phi i32* [ %14, %20 ], [ %25, %24 ]
%31 = phi i8* [ %21, %20 ], [ getelementptr inbounds ([1 x i8], [1 x i8]* @.str.3, i64 0, i64 0), %24 ]
%32 = phi i8* [ %11, %20 ], [ getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), %24 ]
%33 = tail call i32* @fopen(i8* %32, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%34 = icmp eq i32* %33, null
br i1 %34, label %35, label %38
35: ; preds = %29
%36 = load i32, i32* @stderr
%37 = tail call i32 (i32, i8*, ...) @fprintf(i32 %36, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.6, i64 0, i64 0), i8* %32)
br label %42
38: ; preds = %29
%39 = tail call i32 @scot(i32* %30, i32* %33, i8* %31)
%40 = tail call i32 @fclose(i32* %30)
%41 = tail call i32 @fclose(i32* %33)
br label %42
42: ; preds = %38, %35, %26, %16
%43 = phi i32 [ 0, %38 ], [ -1, %35 ], [ -1, %16 ], [ -1, %26 ]
ret i32 %43
}