#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 */
struct passwd {
  int dummy;
};
typedef int /*<<< orphan*/ sigset_t;

/* Variables and functions */
int PATH_MAX;
int /*<<< orphan*/ SIG_SETMASK;
int /*<<< orphan*/ STDIN_FILENO;
char *basename(char *);
struct passwd *do_auth(int /*<<< orphan*/ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ gethostname(char *, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ run_shell(struct passwd *, int);
char *shortname(int /*<<< orphan*/);
int /*<<< orphan*/ sigfillset(int /*<<< orphan*/ *);
int /*<<< orphan*/ sigprocmask(int /*<<< orphan*/, int /*<<< orphan*/ *,
                               int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strdup(char *);
scalar_t__ ttyname_r(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ write_utmp(struct passwd *);
int main(int argc, char *argv[], char *env[]) {
  sigset_t set;
  sigfillset(&set);
  sigprocmask(SIG_SETMASK, &set, NULL);
  char hostname[300];
  gethostname(hostname, 300);
  char *sname = shortname(strdup(hostname));
  char tty_buf[PATH_MAX];
  char *tty = "";
  if (ttyname_r(STDIN_FILENO, tty_buf, PATH_MAX) == 0) {
    tty = basename(tty_buf);
  }
  printf("\033[H\033[J");
  while (true) {
    printf("\nxelix %s\n\n%s ", tty, sname);
    struct passwd *pwd = do_auth(NULL);
    if (pwd) {
      write_utmp(pwd);
      run_shell(pwd, true);
    } else {
      fprintf(stderr, "Login incorrect.\n");
    }
  }
  free(sname);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x190,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
lea    -0x1c(%rbp),%rdi
mov    %rdi,-0x190(%rbp)
call   10a0 <sigfillset@plt>
mov    -0x190(%rbp),%rsi
mov    0x2de5(%rip),%rax
mov    (%rax),%edi
xor    %eax,%eax
mov    %eax,%edx
call   1030 <sigprocmask@plt>
lea    -0x150(%rbp),%rdi
mov    %rdi,-0x188(%rbp)
mov    $0x12c,%esi
call   10d0 <gethostname@plt>
mov    -0x188(%rbp),%rdi
call   10e0 <strdup@plt>
mov    %eax,%edi
call   1060 <shortname@plt>
mov    %rax,-0x158(%rbp)
mov    0x2db1(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x160(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rsi
sub    %rcx,%rsi
mov    %rsi,-0x180(%rbp)
mov    %rsi,%rsp
mov    %rax,-0x168(%rbp)
lea    0xdb3(%rip),%rax
mov    %rax,-0x170(%rbp)
mov    0x2d46(%rip),%rax
mov    (%rax),%edi
mov    0x2d65(%rip),%rax
mov    (%rax),%edx
call   10c0 <ttyname_r@plt>
cmp    $0x0,%rax
jne    12af <main+0xef>
mov    -0x180(%rbp),%rdi
call   1080 <basename@plt>
mov    %rax,-0x170(%rbp)
lea    0xd4a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    12c2 <main+0x102>
mov    -0x170(%rbp),%rsi
mov    -0x158(%rbp),%rdx
lea    0xd30(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1040 <do_auth@plt>
mov    %rax,-0x178(%rbp)
cmpq   $0x0,-0x178(%rbp)
je     131e <main+0x15e>
mov    -0x178(%rbp),%rdi
call   1090 <write_utmp@plt>
mov    -0x178(%rbp),%rdi
mov    $0x1,%esi
call   10b0 <run_shell@plt>
jmp    1333 <main+0x173>
mov    0x2cab(%rip),%rax
mov    (%rax),%edi
lea    0xce8(%rip),%rsi
call   1070 <fprintf@plt>
jmp    12bd <main+0xfd>

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x138,%rsp
lea    -0x2c(%rbp),%rbx
mov    %rbx,%rdi
call   10a0 <sigfillset@plt>
mov    0x2df9(%rip),%rax
mov    (%rax),%edi
mov    %rbx,%rsi
xor    %edx,%edx
call   1030 <sigprocmask@plt>
lea    -0x160(%rbp),%rbx
mov    %rbx,%rdi
mov    $0x12c,%esi
call   10d0 <gethostname@plt>
mov    %rbx,%rdi
call   10e0 <strdup@plt>
mov    %eax,%edi
call   1060 <shortname@plt>
mov    %rax,%r14
mov    0x2dd0(%rip),%rax
mov    (%rax),%edx
mov    %rsp,%rbx
mov    %rdx,%rax
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    0x2d8b(%rip),%rax
mov    (%rax),%edi
mov    %rbx,%rsi
call   10c0 <ttyname_r@plt>
test   %rax,%rax
je     1255 <main+0x95>
lea    0xdd4(%rip),%r13
jmp    1260 <main+0xa0>
mov    %rbx,%rdi
call   1080 <basename@plt>
mov    %rax,%r13
lea    0xd99(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xd92(%rip),%r15
lea    0xd9a(%rip),%r12
jmp    1291 <main+0xd1>
xchg   %ax,%ax
mov    0x2d49(%rip),%rax
mov    (%rax),%edi
mov    %r12,%rsi
call   1070 <fprintf@plt>
mov    %r15,%rdi
mov    %r13,%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
xor    %edi,%edi
call   1040 <do_auth@plt>
test   %rax,%rax
je     1280 <main+0xc0>
mov    %rax,%rbx
mov    %rax,%rdi
call   1090 <write_utmp@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
call   10b0 <run_shell@plt>
jmp    1291 <main+0xd1>

LLVM IR (-O0):
%struct.passwd = type { i32 }
@SIG_SETMASK = global i32 0
@PATH_MAX = global i32 0
@.str = [1 x i8] zeroinitializer
@STDIN_FILENO = global i32 0
@.str.1 = [7 x i8] c"\1B[H\1B[J\00"
@.str.2 = [15 x i8] c"\0Axelix %s\0A\0A%s \00"
@stderr = global i32 0
@.str.3 = [18 x i8] c"Login incorrect.\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 i32
%9 = alloca [300 x i8]
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i64
%13 = alloca i8*
%14 = alloca %struct.passwd*
store i32 0, i32* %4
store i32 %0, i32* %5
store i8** %1, i8*** %6
store i8** %2, i8*** %7
%15 = call i32 @sigfillset(i32* %8)
%16 = load i32, i32* @SIG_SETMASK
%17 = call i32 @sigprocmask(i32 %16, i32* %8, i32* null)
%18 = getelementptr inbounds [300 x i8], [300 x i8]* %9, i64 0, i64 0
%19 = call i32 @gethostname(i8* %18, i32 300)
%20 = getelementptr inbounds [300 x i8], [300 x i8]* %9, i64 0, i64 0
%21 = call i32 @strdup(i8* %20)
%22 = call i8* @shortname(i32 %21)
store i8* %22, i8** %10
%23 = load i32, i32* @PATH_MAX
%24 = zext i32 %23 to i64
%25 = call i8* @llvm.stacksave()
store i8* %25, i8** %11
%26 = alloca i8, i64 %24
store i64 %24, i64* %12
store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8** %13
%27 = load i32, i32* @STDIN_FILENO
%28 = load i32, i32* @PATH_MAX
%29 = call i64 @ttyname_r(i32 %27, i8* %26, i32 %28)
%30 = icmp eq i64 %29, 0
br i1 %30, label %31, label %33
31: ; preds = %3
%32 = call i8* @basename(i8* %26)
store i8* %32, i8** %13
br label %33
33: ; preds = %31, %3
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
br label %35
35: ; preds = %51, %33
br label %36
36: ; preds = %35
%37 = load i8*, i8** %13
%38 = load i8*, i8** %10
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i8* %37, i8* %38)
%40 = call %struct.passwd* @do_auth(i32* null)
store %struct.passwd* %40, %struct.passwd** %14
%41 = load %struct.passwd*, %struct.passwd** %14
%42 = icmp ne %struct.passwd* %41, null
br i1 %42, label %43, label %48
43: ; preds = %36
%44 = load %struct.passwd*, %struct.passwd** %14
%45 = call i32 @write_utmp(%struct.passwd* %44)
%46 = load %struct.passwd*, %struct.passwd** %14
%47 = call i32 @run_shell(%struct.passwd* %46, i32 1)
br label %51
48: ; preds = %36
%49 = load i32, i32* @stderr
%50 = call i32 @fprintf(i32 %49, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0))
br label %51
51: ; preds = %48, %43
br label %35
}

LLVM IR (-O2):
%struct.passwd = type { i32 }
@SIG_SETMASK = global i32 0
@PATH_MAX = global i32 0
@.str = [1 x i8] zeroinitializer
@STDIN_FILENO = global i32 0
@.str.1 = [7 x i8] c"\1B[H\1B[J\00"
@.str.2 = [15 x i8] c"\0Axelix %s\0A\0A%s \00"
@stderr = global i32 0
@.str.3 = [18 x i8] c"Login incorrect.\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1, i8** nocapture readnone %2) {
%4 = alloca i32
%5 = alloca [300 x i8]
%6 = bitcast i32* %4 to i8*
%7 = call i32 @sigfillset(i32* %4)
%8 = load i32, i32* @SIG_SETMASK
%9 = call i32 @sigprocmask(i32 %8, i32* %4, i32* null)
%10 = getelementptr inbounds [300 x i8], [300 x i8]* %5, i64 0, i64 0
%11 = call i32 @gethostname(i8* %10, i32 300)
%12 = call i32 @strdup(i8* %10)
%13 = call i8* @shortname(i32 %12)
%14 = load i32, i32* @PATH_MAX
%15 = zext i32 %14 to i64
%16 = alloca i8, i64 %15
%17 = load i32, i32* @STDIN_FILENO
%18 = call i64 @ttyname_r(i32 %17, i8* %16, i32 %14)
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %3
%21 = call i8* @basename(i8* %16)
br label %22
22: ; preds = %20, %3
%23 = phi i8* [ %21, %20 ], [ getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), %3 ]
%24 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
br label %25
25: ; preds = %35, %22
%26 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i8* %23, i8* %13)
%27 = call %struct.passwd* @do_auth(i32* null)
%28 = icmp eq %struct.passwd* %27, null
br i1 %28, label %32, label %29
29: ; preds = %25
%30 = call i32 @write_utmp(%struct.passwd* %27)
%31 = call i32 @run_shell(%struct.passwd* %27, i32 1)
br label %35
32: ; preds = %25
%33 = load i32, i32* @stderr
%34 = call i32 @fprintf(i32 %33, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0))
br label %35
35: ; preds = %32, %29
br label %25
}