#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 *);
char *get_option(char *, char **, int);
int /*<<< orphan*/ printf(char *, ...);
int recover(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ *stdout;
scalar_t__ strcmp(char *, char *);
int recover_stuff(int argc, char **argv) {
  char *input_path = NULL;
  char *output_path = NULL;
  FILE *fp = NULL;
  FILE *op = stdout;
  int exit_code = 1;
  input_path = get_option("input-file", argv, argc);
  if (input_path == NULL) {
    printf("OPTION PARSING ERROR: --input-file=<filepath> must be supplied.\n");
    return 1;
  }
  output_path = get_option("output-file", argv, argc);
  if (output_path != NULL && strcmp(input_path, output_path) == 0) {
    printf("ERROR: --input-file and --output-file must point to different "
           "files.\n");
    return 1;
  }
  fp = fopen(input_path, "rb");
  if (fp == NULL) {
    printf("ERROR: unable to read file \"%s\".\n", input_path);
    return 1;
  }
  if (output_path != NULL) {
    op = fopen(output_path, "wb");
    if (op == NULL) {
      fclose(fp);
      printf("ERROR: unable to write to \"%s\".\n", output_path);
      return 1;
    }
  }
  exit_code = recover(fp, op);
  fclose(fp);
  if (op != stdout) {
    fclose(op);
  } else {
    printf("\n");
  }
  return exit_code;
}


x86 assembly (clang, -O0):
<recover_stuff>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
mov    0x2e52(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x30(%rbp)
movl   $0x1,-0x34(%rbp)
mov    -0x10(%rbp),%rsi
mov    -0x8(%rbp),%edx
lea    0xe56(%rip),%rdi
call   1080 <get_option@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11d8 <recover_stuff+0x78>
lea    0xe46(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    130d <recover_stuff+0x1ad>
mov    -0x10(%rbp),%rsi
mov    -0x8(%rbp),%edx
lea    0xe66(%rip),%rdi
call   1080 <get_option@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     122b <recover_stuff+0xcb>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    122b <recover_stuff+0xcb>
lea    0xe40(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    130d <recover_stuff+0x1ad>
mov    -0x18(%rbp),%rdi
lea    0xe68(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1268 <recover_stuff+0x108>
mov    -0x18(%rbp),%rsi
lea    0xe4c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    130d <recover_stuff+0x1ad>
cmpq   $0x0,-0x20(%rbp)
je     12be <recover_stuff+0x15e>
mov    -0x20(%rbp),%rdi
lea    0xe45(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    12b9 <recover_stuff+0x159>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x20(%rbp),%rsi
lea    0xe20(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    130d <recover_stuff+0x1ad>
jmp    12be <recover_stuff+0x15e>
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   1070 <recover@plt>
mov    %eax,-0x34(%rbp)
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x30(%rbp),%rax
mov    0x2cfe(%rip),%rcx
cmp    (%rcx),%rax
je     12f9 <recover_stuff+0x199>
mov    -0x30(%rbp),%rdi
call   1030 <fclose@plt>
jmp    1307 <recover_stuff+0x1a7>
lea    0xdc1(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x34(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<recover_stuff>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %edi,%ebp
mov    0x2e49(%rip),%r12
mov    (%r12),%r14
lea    0xe5e(%rip),%rdi
mov    %ebp,%edx
call   10a0 <get_option@plt>
test   %rax,%rax
je     1211 <recover_stuff+0x91>
mov    %rax,%r13
lea    0xe53(%rip),%rdi
mov    %rbx,%rsi
mov    %ebp,%edx
call   10a0 <get_option@plt>
test   %rax,%rax
je     121a <recover_stuff+0x9a>
mov    %rax,%r15
mov    %r13,%rdi
mov    %rax,%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
je     1265 <recover_stuff+0xe5>
mov    %r12,%rbp
lea    0xe2f(%rip),%rsi
mov    %r13,%rdi
call   1080 <fopen@plt>
test   %rax,%rax
je     1259 <recover_stuff+0xd9>
mov    %rax,%r12
lea    0xe3d(%rip),%rsi
mov    %r15,%rdi
call   1080 <fopen@plt>
test   %rax,%rax
je     127f <recover_stuff+0xff>
mov    %rax,%r14
jmp    1234 <recover_stuff+0xb4>
lea    0xe8d(%rip),%rdi
jmp    126c <recover_stuff+0xec>
mov    %r12,%rbp
lea    0xdf3(%rip),%rsi
mov    %r13,%rdi
call   1080 <fopen@plt>
mov    %rax,%r12
test   %rax,%rax
je     1259 <recover_stuff+0xd9>
mov    %r12,%rdi
mov    %r14,%rsi
call   1090 <recover@plt>
mov    %eax,%ebx
mov    %r12,%rdi
call   1050 <fclose@plt>
cmp    0x0(%rbp),%r14
je     1273 <recover_stuff+0xf3>
mov    %r14,%rdi
call   1050 <fclose@plt>
jmp    129d <recover_stuff+0x11d>
lea    0xdba(%rip),%rdi
mov    %r13,%rsi
jmp    1291 <recover_stuff+0x111>
lea    0xdf4(%rip),%rdi
call   1040 <puts@plt>
jmp    1298 <recover_stuff+0x118>
mov    $0xa,%edi
call   1030 <putchar@plt>
jmp    129d <recover_stuff+0x11d>
mov    %r12,%rdi
call   1050 <fclose@plt>
lea    0xdb1(%rip),%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0x1,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stdout = global i32* null
@.str = [11 x i8] c"input-file\00"
@.str.1 = [65 x i8] c"OPTION PARSING ERROR: --input-file=<filepath> must be supplied.\0A\00"
@.str.2 = [12 x i8] c"output-file\00"
@.str.3 = [70 x i8] c"ERROR: --input-file and --output-file must point to different files.\0A\00"
@.str.4 = [3 x i8] c"rb\00"
@.str.5 = [34 x i8] c"ERROR: unable to read file \22%s\22.\0A\00"
@.str.6 = [3 x i8] c"wb\00"
@.str.7 = [33 x i8] c"ERROR: unable to write to \22%s\22.\0A\00"
@.str.8 = [2 x i8] c"\0A\00"
define i32 @recover_stuff(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32*
%9 = alloca i32*
%10 = alloca i32
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* null, i8** %6
store i8* null, i8** %7
store i32* null, i32** %8
%11 = load i32*, i32** @stdout
store i32* %11, i32** %9
store i32 1, i32* %10
%12 = load i8**, i8*** %5
%13 = load i32, i32* %4
%14 = call i8* @get_option(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8** %12, i32 %13)
store i8* %14, i8** %6
%15 = load i8*, i8** %6
%16 = icmp eq i8* %15, null
br i1 %16, label %17, label %19
17: ; preds = %2
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %3
br label %70
19: ; preds = %2
%20 = load i8**, i8*** %5
%21 = load i32, i32* %4
%22 = call i8* @get_option(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i8** %20, i32 %21)
store i8* %22, i8** %7
%23 = load i8*, i8** %7
%24 = icmp ne i8* %23, null
br i1 %24, label %25, label %32
25: ; preds = %19
%26 = load i8*, i8** %6
%27 = load i8*, i8** %7
%28 = call i64 @strcmp(i8* %26, i8* %27)
%29 = icmp eq i64 %28, 0
br i1 %29, label %30, label %32
30: ; preds = %25
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([70 x i8], [70 x i8]* @.str.3, i64 0, i64 0))
store i32 1, i32* %3
br label %70
32: ; preds = %25, %19
%33 = load i8*, i8** %6
%34 = call i32* @fopen(i8* %33, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
store i32* %34, i32** %8
%35 = load i32*, i32** %8
%36 = icmp eq i32* %35, null
br i1 %36, label %37, label %40
37: ; preds = %32
%38 = load i8*, i8** %6
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.5, i64 0, i64 0), i8* %38)
store i32 1, i32* %3
br label %70
40: ; preds = %32
%41 = load i8*, i8** %7
%42 = icmp ne i8* %41, null
br i1 %42, label %43, label %54
43: ; preds = %40
%44 = load i8*, i8** %7
%45 = call i32* @fopen(i8* %44, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0))
store i32* %45, i32** %9
%46 = load i32*, i32** %9
%47 = icmp eq i32* %46, null
br i1 %47, label %48, label %53
48: ; preds = %43
%49 = load i32*, i32** %8
%50 = call i32 @fclose(i32* %49)
%51 = load i8*, i8** %7
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.7, i64 0, i64 0), i8* %51)
store i32 1, i32* %3
br label %70
53: ; preds = %43
br label %54
54: ; preds = %53, %40
%55 = load i32*, i32** %8
%56 = load i32*, i32** %9
%57 = call i32 @recover(i32* %55, i32* %56)
store i32 %57, i32* %10
%58 = load i32*, i32** %8
%59 = call i32 @fclose(i32* %58)
%60 = load i32*, i32** %9
%61 = load i32*, i32** @stdout
%62 = icmp ne i32* %60, %61
br i1 %62, label %63, label %66
63: ; preds = %54
%64 = load i32*, i32** %9
%65 = call i32 @fclose(i32* %64)
br label %68
66: ; preds = %54
%67 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0))
br label %68
68: ; preds = %66, %63
%69 = load i32, i32* %10
store i32 %69, i32* %3
br label %70
70: ; preds = %68, %48, %37, %30, %17
%71 = load i32, i32* %3
ret i32 %71
}

LLVM IR (-O2):
@stdout = global i32* null
@.str = [11 x i8] c"input-file\00"
@.str.2 = [12 x i8] c"output-file\00"
@.str.4 = [3 x i8] c"rb\00"
@.str.5 = [34 x i8] c"ERROR: unable to read file \22%s\22.\0A\00"
@.str.6 = [3 x i8] c"wb\00"
@.str.7 = [33 x i8] c"ERROR: unable to write to \22%s\22.\0A\00"
@str = [69 x i8] c"ERROR: --input-file and --output-file must point to different files.\00"
@str.9 = [64 x i8] c"OPTION PARSING ERROR: --input-file=<filepath> must be supplied.\00"
define i32 @recover_stuff(i32 %0, i8** %1) {
%3 = load i32*, i32** @stdout
%4 = tail call i8* @get_option(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8** %1, i32 %0)
%5 = icmp eq i8* %4, null
br i1 %5, label %6, label %8
6: ; preds = %2
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([64 x i8], [64 x i8]* @str.9, i64 0, i64 0))
br label %41
8: ; preds = %2
%9 = tail call i8* @get_option(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i8** %1, i32 %0)
%10 = icmp eq i8* %9, null
br i1 %10, label %16, label %11
11: ; preds = %8
%12 = tail call i64 @strcmp(i8* %4, i8* %9)
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %19
14: ; preds = %11
%15 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([69 x i8], [69 x i8]* @str, i64 0, i64 0))
br label %41
16: ; preds = %8
%17 = tail call i32* @fopen(i8* %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%18 = icmp eq i32* %17, null
br i1 %18, label %22, label %30
19: ; preds = %11
%20 = tail call i32* @fopen(i8* %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%21 = icmp eq i32* %20, null
br i1 %21, label %22, label %24
22: ; preds = %19, %16
%23 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.5, i64 0, i64 0), i8* %4)
br label %41
24: ; preds = %19
%25 = tail call i32* @fopen(i8* %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0))
%26 = icmp eq i32* %25, null
br i1 %26, label %27, label %30
27: ; preds = %24
%28 = tail call i32 @fclose(i32* %20)
%29 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.7, i64 0, i64 0), i8* %9)
br label %41
30: ; preds = %16, %24
%31 = phi i32* [ %20, %24 ], [ %17, %16 ]
%32 = phi i32* [ %25, %24 ], [ %3, %16 ]
%33 = tail call i32 @recover(i32* %31, i32* %32)
%34 = tail call i32 @fclose(i32* %31)
%35 = load i32*, i32** @stdout
%36 = icmp eq i32* %32, %35
br i1 %36, label %39, label %37
37: ; preds = %30
%38 = tail call i32 @fclose(i32* %32)
br label %41
39: ; preds = %30
%40 = tail call i32 @putchar(i32 10)
br label %41
41: ; preds = %37, %39, %27, %22, %14, %6
%42 = phi i32 [ 1, %6 ], [ 1, %14 ], [ 1, %22 ], [ 1, %27 ], [ %33, %39 ], [ %33, %37 ]
ret i32 %42
}