// File: /workspace/github_c_makefile_star2_O1/RodionGork[P]tinyscheme/scheme.c
// Function: main
int main(int argc, char **argv) {
  scheme sc;
  FILE *fin = NULL;
  char *file_name = InitFile;
  char *executable_name = argv[0];
  int retcode;
  int isfile = 1;

  initFromEnv();
  if (argc == 1) {
    printf("%s", get_version());
  }
  if (argc == 2 && str_eq(argv[1], "-?")) {
    printf("Usage: tinyscheme -?\n");
    printf("or:    tinyscheme [<file1> <file2> ...]\n");
    printf("followed by\n");
    printf("          -1 <file> [<arg1> <arg2> ...]\n");
    printf("          -c <Scheme commands> [<arg1> <arg2> ...]\n");
    printf("assuming that the executable is named tinyscheme.\n");
    printf("Use - as filename for stdin.\n");
    return 1;
  }
  if (!scheme_init(&sc)) {
    fprintf(stderr, "Could not initialize!\n");
    return 2;
  }
  scheme_set_input_port_file(&sc, stdin);
  scheme_set_output_port_file(&sc, stdout);
#if USE_DL
  scheme_define(&sc, sc.global_env, mk_symbol(&sc, "load-extension"),
      mk_foreign_func(&sc, scm_load_ext));
#endif
  argv++;
  if (access(file_name, 0) != 0) {
    char *p = getenv("TINYSCHEMEINIT");
    if (p != 0) {
      file_name = p;
    } else {
      strcpy(sc.strbuff, executable_name);
      p = strrchr(sc.strbuff, '/');
      if (p != 0) {
        strcpy(p + 1, file_name);
        file_name = sc.strbuff;
      }
    }
  }
  evalcnt = 0;
  do {
    if (str_eq(file_name, "-1") || str_eq(file_name, "-c")) {
      pointer args = sc.NIL;
      isfile = file_name[1] == '1';
      file_name = *argv++;
      if (isfile) {
        fin = open_file(file_name);
      }
      for (; *argv; argv++) {
        pointer value = mk_string(&sc, *argv);
        args = cons(&sc, value, args);
      }
      args = reverse_in_place(&sc, sc.NIL, args);
      scheme_define(&sc, sc.global_env, mk_symbol(&sc, "*args*"), args);

    } else {
      fin = open_file(file_name);
    }
    if (isfile && fin == 0) {
      fprintf(stderr, "Could not open file %s\n", file_name);
    } else {
      if (isfile) {
        scheme_load_named_file(&sc, fin, file_name);
      } else {
        scheme_load_string(&sc, file_name);
      }
      if (!isfile || fin != stdin) {
        if (sc.retcode != 0) {
          fprintf(stderr, "Errors encountered reading %s\n", file_name);
        }
        if (isfile) {
          fclose(fin);
        }
      }
    }
    file_name = *argv++;
  } while (file_name != 0);
  if (argc == 1) {
    scheme_load_named_file(&sc, stdin, "-");
  }
  retcode = sc.retcode;
  scheme_deinit(&sc);

  return retcode;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xf08, %rsp            # imm = 0xF08
movq %rsi, %r14
movl %edi, %ebp
movq (%rsi), %rbx
callq 0x605e
cmpl $0x1, %ebp
jne 0x60e5
leaq 0x7c05(%rip), %rdi      # 0xdcdc
leaq 0x749f(%rip), %rsi      # 0xd57d
xorl %eax, %eax
callq 0x40d0
cmpl $0x2, %ebp
jne 0x6102
movq 0x8(%r14), %rdi
leaq 0x829a(%rip), %rsi      # 0xe38f
callq 0x41a0
testl %eax, %eax
je 0x63e5
movq 0xced7(%rip), %rsi      # 0x12fe0
movq 0xcea0(%rip), %rdx      # 0x12fb0
leaq 0x10(%rsp), %rdi
callq 0x4f3a
testl %eax, %eax
je 0x6440
movq 0xcea7(%rip), %rax      # 0x12fd0
movq (%rax), %rsi
leaq 0x10(%rsp), %r15
movq %r15, %rdi
movl $0x10, %edx
callq 0x5573
movq %rax, 0x170(%r15)
movq 0xce7c(%rip), %rax      # 0x12fc8
movq (%rax), %rsi
movq %r15, %rdi
movl $0x20, %edx
callq 0x5573
movq %rax, 0x178(%r15)
leaq 0x7445(%rip), %r15      # 0xd5af
movq %r15, %rdi
xorl %esi, %esi
callq 0x4230
testl %eax, %eax
movl %ebp, 0x4(%rsp)
je 0x61d6
leaq 0x744c(%rip), %rdi      # 0xd5cf
callq 0x4040
movq %rax, %r13
testq %rax, %rax
jne 0x61d9
movq 0xeb0(%rsp), %rdi
movq %rbx, %rsi
callq 0x4050
movq 0xeb0(%rsp), %rdi
movl $0x2f, %esi
callq 0x4100
movq %r15, %r13
testq %rax, %rax
je 0x61d9
movabsq $0x6d63732e74696e69, %rcx # imm = 0x6D63732E74696E69
movq %rcx, 0x1(%rax)
movb $0x0, 0x9(%rax)
movq 0xeb0(%rsp), %r13
jmp 0x61d9
movq %r15, %r13
movq $0x0, 0xcfe4(%rip) # 0x131c8
movl $0x1, %r12d
leaq 0x10(%rsp), %rbp
xorl %ebx, %ebx
leaq 0x8(%r14), %r15
movq %r13, %rdi
leaq 0x73df(%rip), %rsi      # 0xd5de
callq 0x41a0
testl %eax, %eax
je 0x622e
movq %r13, %rdi
leaq 0x73cf(%rip), %rsi      # 0xd5e1
callq 0x41a0
testl %eax, %eax
je 0x622e
movq %r13, %rdi
callq 0x601b
movq %rax, %rbx
movq %r15, %r14
jmp 0x630e
movq %rbx, 0x8(%rsp)
movq 0xa0(%rsp), %rbx
xorl %r12d, %r12d
cmpb $0x31, 0x1(%r13)
sete 0x3(%rsp)
movq (%r15), %r13
jne 0x625a
movq %r13, %rdi
callq 0x601b
movq %rax, 0x8(%rsp)
movq 0x10(%r14), %r15
addq $0x10, %r14
testq %r15, %r15
je 0x62ad
movq %r15, %rdi
callq 0x40c0
movq %rbp, %rdi
movq %r15, %rsi
movl %eax, %edx
callq 0x47a7
movq %rax, %r15
movq %rbp, %rdi
movq %rax, %rsi
movq %rbx, %rdx
callq 0x4689
movl $0x5, (%rax)
movq %r15, 0x8(%rax)
movq %rbx, 0x10(%rax)
movq 0x8(%r14), %r15
addq $0x8, %r14
movq %rax, %rbx
testq %r15, %r15
jne 0x6267
jmp 0x62b0
movq %rbx, %rax
movq 0xa0(%rsp), %rcx
cmpq %rax, %rcx
je 0x62d7
movq %rax, %rbx
movq 0x10(%rax), %rax
movq %rcx, 0x10(%rbx)
movq %rbx, %rcx
cmpq 0xa0(%rsp), %rax
jne 0x62bd
jmp 0x62da
movq %rcx, %rbx
movb 0x3(%rsp), %al
movb %al, %r12b
movq 0x110(%rsp), %r15
movq %rbp, %rdi
leaq 0x72f1(%rip), %rsi      # 0xd5e4
callq 0x4908
movq %rbp, %rdi
movq %r15, %rsi
movq %rax, %rdx
movq %rbx, %rcx
callq 0x5e0d
movq 0x8(%rsp), %rbx
testl %r12d, %r12d
je 0x6318
testq %rbx, %rbx
je 0x6368
movq %rbp, %rdi
testl %r12d, %r12d
je 0x632d
movq %rbx, %rsi
movq %r13, %rdx
callq 0x59c7
jmp 0x6335
movq %r13, %rsi
callq 0x5d31
testl %r12d, %r12d
je 0x6346
movq 0xcc8f(%rip), %rax      # 0x12fd0
cmpq (%rax), %rbx
je 0x635a
cmpl $0x0, 0x20(%rsp)
jne 0x6385
testl %r12d, %r12d
je 0x635a
movq %rbx, %rdi
callq 0x40b0
movq (%r14), %r13
testq %r13, %r13
jne 0x61f1
jmp 0x63a2
movq 0xcc89(%rip), %rax      # 0x12ff8
movq (%rax), %rdi
leaq 0x7272(%rip), %rsi      # 0xd5eb
movq %r13, %rdx
xorl %eax, %eax
callq 0x41b0
jmp 0x635a
movq 0xcc6c(%rip), %rax      # 0x12ff8
movq (%rax), %rdi
leaq 0x726d(%rip), %rsi      # 0xd603
movq %r13, %rdx
xorl %eax, %eax
callq 0x41b0
jmp 0x634d
cmpl $0x1, 0x4(%rsp)
jne 0x63c4
movq 0xcc20(%rip), %rax      # 0x12fd0
movq (%rax), %rsi
leaq 0x71c1(%rip), %rdx      # 0xd57b
leaq 0x10(%rsp), %rdi
callq 0x59c7
leaq 0x10(%rsp), %rdi
movl 0x10(%rdi), %ebx
callq 0x568b
movl %ebx, %eax
addq $0xf08, %rsp            # imm = 0xF08
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x7f91(%rip), %rdi      # 0xe37d
callq 0x4070
leaq 0x7f9a(%rip), %rdi      # 0xe392
callq 0x4070
leaq 0x7fb6(%rip), %rdi      # 0xe3ba
callq 0x4070
leaq 0x7fb6(%rip), %rdi      # 0xe3c6
callq 0x4070
leaq 0x7fd2(%rip), %rdi      # 0xe3ee
callq 0x4070
leaq 0x7ff9(%rip), %rdi      # 0xe421
callq 0x4070
leaq 0x801f(%rip), %rdi      # 0xe453
callq 0x4070
movl $0x1, %ebx
jmp 0x63d1
callq 0x4375
movl $0x2, %ebx
jmp 0x63d1