// File: /workspace/github_c_makefile_star2_O3/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 %r14
pushq %rbx
subq $0x130, %rsp            # imm = 0x130
movq %rdi, %rbx
leaq 0xc(%rsp), %rdi
leaq 0x30(%rsp), %rsi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x455400
cmpl $-0x1, %eax
je 0x401743
testl %eax, %eax
je 0x40174f
movl 0xc(%rsp), %ecx
movl %ecx, (%rbx)
addq $0x130, %rsp            # imm = 0x130
popq %rbx
popq %r14
popq %rbp
retq
cmpl $0x0, 0xd3bc2(%rip)     # 0x4d5318
je 0x4018a4
movl $0x541d, %esi           # imm = 0x541D
xorl %edi, %edi
xorl %edx, %edx
xorl %eax, %eax
callq 0x4517d0
movl 0xd3bae(%rip), %ecx     # 0x4d5320
testl %eax, %eax
jne 0x401783
testl %ecx, %ecx
jne 0x401880
jmp 0x4018a4
testl %ecx, %ecx
jne 0x401791
callq 0x404fb0
movq %rax, %rbx
jmp 0x4017c3
leaq 0xa089a(%rip), %rsi     # 0x4a2032
movl $0xa, %edx
movl $0x1, %edi
callq 0x450b20
callq 0x404fb0
movq %rax, %rbx
movl (%rax), %edi
callq 0x423460
movl $0x1, %edi
movq %rax, %rsi
callq 0x4016e8
cmpl $0x10, (%rbx)
jne 0x40185c
leaq 0xa086a(%rip), %rdi     # 0x4a203d
xorl %r14d, %r14d
movl $0x1, %esi
xorl %eax, %eax
callq 0x450950
testl %eax, %eax
js 0x401872
movl %eax, %ebp
movl $0x541d, %esi           # imm = 0x541D
movl %eax, %edi
xorl %edx, %edx
xorl %eax, %eax
callq 0x4517d0
testl %eax, %eax
jne 0x401861
movl $0x541d, %esi           # imm = 0x541D
xorl %edi, %edi
xorl %edx, %edx
xorl %eax, %eax
callq 0x4517d0
movl %eax, %r14d
cmpl $0x0, 0xd3b06(%rip)     # 0x4d5320
setne %al
testl %r14d, %r14d
setne %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0x401864
leaq 0xa0801(%rip), %rsi     # 0x4a2032
movl $0x1, %r14d
movl $0xa, %edx
movl $0x1, %edi
callq 0x450b20
movl (%rbx), %edi
callq 0x423460
movl $0x1, %edi
movq %rax, %rsi
callq 0x4016e8
jmp 0x401864
xorl %r14d, %r14d
jmp 0x401872
movl %eax, %r14d
movl %ebp, %edi
callq 0x450bf0
testl %r14d, %r14d
sete %r14b
cmpl $0x0, 0xd3aa7(%rip)     # 0x4d5320
je 0x4018a4
testb %r14b, %r14b
je 0x40188e
leaq 0xa07dc(%rip), %rsi     # 0x4a2063
movl $0x13, %edx
jmp 0x40189a
leaq 0xa07b2(%rip), %rsi     # 0x4a2047
movl $0x1b, %edx
movl $0x1, %edi
callq 0x450b20
movaps 0xd0105(%rip), %xmm0    # 0x4d19b0
leaq 0x10(%rsp), %rsi
movaps %xmm0, 0x10(%rsi)
movaps 0xd00e5(%rip), %xmm0    # 0x4d19a0
movaps %xmm0, (%rsi)
movq 0xd3a7b(%rip), %rdx     # 0x4d5340
leaq 0xa07ab(%rip), %rdi     # 0x4a2077
callq 0x4500c0
leaq 0xa08f9(%rip), %rdi     # 0x4a21d1
callq 0x413790
movl $0x1, %edi
callq 0x40b8d0