#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*/ errno;
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ scr2str(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ *stdin;
int /*<<< orphan*/ *stdout;
int /*<<< orphan*/ str2scr(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
scalar_t__ strcmp(char *, char *);
char *strerror(int /*<<< orphan*/);
int strlen(char *);
int main(int argc, char **argv, char **env) {
  int arglen = strlen(argv[0]) - strlen("scr2str");
  int what = !strcmp(argv[0] + arglen, "scr2str");
  FILE *in = stdin;
  FILE *out = stdout;
  if (argc > 1) {
    if (strcmp(argv[1], "-")) {
      if (!(in = fopen(argv[1], "rb"))) {
        fprintf(stderr, "Error opening input file: %s\n", strerror(errno));
        return -1;
      }
    }
  }
  if (argc > 2) {
    if (!(out = fopen(argv[2], "wb"))) {
      fprintf(stderr, "Error opening output file: %s\n", strerror(errno));
      return -1;
    }
  }
  if (what)
    scr2str(in, out);
  else
    str2scr(in, out);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x34(%rbp)
lea    0xe60(%rip),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x34(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
movslq -0x1c(%rbp),%rax
add    %rax,%rdi
lea    0xe3c(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x20(%rbp)
mov    0x2e07(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
mov    0x2dd9(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x30(%rbp)
cmpl   $0x1,-0x8(%rbp)
jle    1282 <main+0x112>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xdf9(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
je     127d <main+0x10d>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xddd(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    1278 <main+0x108>
mov    0x2d91(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x38(%rbp)
mov    0x2d7d(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x38(%rbp),%edi
mov    %rax,%rdx
lea    0xda6(%rip),%rsi
call   1060 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    131b <main+0x1ab>
jmp    127d <main+0x10d>
jmp    1282 <main+0x112>
cmpl   $0x2,-0x8(%rbp)
jle    12eb <main+0x17b>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xd90(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
jne    12e6 <main+0x176>
mov    0x2d23(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x3c(%rbp)
mov    0x2d0f(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x3c(%rbp),%edi
mov    %rax,%rdx
lea    0xd59(%rip),%rsi
call   1060 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    131b <main+0x1ab>
jmp    12eb <main+0x17b>
cmpl   $0x0,-0x20(%rbp)
je     1307 <main+0x197>
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   1030 <scr2str@plt>
jmp    1314 <main+0x1a4>
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   1070 <str2scr@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %edi,%r13d
mov    (%rsi),%rdi
call   1040 <strlen@plt>
mov    %eax,%ebp
lea    0xe6e(%rip),%r14
mov    %r14,%rdi
call   1040 <strlen@plt>
sub    %eax,%ebp
movslq %ebp,%rdi
add    (%rbx),%rdi
mov    %r14,%rsi
call   1050 <strcmp@plt>
mov    %rax,%r14
mov    0x2e34(%rip),%rax
mov    (%rax),%r15
mov    0x2e0a(%rip),%rax
mov    (%rax),%r12
cmp    $0x2,%r13d
jl     1212 <main+0xa2>
mov    0x8(%rbx),%rdi
lea    0xe36(%rip),%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
je     11f4 <main+0x84>
mov    0x8(%rbx),%rdi
lea    0xe23(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,%r15
test   %rax,%rax
je     123a <main+0xca>
cmp    $0x3,%r13d
jb     1212 <main+0xa2>
mov    0x10(%rbx),%rdi
lea    0xe26(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,%r12
test   %rax,%rax
je     125a <main+0xea>
mov    %r15,%rdi
mov    %r12,%rsi
test   %r14,%r14
je     1224 <main+0xb4>
call   1070 <str2scr@plt>
jmp    1229 <main+0xb9>
call   1030 <scr2str@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d97(%rip),%rax
mov    (%rax),%ebx
mov    0x2d86(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
lea    0xdb5(%rip),%rsi
jmp    1278 <main+0x108>
mov    0x2d77(%rip),%rax
mov    (%rax),%ebx
mov    0x2d66(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
lea    0xdb6(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   1060 <fprintf@plt>
mov    $0xffffffff,%eax
jmp    122b <main+0xbb>

LLVM IR (-O0):
@.str = [8 x i8] c"scr2str\00"
@stdin = global i32* null
@stdout = global i32* null
@.str.1 = [2 x i8] c"-\00"
@.str.2 = [3 x i8] c"rb\00"
@stderr = global i32 0
@.str.3 = [30 x i8] c"Error opening input file: %s\0A\00"
@errno = global i32 0
@.str.4 = [3 x i8] c"wb\00"
@.str.5 = [31 x i8] c"Error opening output file: %s\0A\00"
define i32 @main(i32 %0, i8** %1, i8** %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8**
%7 = alloca i8**
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32*
%11 = alloca i32*
store i32 0, i32* %4
store i32 %0, i32* %5
store i8** %1, i8*** %6
store i8** %2, i8*** %7
%12 = load i8**, i8*** %6
%13 = getelementptr inbounds i8*, i8** %12, i64 0
%14 = load i8*, i8** %13
%15 = call i32 @strlen(i8* %14)
%16 = call i32 @strlen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%17 = sub nsw i32 %15, %16
store i32 %17, i32* %8
%18 = load i8**, i8*** %6
%19 = getelementptr inbounds i8*, i8** %18, i64 0
%20 = load i8*, i8** %19
%21 = load i32, i32* %8
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8, i8* %20, i64 %22
%24 = call i64 @strcmp(i8* %23, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%25 = icmp ne i64 %24, 0
%26 = xor i1 %25, true
%27 = zext i1 %26 to i32
store i32 %27, i32* %9
%28 = load i32*, i32** @stdin
store i32* %28, i32** %10
%29 = load i32*, i32** @stdout
store i32* %29, i32** %11
%30 = load i32, i32* %5
%31 = icmp sgt i32 %30, 1
br i1 %31, label %32, label %51
32: ; preds = %3
%33 = load i8**, i8*** %6
%34 = getelementptr inbounds i8*, i8** %33, i64 1
%35 = load i8*, i8** %34
%36 = call i64 @strcmp(i8* %35, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%37 = icmp ne i64 %36, 0
br i1 %37, label %38, label %50
38: ; preds = %32
%39 = load i8**, i8*** %6
%40 = getelementptr inbounds i8*, i8** %39, i64 1
%41 = load i8*, i8** %40
%42 = call i32* @fopen(i8* %41, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
store i32* %42, i32** %10
%43 = icmp ne i32* %42, null
br i1 %43, label %49, label %44
44: ; preds = %38
%45 = load i32, i32* @stderr
%46 = load i32, i32* @errno
%47 = call i8* @strerror(i32 %46)
%48 = call i32 @fprintf(i32 %45, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0), i8* %47)
store i32 -1, i32* %4
br label %78
49: ; preds = %38
br label %50
50: ; preds = %49, %32
br label %51
51: ; preds = %50, %3
%52 = load i32, i32* %5
%53 = icmp sgt i32 %52, 2
br i1 %53, label %54, label %66
54: ; preds = %51
%55 = load i8**, i8*** %6
%56 = getelementptr inbounds i8*, i8** %55, i64 2
%57 = load i8*, i8** %56
%58 = call i32* @fopen(i8* %57, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
store i32* %58, i32** %11
%59 = icmp ne i32* %58, null
br i1 %59, label %65, label %60
60: ; preds = %54
%61 = load i32, i32* @stderr
%62 = load i32, i32* @errno
%63 = call i8* @strerror(i32 %62)
%64 = call i32 @fprintf(i32 %61, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.5, i64 0, i64 0), i8* %63)
store i32 -1, i32* %4
br label %78
65: ; preds = %54
br label %66
66: ; preds = %65, %51
%67 = load i32, i32* %9
%68 = icmp ne i32 %67, 0
br i1 %68, label %69, label %73
69: ; preds = %66
%70 = load i32*, i32** %10
%71 = load i32*, i32** %11
%72 = call i32 @scr2str(i32* %70, i32* %71)
br label %77
73: ; preds = %66
%74 = load i32*, i32** %10
%75 = load i32*, i32** %11
%76 = call i32 @str2scr(i32* %74, i32* %75)
br label %77
77: ; preds = %73, %69
store i32 0, i32* %4
br label %78
78: ; preds = %77, %60, %44
%79 = load i32, i32* %4
ret i32 %79
}

LLVM IR (-O2):
@.str = [8 x i8] c"scr2str\00"
@stdin = global i32* null
@stdout = global i32* null
@.str.1 = [2 x i8] c"-\00"
@.str.2 = [3 x i8] c"rb\00"
@stderr = global i32 0
@.str.3 = [30 x i8] c"Error opening input file: %s\0A\00"
@errno = global i32 0
@.str.4 = [3 x i8] c"wb\00"
@.str.5 = [31 x i8] c"Error opening output file: %s\0A\00"
define i32 @main(i32 %0, i8** nocapture %1, i8** nocapture readnone %2) {
%4 = load i8*, i8** %1
%5 = tail call i32 @strlen(i8* %4)
%6 = tail call i32 @strlen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%7 = sub nsw i32 %5, %6
%8 = load i8*, i8** %1
%9 = sext i32 %7 to i64
%10 = getelementptr inbounds i8, i8* %8, i64 %9
%11 = tail call i64 @strcmp(i8* %10, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%12 = icmp eq i64 %11, 0
%13 = load i32*, i32** @stdin
%14 = load i32*, i32** @stdout
%15 = icmp sgt i32 %0, 1
br i1 %15, label %16, label %43
16: ; preds = %3
%17 = getelementptr inbounds i8*, i8** %1, i64 1
%18 = load i8*, i8** %17
%19 = tail call i64 @strcmp(i8* %18, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%20 = icmp eq i64 %19, 0
br i1 %20, label %30, label %21
21: ; preds = %16
%22 = load i8*, i8** %17
%23 = tail call i32* @fopen(i8* %22, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%24 = icmp eq i32* %23, null
br i1 %24, label %25, label %30
25: ; preds = %21
%26 = load i32, i32* @stderr
%27 = load i32, i32* @errno
%28 = tail call i8* @strerror(i32 %27)
%29 = tail call i32 @fprintf(i32 %26, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0), i8* %28)
br label %50
30: ; preds = %16, %21
%31 = phi i32* [ %23, %21 ], [ %13, %16 ]
%32 = icmp ugt i32 %0, 2
br i1 %32, label %33, label %43
33: ; preds = %30
%34 = getelementptr inbounds i8*, i8** %1, i64 2
%35 = load i8*, i8** %34
%36 = tail call i32* @fopen(i8* %35, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%37 = icmp eq i32* %36, null
br i1 %37, label %38, label %43
38: ; preds = %33
%39 = load i32, i32* @stderr
%40 = load i32, i32* @errno
%41 = tail call i8* @strerror(i32 %40)
%42 = tail call i32 @fprintf(i32 %39, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.5, i64 0, i64 0), i8* %41)
br label %50
43: ; preds = %3, %33, %30
%44 = phi i32* [ %31, %33 ], [ %31, %30 ], [ %13, %3 ]
%45 = phi i32* [ %36, %33 ], [ %14, %30 ], [ %14, %3 ]
br i1 %12, label %46, label %48
46: ; preds = %43
%47 = tail call i32 @scr2str(i32* %44, i32* %45)
br label %50
48: ; preds = %43
%49 = tail call i32 @str2scr(i32* %44, i32* %45)
br label %50
50: ; preds = %46, %48, %38, %25
%51 = phi i32 [ -1, %38 ], [ -1, %25 ], [ 0, %48 ], [ 0, %46 ]
ret i32 %51
}