// File: /workspace/github_c_makefile_star2_O0/nurse[P]nkf/nkf.c
// Function: main
int
main(int argc, char **argv)
{
    FILE  *fin;
    unsigned char  *cp;

    char *outfname = NULL;
    char *origfname;

#ifdef EASYWIN /*Easy Win */
    _BufferSize.y = 400;/*Set Scroll Buffer Size*/
#endif
#ifdef DEFAULT_CODE_LOCALE
    setlocale(LC_CTYPE, "");
#endif
    nkf_state_init();

    for (argc--,argv++; (argc > 0) && **argv == '-'; argc--, argv++) {
	cp = (unsigned char *)*argv;
	options(cp);
#ifdef EXEC_IO
	if (exec_f){
	    int fds[2], pid;
	    if (pipe(fds) < 0 || (pid = fork()) < 0){
		abort();
	    }
	    if (pid == 0){
		if (exec_f > 0){
		    close(fds[0]);
		    dup2(fds[1], 1);
		}else{
		    close(fds[1]);
		    dup2(fds[0], 0);
		}
		execvp(argv[1], &argv[1]);
	    }
	    if (exec_f > 0){
		close(fds[1]);
		dup2(fds[0], 0);
	    }else{
		close(fds[0]);
		dup2(fds[1], 1);
	    }
	    argc = 0;
	    break;
	}
#endif
    }

    if (guess_f) {
#ifdef CHECK_OPTION
	int debug_f_back = debug_f;
#endif
#ifdef EXEC_IO
	int exec_f_back = exec_f;
#endif
#ifdef X0212_ENABLE
	int x0212_f_back = x0212_f;
#endif
	int x0213_f_back = x0213_f;
	int guess_f_back = guess_f;
	reinit();
	guess_f = guess_f_back;
	mime_f = FALSE;
#ifdef CHECK_OPTION
	debug_f = debug_f_back;
#endif
#ifdef EXEC_IO
	exec_f = exec_f_back;
#endif
	x0212_f = x0212_f_back;
	x0213_f = x0213_f_back;
    }

    if (binmode_f == TRUE)
#if defined(__OS2__) && (defined(__IBMC__) || defined(__IBMCPP__))
	if (freopen("","wb",stdout) == NULL)
	    return (-1);
#else
    setbinmode(stdout);
#endif

    if (unbuf_f)
	setbuf(stdout, (char *) NULL);
    else
	setvbuffer(stdout, (char *) stdobuf, IOBUF_SIZE);

    if (argc == 0) {
	if (binmode_f == TRUE)
#if defined(__OS2__) && (defined(__IBMC__) || defined(__IBMCPP__))
	    if (freopen("","rb",stdin) == NULL) return (-1);
#else
	setbinmode(stdin);
#endif
	setvbuffer(stdin, (char *) stdibuf, IOBUF_SIZE);
	if (nop_f)
	    noconvert(stdin);
	else {
	    kanji_convert(stdin);
	    if (guess_f) print_guessed_code(NULL);
	}
    } else {
	int nfiles = argc;
	int is_argument_error = FALSE;
	while (argc--) {
	    input_codename = NULL;
	    input_eol = 0;
#ifdef CHECK_OPTION
	    iconv_for_check = 0;
#endif
	    if ((fin = fopen((origfname = *argv++), "r")) == NULL) {
		perror(*(argv-1));
		is_argument_error = TRUE;
		continue;
	    } else {
#ifdef OVERWRITE
		int fd = 0;
		int fd_backup = 0;
#endif

		/* reopen file for stdout */
		if (file_out_f == TRUE) {
#ifdef OVERWRITE
		    if (overwrite_f){
			outfname = nkf_xmalloc(strlen(origfname)
					  + strlen(".nkftmpXXXXXX")
					  + 1);
			strcpy(outfname, origfname);
#ifdef MSDOS
			{
			    int i;
			    for (i = strlen(outfname); i; --i){
				if (outfname[i - 1] == '/'
				    || outfname[i - 1] == '\\'){
				    break;
				}
			    }
			    outfname[i] = '\0';
			}
			strcat(outfname, "ntXXXXXX");
			mktemp(outfname);
			fd = open(outfname, O_WRONLY | O_CREAT | O_TRUNC | O_EXCL,
				  S_IREAD | S_IWRITE);
#else
			strcat(outfname, ".nkftmpXXXXXX");
			fd = mkstemp(outfname);
#endif
			if (fd < 0
			    || (fd_backup = dup(fileno(stdout))) < 0
			    || dup2(fd, fileno(stdout)) < 0
			   ){
			    perror(origfname);
			    return -1;
			}
		    }else
#endif
		    if(argc == 1) {
			outfname = *argv++;
			argc--;
		    } else {
			outfname = "nkf.out";
		    }

		    if(freopen(outfname, "w", stdout) == NULL) {
			perror (outfname);
			return (-1);
		    }
		    if (binmode_f == TRUE) {
#if defined(__OS2__) && (defined(__IBMC__) || defined(__IBMCPP__))
			if (freopen("","wb",stdout) == NULL)
			    return (-1);
#else
			setbinmode(stdout);
#endif
		    }
		}
		if (binmode_f == TRUE)
#if defined(__OS2__) && (defined(__IBMC__) || defined(__IBMCPP__))
		    if (freopen("","rb",fin) == NULL)
			return (-1);
#else
		setbinmode(fin);
#endif
		setvbuffer(fin, (char *) stdibuf, IOBUF_SIZE);
		if (nop_f)
		    noconvert(fin);
		else {
		    char *filename = NULL;
		    kanji_convert(fin);
		    if (nfiles > 1) filename = origfname;
		    if (guess_f) print_guessed_code(filename);
		}
		fclose(fin);
#ifdef OVERWRITE
		if (overwrite_f) {
		    struct stat     sb;
#if defined(MSDOS) && !defined(__MINGW32__) && !defined(__WIN32__) && !defined(__WATCOMC__) && !defined(__EMX__) && !defined(__OS2__) && !defined(__DJGPP__)
		    time_t tb[2];
#else
		    struct utimbuf  tb;
#endif

		    fflush(stdout);
		    close(fd);
		    if (dup2(fd_backup, fileno(stdout)) < 0){
			perror("dup2");
		    }
		    if (stat(origfname, &sb)) {
			fprintf(stderr, "Can't stat %s\n", origfname);
		    }
		    /* $B%Q!<%_%C%7%g%s$rI|85(B */
		    if (chmod(outfname, sb.st_mode)) {
			fprintf(stderr, "Can't set permission %s\n", outfname);
		    }

		    /* $B%?%$%`%9%?%s%W$rI|85(B */
		    if(preserve_time_f){
#if defined(MSDOS) && !defined(__MINGW32__) && !defined(__WIN32__) && !defined(__WATCOMC__) && !defined(__EMX__) && !defined(__OS2__) && !defined(__DJGPP__)
			tb[0] = tb[1] = sb.st_mtime;
			if (utime(outfname, tb)) {
			    fprintf(stderr, "Can't set timestamp %s\n", outfname);
			}
#else
			tb.actime  = sb.st_atime;
			tb.modtime = sb.st_mtime;
			if (utime(outfname, &tb)) {
			    fprintf(stderr, "Can't set timestamp %s\n", outfname);
			}
#endif
		    }
		    if(backup_f){
			char *backup_filename = get_backup_filename(backup_suffix, origfname);
#ifdef MSDOS
			unlink(backup_filename);
#endif
			if (rename(origfname, backup_filename)) {
			    perror(backup_filename);
			    fprintf(stderr, "Can't rename %s to %s\n",
				    origfname, backup_filename);
			}
			nkf_xfree(backup_filename);
		    }else{
#ifdef MSDOS
			if (unlink(origfname)){
			    perror(origfname);
			}
#endif
		    }
		    if (rename(outfname, origfname)) {
			perror(origfname);
			fprintf(stderr, "Can't rename %s to %s\n",
				outfname, origfname);
		    }
		    nkf_xfree(outfname);
		}
#endif
	    }
	}
	if (is_argument_error)
	    return(-1);
    }
#ifdef EASYWIN /*Easy Win */
    if (file_out_f == FALSE)
	scanf("%d",&end_check);
    else
	fclose(stdout);
#else /* for Other OS */
    if (file_out_f == TRUE)
	fclose(stdout);
#endif /*Easy Win */
    return (0);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x110, %rsp            # imm = 0x110
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq $0x0, -0x28(%rbp)
xorl %edi, %edi
leaq 0xf128(%rip), %rsi      # 0x1d532
callq 0xc1b0
callq 0xe9e0
movl -0x8(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x8(%rbp)
movq -0x10(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x10(%rbp)
xorl %eax, %eax
cmpl $0x0, -0x8(%rbp)
movb %al, -0x101(%rbp)
jle 0xe44d
movq -0x10(%rbp), %rax
movq (%rax), %rax
movsbl (%rax), %eax
cmpl $0x2d, %eax
sete %al
movb %al, -0x101(%rbp)
movb -0x101(%rbp), %al
testb $0x1, %al
jne 0xe459
jmp 0xe484
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rdi
callq 0xeaa0
movl -0x8(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x8(%rbp)
movq -0x10(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x10(%rbp)
jmp 0xe429
cmpl $0x0, 0x43f85(%rip)     # 0x52410
je 0xe4e4
movl 0x43f81(%rip), %eax     # 0x52414
movl %eax, -0x34(%rbp)
movl 0x43f7c(%rip), %eax     # 0x52418
movl %eax, -0x38(%rbp)
movl 0x43f77(%rip), %eax     # 0x5241c
movl %eax, -0x3c(%rbp)
movl 0x43f62(%rip), %eax     # 0x52410
movl %eax, -0x40(%rbp)
callq 0x10460
movl -0x40(%rbp), %eax
movl %eax, 0x43f51(%rip)     # 0x52410
movl $0x0, 0x43db7(%rip)     # 0x52280
movl -0x34(%rbp), %eax
movl %eax, 0x43f42(%rip)     # 0x52414
movl -0x38(%rbp), %eax
movl %eax, 0x43f3d(%rip)     # 0x52418
movl -0x3c(%rbp), %eax
movl %eax, 0x43f38(%rip)     # 0x5241c
cmpl $0x1, 0x43d99(%rip)     # 0x52284
jne 0xe4ed
cmpl $0x0, 0x43f2c(%rip)     # 0x52420
je 0xe50b
movq 0x43ad3(%rip), %rax     # 0x51fd0
movq (%rax), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0xc0a0
jmp 0xe528
movq 0x43abe(%rip), %rax     # 0x51fd0
movq (%rax), %rdi
leaq 0x43f14(%rip), %rsi     # 0x52430
xorl %edx, %edx
movl $0x4000, %ecx           # imm = 0x4000
callq 0xc1c0
cmpl $0x0, -0x8(%rbp)
jne 0xe596
cmpl $0x1, 0x43d4f(%rip)     # 0x52284
jne 0xe537
movq 0x43a9a(%rip), %rax     # 0x51fd8
movq (%rax), %rdi
leaq 0x47ee8(%rip), %rsi     # 0x56430
xorl %edx, %edx
movl $0x4000, %ecx           # imm = 0x4000
callq 0xc1c0
cmpl $0x0, 0x4bed5(%rip)     # 0x5a430
je 0xe56e
movq 0x43a74(%rip), %rax     # 0x51fd8
movq (%rax), %rdi
callq 0x10810
jmp 0xe591
movq 0x43a63(%rip), %rax     # 0x51fd8
movq (%rax), %rdi
callq 0x10870
cmpl $0x0, 0x43e8c(%rip)     # 0x52410
je 0xe58f
xorl %eax, %eax
movl %eax, %edi
callq 0x11b90
jmp 0xe591
jmp 0xe9b3
movl -0x8(%rbp), %eax
movl %eax, -0x44(%rbp)
movl $0x0, -0x48(%rbp)
movl -0x8(%rbp), %eax
movl %eax, %ecx
addl $-0x1, %ecx
movl %ecx, -0x8(%rbp)
cmpl $0x0, %eax
je 0xe9a2
movq $0x0, 0x4be76(%rip) # 0x5a438
movl $0x0, 0x4be74(%rip)     # 0x5a440
movq $0x0, 0x4be71(%rip) # 0x5a448
movq -0x10(%rbp), %rax
movq %rax, %rcx
addq $0x8, %rcx
movq %rcx, -0x10(%rbp)
movq (%rax), %rdi
movq %rdi, -0x30(%rbp)
leaq 0xeadd(%rip), %rsi      # 0x1d0d1
callq 0xc1e0
movq %rax, -0x18(%rbp)
cmpq $0x0, %rax
jne 0xe619
movq -0x10(%rbp), %rax
movq -0x8(%rax), %rdi
callq 0xc1f0
movl $0x1, -0x48(%rbp)
jmp 0xe5a3
movl $0x0, -0x4c(%rbp)
movl $0x0, -0x50(%rbp)
cmpl $0x1, 0x4be22(%rip)     # 0x5a450
jne 0xe760
cmpl $0x0, 0x4be19(%rip)     # 0x5a454
je 0xe6ec
movq -0x30(%rbp), %rdi
callq 0xc090
movq %rax, %rdi
addq $0xd, %rdi
addq $0x1, %rdi
callq 0x11d50
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rdi
movq -0x30(%rbp), %rsi
callq 0xc070
movq -0x28(%rbp), %rdi
leaq 0xe8cc(%rip), %rsi      # 0x1cf42
callq 0xc210
movq -0x28(%rbp), %rdi
callq 0xc190
movl %eax, -0x4c(%rbp)
cmpl $0x0, -0x4c(%rbp)
jl 0xe6d5
movq 0x4393c(%rip), %rax     # 0x51fd0
movq (%rax), %rdi
callq 0xc150
movl %eax, %edi
callq 0xc0d0
movl %eax, -0x50(%rbp)
cmpl $0x0, %eax
jl 0xe6d5
movl -0x4c(%rbp), %eax
movl %eax, -0x108(%rbp)
movq 0x43915(%rip), %rax     # 0x51fd0
movq (%rax), %rdi
callq 0xc150
movl -0x108(%rbp), %edi
movl %eax, %esi
callq 0xc0b0
cmpl $0x0, %eax
jge 0xe6ea
movq -0x30(%rbp), %rdi
callq 0xc1f0
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0xe9d2
jmp 0xe720
cmpl $0x1, -0x8(%rbp)
jne 0xe713
movq -0x10(%rbp), %rax
movq %rax, %rcx
addq $0x8, %rcx
movq %rcx, -0x10(%rbp)
movq (%rax), %rax
movq %rax, -0x28(%rbp)
movl -0x8(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x8(%rbp)
jmp 0xe71e
leaq 0xe836(%rip), %rax      # 0x1cf50
movq %rax, -0x28(%rbp)
jmp 0xe720
movq -0x28(%rbp), %rdi
movq 0x438a5(%rip), %rax     # 0x51fd0
movq (%rax), %rdx
leaq 0xea41(%rip), %rsi      # 0x1d176
callq 0xc0f0
cmpq $0x0, %rax
jne 0xe755
movq -0x28(%rbp), %rdi
callq 0xc1f0
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0xe9d2
cmpl $0x1, 0x43b28(%rip)     # 0x52284
jne 0xe75e
jmp 0xe760
cmpl $0x1, 0x43b1d(%rip)     # 0x52284
jne 0xe769
movq -0x18(%rbp), %rdi
leaq 0x47cbc(%rip), %rsi     # 0x56430
xorl %edx, %edx
movl $0x4000, %ecx           # imm = 0x4000
callq 0xc1c0
cmpl $0x0, 0x4bca9(%rip)     # 0x5a430
je 0xe794
movq -0x18(%rbp), %rdi
callq 0x10810
jmp 0xe7c7
movq $0x0, -0x58(%rbp)
movq -0x18(%rbp), %rdi
callq 0x10870
cmpl $0x1, -0x44(%rbp)
jle 0xe7b3
movq -0x30(%rbp), %rax
movq %rax, -0x58(%rbp)
cmpl $0x0, 0x43c56(%rip)     # 0x52410
je 0xe7c5
movq -0x58(%rbp), %rdi
callq 0x11b90
jmp 0xe7c7
movq -0x18(%rbp), %rdi
callq 0xc080
cmpl $0x0, 0x4bc7d(%rip)     # 0x5a454
je 0xe99b
movq 0x437ec(%rip), %rax     # 0x51fd0
movq (%rax), %rdi
callq 0xc170
movl -0x4c(%rbp), %edi
callq 0xc110
movl -0x50(%rbp), %eax
movl %eax, -0x10c(%rbp)
movq 0x437cc(%rip), %rax     # 0x51fd0
movq (%rax), %rdi
callq 0xc150
movl -0x10c(%rbp), %edi
movl %eax, %esi
callq 0xc0b0
cmpl $0x0, %eax
jge 0xe82a
leaq 0xe733(%rip), %rdi      # 0x1cf58
callq 0xc1f0
movq -0x30(%rbp), %rdi
leaq -0xe8(%rbp), %rsi
callq 0xc140
cmpl $0x0, %eax
je 0xe85b
movq 0x437b2(%rip), %rax     # 0x51ff8
movq (%rax), %rdi
movq -0x30(%rbp), %rdx
leaq 0xe709(%rip), %rsi      # 0x1cf5d
movb $0x0, %al
callq 0xc130
movq -0x28(%rbp), %rdi
movl -0xd0(%rbp), %esi
callq 0xc1d0
cmpl $0x0, %eax
je 0xe88b
movq 0x43782(%rip), %rax     # 0x51ff8
movq (%rax), %rdi
movq -0x28(%rbp), %rdx
leaq 0xe6e8(%rip), %rsi      # 0x1cf6c
movb $0x0, %al
callq 0xc130
cmpl $0x0, 0x4bbc6(%rip)     # 0x5a458
je 0xe8e3
movq -0xa0(%rbp), %rax
movq %rax, -0xf8(%rbp)
movq -0x90(%rbp), %rax
movq %rax, -0xf0(%rbp)
movq -0x28(%rbp), %rdi
leaq -0xf8(%rbp), %rsi
callq 0xc030
cmpl $0x0, %eax
je 0xe8e1
movq 0x4372c(%rip), %rax     # 0x51ff8
movq (%rax), %rdi
movq -0x28(%rbp), %rdx
leaq 0xe6ab(%rip), %rsi      # 0x1cf85
movb $0x0, %al
callq 0xc130
jmp 0xe8e3
cmpl $0x0, 0x4bb72(%rip)     # 0x5a45c
je 0xe955
movq 0x43995(%rip), %rdi     # 0x52288
movq -0x30(%rbp), %rsi
callq 0x11da0
movq %rax, -0x100(%rbp)
movq -0x30(%rbp), %rdi
movq -0x100(%rbp), %rsi
callq 0xc200
cmpl $0x0, %eax
je 0xe947
movq -0x100(%rbp), %rdi
callq 0xc1f0
movq 0x436cd(%rip), %rax     # 0x51ff8
movq (%rax), %rdi
movq -0x30(%rbp), %rdx
movq -0x100(%rbp), %rcx
leaq 0xe65d(%rip), %rsi      # 0x1cf9d
movb $0x0, %al
callq 0xc130
movq -0x100(%rbp), %rdi
callq 0xc040
jmp 0xe957
jmp 0xe957
movq -0x28(%rbp), %rdi
movq -0x30(%rbp), %rsi
callq 0xc200
cmpl $0x0, %eax
je 0xe992
movq -0x30(%rbp), %rdi
callq 0xc1f0
movq 0x4367f(%rip), %rax     # 0x51ff8
movq (%rax), %rdi
movq -0x28(%rbp), %rdx
movq -0x30(%rbp), %rcx
leaq 0xe612(%rip), %rsi      # 0x1cf9d
movb $0x0, %al
callq 0xc130
movq -0x28(%rbp), %rdi
callq 0xc040
jmp 0xe99d
jmp 0xe5a3
cmpl $0x0, -0x48(%rbp)
je 0xe9b1
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0xe9d2
jmp 0xe9b3
cmpl $0x1, 0x4ba96(%rip)     # 0x5a450
jne 0xe9cb
movq 0x4360d(%rip), %rax     # 0x51fd0
movq (%rax), %rdi
callq 0xc080
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x110, %rsp            # imm = 0x110
popq %rbp
retq
nop