// File: /workspace/github_c_makefile_star2_O1/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 0x401897
movl $0x541d, %esi           # imm = 0x541D
xorl %edi, %edi
xorl %edx, %edx
xorl %eax, %eax
callq 0x4517d0
movb $0x1, %bpl
testl %eax, %eax
je 0x401860
cmpl $0x0, 0xd3ba2(%rip)     # 0x4d5320
je 0x4017af
leaq 0xa08ab(%rip), %rsi     # 0x4a2032
movl $0xa, %edx
movl $0x1, %edi
callq 0x450b20
callq 0x404fa0
movl (%rax), %edi
callq 0x423450
movl $0x1, %edi
movq %rax, %rsi
callq 0x4016e8
callq 0x404fa0
cmpl $0x10, (%rax)
jne 0x40184d
movq %rax, %r14
leaq 0xa0876(%rip), %rdi     # 0x4a203d
xorl %ebp, %ebp
movl $0x1, %esi
xorl %eax, %eax
callq 0x450950
testl %eax, %eax
js 0x401860
movl %eax, %ebx
movl $0x541d, %esi           # imm = 0x541D
movl %eax, %edi
xorl %edx, %edx
xorl %eax, %eax
callq 0x4517d0
testl %eax, %eax
jne 0x401851
movl $0x541d, %esi           # imm = 0x541D
xorl %edi, %edi
xorl %edx, %edx
xorl %eax, %eax
callq 0x4517d0
movl %eax, %ebp
cmpl $0x0, 0xd3b14(%rip)     # 0x4d5320
setne %al
testl %ebp, %ebp
setne %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0x401853
leaq 0xa0810(%rip), %rsi     # 0x4a2032
movl $0x1, %ebp
movl $0xa, %edx
movl $0x1, %edi
callq 0x450b20
movl (%r14), %edi
callq 0x423450
movl $0x1, %edi
movq %rax, %rsi
callq 0x4016e8
jmp 0x401853
xorl %ebp, %ebp
jmp 0x401860
movl %eax, %ebp
movl %ebx, %edi
callq 0x450bf0
testl %ebp, %ebp
sete %bpl
cmpl $0x0, 0xd3ab9(%rip)     # 0x4d5320
je 0x401897
movl %ebp, %eax
xorb $0x1, %al
movzbl %al, %eax
leaq 0x13(,%rax,8), %rdx
leaq 0xa07e4(%rip), %rax     # 0x4a2063
leaq 0xa07c1(%rip), %rsi     # 0x4a2047
testb %bpl, %bpl
cmovneq %rax, %rsi
movl $0x1, %edi
callq 0x450b20
movaps 0xd0102(%rip), %xmm0    # 0x4d19a0
leaq 0x10(%rsp), %rsi
movaps %xmm0, (%rsi)
movaps 0xd0103(%rip), %xmm0    # 0x4d19b0
movaps %xmm0, 0x10(%rsi)
movq (%rsi), %rdi
movq 0xd3a85(%rip), %rdx     # 0x4d5340
callq 0x4500c0
leaq 0xa090a(%rip), %rdi     # 0x4a21d1
callq 0x413780
movl $0x1, %edi
callq 0x40b8c0