#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*/ free(char *);
int /*<<< orphan*/ help();
char *input_filename(char *);
int input_to_output(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
char *output_filename(char *, char *);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  int iOS = 0;
  char *pInputFile = NULL;
  char *pOutputFile = NULL;
  if (argc > 1) {
    FILE *pInputStream = NULL;
    FILE *pOutputStream = NULL;
    pInputFile = input_filename(argv[1]);
    pOutputFile = output_filename(pInputFile, argc > 2 ? argv[2] : NULL);
    if (pInputFile == NULL) {
      fprintf(stderr, "MANTOMAK:  Unable to form input filename\n");
      iOS = 1;
    } else {
      pInputStream = fopen(pInputFile, "rb");
      if (pInputStream == NULL) {
        fprintf(stderr, "MANTOMAK:  Unable to open input file %s\n",
                pInputFile);
        iOS = 1;
      }
    }
    if (pOutputFile == NULL) {
      fprintf(stderr, "MANTOMAK:  Unable to form output filename\n");
      iOS = 1;
    } else if (pInputStream != NULL) {
      pOutputStream = fopen(pOutputFile, "wt");
      if (pOutputStream == NULL) {
        fprintf(stderr, "MANTOMAK:  Unable to open output file %s\n",
                pOutputFile);
        iOS = 1;
      }
    }
    if (iOS == 0) {
      iOS = input_to_output(pInputStream, pOutputStream);
    }
    if (pInputStream != NULL) {
      fclose(pInputStream);
      pInputStream = NULL;
    }
    if (pOutputStream != NULL) {
      fclose(pOutputStream);
      pOutputStream = NULL;
    }
  } else {
    help();
    iOS = 1;
  }
  if (pInputFile) {
    free(pInputFile);
    pInputFile = NULL;
  }
  if (pOutputFile) {
    free(pOutputFile);
    pOutputFile = NULL;
  }
  return (iOS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
cmpl   $0x1,-0x8(%rbp)
jle    1366 <main+0x1e6>
movq   $0x0,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10a0 <input_filename@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x40(%rbp)
cmpl   $0x2,-0x8(%rbp)
jle    11fb <main+0x7b>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x48(%rbp)
jmp    1206 <main+0x86>
xor    %eax,%eax
mov    %rax,-0x48(%rbp)
jmp    1206 <main+0x86>
mov    -0x40(%rbp),%rdi
mov    -0x48(%rbp),%rsi
call   1050 <output_filename@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1245 <main+0xc5>
mov    0x2db7(%rip),%rax
mov    (%rax),%edi
lea    0xdce(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x1,-0x14(%rbp)
jmp    128b <main+0x10b>
mov    -0x20(%rbp),%rdi
lea    0xdda(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    1286 <main+0x106>
mov    0x2d75(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rdx
lea    0xdb5(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x1,-0x14(%rbp)
jmp    128b <main+0x10b>
cmpq   $0x0,-0x28(%rbp)
jne    12b9 <main+0x139>
mov    0x2d43(%rip),%rax
mov    (%rax),%edi
lea    0xdb0(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x1,-0x14(%rbp)
jmp    130f <main+0x18f>
cmpq   $0x0,-0x30(%rbp)
je     130a <main+0x18a>
mov    -0x28(%rbp),%rdi
lea    0xdb2(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    1305 <main+0x185>
mov    0x2cf6(%rip),%rax
mov    (%rax),%edi
mov    -0x28(%rbp),%rdx
lea    0xd8d(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x1,-0x14(%rbp)
jmp    130a <main+0x18a>
jmp    130f <main+0x18f>
cmpl   $0x0,-0x14(%rbp)
jne    1329 <main+0x1a9>
mov    -0x30(%rbp),%rdi
mov    -0x38(%rbp),%rsi
call   1080 <input_to_output@plt>
mov    %eax,-0x14(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     1345 <main+0x1c5>
mov    -0x30(%rbp),%rdi
call   1040 <fclose@plt>
movq   $0x0,-0x30(%rbp)
cmpq   $0x0,-0x38(%rbp)
je     1361 <main+0x1e1>
mov    -0x38(%rbp),%rdi
call   1040 <fclose@plt>
movq   $0x0,-0x38(%rbp)
jmp    1374 <main+0x1f4>
mov    $0x0,%al
call   1090 <help@plt>
movl   $0x1,-0x14(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1390 <main+0x210>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x20(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     13ac <main+0x22c>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x28(%rbp)
mov    -0x14(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
cmp    $0x2,%edi
jl     11aa <main+0x2a>
mov    %rsi,%rbx
mov    %edi,%ebp
mov    0x8(%rsi),%rdi
call   10a0 <input_filename@plt>
mov    %rax,%r15
cmp    $0x2,%ebp
jne    11bb <main+0x3b>
xor    %esi,%esi
jmp    11bf <main+0x3f>
xor    %eax,%eax
call   1090 <help@plt>
mov    $0x1,%ebp
jmp    12e0 <main+0x160>
mov    0x10(%rbx),%rsi
mov    %r15,%rdi
call   1050 <output_filename@plt>
mov    %rax,%r14
test   %r15,%r15
je     1212 <main+0x92>
lea    0xe54(%rip),%rsi
mov    %r15,%rdi
call   1070 <fopen@plt>
test   %rax,%rax
je     122e <main+0xae>
mov    %rax,%rbx
mov    $0x1,%r13b
test   %r14,%r14
jne    1252 <main+0xd2>
mov    0x2deb(%rip),%rax
mov    (%rax),%edi
lea    0xe58(%rip),%rsi
xor    %r12d,%r12d
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0x1,%ebp
jmp    12ac <main+0x12c>
mov    0x2dc7(%rip),%rax
mov    (%rax),%edi
lea    0xdde(%rip),%rsi
xor    %r13d,%r13d
xor    %eax,%eax
call   1060 <fprintf@plt>
jmp    124b <main+0xcb>
mov    0x2dab(%rip),%rax
mov    (%rax),%edi
lea    0xdef(%rip),%rsi
xor    %r13d,%r13d
mov    %r15,%rdx
xor    %eax,%eax
call   1060 <fprintf@plt>
xor    %ebx,%ebx
test   %r14,%r14
je     11ee <main+0x6e>
test   %rbx,%rbx
je     1292 <main+0x112>
lea    0xe23(%rip),%rsi
mov    %r14,%rdi
call   1070 <fopen@plt>
mov    %rax,%r12
test   %rax,%rax
jne    1295 <main+0x115>
mov    0x2d6b(%rip),%rax
mov    (%rax),%edi
lea    0xe06(%rip),%rsi
xor    %r12d,%r12d
mov    %r14,%rdx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0x1,%ebp
jmp    12b1 <main+0x131>
xor    %r12d,%r12d
mov    $0x1,%ebp
test   %r13b,%r13b
je     12ac <main+0x12c>
mov    %rbx,%rdi
mov    %r12,%rsi
call   1080 <input_to_output@plt>
mov    %eax,%ebp
test   %rbx,%rbx
je     12b9 <main+0x139>
mov    %rbx,%rdi
call   1040 <fclose@plt>
test   %r12,%r12
je     12c6 <main+0x146>
mov    %r12,%rdi
call   1040 <fclose@plt>
test   %r15,%r15
je     12d3 <main+0x153>
mov    %r15,%rdi
call   1030 <free@plt>
test   %r14,%r14
je     12e0 <main+0x160>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [42 x i8] c"MANTOMAK: Unable to form input filename\0A\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [41 x i8] c"MANTOMAK: Unable to open input file %s\0A\00"
@.str.3 = [43 x i8] c"MANTOMAK: Unable to form output filename\0A\00"
@.str.4 = [3 x i8] c"wt\00"
@.str.5 = [42 x i8] c"MANTOMAK: Unable to open output file %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32*
%10 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
store i8* null, i8** %7
store i8* null, i8** %8
%11 = load i32, i32* %4
%12 = icmp sgt i32 %11, 1
br i1 %12, label %13, label %84
13: ; preds = %2
store i32* null, i32** %9
store i32* null, i32** %10
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 1
%16 = load i8*, i8** %15
%17 = call i8* @input_filename(i8* %16)
store i8* %17, i8** %7
%18 = load i8*, i8** %7
%19 = load i32, i32* %4
%20 = icmp sgt i32 %19, 2
br i1 %20, label %21, label %25
21: ; preds = %13
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 2
%24 = load i8*, i8** %23
br label %26
25: ; preds = %13
br label %26
26: ; preds = %25, %21
%27 = phi i8* [ %24, %21 ], [ null, %25 ]
%28 = call i8* @output_filename(i8* %18, i8* %27)
store i8* %28, i8** %8
%29 = load i8*, i8** %7
%30 = icmp eq i8* %29, null
br i1 %30, label %31, label %34
31: ; preds = %26
%32 = load i32, i32* @stderr
%33 = call i32 (i32, i8*, ...) @fprintf(i32 %32, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %6
br label %44
34: ; preds = %26
%35 = load i8*, i8** %7
%36 = call i32* @fopen(i8* %35, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %36, i32** %9
%37 = load i32*, i32** %9
%38 = icmp eq i32* %37, null
br i1 %38, label %39, label %43
39: ; preds = %34
%40 = load i32, i32* @stderr
%41 = load i8*, i8** %7
%42 = call i32 (i32, i8*, ...) @fprintf(i32 %40, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.2, i64 0, i64 0), i8* %41)
store i32 1, i32* %6
br label %43
43: ; preds = %39, %34
br label %44
44: ; preds = %43, %31
%45 = load i8*, i8** %8
%46 = icmp eq i8* %45, null
br i1 %46, label %47, label %50
47: ; preds = %44
%48 = load i32, i32* @stderr
%49 = call i32 (i32, i8*, ...) @fprintf(i32 %48, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.3, i64 0, i64 0))
store i32 1, i32* %6
br label %64
50: ; preds = %44
%51 = load i32*, i32** %9
%52 = icmp ne i32* %51, null
br i1 %52, label %53, label %63
53: ; preds = %50
%54 = load i8*, i8** %8
%55 = call i32* @fopen(i8* %54, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
store i32* %55, i32** %10
%56 = load i32*, i32** %10
%57 = icmp eq i32* %56, null
br i1 %57, label %58, label %62
58: ; preds = %53
%59 = load i32, i32* @stderr
%60 = load i8*, i8** %8
%61 = call i32 (i32, i8*, ...) @fprintf(i32 %59, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.5, i64 0, i64 0), i8* %60)
store i32 1, i32* %6
br label %62
62: ; preds = %58, %53
br label %63
63: ; preds = %62, %50
br label %64
64: ; preds = %63, %47
%65 = load i32, i32* %6
%66 = icmp eq i32 %65, 0
br i1 %66, label %67, label %71
67: ; preds = %64
%68 = load i32*, i32** %9
%69 = load i32*, i32** %10
%70 = call i32 @input_to_output(i32* %68, i32* %69)
store i32 %70, i32* %6
br label %71
71: ; preds = %67, %64
%72 = load i32*, i32** %9
%73 = icmp ne i32* %72, null
br i1 %73, label %74, label %77
74: ; preds = %71
%75 = load i32*, i32** %9
%76 = call i32 @fclose(i32* %75)
store i32* null, i32** %9
br label %77
77: ; preds = %74, %71
%78 = load i32*, i32** %10
%79 = icmp ne i32* %78, null
br i1 %79, label %80, label %83
80: ; preds = %77
%81 = load i32*, i32** %10
%82 = call i32 @fclose(i32* %81)
store i32* null, i32** %10
br label %83
83: ; preds = %80, %77
br label %86
84: ; preds = %2
%85 = call i32 (...) @help()
store i32 1, i32* %6
br label %86
86: ; preds = %84, %83
%87 = load i8*, i8** %7
%88 = icmp ne i8* %87, null
br i1 %88, label %89, label %92
89: ; preds = %86
%90 = load i8*, i8** %7
%91 = call i32 @free(i8* %90)
store i8* null, i8** %7
br label %92
92: ; preds = %89, %86
%93 = load i8*, i8** %8
%94 = icmp ne i8* %93, null
br i1 %94, label %95, label %98
95: ; preds = %92
%96 = load i8*, i8** %8
%97 = call i32 @free(i8* %96)
store i8* null, i8** %8
br label %98
98: ; preds = %95, %92
%99 = load i32, i32* %6
ret i32 %99
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [42 x i8] c"MANTOMAK: Unable to form input filename\0A\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [41 x i8] c"MANTOMAK: Unable to open input file %s\0A\00"
@.str.3 = [43 x i8] c"MANTOMAK: Unable to form output filename\0A\00"
@.str.4 = [3 x i8] c"wt\00"
@.str.5 = [42 x i8] c"MANTOMAK: Unable to open output file %s\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp sgt i32 %0, 1
br i1 %3, label %4, label %58
4: ; preds = %2
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = tail call i8* @input_filename(i8* %6)
%8 = icmp eq i32 %0, 2
br i1 %8, label %12, label %9
9: ; preds = %4
%10 = getelementptr inbounds i8*, i8** %1, i64 2
%11 = load i8*, i8** %10
br label %12
12: ; preds = %4, %9
%13 = phi i8* [ %11, %9 ], [ null, %4 ]
%14 = tail call i8* @output_filename(i8* %7, i8* %13)
%15 = icmp eq i8* %7, null
br i1 %15, label %16, label %19
16: ; preds = %12
%17 = load i32, i32* @stderr
%18 = tail call i32 (i32, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0))
br label %25
19: ; preds = %12
%20 = tail call i32* @fopen(i8* %7, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%21 = icmp eq i32* %20, null
br i1 %21, label %22, label %25
22: ; preds = %19
%23 = load i32, i32* @stderr
%24 = tail call i32 (i32, i8*, ...) @fprintf(i32 %23, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.2, i64 0, i64 0), i8* %7)
br label %25
25: ; preds = %19, %22, %16
%26 = phi i1 [ true, %19 ], [ false, %22 ], [ false, %16 ]
%27 = phi i32* [ %20, %19 ], [ null, %22 ], [ null, %16 ]
%28 = icmp eq i8* %14, null
br i1 %28, label %29, label %32
29: ; preds = %25
%30 = load i32, i32* @stderr
%31 = tail call i32 (i32, i8*, ...) @fprintf(i32 %30, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.3, i64 0, i64 0))
br label %44
32: ; preds = %25
%33 = icmp eq i32* %27, null
br i1 %33, label %40, label %34
34: ; preds = %32
%35 = tail call i32* @fopen(i8* %14, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%36 = icmp eq i32* %35, null
br i1 %36, label %37, label %40
37: ; preds = %34
%38 = load i32, i32* @stderr
%39 = tail call i32 (i32, i8*, ...) @fprintf(i32 %38, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.5, i64 0, i64 0), i8* %14)
br label %48
40: ; preds = %32, %34
%41 = phi i32* [ %35, %34 ], [ null, %32 ]
br i1 %26, label %42, label %44
42: ; preds = %40
%43 = tail call i32 @input_to_output(i32* %27, i32* %41)
br label %44
44: ; preds = %29, %42, %40
%45 = phi i32* [ %41, %42 ], [ %41, %40 ], [ null, %29 ]
%46 = phi i32 [ %43, %42 ], [ 1, %40 ], [ 1, %29 ]
%47 = icmp eq i32* %27, null
br i1 %47, label %52, label %48
48: ; preds = %37, %44
%49 = phi i32 [ 1, %37 ], [ %46, %44 ]
%50 = phi i32* [ null, %37 ], [ %45, %44 ]
%51 = tail call i32 @fclose(i32* %27)
br label %52
52: ; preds = %48, %44
%53 = phi i32 [ %49, %48 ], [ %46, %44 ]
%54 = phi i32* [ %50, %48 ], [ %45, %44 ]
%55 = icmp eq i32* %54, null
br i1 %55, label %60, label %56
56: ; preds = %52
%57 = tail call i32 @fclose(i32* %54)
br label %60
58: ; preds = %2
%59 = tail call i32 (...) @help()
br label %66
60: ; preds = %52, %56
br i1 %15, label %63, label %61
61: ; preds = %60
%62 = tail call i32 @free(i8* %7)
br label %63
63: ; preds = %61, %60
br i1 %28, label %66, label %64
64: ; preds = %63
%65 = tail call i32 @free(i8* %14)
br label %66
66: ; preds = %58, %64, %63
%67 = phi i32 [ 1, %58 ], [ %53, %64 ], [ %53, %63 ]
ret i32 %67
}