#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */
typedef int /*<<< orphan*/ pid_t;

/* Variables and functions */
int /*<<< orphan*/ execv(char *, char **);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ print_banner(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ setsid();
int /*<<< orphan*/ stdin;
int strlen(char *);
int /*<<< orphan*/ tcsetpgrp(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ ttyname(int /*<<< orphan*/);
int main(int argc, char *argv[], char *envp[]) {
  print_banner(ttyname(0));
  char name[30];
  fgets(name, 30, stdin);
  name[strlen(name) - 1] = '\0';
  char *login_argv[] = {name, NULL};
  pid_t pgrp = setsid();
  tcsetpgrp(0, pgrp);
  execv("/usr/bin/login", login_argv);
  printf("getty: can't exec!\n");
  while (1)
    ;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
xor    %edi,%edi
call   1070 <ttyname@plt>
mov    %eax,%edi
call   1090 <print_banner@plt>
lea    -0x40(%rbp),%rdi
mov    0x2e35(%rip),%rax
mov    (%rax),%edx
mov    $0x1e,%esi
call   1060 <fgets@plt>
lea    -0x40(%rbp),%rdi
call   1030 <strlen@plt>
sub    $0x1,%eax
cltq
movb   $0x0,-0x40(%rbp,%rax,1)
lea    -0x40(%rbp),%rax
mov    %rax,-0x50(%rbp)
movq   $0x0,-0x48(%rbp)
mov    $0x0,%al
call   1050 <setsid@plt>
mov    %eax,-0x54(%rbp)
mov    -0x54(%rbp),%esi
xor    %edi,%edi
call   1080 <tcsetpgrp@plt>
lea    -0x50(%rbp),%rsi
lea    0xdff(%rip),%rdi
call   10a0 <execv@plt>
lea    0xe02(%rip),%rdi
call   1040 <printf@plt>
jmp    1212 <main+0x92>

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x30,%rsp
xor    %edi,%edi
call   1070 <ttyname@plt>
mov    %eax,%edi
call   1090 <print_banner@plt>
mov    0x2e4e(%rip),%rax
mov    (%rax),%edx
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x1e,%esi
call   1060 <fgets@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%rbx,1)
mov    %rbx,(%rsp)
movq   $0x0,0x8(%rsp)
xor    %eax,%eax
call   1050 <setsid@plt>
xor    %edi,%edi
mov    %eax,%esi
call   1080 <tcsetpgrp@plt>
lea    0xe1f(%rip),%rdi
mov    %rsp,%rsi
call   10a0 <execv@plt>
lea    0xe1f(%rip),%rdi
call   1030 <puts@plt>
cs nopw 0x0(%rax,%rax,1)
nop
jmp    1200 <main+0x80>

LLVM IR (-O0):
@stdin = global i32 0
@.str = [15 x i8] c"/usr/bin/login\00"
@.str.1 = [20 x i8] c"getty: can't exec!\0A\00"
define i32 @main(i32 %0, i8** %1, i8** %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8**
%7 = alloca i8**
%8 = alloca [30 x i8]
%9 = alloca [2 x i8*]
%10 = alloca i32
store i32 0, i32* %4
store i32 %0, i32* %5
store i8** %1, i8*** %6
store i8** %2, i8*** %7
%11 = call i32 @ttyname(i32 0)
%12 = call i32 @print_banner(i32 %11)
%13 = getelementptr inbounds [30 x i8], [30 x i8]* %8, i64 0, i64 0
%14 = load i32, i32* @stdin
%15 = call i32 @fgets(i8* %13, i32 30, i32 %14)
%16 = getelementptr inbounds [30 x i8], [30 x i8]* %8, i64 0, i64 0
%17 = call i32 @strlen(i8* %16)
%18 = sub nsw i32 %17, 1
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds [30 x i8], [30 x i8]* %8, i64 0, i64 %19
store i8 0, i8* %20
%21 = getelementptr inbounds [2 x i8*], [2 x i8*]* %9, i64 0, i64 0
%22 = getelementptr inbounds [30 x i8], [30 x i8]* %8, i64 0, i64 0
store i8* %22, i8** %21
%23 = getelementptr inbounds i8*, i8** %21, i64 1
store i8* null, i8** %23
%24 = call i32 (...) @setsid()
store i32 %24, i32* %10
%25 = load i32, i32* %10
%26 = call i32 @tcsetpgrp(i32 0, i32 %25)
%27 = getelementptr inbounds [2 x i8*], [2 x i8*]* %9, i64 0, i64 0
%28 = call i32 @execv(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8** %27)
%29 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
br label %30
30: ; preds = %3, %30
br label %30
}

LLVM IR (-O2):
@stdin = global i32 0
@.str = [15 x i8] c"/usr/bin/login\00"
@str = [19 x i8] c"getty: can't exec!\00"
define i32 @main(i32 %0, i8** nocapture readnone %1, i8** nocapture readnone %2) {
%4 = alloca [30 x i8]
%5 = alloca [2 x i8*]
%6 = tail call i32 @ttyname(i32 0)
%7 = tail call i32 @print_banner(i32 %6)
%8 = getelementptr inbounds [30 x i8], [30 x i8]* %4, i64 0, i64 0
%9 = load i32, i32* @stdin
%10 = call i32 @fgets(i8* %8, i32 30, i32 %9)
%11 = call i32 @strlen(i8* %8)
%12 = add nsw i32 %11, -1
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds [30 x i8], [30 x i8]* %4, i64 0, i64 %13
store i8 0, i8* %14
%15 = bitcast [2 x i8*]* %5 to i8*
%16 = getelementptr inbounds [2 x i8*], [2 x i8*]* %5, i64 0, i64 0
store i8* %8, i8** %16
%17 = getelementptr inbounds [2 x i8*], [2 x i8*]* %5, i64 0, i64 1
store i8* null, i8** %17
%18 = call i32 (...) @setsid()
%19 = call i32 @tcsetpgrp(i32 0, i32 %18)
%20 = call i32 @execv(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8** %16)
%21 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str, i64 0, i64 0))
br label %22
22: ; preds = %22, %3
br label %22
}