#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*/ abort();
int /*<<< orphan*/ banner();
int /*<<< orphan*/ eccedc_init();
int /*<<< orphan*/ ecmify(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, ...);
char *malloc(scalar_t__);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ sprintf(char *, char *, char *);
int /*<<< orphan*/ stderr;
scalar_t__ strlen(char *);
int main(int argc, char **argv) {
  FILE *fin, *fout;
  char *infilename;
  char *outfilename;
  banner();
  eccedc_init();
  if ((argc != 2) && (argc != 3)) {
    fprintf(stderr, "usage: %s cdimagefile [ecmfile]\n", argv[0]);
    return 1;
  }
  infilename = argv[1];
  if (argc == 3) {
    outfilename = argv[2];
  } else {
    outfilename = malloc(strlen(infilename) + 5);
    if (!outfilename)
      abort();
    sprintf(outfilename, "%s.ecm", infilename);
  }
  fprintf(stderr, "Encoding %s to %s.\n", infilename, outfilename);
  fin = fopen(infilename, "rb");
  if (!fin) {
    perror(infilename);
    return 1;
  }
  fout = fopen(outfilename, "wb");
  if (!fout) {
    perror(outfilename);
    fclose(fin);
    return 1;
  }
  ecmify(fin, fout);
  fclose(fout);
  fclose(fin);
  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)
mov    $0x0,%al
call   1070 <banner@plt>
mov    $0x0,%al
call   1090 <eccedc_init@plt>
cmpl   $0x2,-0x8(%rbp)
je     1212 <main+0x62>
cmpl   $0x3,-0x8(%rbp)
je     1212 <main+0x62>
mov    0x2df1(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe01(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    132e <main+0x17e>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x28(%rbp)
cmpl   $0x3,-0x8(%rbp)
jne    1239 <main+0x89>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x30(%rbp)
jmp    1278 <main+0xc8>
mov    -0x28(%rbp),%rdi
call   1060 <strlen@plt>
mov    %rax,%rdi
add    $0x5,%rdi
call   10a0 <malloc@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    1264 <main+0xb4>
mov    $0x0,%al
call   1040 <abort@plt>
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%rdx
lea    0xdae(%rip),%rsi
call   10d0 <sprintf@plt>
mov    0x2d61(%rip),%rax
mov    (%rax),%edi
mov    -0x28(%rbp),%rdx
mov    -0x30(%rbp),%rcx
lea    0xd98(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    -0x28(%rbp),%rdi
lea    0xd9a(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    12cb <main+0x11b>
mov    -0x28(%rbp),%rdi
call   10c0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    132e <main+0x17e>
mov    -0x30(%rbp),%rdi
lea    0xd69(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1308 <main+0x158>
mov    -0x30(%rbp),%rdi
call   10c0 <perror@plt>
mov    -0x18(%rbp),%rdi
call   1050 <fclose@plt>
movl   $0x1,-0x4(%rbp)
jmp    132e <main+0x17e>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1030 <ecmify@plt>
mov    -0x20(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x18(%rbp),%rdi
call   1050 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %edi,%ebp
xor    %eax,%eax
call   1070 <banner@plt>
xor    %eax,%eax
call   1090 <eccedc_init@plt>
mov    %ebp,%eax
and    $0xfffffffe,%eax
cmp    $0x2,%eax
jne    11e3 <main+0x33>
mov    0x8(%rbx),%r14
cmp    $0x3,%ebp
jne    1207 <main+0x57>
mov    0x10(%rbx),%r15
jmp    1236 <main+0x86>
mov    0x2df6(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xe0a(%rip),%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    $0x1,%eax
jmp    129e <main+0xee>
mov    %r14,%rdi
call   1060 <strlen@plt>
lea    0x5(%rax),%rdi
call   10a0 <malloc@plt>
test   %rax,%rax
je     12cf <main+0x11f>
mov    %rax,%r15
lea    0xdf6(%rip),%rsi
mov    %rax,%rdi
mov    %r14,%rdx
call   10d0 <sprintf@plt>
mov    0x2da3(%rip),%rax
mov    (%rax),%edi
lea    0xde2(%rip),%rsi
mov    %r14,%rdx
mov    %r15,%rcx
xor    %eax,%eax
call   1080 <fprintf@plt>
lea    0xde2(%rip),%rsi
mov    %r14,%rdi
call   10b0 <fopen@plt>
test   %rax,%rax
je     12a9 <main+0xf9>
mov    %rax,%rbx
lea    0xdce(%rip),%rsi
mov    %r15,%rdi
call   10b0 <fopen@plt>
test   %rax,%rax
je     12b8 <main+0x108>
mov    %rax,%rbp
mov    %rbx,%rdi
mov    %rax,%rsi
call   1030 <ecmify@plt>
mov    %rbp,%rdi
call   1050 <fclose@plt>
mov    %rbx,%rdi
call   1050 <fclose@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %r14,%rdi
call   10c0 <perror@plt>
mov    $0x1,%eax
jmp    129e <main+0xee>
mov    %r15,%rdi
call   10c0 <perror@plt>
mov    %rbx,%rdi
call   1050 <fclose@plt>
mov    $0x1,%eax
jmp    129e <main+0xee>
xor    %eax,%eax
call   1040 <abort@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [33 x i8] c"usage: %s cdimagefile [ecmfile]\0A\00"
@.str.1 = [7 x i8] c"%s.ecm\00"
@.str.2 = [20 x i8] c"Encoding %s to %s.\0A\00"
@.str.3 = [3 x i8] c"rb\00"
@.str.4 = [3 x i8] c"wb\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
%10 = call i32 (...) @banner()
%11 = call i32 (...) @eccedc_init()
%12 = load i32, i32* %4
%13 = icmp ne i32 %12, 2
br i1 %13, label %14, label %23
14: ; preds = %2
%15 = load i32, i32* %4
%16 = icmp ne i32 %15, 3
br i1 %16, label %17, label %23
17: ; preds = %14
%18 = load i32, i32* @stderr
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 0
%21 = load i8*, i8** %20
%22 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %18, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i8* %21)
store i32 1, i32* %3
br label %76
23: ; preds = %14, %2
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 1
%26 = load i8*, i8** %25
store i8* %26, i8** %8
%27 = load i32, i32* %4
%28 = icmp eq i32 %27, 3
br i1 %28, label %29, label %33
29: ; preds = %23
%30 = load i8**, i8*** %5
%31 = getelementptr inbounds i8*, i8** %30, i64 2
%32 = load i8*, i8** %31
store i8* %32, i8** %9
br label %46
33: ; preds = %23
%34 = load i8*, i8** %8
%35 = call i64 @strlen(i8* %34)
%36 = add nsw i64 %35, 5
%37 = call i8* @malloc(i64 %36)
store i8* %37, i8** %9
%38 = load i8*, i8** %9
%39 = icmp ne i8* %38, null
br i1 %39, label %42, label %40
40: ; preds = %33
%41 = call i32 (...) @abort()
unreachable
42: ; preds = %33
%43 = load i8*, i8** %9
%44 = load i8*, i8** %8
%45 = call i32 @sprintf(i8* %43, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* %44)
br label %46
46: ; preds = %42, %29
%47 = load i32, i32* @stderr
%48 = load i8*, i8** %8
%49 = load i8*, i8** %9
%50 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %47, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i8* %48, i8* %49)
%51 = load i8*, i8** %8
%52 = call i32* @fopen(i8* %51, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
store i32* %52, i32** %6
%53 = load i32*, i32** %6
%54 = icmp ne i32* %53, null
br i1 %54, label %58, label %55
55: ; preds = %46
%56 = load i8*, i8** %8
%57 = call i32 @perror(i8* %56)
store i32 1, i32* %3
br label %76
58: ; preds = %46
%59 = load i8*, i8** %9
%60 = call i32* @fopen(i8* %59, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
store i32* %60, i32** %7
%61 = load i32*, i32** %7
%62 = icmp ne i32* %61, null
br i1 %62, label %68, label %63
63: ; preds = %58
%64 = load i8*, i8** %9
%65 = call i32 @perror(i8* %64)
%66 = load i32*, i32** %6
%67 = call i32 @fclose(i32* %66)
store i32 1, i32* %3
br label %76
68: ; preds = %58
%69 = load i32*, i32** %6
%70 = load i32*, i32** %7
%71 = call i32 @ecmify(i32* %69, i32* %70)
%72 = load i32*, i32** %7
%73 = call i32 @fclose(i32* %72)
%74 = load i32*, i32** %6
%75 = call i32 @fclose(i32* %74)
store i32 0, i32* %3
br label %76
76: ; preds = %68, %63, %55, %17
%77 = load i32, i32* %3
ret i32 %77
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [33 x i8] c"usage: %s cdimagefile [ecmfile]\0A\00"
@.str.1 = [7 x i8] c"%s.ecm\00"
@.str.2 = [20 x i8] c"Encoding %s to %s.\0A\00"
@.str.3 = [3 x i8] c"rb\00"
@.str.4 = [3 x i8] c"wb\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = tail call i32 (...) @banner()
%4 = tail call i32 (...) @eccedc_init()
%5 = and i32 %0, -2
%6 = icmp eq i32 %5, 2
br i1 %6, label %11, label %7
7: ; preds = %2
%8 = load i32, i32* @stderr
%9 = load i8*, i8** %1
%10 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %8, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i8* %9)
br label %45
11: ; preds = %2
%12 = getelementptr inbounds i8*, i8** %1, i64 1
%13 = load i8*, i8** %12
%14 = icmp eq i32 %0, 3
br i1 %14, label %15, label %18
15: ; preds = %11
%16 = getelementptr inbounds i8*, i8** %1, i64 2
%17 = load i8*, i8** %16
br label %27
18: ; preds = %11
%19 = tail call i64 @strlen(i8* dereferenceable(1) %13)
%20 = add nsw i64 %19, 5
%21 = tail call i8* @malloc(i64 %20)
%22 = icmp eq i8* %21, null
br i1 %22, label %23, label %25
23: ; preds = %18
%24 = tail call i32 (...) @abort()
unreachable
25: ; preds = %18
%26 = tail call i32 @sprintf(i8* %21, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* %13)
br label %27
27: ; preds = %25, %15
%28 = phi i8* [ %17, %15 ], [ %21, %25 ]
%29 = load i32, i32* @stderr
%30 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %29, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i8* %13, i8* %28)
%31 = tail call i32* @fopen(i8* %13, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%32 = icmp eq i32* %31, null
br i1 %32, label %33, label %35
33: ; preds = %27
%34 = tail call i32 @perror(i8* %13)
br label %45
35: ; preds = %27
%36 = tail call i32* @fopen(i8* %28, 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 %41
38: ; preds = %35
%39 = tail call i32 @perror(i8* %28)
%40 = tail call i32 @fclose(i32* %31)
br label %45
41: ; preds = %35
%42 = tail call i32 @ecmify(i32* %31, i32* %36)
%43 = tail call i32 @fclose(i32* %36)
%44 = tail call i32 @fclose(i32* %31)
br label %45
45: ; preds = %41, %38, %33, %7
%46 = phi i32 [ 1, %7 ], [ 0, %41 ], [ 1, %38 ], [ 1, %33 ]
ret i32 %46
}