#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 */

/* Variables and functions */
int /*<<< orphan*/ emit_results();
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ file_exists(char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
double now();
int /*<<< orphan*/ prep_hex_input(char *, char *);
int product_tree();
int /*<<< orphan*/ remainder_tree(int);
int /*<<< orphan*/ remove(char *);
scalar_t__ rename(char *, char *);
int /*<<< orphan*/ stderr;
scalar_t__ strcmp(char *, char *);
int main(int argc, char *argv[]) {
  double start = now();
  if (argc != 2) {
    fprintf(stderr, "usage: %s INPUT | --resume\n", argv[0]);
    exit(1);
  }
  if (strcmp(argv[1], "--resume")) {
    char *input = argv[1];
    remove("input.mpz");
    prep_hex_input(input, "input.tmp");
    if (rename("input.tmp", "input.mpz")) {
      fprintf(stderr, "can't rename input temp file\n");
      exit(1);
    }
  } else if (!file_exists("input.mpz")) {
    fprintf(stderr, "unable to resume\n");
    exit(1);
  }
  int level = product_tree();
  remainder_tree(level - 1);
  emit_results();
  fprintf(stderr, "run took %0.3fs\n", now() - start);
  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   10c0 <now@plt>
movsd  %xmm0,-0x18(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     1204 <main+0x54>
mov    0x2dfd(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe0d(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe09(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%rax
je     128d <main+0xdd>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x20(%rbp)
lea    0xdf0(%rip),%rdi
call   1030 <remove@plt>
mov    -0x20(%rbp),%rdi
lea    0xdea(%rip),%rsi
call   1050 <prep_hex_input@plt>
lea    0xdde(%rip),%rdi
lea    0xdcd(%rip),%rsi
call   10b0 <rename@plt>
cmp    $0x0,%rax
je     1288 <main+0xd8>
mov    0x2d72(%rip),%rax
mov    (%rax),%edi
lea    0xdc2(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
jmp    12c8 <main+0x118>
lea    0xd91(%rip),%rdi
call   1040 <file_exists@plt>
cmp    $0x0,%eax
jne    12c3 <main+0x113>
mov    0x2d37(%rip),%rax
mov    (%rax),%edi
lea    0xda5(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
jmp    12c8 <main+0x118>
mov    $0x0,%al
call   1090 <product_tree@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%edi
sub    $0x1,%edi
call   1070 <remainder_tree@plt>
mov    $0x0,%al
call   1060 <emit_results@plt>
mov    0x2cf5(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    $0x0,%al
call   10c0 <now@plt>
mov    -0x28(%rbp),%edi
subsd  -0x18(%rbp),%xmm0
lea    0xd63(%rip),%rsi
mov    $0x1,%al
call   10a0 <fprintf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
xor    %eax,%eax
call   10c0 <now@plt>
movsd  %xmm0,0x8(%rsp)
cmp    $0x2,%ebp
jne    1289 <main+0xd9>
mov    0x8(%rbx),%rdi
lea    0xe3e(%rip),%rsi
call   1080 <strcmp@plt>
test   %rax,%rax
je     1232 <main+0x82>
mov    0x8(%rbx),%rbx
lea    0xe32(%rip),%r14
mov    %r14,%rdi
call   1030 <remove@plt>
lea    0xe2d(%rip),%rbp
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1050 <prep_hex_input@plt>
mov    %rbp,%rdi
mov    %r14,%rsi
call   10b0 <rename@plt>
test   %rax,%rax
je     1242 <main+0x92>
mov    0x2dbc(%rip),%rax
mov    (%rax),%edi
lea    0xe0c(%rip),%rsi
jmp    12bd <main+0x10d>
lea    0xdec(%rip),%rdi
call   1040 <file_exists@plt>
test   %eax,%eax
je     12ad <main+0xfd>
xor    %eax,%eax
call   1090 <product_tree@plt>
lea    -0x1(%rax),%edi
call   1070 <remainder_tree@plt>
xor    %eax,%eax
call   1060 <emit_results@plt>
mov    0x2d81(%rip),%rax
mov    (%rax),%ebx
xor    %eax,%eax
call   10c0 <now@plt>
subsd  0x8(%rsp),%xmm0
lea    0xdf4(%rip),%rsi
mov    %ebx,%edi
mov    $0x1,%al
call   10a0 <fprintf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    0x2d50(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xd64(%rip),%rsi
xor    %eax,%eax
call   10a0 <fprintf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
mov    0x2d2c(%rip),%rax
mov    (%rax),%edi
lea    0xd9a(%rip),%rsi
xor    %eax,%eax
call   10a0 <fprintf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [28 x i8] c"usage: %s INPUT | --resume\0A\00"
@.str.1 = [9 x i8] c"--resume\00"
@.str.2 = [10 x i8] c"input.mpz\00"
@.str.3 = [10 x i8] c"input.tmp\00"
@.str.4 = [30 x i8] c"can't rename input temp file\0A\00"
@.str.5 = [18 x i8] c"unable to resume\0A\00"
@.str.6 = [17 x i8] c"run took %0.3fs\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca double
%7 = alloca i8*
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = call double (...) @now()
store double %9, double* %6
%10 = load i32, i32* %4
%11 = icmp ne i32 %10, 2
br i1 %11, label %12, label %19
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 0
%16 = load i8*, i8** %15
%17 = call i32 (i32, i8*, ...) @fprintf(i32 %13, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* %16)
%18 = call i32 @exit(i32 1)
unreachable
19: ; preds = %2
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
%23 = call i64 @strcmp(i8* %22, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%24 = icmp ne i64 %23, 0
br i1 %24, label %25, label %39
25: ; preds = %19
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 1
%28 = load i8*, i8** %27
store i8* %28, i8** %7
%29 = call i32 @remove(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
%30 = load i8*, i8** %7
%31 = call i32 @prep_hex_input(i8* %30, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0))
%32 = call i64 @rename(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
%33 = icmp ne i64 %32, 0
br i1 %33, label %34, label %38
34: ; preds = %25
%35 = load i32, i32* @stderr
%36 = call i32 (i32, i8*, ...) @fprintf(i32 %35, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.4, i64 0, i64 0))
%37 = call i32 @exit(i32 1)
unreachable
38: ; preds = %25
br label %47
39: ; preds = %19
%40 = call i32 @file_exists(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
%41 = icmp ne i32 %40, 0
br i1 %41, label %46, label %42
42: ; preds = %39
%43 = load i32, i32* @stderr
%44 = call i32 (i32, i8*, ...) @fprintf(i32 %43, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0))
%45 = call i32 @exit(i32 1)
unreachable
46: ; preds = %39
br label %47
47: ; preds = %46, %38
%48 = call i32 (...) @product_tree()
store i32 %48, i32* %8
%49 = load i32, i32* %8
%50 = sub nsw i32 %49, 1
%51 = call i32 @remainder_tree(i32 %50)
%52 = call i32 (...) @emit_results()
%53 = load i32, i32* @stderr
%54 = call double (...) @now()
%55 = load double, double* %6
%56 = fsub double %54, %55
%57 = call i32 (i32, i8*, ...) @fprintf(i32 %53, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0), double %56)
ret i32 0
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [28 x i8] c"usage: %s INPUT | --resume\0A\00"
@.str.1 = [9 x i8] c"--resume\00"
@.str.2 = [10 x i8] c"input.mpz\00"
@.str.3 = [10 x i8] c"input.tmp\00"
@.str.4 = [30 x i8] c"can't rename input temp file\0A\00"
@.str.5 = [18 x i8] c"unable to resume\0A\00"
@.str.6 = [17 x i8] c"run took %0.3fs\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = tail call double (...) @now()
%4 = icmp eq i32 %0, 2
br i1 %4, label %10, label %5
5: ; preds = %2
%6 = load i32, i32* @stderr
%7 = load i8*, i8** %1
%8 = tail call i32 (i32, i8*, ...) @fprintf(i32 %6, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* %7)
%9 = tail call i32 @exit(i32 1)
unreachable
10: ; preds = %2
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = tail call i64 @strcmp(i8* %12, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%14 = icmp eq i64 %13, 0
br i1 %14, label %25, label %15
15: ; preds = %10
%16 = load i8*, i8** %11
%17 = tail call i32 @remove(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
%18 = tail call i32 @prep_hex_input(i8* %16, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0))
%19 = tail call i64 @rename(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
%20 = icmp eq i64 %19, 0
br i1 %20, label %32, label %21
21: ; preds = %15
%22 = load i32, i32* @stderr
%23 = tail call i32 (i32, i8*, ...) @fprintf(i32 %22, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.4, i64 0, i64 0))
%24 = tail call i32 @exit(i32 1)
unreachable
25: ; preds = %10
%26 = tail call i32 @file_exists(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
%27 = icmp eq i32 %26, 0
br i1 %27, label %28, label %32
28: ; preds = %25
%29 = load i32, i32* @stderr
%30 = tail call i32 (i32, i8*, ...) @fprintf(i32 %29, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0))
%31 = tail call i32 @exit(i32 1)
unreachable
32: ; preds = %15, %25
%33 = tail call i32 (...) @product_tree()
%34 = add nsw i32 %33, -1
%35 = tail call i32 @remainder_tree(i32 %34)
%36 = tail call i32 (...) @emit_results()
%37 = load i32, i32* @stderr
%38 = tail call double (...) @now()
%39 = fsub double %38, %3
%40 = tail call i32 (i32, i8*, ...) @fprintf(i32 %37, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0), double %39)
ret i32 0
}