#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 scalar_t__ pid_t;

/* Variables and functions */
int /*<<< orphan*/ execlp(char *, char *, char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ print_issue(char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ scanf(char *, char *);
scalar_t__ setsid();
int /*<<< orphan*/ stderr;
scalar_t__ strlen(char *);
int /*<<< orphan*/ tty_open(char *);
int /*<<< orphan*/ usage();
int main(int argc, char *argv[], char *envp[]) {
  char username[80];
  pid_t pid;
  if (argc < 2) {
    usage();
    return 0;
  }
  pid = setsid();
  if (pid < 0) {
    fprintf(stderr, "getty: already a group leader!\n");
    return 255;
  }
  if (!tty_open(argv[1])) {
    return 255;
  }
  print_issue(argv[1]);
  while (strlen(username) == 0) {
    printf("login: ");
    scanf("%s", username);
  }
  execlp("/sbin/login", "/sbin/login", username, NULL);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    11ca <main+0x3a>
mov    $0x0,%al
call   1080 <usage@plt>
movl   $0x0,-0x4(%rbp)
jmp    1282 <main+0xf2>
mov    $0x0,%al
call   1050 <setsid@plt>
mov    %rax,-0x78(%rbp)
cmpq   $0x0,-0x78(%rbp)
jge    1201 <main+0x71>
mov    0x2df9(%rip),%rax
mov    (%rax),%edi
lea    0xe10(%rip),%rsi
call   1060 <fprintf@plt>
movl   $0xff,-0x4(%rbp)
jmp    1282 <main+0xf2>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10a0 <tty_open@plt>
cmp    $0x0,%eax
jne    1223 <main+0x93>
movl   $0xff,-0x4(%rbp)
jmp    1282 <main+0xf2>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1070 <print_issue@plt>
lea    -0x70(%rbp),%rdi
call   1030 <strlen@plt>
cmp    $0x0,%rax
jne    1264 <main+0xd4>
lea    0xdd6(%rip),%rdi
call   1040 <printf@plt>
lea    -0x70(%rbp),%rsi
lea    0xdce(%rip),%rdi
call   1090 <scanf@plt>
jmp    1230 <main+0xa0>
lea    -0x70(%rbp),%rdx
lea    0xdbc(%rip),%rsi
xor    %eax,%eax
mov    %eax,%ecx
mov    %rsi,%rdi
call   10b0 <execlp@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x50,%rsp
cmp    $0x1,%edi
jg     1175 <main+0x15>
xor    %ebx,%ebx
xor    %eax,%eax
call   1060 <usage@plt>
jmp    11cc <main+0x6c>
mov    %rsi,%rbx
xor    %eax,%eax
call   1030 <setsid@plt>
test   %rax,%rax
js     11b2 <main+0x52>
mov    0x8(%rbx),%rdi
call   1070 <tty_open@plt>
test   %eax,%eax
je     11c7 <main+0x67>
mov    0x8(%rbx),%rdi
call   1050 <print_issue@plt>
lea    0xe7f(%rip),%rdi
xor    %ebx,%ebx
mov    %rsp,%rdx
mov    %rdi,%rsi
xor    %ecx,%ecx
call   1080 <execlp@plt>
jmp    11cc <main+0x6c>
mov    0x2e27(%rip),%rax
mov    (%rax),%edi
lea    0xe3e(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0xff,%ebx
mov    %ebx,%eax
add    $0x50,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [32 x i8] c"getty: already a group leader!\0A\00"
@.str.1 = [8 x i8] c"login: \00"
@.str.2 = [3 x i8] c"%s\00"
@.str.3 = [12 x i8] c"/sbin/login\00"
define i32 @main(i32 %0, i8** %1, i8** %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8**
%7 = alloca i8**
%8 = alloca [80 x i8]
%9 = alloca i64
store i32 0, i32* %4
store i32 %0, i32* %5
store i8** %1, i8*** %6
store i8** %2, i8*** %7
%10 = load i32, i32* %5
%11 = icmp slt i32 %10, 2
br i1 %11, label %12, label %14
12: ; preds = %3
%13 = call i32 (...) @usage()
store i32 0, i32* %4
br label %44
14: ; preds = %3
%15 = call i64 (...) @setsid()
store i64 %15, i64* %9
%16 = load i64, i64* %9
%17 = icmp slt i64 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %14
%19 = load i32, i32* @stderr
%20 = call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
store i32 255, i32* %4
br label %44
21: ; preds = %14
%22 = load i8**, i8*** %6
%23 = getelementptr inbounds i8*, i8** %22, i64 1
%24 = load i8*, i8** %23
%25 = call i32 @tty_open(i8* %24)
%26 = icmp ne i32 %25, 0
br i1 %26, label %28, label %27
27: ; preds = %21
store i32 255, i32* %4
br label %44
28: ; preds = %21
%29 = load i8**, i8*** %6
%30 = getelementptr inbounds i8*, i8** %29, i64 1
%31 = load i8*, i8** %30
%32 = call i32 @print_issue(i8* %31)
br label %33
33: ; preds = %37, %28
%34 = getelementptr inbounds [80 x i8], [80 x i8]* %8, i64 0, i64 0
%35 = call i64 @strlen(i8* %34)
%36 = icmp eq i64 %35, 0
br i1 %36, label %37, label %41
37: ; preds = %33
%38 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%39 = getelementptr inbounds [80 x i8], [80 x i8]* %8, i64 0, i64 0
%40 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %39)
br label %33
41: ; preds = %33
%42 = getelementptr inbounds [80 x i8], [80 x i8]* %8, i64 0, i64 0
%43 = call i32 @execlp(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i8* %42, i32* null)
store i32 0, i32* %4
br label %44
44: ; preds = %41, %27, %18, %12
%45 = load i32, i32* %4
ret i32 %45
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [32 x i8] c"getty: already a group leader!\0A\00"
@.str.3 = [12 x i8] c"/sbin/login\00"
define i32 @main(i32 %0, i8** nocapture %1, i8** nocapture readnone %2) {
%4 = alloca [80 x i8]
%5 = getelementptr inbounds [80 x i8], [80 x i8]* %4, i64 0, i64 0
%6 = icmp slt i32 %0, 2
br i1 %6, label %7, label %9
7: ; preds = %3
%8 = tail call i32 (...) @usage()
br label %24
9: ; preds = %3
%10 = tail call i64 (...) @setsid()
%11 = icmp slt i64 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %9
%13 = load i32, i32* @stderr
%14 = tail call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
br label %24
15: ; preds = %9
%16 = getelementptr inbounds i8*, i8** %1, i64 1
%17 = load i8*, i8** %16
%18 = tail call i32 @tty_open(i8* %17)
%19 = icmp eq i32 %18, 0
br i1 %19, label %24, label %20
20: ; preds = %15
%21 = load i8*, i8** %16
%22 = tail call i32 @print_issue(i8* %21)
%23 = call i32 @execlp(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i8* %5, i32* null)
br label %24
24: ; preds = %15, %20, %12, %7
%25 = phi i32 [ 0, %7 ], [ 255, %12 ], [ 0, %20 ], [ 255, %15 ]
ret i32 %25
}