// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x140, %rsp            # imm = 0x140
movq %rdi, -0x10(%rbp)
movl $0x0, -0x20(%rbp)
leaq -0x120(%rbp), %rsi
leaq -0x18(%rbp), %rdi
xorl %eax, %eax
movl %eax, %ecx
movq %rcx, %rdx
callq 0x4557d0
movl %eax, -0x14(%rbp)
cmpl $0x0, -0x14(%rbp)
jne 0x40190d
cmpl $0x0, 0xd3bc7(%rip)     # 0x4d5338
je 0x4018a3
xorl %edx, %edx
movl $0x541d, %esi           # imm = 0x541D
movl %edx, %edi
movb $0x0, %al
callq 0x451b90
movl %eax, -0x20(%rbp)
cmpl $0x0, %eax
je 0x40186c
cmpl $0x0, 0xd3ba6(%rip)     # 0x4d5340
je 0x4017c6
movl $0x1, %edi
leaq 0xa0862(%rip), %rsi     # 0x4a200a
callq 0x4016e0
callq 0x405690
movl (%rax), %edi
callq 0x423810
movq %rax, %rsi
movl $0x1, %edi
callq 0x4016e0
callq 0x405690
cmpl $0x10, (%rax)
jne 0x40186a
leaq 0xa083a(%rip), %rdi     # 0x4a2015
movl $0x1, %esi
movb $0x0, %al
callq 0x450d10
movl %eax, -0x1c(%rbp)
cmpl $0x0, -0x1c(%rbp)
jl 0x401861
movl -0x1c(%rbp), %edi
movl $0x541d, %esi           # imm = 0x541D
xorl %edx, %edx
movb $0x0, %al
callq 0x451b90
movl %eax, -0x20(%rbp)
cmpl $0x0, %eax
jne 0x401857
xorl %edx, %edx
movl $0x541d, %esi           # imm = 0x541D
movl %edx, %edi
movb $0x0, %al
callq 0x451b90
movl %eax, -0x20(%rbp)
cmpl $0x0, 0xd3b1d(%rip)     # 0x4d5340
je 0x401855
cmpl $0x0, -0x20(%rbp)
je 0x401855
movl $0x1, %edi
leaq 0xa07d3(%rip), %rsi     # 0x4a200a
callq 0x4016e0
callq 0x405690
movl (%rax), %edi
callq 0x423810
movq %rax, %rsi
movl $0x1, %edi
callq 0x4016e0
jmp 0x401857
movl -0x1c(%rbp), %edi
callq 0x450fb0
jmp 0x401868
movl $0xffffffff, -0x20(%rbp) # imm = 0xFFFFFFFF
jmp 0x40186a
jmp 0x40186c
cmpl $0x0, 0xd3acd(%rip)     # 0x4d5340
je 0x4018a1
cmpl $0x0, -0x20(%rbp)
je 0x40188e
movl $0x1, %edi
leaq 0xa0798(%rip), %rsi     # 0x4a201f
callq 0x4016e0
jmp 0x40189f
movl $0x1, %edi
leaq 0xa07a1(%rip), %rsi     # 0x4a203b
callq 0x4016e0
jmp 0x4018a1
jmp 0x4018a3
movq 0xd00f6(%rip), %rax     # 0x4d19a0
movq %rax, -0x140(%rbp)
movq 0xd00f0(%rip), %rax     # 0x4d19a8
movq %rax, -0x138(%rbp)
movq 0xd00ea(%rip), %rax     # 0x4d19b0
movq %rax, -0x130(%rbp)
movq 0xd00e4(%rip), %rax     # 0x4d19b8
movq %rax, -0x128(%rbp)
movq -0x140(%rbp), %rdi
leaq -0x140(%rbp), %rsi
movq 0xd3a70(%rip), %rdx     # 0x4d5360
callq 0x450480
leaq 0xa0761(%rip), %rdi     # 0x4a205d
movb $0x0, %al
callq 0x40d110
movl $0x1, %edi
callq 0x40bfb0
cmpl $-0x1, -0x14(%rbp)
jne 0x40191c
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x40192b
movl -0x18(%rbp), %ecx
movq -0x10(%rbp), %rax
movl %ecx, (%rax)
movl -0x14(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x140, %rsp            # imm = 0x140
popq %rbp
retq
nopw (%rax,%rax)