// File: /workspace/github_c_makefile_star2_O2/jelaas[P]egetty/egetty.c
// Function: login
pid_t login(int *fd)
{
	pid_t pid;
	int amaster, tty, rc=0;
	char name[256];

	pid = forkpty(&amaster, name,
		      NULL, NULL);
	if(pid == 0) {
		/* child */
		if(conf.kmsg) {
			if ((rc=ioctl(0, TIOCCONS, 0))) {
				if(conf.debug) {
					putfd(1, "TIOCCONS: ");
					putfd(1, strerror(errno));
				}
				if (errno == EBUSY) {
					tty = open("/dev/tty0", O_WRONLY);
					if (tty >= 0) {
						if ((rc=ioctl(tty, TIOCCONS, 0))==0) {
							rc=ioctl(0, TIOCCONS, 0);
							if(conf.debug && rc) {
								putfd(1, "TIOCCONS: ");
								putfd(1, strerror(errno));
							}
						}
						close(tty);
					} else
						rc = -1;
				}
			}
			if(conf.debug) {
				if(rc)
					putfd(1, "failed to redirect console\n");
				else
					putfd(1, "redirected console\n");
			}
		}

		char *argv[]={"/bin/login", "--", 0, 0};
		(void) execve( argv[0], argv, envp );
		printf("execve failed\n");
		exit(1);
	}
	if(pid == -1) return -1;
	*fd = amaster;

	return pid;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
subq $0x138, %rsp            # imm = 0x138
movq %rdi, %rbx
leaq 0xc(%rsp), %rdi
leaq 0x30(%rsp), %rsi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x455280
cmpl $-0x1, %eax
je 0x401745
testl %eax, %eax
je 0x401753
movl 0xc(%rsp), %ecx
movl %ecx, (%rbx)
addq $0x138, %rsp            # imm = 0x138
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
cmpl $0x0, 0xd3bbe(%rip)     # 0x4d5318
je 0x401877
movl $0x541d, %esi           # imm = 0x541D
xorl %edi, %edi
xorl %edx, %edx
xorl %eax, %eax
callq 0x451650
movl 0xd3baa(%rip), %ecx     # 0x4d5320
testl %eax, %eax
jne 0x401787
testl %ecx, %ecx
jne 0x40185f
jmp 0x401877
testl %ecx, %ecx
jne 0x401795
callq 0x404e40
movq %rax, %rbx
jmp 0x4017bf
leaq 0xa0896(%rip), %rsi     # 0x4a2032
pushq $0x1
popq %rbp
movl %ebp, %edi
callq 0x4016e8
callq 0x404e40
movq %rax, %rbx
movl (%rax), %edi
callq 0x4232f0
movl %ebp, %edi
movq %rax, %rsi
callq 0x4016e8
cmpl $0x10, (%rbx)
jne 0x40183c
leaq 0xa0872(%rip), %rdi     # 0x4a203d
xorl %r15d, %r15d
pushq $0x1
popq %rbp
movl %ebp, %esi
xorl %eax, %eax
callq 0x4507d0
testl %eax, %eax
js 0x401851
movl %eax, %r14d
movl $0x541d, %esi           # imm = 0x541D
movl %eax, %edi
xorl %edx, %edx
xorl %eax, %eax
callq 0x451650
testl %eax, %eax
jne 0x401841
movl $0x541d, %esi           # imm = 0x541D
xorl %edi, %edi
xorl %edx, %edx
xorl %eax, %eax
callq 0x451650
cmpl $0x0, 0xd3b14(%rip)     # 0x4d5320
setne %cl
testl %eax, %eax
setne %dl
andb %cl, %dl
cmpb $0x1, %dl
jne 0x401841
leaq 0xa0810(%rip), %rsi     # 0x4a2032
movl %ebp, %edi
callq 0x4016e8
movl (%rbx), %edi
callq 0x4232f0
movl %ebp, %edi
movq %rax, %rsi
callq 0x4016e8
jmp 0x401843
xorl %r15d, %r15d
jmp 0x401851
movl %eax, %ebp
movl %r14d, %edi
callq 0x450a70
testl %ebp, %ebp
sete %r15b
cmpl $0x0, 0xd3ac8(%rip)     # 0x4d5320
je 0x401877
testb %r15b, %r15b
je 0x401868
leaq 0xa07fd(%rip), %rsi     # 0x4a2063
jmp 0x40186f
leaq 0xa07d8(%rip), %rsi     # 0x4a2047
pushq $0x1
popq %rdi
callq 0x4016e8
movaps 0xd0132(%rip), %xmm0    # 0x4d19b0
leaq 0x10(%rsp), %rsi
movaps %xmm0, 0x10(%rsi)
movaps 0xd0112(%rip), %xmm0    # 0x4d19a0
movaps %xmm0, (%rsi)
movq 0xd3aa8(%rip), %rdx     # 0x4d5340
leaq 0xa07d8(%rip), %rdi     # 0x4a2077
callq 0x44ff40
leaq 0xa0926(%rip), %rdi     # 0x4a21d1
callq 0x413620
pushq $0x1
popq %rdi
callq 0x40b760